Skip to content

Fix default workspace class is not selected #12436

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 1 commit into from
Aug 29, 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
8 changes: 6 additions & 2 deletions components/dashboard/src/service/service-mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

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

const u1: User = {
id: "1234",
Expand Down Expand Up @@ -218,15 +219,15 @@ const gitpodServiceMock = createServiceMock({
displayName: "Standard",
description: "Up to 4 vCPU, 8GB memory, 30GB disk",
powerups: 1,
isDefault: true,
isSelected: true,
},
{
id: "g1-large",
category: "GENERAL PURPOSE",
displayName: "Large",
description: "Up to 8 vCPU, 16GB memory, 50GB disk",
powerups: 2,
isDefault: false,
isSelected: false,
},
];
},
Expand Down Expand Up @@ -265,6 +266,9 @@ const gitpodServiceMock = createServiceMock({
},
};
},
getBillingModeForUser: async () => {
Copy link
Member

Choose a reason for hiding this comment

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

This seems unrelated to the PR, why is this change needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

The settings page calls this method and if it is not there the page cannot be displayed when using the service mock.

return BillingMode.NONE;
},
});

export { gitpodServiceMock };
2 changes: 1 addition & 1 deletion components/dashboard/src/settings/selectClass.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default function SelectWorkspaceClass(props: SelectWorkspaceClassProps) {
setSupportedClasses(classes);

if (!workspaceClass) {
setWorkspaceClass(supportedClasses.find((c) => c.isDefault)?.id || "");
setWorkspaceClass(classes.find((c) => c.isSelected)?.id || "");
}
};

Expand Down
2 changes: 1 addition & 1 deletion components/gitpod-protocol/src/workspace-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ export interface SupportedWorkspaceClass {
displayName: string;
description: string;
powerups: number;
isDefault: boolean;
isSelected: boolean;
}
12 changes: 11 additions & 1 deletion components/server/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ import { BillableSession, BillableSessionRequest } from "@gitpod/gitpod-protocol
import { WorkspaceClusterImagebuilderClientProvider } from "./workspace-cluster-imagebuilder-client-provider";
import { VerificationService } from "../auth/verification-service";
import { BillingMode } from "@gitpod/gitpod-protocol/lib/billing-mode";
import { EntitlementService } from "../billing/entitlement-service";
import { WorkspaceClasses } from "./workspace-classes";

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

@inject(VerificationService) protected readonly verificationService: VerificationService;
@inject(EntitlementService) protected readonly entitlementService: EntitlementService;

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

async getSupportedWorkspaceClasses(ctx: TraceContext): Promise<SupportedWorkspaceClass[]> {
let user = this.checkAndBlockUser("getSupportedWorkspaceClasses");
let selectedClass = await WorkspaceClasses.getConfiguredOrUpgradeFromLegacy(
user,
this.config.workspaceClasses,
this.entitlementService,
);

let classes = this.config.workspaceClasses
.filter((c) => !c.deprecated)
.map((c) => ({
Expand All @@ -3062,7 +3072,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
displayName: c.displayName,
description: c.description,
powerups: c.powerups,
isDefault: c.isDefault,
isSelected: selectedClass === c.id,
}));

return classes;
Expand Down