Skip to content

Configure workspace classes from dashboard #11038

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 10 additions & 3 deletions components/dashboard/src/settings/Preferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import getSettingsMenu from "./settings-menu";
import { trackEvent } from "../Analytics";
import { PaymentContext } from "../payment-context";
import SelectIDE from "./SelectIDE";
import { getExperimentsClient } from "../experiments/client";
import SelectWorkspaceClass from "./selectClass";

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

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

const [isShowWorkspaceClasses, setIsShowWorkspaceClasses] = useState<boolean>(false);
(async () => {
const showWorkspaceClasses = await getExperimentsClient().getValueAsync("workspace_classes", false, {});
setIsShowWorkspaceClasses(showWorkspaceClasses);
})();

return (
<div>
<PageWithSubMenu
Expand Down Expand Up @@ -115,9 +123,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 +147,7 @@ export default function Preferences() {
</p>
</div>
</div>
<SelectWorkspaceClass enabled={isShowWorkspaceClasses} />
</PageWithSubMenu>
</div>
);
Expand Down
90 changes: 90 additions & 0 deletions components/dashboard/src/settings/selectClass.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License-AGPL.txt in the project root for license information.
*/

import { useContext, useState } from "react";
import SelectableCardSolid from "../components/SelectableCardSolid";
import { getGitpodService } from "../service/service";
import { UserContext } from "../user-context";
import { trackEvent } from "../Analytics";
import { WorkspaceClasses } from "@gitpod/gitpod-protocol";

interface SelectWorkspaceClassProps {
enabled: boolean;
}

export default function SelectWorkspaceClass(props: SelectWorkspaceClassProps) {
const { user } = useContext(UserContext);

const [workspaceClass, setWorkspaceClass] = useState<string>(
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);
}
};

if (!props.enabled) {
return <div></div>;
} else {
return (
<div>
<h3 className="mt-12">Workspaces</h3>
<p className="text-base text-gray-500 dark:text-gray-400">
Choose the workspace machine type for your workspaces.
</p>
<div className="mt-4 space-x-3 flex">
<SelectableCardSolid
className="w-36 h-32"
title="Standard"
selected={workspaceClass === "standard"}
onClick={() => actuallySetWorkspaceClass("standard")}
>
<div className="flex-grow flex items-end p-1">
<svg width="112" height="64" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M0 8a8 8 0 0 1 8-8h16a8 8 0 1 1 0 16H8a8 8 0 0 1-8-8ZM0 32a8 8 0 0 1 8-8h16a8 8 0 1 1 0 16H8a8 8 0 0 1-8-8ZM0 56a8 8 0 0 1 8-8h16a8 8 0 1 1 0 16H8a8 8 0 0 1-8-8ZM40 6a6 6 0 0 1 6-6h60a6 6 0 0 1 6 6v28a6 6 0 0 1-6 6H46a6 6 0 0 1-6-6V6Z"
fill="#D6D3D1"
/>
</svg>
</div>
</SelectableCardSolid>
Comment on lines +51 to +65
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: Friendly reminder to avoid merging this with SVG icons used for the theme preference. ❗

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi George, the current icons are placeholders. These icons will not be visible to the user at the moment (will be hidden behind a feature flag as the current design and workspace class names have not been finalized). This is just for setting up the logic in the frontend, so that I can continue with the other changes in the backend.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok! Thanks for clarifying, @Furisto! 🙏

Feel free to ignore these two comments[1][2] then.

Comment on lines +51 to +65
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Re-posting some updated design specs after taking into account some feedback, see relevant discussion (internal) and design specs. Cc @atduarte

Option 🅰️ Option 🅱️
WorkspaceClasses WorkspaceClasses-1

<SelectableCardSolid
className="w-36 h-32"
title="XL"
selected={workspaceClass === "XL"}
onClick={() => actuallySetWorkspaceClass("XL")}
>
<div className="flex-grow flex items-end p-1">
<svg width="112" height="64" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M0 8a8 8 0 0 1 8-8h16a8 8 0 1 1 0 16H8a8 8 0 0 1-8-8ZM40 6a6 6 0 0 1 6-6h60a6 6 0 0 1 6 6v28a6 6 0 0 1-6 6H46a6 6 0 0 1-6-6V6Z"
fill="#D9D9D9"
/>
<path
d="M84 0h22a6 6 0 0 1 6 6v28a6 6 0 0 1-6 6H68L84 0ZM0 32a8 8 0 0 1 8-8h16a8 8 0 1 1 0 16H8a8 8 0 0 1-8-8Z"
fill="#78716C"
/>
<path d="M0 56a8 8 0 0 1 8-8h16a8 8 0 1 1 0 16H8a8 8 0 0 1-8-8Z" fill="#D9D9D9" />
</svg>
</div>
</SelectableCardSolid>
</div>
</div>
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const end = new Date(Date.UTC(2000, 2, 1)).toISOString();
emailNotificationSettings: {
allowsChangelogMail: true,
allowsDevXMail: true
}
},
}
});
await this.workspaceDb.store({
Expand Down
7 changes: 7 additions & 0 deletions components/gitpod-protocol/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,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;
// additional user profile data
profile?: ProfileDetails;
}
Expand Down Expand Up @@ -186,6 +188,11 @@ export type IDESettings = {
useLatestVersion?: boolean;
};

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

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