From c3399de83db775d50c40228289272482f0d1e8fa Mon Sep 17 00:00:00 2001 From: Thomas Schubart Date: Mon, 20 Jun 2022 17:03:17 +0000 Subject: [PATCH] [dashboard] Allow user to set workspace class --- components/dashboard/src/Analytics.tsx | 7 +- .../dashboard/src/settings/Preferences.tsx | 68 ++++++++++++++++++- .../src/accounting/account-service.spec.db.ts | 6 +- .../gitpod-db/src/typeorm/user-db-impl.ts | 4 ++ components/gitpod-protocol/src/protocol.ts | 7 ++ 5 files changed, 87 insertions(+), 5 deletions(-) diff --git a/components/dashboard/src/Analytics.tsx b/components/dashboard/src/Analytics.tsx index 4e7704f8c7f5e4..027718858ce05e 100644 --- a/components/dashboard/src/Analytics.tsx +++ b/components/dashboard/src/Analytics.tsx @@ -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; diff --git a/components/dashboard/src/settings/Preferences.tsx b/components/dashboard/src/settings/Preferences.tsx index ce47dd27507769..50037c4dfe960a 100644 --- a/components/dashboard/src/settings/Preferences.tsx +++ b/components/dashboard/src/settings/Preferences.tsx @@ -14,8 +14,10 @@ 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"; +// type WorkspaceClass = "standard" | "XL"; export default function Preferences() { const { user } = useContext(UserContext); @@ -50,6 +52,26 @@ export default function Preferences() { } }; + const [workspaceClass, setWorkspaceClass] = useState( + user?.additionalData?.workspaceClasses?.regular || "standard", + ); + const actuallySetWorkspaceClass = async (value: string) => { + const additionalData = user?.additionalData || {}; + const prevWorkspaceClass = additionalData?.workspaceClasses?.regular || "standard"; + const workspaceClasses = (additionalData?.workspaceClasses || {}) as WorkspaceClasses; + workspaceClasses.regular = value; + workspaceClasses.prebuild = value; + additionalData.workspaceClasses = workspaceClasses; + if (value !== prevWorkspaceClass) { + await getGitpodService().server.updateLoggedInUser({ additionalData }); + trackEvent("workspace_class_changed", { + previous: prevWorkspaceClass, + current: value, + }); + setWorkspaceClass(value); + } + }; + return (
-

- Dotfiles{" "} -

+

Dotfiles

Customize workspaces using dotfiles.

Repository URL

@@ -141,6 +161,48 @@ export default function Preferences() {

+ +

Workspaces

+

+ Choose the workspace machine type for your workspaces. +

+
+ actuallySetWorkspaceClass("standard")} + > +
+ + + +
+
+ actuallySetWorkspaceClass("XL")} + > +
+ + + + + +
+
+
); diff --git a/components/ee/payment-endpoint/src/accounting/account-service.spec.db.ts b/components/ee/payment-endpoint/src/accounting/account-service.spec.db.ts index bf4ff4228b7e3c..098111cf55aab7 100644 --- a/components/ee/payment-endpoint/src/accounting/account-service.spec.db.ts +++ b/components/ee/payment-endpoint/src/accounting/account-service.spec.db.ts @@ -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({ diff --git a/components/gitpod-db/src/typeorm/user-db-impl.ts b/components/gitpod-db/src/typeorm/user-db-impl.ts index c423aafd10f128..da290e67e47f5b 100644 --- a/components/gitpod-db/src/typeorm/user-db-impl.ts +++ b/components/gitpod-db/src/typeorm/user-db-impl.ts @@ -109,6 +109,10 @@ export class TypeORMUserDBImpl implements UserDB { allowsDevXMail: true, allowsOnboardingMail: true, }, + workspaceClasses: { + regular: "default", + prebuild: "default", + }, }, }; await this.storeUser(user); diff --git a/components/gitpod-protocol/src/protocol.ts b/components/gitpod-protocol/src/protocol.ts index df6ca44934c4d7..0df0d9ecd1bdc3 100644 --- a/components/gitpod-protocol/src/protocol.ts +++ b/components/gitpod-protocol/src/protocol.ts @@ -154,6 +154,8 @@ 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 { @@ -172,6 +174,11 @@ export type IDESettings = { useLatestVersion?: boolean; }; +export interface WorkspaceClasses { + regular: string; + prebuild: string; +} + export interface UserPlatform { uid: string; userAgent: string;