-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fetch workspace classes from server #11571
Changes from all commits
4db80e7
1e7514e
1299ba8
29778a5
15875d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,13 @@ | |
* See License-AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import { useContext, useState } from "react"; | ||
import { useContext, useEffect, useState } from "react"; | ||
import { getGitpodService } from "../service/service"; | ||
import { UserContext } from "../user-context"; | ||
import { trackEvent } from "../Analytics"; | ||
import { WorkspaceClasses } from "@gitpod/gitpod-protocol"; | ||
import WorkspaceClass from "../components/WorkspaceClass"; | ||
import { SupportedWorkspaceClass } from "@gitpod/gitpod-protocol/lib/workspace-class"; | ||
|
||
interface SelectWorkspaceClassProps { | ||
enabled: boolean; | ||
|
@@ -18,12 +19,10 @@ interface SelectWorkspaceClassProps { | |
export default function SelectWorkspaceClass(props: SelectWorkspaceClassProps) { | ||
const { user } = useContext(UserContext); | ||
|
||
const [workspaceClass, setWorkspaceClass] = useState<string>( | ||
user?.additionalData?.workspaceClasses?.regular || "g1-standard", | ||
); | ||
const [workspaceClass, setWorkspaceClass] = useState<string>(user?.additionalData?.workspaceClasses?.regular || ""); | ||
const actuallySetWorkspaceClass = async (value: string) => { | ||
const additionalData = user?.additionalData || {}; | ||
const prevWorkspaceClass = additionalData?.workspaceClasses?.regular || "g1-standard"; | ||
const prevWorkspaceClass = additionalData?.workspaceClasses?.regular || ""; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, that is only because I edited the configmap to better illustrate what it would look like. The installer only installs the Default workspace class as Tarun has posted below. |
||
const workspaceClasses = (additionalData?.workspaceClasses || {}) as WorkspaceClasses; | ||
workspaceClasses.regular = value; | ||
workspaceClasses.prebuild = value; | ||
|
@@ -38,6 +37,21 @@ export default function SelectWorkspaceClass(props: SelectWorkspaceClassProps) { | |
} | ||
}; | ||
|
||
const [supportedClasses, setSupportedClasses] = useState<SupportedWorkspaceClass[]>([]); | ||
|
||
useEffect(() => { | ||
const fetchClasses = async () => { | ||
const classes = await getGitpodService().server.getSupportedWorkspaceClasses(); | ||
setSupportedClasses(classes); | ||
|
||
if (!workspaceClass) { | ||
setWorkspaceClass(supportedClasses.find((c) => c.isDefault)?.id || ""); | ||
} | ||
}; | ||
|
||
fetchClasses().catch(console.error); | ||
}); | ||
|
||
if (!props.enabled) { | ||
return <div></div>; | ||
} else { | ||
|
@@ -48,24 +62,19 @@ export default function SelectWorkspaceClass(props: SelectWorkspaceClassProps) { | |
Choose the workspace machine type for your workspaces. | ||
</p> | ||
<div className="mt-4 space-x-3 flex"> | ||
<WorkspaceClass | ||
additionalStyles="w-80 h-32" | ||
selected={workspaceClass === "g1-standard"} | ||
onClick={() => actuallySetWorkspaceClass("g1-standard")} | ||
category="GENERAL PURPOSE" | ||
friendlyName="Standard" | ||
description="Up to 4 vCPU, 8GB memory, 30GB disk" | ||
powerUps={1} | ||
/> | ||
<WorkspaceClass | ||
additionalStyles="w-80 h-32" | ||
selected={workspaceClass === "g1-large"} | ||
onClick={() => actuallySetWorkspaceClass("g1-large")} | ||
category="GENERAL PURPOSE" | ||
friendlyName="Large" | ||
description="Up to 8 vCPU, 16GB memory, 50GB disk" | ||
powerUps={2} | ||
/> | ||
{supportedClasses.map((c) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! Now it becomes apparent that this config is far to hidden. But now we have everything in place to maybe show it on ☁️ Clearly out-of-scope here, just wanted to raise in this context. /cc @gtsiolis |
||
return ( | ||
<WorkspaceClass | ||
additionalStyles="w-80 h-32" | ||
selected={workspaceClass === c.id} | ||
onClick={() => actuallySetWorkspaceClass(c.id)} | ||
category={c.category} | ||
friendlyName={c.displayName} | ||
description={c.description} | ||
powerUps={c.powerups} | ||
/> | ||
); | ||
})} | ||
</div> | ||
</div> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
export interface SupportedWorkspaceClass { | ||
id: string; | ||
category: string; | ||
displayName: string; | ||
description: string; | ||
powerups: number; | ||
isDefault: boolean; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: On first load I was confused because no class was selected.
It would make sense to highlight the one with
isDefault: true
, though. Maybe by moving theWorkspacClasses
code intogitpod-protocol
, und re-using it here...? 🤔 Or we introduce an explicit API method:getDefaultWorkspaceClass
🤷There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
☝️ This can easily be a follow-up issue. 🧘