Skip to content

Commit 0004d16

Browse files
committed
Ensure class is selected
1 parent 435f652 commit 0004d16

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

Diff for: components/dashboard/src/service/service-mock.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
import { createServiceMock, Event, Project, Team, User } from "@gitpod/gitpod-protocol";
8+
import { BillingMode } from "@gitpod/gitpod-protocol/lib/billing-mode";
89

910
const u1: User = {
1011
id: "1234",
@@ -218,15 +219,15 @@ const gitpodServiceMock = createServiceMock({
218219
displayName: "Standard",
219220
description: "Up to 4 vCPU, 8GB memory, 30GB disk",
220221
powerups: 1,
221-
isDefault: true,
222+
isSelected: true,
222223
},
223224
{
224225
id: "g1-large",
225226
category: "GENERAL PURPOSE",
226227
displayName: "Large",
227228
description: "Up to 8 vCPU, 16GB memory, 50GB disk",
228229
powerups: 2,
229-
isDefault: false,
230+
isSelected: false,
230231
},
231232
];
232233
},
@@ -265,6 +266,9 @@ const gitpodServiceMock = createServiceMock({
265266
},
266267
};
267268
},
269+
getBillingModeForUser: async () => {
270+
return BillingMode.NONE;
271+
},
268272
});
269273

270274
export { gitpodServiceMock };

Diff for: components/dashboard/src/settings/selectClass.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,13 @@ export default function SelectWorkspaceClass(props: SelectWorkspaceClassProps) {
4242
useEffect(() => {
4343
const fetchClasses = async () => {
4444
const classes = await getGitpodService().server.getSupportedWorkspaceClasses();
45+
console.log(JSON.stringify(classes));
4546
setSupportedClasses(classes);
4647

48+
console.log("is workspace class selected");
4749
if (!workspaceClass) {
48-
setWorkspaceClass(supportedClasses.find((c) => c.isDefault)?.id || "");
50+
console.log("need to set default");
51+
setWorkspaceClass(classes.find((c) => c.isSelected)?.id || "");
4952
}
5053
};
5154

Diff for: components/gitpod-protocol/src/workspace-class.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ export interface SupportedWorkspaceClass {
1010
displayName: string;
1111
description: string;
1212
powerups: number;
13-
isDefault: boolean;
13+
isSelected: boolean;
1414
}

Diff for: components/server/src/workspace/gitpod-server-impl.ts

+18-1
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ import { getExperimentsClientForBackend } from "@gitpod/gitpod-protocol/lib/expe
176176
import { BillableSession, BillableSessionRequest } from "@gitpod/gitpod-protocol/lib/usage";
177177
import { WorkspaceClusterImagebuilderClientProvider } from "./workspace-cluster-imagebuilder-client-provider";
178178
import { BillingMode } from "@gitpod/gitpod-protocol/lib/billing-mode";
179+
import { EntitlementService } from "../billing/entitlement-service";
180+
import { WorkspaceClasses } from "./workspace-classes";
179181

180182
// shortcut
181183
export const traceWI = (ctx: TraceContext, wi: Omit<LogContext, "userId">) => TraceContext.setOWI(ctx, wi); // userId is already taken care of in WebsocketConnectionManager
@@ -244,6 +246,8 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
244246

245247
@inject(IDEConfigService) protected readonly ideConfigService: IDEConfigService;
246248

249+
@inject(EntitlementService) protected readonly entitlementService: EntitlementService;
250+
247251
/** Id the uniquely identifies this server instance */
248252
public readonly uuid: string = uuidv4();
249253
public readonly clientMetadata: ClientMetadata;
@@ -3030,6 +3034,19 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
30303034
}
30313035

30323036
async getSupportedWorkspaceClasses(ctx: TraceContext): Promise<SupportedWorkspaceClass[]> {
3037+
let user = this.checkAndBlockUser("getSupportedWorkspaceClasses");
3038+
let selectedClass: string;
3039+
if (user.additionalData?.workspaceClasses?.regular) {
3040+
selectedClass =
3041+
this.config.workspaceClasses.find((c) => c.id === user.additionalData?.workspaceClasses?.regular)?.id ??
3042+
WorkspaceClasses.getDefaultId(this.config.workspaceClasses);
3043+
} else {
3044+
selectedClass = WorkspaceClasses.getDefaultId(this.config.workspaceClasses);
3045+
if (await this.entitlementService.userGetsMoreResources(user)) {
3046+
selectedClass = WorkspaceClasses.getMoreResourcesIdOrDefault(this.config.workspaceClasses);
3047+
}
3048+
}
3049+
30333050
let classes = this.config.workspaceClasses
30343051
.filter((c) => !c.deprecated)
30353052
.map((c) => ({
@@ -3038,7 +3055,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
30383055
displayName: c.displayName,
30393056
description: c.description,
30403057
powerups: c.powerups,
3041-
isDefault: c.isDefault,
3058+
isSelected: selectedClass === c.id,
30423059
}));
30433060

30443061
return classes;

0 commit comments

Comments
 (0)