Skip to content

Commit

Permalink
[dashboard] Allow user to set workspace class
Browse files Browse the repository at this point in the history
  • Loading branch information
Furisto committed Jun 30, 2022
1 parent 5800e3c commit 3a395e2
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 5 deletions.
7 changes: 6 additions & 1 deletion components/dashboard/src/Analytics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import Cookies from "js-cookie";
import { v4 } from "uuid";
import { Experiment } from "./experiments";

export type Event = "invite_url_requested" | "organisation_authorised" | "dotfile_repo_changed" | "feedback_submitted";
export type Event =
| "invite_url_requested"
| "organisation_authorised"
| "dotfile_repo_changed"
| "feedback_submitted"
| "workspace_class_changed";
type InternalEvent = Event | "path_changed" | "dashboard_clicked";

export type EventProperties = TrackOrgAuthorised | TrackInviteUrlRequested | TrackDotfileRepo | TrackFeedback;
Expand Down
49 changes: 46 additions & 3 deletions components/dashboard/src/settings/Preferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import getSettingsMenu from "./settings-menu";
import { trackEvent } from "../Analytics";
import { PaymentContext } from "../payment-context";
import SelectIDE from "./SelectIDE";
import { WorkspaceClasses } from "@gitpod/gitpod-protocol";

type Theme = "light" | "dark" | "system";

Expand Down Expand Up @@ -50,6 +51,25 @@ export default function Preferences() {
}
};

const [workspaceClass, setWorkspaceClass] = useState<string>(
user?.additionalData?.workspaceClasses?.regular || "default",
);
const actuallySetWorkspaceClass = async (value: string) => {
const additionalData = user?.additionalData || {};
const prevWorkspaceClass = additionalData?.workspaceClasses?.regular || "";
const workspaceClasses = (additionalData?.workspaceClasses || {}) as WorkspaceClasses;
workspaceClasses.regular = value;
workspaceClasses.prebuild = value;
additionalData.workspaceClasses = workspaceClasses;
await getGitpodService().server.updateLoggedInUser({ additionalData });
if (value !== prevWorkspaceClass) {
trackEvent("workspace_class_changed", {
previous: prevWorkspaceClass,
current: value,
});
}
};

return (
<div>
<PageWithSubMenu
Expand Down Expand Up @@ -115,9 +135,7 @@ export default function Preferences() {
</SelectableCardSolid>
</div>

<h3 className="mt-12">
Dotfiles{" "}
</h3>
<h3 className="mt-12">Dotfiles </h3>
<p className="text-base text-gray-500 dark:text-gray-400">Customize workspaces using dotfiles.</p>
<div className="mt-4 max-w-xl">
<h4>Repository URL</h4>
Expand All @@ -141,6 +159,31 @@ export default function Preferences() {
</p>
</div>
</div>

<h3 className="mt-12">Workspace Classes </h3>
<p className="text-base text-gray-500 dark:text-gray-400">Set default workspace classes</p>
<div className="mt-4 max-w-xl">
<h4>Workspace class</h4>
<span className="flex">
<input
type="text"
value={workspaceClass}
className="w-96 h-9"
placeholder="e.g. XL"
onChange={(e) => setWorkspaceClass(e.target.value)}
/>
<button className="secondary ml-2" onClick={() => actuallySetWorkspaceClass(dotfileRepo)}>
Save Changes
</button>
</span>
<div className="mt-1">
<p className="text-gray-500 dark:text-gray-400">
Add a repository URL that includes dotfiles. Gitpod will
<br />
clone and install your dotfiles for every new workspace.
</p>
</div>
</div>
</PageWithSubMenu>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ const end = new Date(Date.UTC(2000, 2, 1)).toISOString();
emailNotificationSettings: {
allowsChangelogMail: true,
allowsDevXMail: true
}
},
workspaceClasses: {
regular: "default",
prebuild: "default,"
},
}
});
await this.workspaceDb.store({
Expand Down
4 changes: 4 additions & 0 deletions components/gitpod-db/src/typeorm/user-db-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ export class TypeORMUserDBImpl implements UserDB {
allowsDevXMail: true,
allowsOnboardingMail: true,
},
workspaceClasses: {
regular: "default",
prebuild: "default",
},
},
};
await this.storeUser(user);
Expand Down
8 changes: 8 additions & 0 deletions components/gitpod-protocol/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ export interface AdditionalUserData {
dotfileRepo?: string;
// Identifies an explicit team or user ID to which all the user's workspace usage should be attributed to (e.g. for billing purposes)
usageAttributionId?: string;

// preferred workspace classes
workspaceClasses?: WorkspaceClasses;
}

export interface EmailNotificationSettings {
Expand All @@ -172,6 +175,11 @@ export type IDESettings = {
useLatestVersion?: boolean;
};

export interface WorkspaceClasses {
regular: string;
prebuild: string;
}

export interface UserPlatform {
uid: string;
userAgent: string;
Expand Down

0 comments on commit 3a395e2

Please sign in to comment.