Skip to content

Commit 8fa7544

Browse files
Furistoroboquat
authored andcommitted
Ensure workspace class is selected if no user choice has been made
1 parent a2b7412 commit 8fa7544

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

components/dashboard/src/service/service-mock.ts

Lines changed: 6 additions & 2 deletions
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 };

components/dashboard/src/settings/selectClass.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export default function SelectWorkspaceClass(props: SelectWorkspaceClassProps) {
4545
setSupportedClasses(classes);
4646

4747
if (!workspaceClass) {
48-
setWorkspaceClass(supportedClasses.find((c) => c.isDefault)?.id || "");
48+
setWorkspaceClass(classes.find((c) => c.isSelected)?.id || "");
4949
}
5050
};
5151

components/gitpod-protocol/src/workspace-class.ts

Lines changed: 1 addition & 1 deletion
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
}

components/server/src/workspace/gitpod-server-impl.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ import { BillableSession, BillableSessionRequest } from "@gitpod/gitpod-protocol
177177
import { WorkspaceClusterImagebuilderClientProvider } from "./workspace-cluster-imagebuilder-client-provider";
178178
import { VerificationService } from "../auth/verification-service";
179179
import { BillingMode } from "@gitpod/gitpod-protocol/lib/billing-mode";
180+
import { EntitlementService } from "../billing/entitlement-service";
181+
import { WorkspaceClasses } from "./workspace-classes";
180182

181183
// shortcut
182184
export const traceWI = (ctx: TraceContext, wi: Omit<LogContext, "userId">) => TraceContext.setOWI(ctx, wi); // userId is already taken care of in WebsocketConnectionManager
@@ -246,6 +248,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
246248
@inject(IDEConfigService) protected readonly ideConfigService: IDEConfigService;
247249

248250
@inject(VerificationService) protected readonly verificationService: VerificationService;
251+
@inject(EntitlementService) protected readonly entitlementService: EntitlementService;
249252

250253
/** Id the uniquely identifies this server instance */
251254
public readonly uuid: string = uuidv4();
@@ -3054,6 +3057,13 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
30543057
}
30553058

30563059
async getSupportedWorkspaceClasses(ctx: TraceContext): Promise<SupportedWorkspaceClass[]> {
3060+
let user = this.checkAndBlockUser("getSupportedWorkspaceClasses");
3061+
let selectedClass = await WorkspaceClasses.getConfiguredOrUpgradeFromLegacy(
3062+
user,
3063+
this.config.workspaceClasses,
3064+
this.entitlementService,
3065+
);
3066+
30573067
let classes = this.config.workspaceClasses
30583068
.filter((c) => !c.deprecated)
30593069
.map((c) => ({
@@ -3062,7 +3072,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
30623072
displayName: c.displayName,
30633073
description: c.description,
30643074
powerups: c.powerups,
3065-
isDefault: c.isDefault,
3075+
isSelected: selectedClass === c.id,
30663076
}));
30673077

30683078
return classes;

0 commit comments

Comments
 (0)