Skip to content

Commit a6f4722

Browse files
authored
Revert "Refine workspace API (#19138)" (#19172)
This reverts commit da0c590.
1 parent a997229 commit a6f4722

26 files changed

+1643
-5640
lines changed

components/dashboard/src/data/setup.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import * as SSHClasses from "@gitpod/public-api/lib/gitpod/v1/ssh_pb";
3232
// This is used to version the cache
3333
// If data we cache changes in a non-backwards compatible way, increment this version
3434
// That will bust any previous cache versions a client may have stored
35-
const CACHE_VERSION = "12";
35+
const CACHE_VERSION = "13";
3636

3737
export function noPersistence(queryKey: QueryKey): QueryKey {
3838
return [...queryKey, "no-persistence"];

components/dashboard/src/data/workspaces/toggle-workspace-pinned-mutation.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
88
import { getGitpodService } from "../../service/service";
99
import { getListWorkspacesQueryKey, ListWorkspacesQueryResult } from "./list-workspaces-query";
1010
import { useCurrentOrg } from "../organizations/orgs-query";
11-
import { Workspace, WorkspaceMetadata } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
11+
import { Workspace } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
1212

1313
type ToggleWorkspacePinnedArgs = {
1414
workspaceId: string;
@@ -33,10 +33,7 @@ export const useToggleWorkspacedPinnedMutation = () => {
3333
return info;
3434
}
3535
const workspace = new Workspace(info);
36-
if (!workspace.metadata) {
37-
workspace.metadata = new WorkspaceMetadata();
38-
}
39-
workspace.metadata.pinned = !workspace.metadata.pinned;
36+
workspace.pinned = !workspace.pinned;
4037
return workspace;
4138
});
4239
});

components/dashboard/src/data/workspaces/toggle-workspace-shared-mutation.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
88
import { getGitpodService } from "../../service/service";
99
import { getListWorkspacesQueryKey, ListWorkspacesQueryResult } from "./list-workspaces-query";
1010
import { useCurrentOrg } from "../organizations/orgs-query";
11-
import { AdmissionLevel, Workspace, WorkspaceSpec } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
11+
import { AdmissionLevel, Workspace } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
1212

1313
type ToggleWorkspaceSharedArgs = {
1414
workspaceId: string;
@@ -44,10 +44,9 @@ export const useToggleWorkspaceSharedMutation = () => {
4444
}
4545

4646
const workspace = new Workspace(info);
47-
if (!workspace.spec) {
48-
workspace.spec = new WorkspaceSpec();
47+
if (workspace.status) {
48+
workspace.status.admission = level;
4949
}
50-
workspace.spec.admission = level;
5150
return workspace;
5251
});
5352
});

components/dashboard/src/data/workspaces/update-workspace-description-mutation.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
88
import { getGitpodService } from "../../service/service";
99
import { getListWorkspacesQueryKey, ListWorkspacesQueryResult } from "./list-workspaces-query";
1010
import { useCurrentOrg } from "../organizations/orgs-query";
11-
import { Workspace, WorkspaceMetadata } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
11+
import { Workspace } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
1212

1313
type UpdateWorkspaceDescriptionArgs = {
1414
workspaceId: string;
@@ -36,10 +36,7 @@ export const useUpdateWorkspaceDescriptionMutation = () => {
3636
// TODO: Once the update description response includes an updated record,
3737
// we can return that instead of having to know what to merge manually (same for other mutations)
3838
const workspace = new Workspace(info);
39-
if (!workspace.metadata) {
40-
workspace.metadata = new WorkspaceMetadata();
41-
}
42-
workspace.metadata.name = newDescription;
39+
workspace.name = newDescription;
4340
return workspace;
4441
});
4542
});

components/dashboard/src/service/json-rpc-workspace-client.ts

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ import {
2828
SendHeartBeatResponse,
2929
WorkspacePhase_Phase,
3030
GetWorkspaceDefaultImageResponse_Source,
31-
ParseContextURLRequest,
32-
ParseContextURLResponse,
33-
UpdateWorkspaceRequest,
34-
UpdateWorkspaceResponse,
3531
} from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
3632
import { converter } from "./public-api";
3733
import { getGitpodService } from "./service";
@@ -135,25 +131,25 @@ export class JsonRpcWorkspaceClient implements PromiseClient<typeof WorkspaceSer
135131
if (request.source?.case !== "contextUrl") {
136132
throw new ApplicationError(ErrorCodes.UNIMPLEMENTED, "not implemented");
137133
}
138-
if (!request.metadata || !request.metadata.organizationId || !uuidValidate(request.metadata.organizationId)) {
134+
if (!request.organizationId || !uuidValidate(request.organizationId)) {
139135
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "organizationId is required");
140136
}
141-
if (!request.source.value.editor?.name) {
137+
if (!request.editor) {
142138
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "editor is required");
143139
}
144-
if (!request.source.value.url) {
140+
if (!request.source.value) {
145141
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "source is required");
146142
}
147143
const response = await getGitpodService().server.createWorkspace({
148-
organizationId: request.metadata.organizationId,
144+
organizationId: request.organizationId,
149145
ignoreRunningWorkspaceOnSameCommit: true,
150-
contextUrl: request.source.value.url,
146+
contextUrl: request.source.value,
151147
forceDefaultConfig: request.forceDefaultConfig,
152-
workspaceClass: request.source.value.workspaceClass,
153-
projectId: request.metadata.configurationId,
148+
workspaceClass: request.workspaceClass,
149+
projectId: request.configurationId,
154150
ideSettings: {
155-
defaultIde: request.source.value.editor.name,
156-
useLatestVersion: request.source.value.editor.version === "latest",
151+
defaultIde: request.editor.name,
152+
useLatestVersion: request.editor.version === "latest",
157153
},
158154
});
159155
const workspace = await this.getWorkspace({ workspaceId: response.createdWorkspaceId });
@@ -244,18 +240,4 @@ export class JsonRpcWorkspaceClient implements PromiseClient<typeof WorkspaceSer
244240
result.editorCredentials = credentials;
245241
return result;
246242
}
247-
248-
async updateWorkspace(
249-
request: PartialMessage<UpdateWorkspaceRequest>,
250-
_options?: CallOptions | undefined,
251-
): Promise<UpdateWorkspaceResponse> {
252-
throw new ApplicationError(ErrorCodes.UNIMPLEMENTED, "not implemented");
253-
}
254-
255-
async parseContextURL(
256-
request: PartialMessage<ParseContextURLRequest>,
257-
_options?: CallOptions | undefined,
258-
): Promise<ParseContextURLResponse> {
259-
throw new ApplicationError(ErrorCodes.UNIMPLEMENTED, "not implemented");
260-
}
261243
}

components/dashboard/src/start/StartWorkspace.tsx

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import {
2828
StartWorkspaceResponse,
2929
Workspace,
3030
WorkspacePhase_Phase,
31-
WorkspaceSpec_WorkspaceType,
3231
} from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
3332
import { PartialMessage } from "@bufbuild/protobuf";
3433

@@ -170,7 +169,7 @@ export default class StartWorkspace extends React.Component<StartWorkspaceProps,
170169
componentDidUpdate(prevPros: StartWorkspaceProps, prevState: StartWorkspaceState) {
171170
const newPhase = this.state?.workspace?.status?.phase?.name;
172171
const oldPhase = prevState.workspace?.status?.phase?.name;
173-
const type = this.state.workspace?.spec?.type === WorkspaceSpec_WorkspaceType.PREBUILD ? "prebuild" : "regular";
172+
const type = !!this.state.workspace?.prebuild ? "prebuild" : "regular";
174173
if (newPhase !== oldPhase) {
175174
getGitpodService().server.trackEvent({
176175
event: "status_rendered",
@@ -374,10 +373,10 @@ export default class StartWorkspace extends React.Component<StartWorkspaceProps,
374373
if (
375374
!error &&
376375
workspace.status.phase?.name === WorkspacePhase_Phase.STOPPED &&
377-
this.state.workspace?.spec?.type === WorkspaceSpec_WorkspaceType.PREBUILD
376+
!!this.state.workspace?.prebuild
378377
) {
379378
// here we want to point to the original context, w/o any modifiers "workspace" was started with (as this might have been a manually triggered prebuild!)
380-
const contextURL = this.state.workspace.metadata?.originalContextUrl;
379+
const contextURL = this.state.workspace.contextUrl;
381380
if (contextURL) {
382381
this.redirectTo(gitpodHostUrl.withContext(contextURL.toString()).toString());
383382
} else {
@@ -458,20 +457,15 @@ export default class StartWorkspace extends React.Component<StartWorkspaceProps,
458457

459458
render() {
460459
const { error } = this.state;
461-
const isPrebuild = this.state.workspace?.spec?.type === WorkspaceSpec_WorkspaceType.PREBUILD;
462-
let withPrebuild = false;
463-
for (const initializer of this.state.workspace?.spec?.initializer?.specs ?? []) {
464-
if (initializer.spec.case === "prebuild") {
465-
withPrebuild = !!initializer.spec.value.prebuildId;
466-
}
467-
}
460+
const isPrebuild = this.state.workspace?.prebuild;
461+
const withPrebuild = !!this.state.workspace?.prebuildId;
468462
let phase: StartPhase | undefined = StartPhase.Preparing;
469463
let title = undefined;
470464
let isStoppingOrStoppedPhase = false;
471465
let isError = error ? true : false;
472466
let statusMessage = !!error ? undefined : <p className="text-base text-gray-400">Preparing workspace …</p>;
473-
const contextURL = this.state.workspace?.metadata?.originalContextUrl;
474-
const useLatest = this.state.workspace?.spec?.editor?.version === "latest";
467+
const contextURL = this.state.workspace?.contextUrl;
468+
const useLatest = this.state.workspace?.editor?.version === "latest";
475469

476470
switch (this.state?.workspace?.status?.phase?.name) {
477471
// unknown indicates an issue within the system in that it cannot determine the actual phase of

components/dashboard/src/workspaces/CreateWorkspacePage.tsx

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import { SelectAccountModal } from "../user-settings/SelectAccountModal";
3737
import { settingsPathIntegrations } from "../user-settings/settings.routes";
3838
import { WorkspaceEntry } from "./WorkspaceEntry";
3939
import { AuthProviderType } from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb";
40-
import { WorkspaceMetadata, WorkspacePhase_Phase } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
40+
import { WorkspacePhase_Phase } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
4141
import { Button } from "@podkit/buttons/Button";
4242
import { LoadingButton } from "@podkit/buttons/LoadingButton";
4343
import { CreateAndStartWorkspaceRequest } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
@@ -172,14 +172,7 @@ export function CreateWorkspacePage() {
172172
const [selectAccountError, setSelectAccountError] = useState<SelectAccountPayload | undefined>(undefined);
173173

174174
const createWorkspace = useCallback(
175-
/**
176-
* options will omit
177-
* - source.url
178-
* - source.workspaceClass
179-
* - metadata.organizationId
180-
* - metadata.configurationId
181-
*/
182-
async (options?: PartialMessage<CreateAndStartWorkspaceRequest>) => {
175+
async (options?: Omit<PartialMessage<CreateAndStartWorkspaceRequest>, "contextUrl" | "organizationId">) => {
183176
// add options from search params
184177
const opts = options || {};
185178

@@ -199,6 +192,16 @@ export function CreateWorkspacePage() {
199192
opts.forceDefaultConfig = true;
200193
}
201194

195+
if (!opts.workspaceClass) {
196+
opts.workspaceClass = selectedWsClass;
197+
}
198+
if (!opts.editor) {
199+
opts.editor = {
200+
name: selectedIde,
201+
version: useLatestIde ? "latest" : undefined,
202+
};
203+
}
204+
202205
try {
203206
if (createWorkspaceMutation.isStarting) {
204207
console.log("Skipping duplicate createWorkspace call.");
@@ -207,28 +210,14 @@ export function CreateWorkspacePage() {
207210
// we wait at least 5 secs
208211
const timeout = new Promise((resolve) => setTimeout(resolve, 5000));
209212

210-
if (!opts.metadata) {
211-
opts.metadata = new WorkspaceMetadata();
212-
}
213-
opts.metadata.organizationId = organizationId;
214-
opts.metadata.configurationId = selectedProjectID;
215-
216213
const result = await createWorkspaceMutation.createWorkspace({
217214
source: {
218215
case: "contextUrl",
219-
value: {
220-
url: contextURL,
221-
workspaceClass: selectedWsClass,
222-
editor:
223-
opts.source?.case === "contextUrl" && opts.source.value.editor
224-
? opts.source.value.editor
225-
: {
226-
name: selectedIde,
227-
version: useLatestIde ? "latest" : undefined,
228-
},
229-
},
216+
value: contextURL,
230217
},
231218
...opts,
219+
organizationId,
220+
configurationId: selectedProjectID,
232221
});
233222
await storeAutoStartOptions();
234223
await timeout;

components/dashboard/src/workspaces/DeleteWorkspaceModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const DeleteWorkspaceModal: FunctionComponent<Props> = ({ workspace, onCl
3333
areYouSureText="Are you sure you want to delete this workspace?"
3434
children={{
3535
name: workspace.id,
36-
description: workspace.metadata?.name,
36+
description: workspace.name,
3737
}}
3838
buttonText="Delete Workspace"
3939
warningText={deleteWorkspace.isError ? "There was a problem deleting your workspace." : undefined}

components/dashboard/src/workspaces/RenameWorkspaceModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type Props = {
1616
};
1717
export const RenameWorkspaceModal: FunctionComponent<Props> = ({ workspace, onClose }) => {
1818
const [errorMessage, setErrorMessage] = useState("");
19-
const [description, setDescription] = useState(workspace.metadata?.name || "");
19+
const [description, setDescription] = useState(workspace.name || "");
2020
const updateDescription = useUpdateWorkspaceDescriptionMutation();
2121

2222
const updateWorkspaceDescription = useCallback(async () => {

components/dashboard/src/workspaces/WorkspaceEntry.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ export const WorkspaceEntry: FunctionComponent<Props> = ({ info, shortVersion })
2727
const workspace = info;
2828
const currentBranch = gitStatus?.branch || "<unknown>";
2929
const project = getProjectPath(workspace);
30-
const normalizedContextUrl = workspace.metadata!.originalContextUrl;
31-
const normalizedContextUrlDescription = workspace.metadata!.originalContextUrl; // Instead of showing nothing, we prefer to show the raw content instead
30+
const normalizedContextUrl = workspace.contextUrl;
31+
const normalizedContextUrlDescription = workspace.contextUrl; // Instead of showing nothing, we prefer to show the raw content instead
3232

3333
const changeMenuState = (state: boolean) => {
3434
setMenuActive(state);
@@ -69,7 +69,7 @@ export const WorkspaceEntry: FunctionComponent<Props> = ({ info, shortVersion })
6969
<>
7070
<ItemField className="w-4/12 flex flex-col my-auto">
7171
<div className="text-gray-500 dark:text-gray-400 overflow-ellipsis truncate">
72-
{workspace.metadata!.name}
72+
{workspace.name}
7373
</div>
7474
<a href={normalizedContextUrl}>
7575
<div className="text-sm text-gray-400 dark:text-gray-500 overflow-ellipsis truncate hover:text-blue-600 dark:hover:text-blue-400">
@@ -105,5 +105,5 @@ export const WorkspaceEntry: FunctionComponent<Props> = ({ info, shortVersion })
105105

106106
export function getProjectPath(ws: Workspace) {
107107
// TODO: Remove and call papi ContextService
108-
return ws.metadata!.originalContextUrl.replace("https://", "");
108+
return ws.contextUrl.replace("https://", "");
109109
}

components/dashboard/src/workspaces/WorkspaceOverflowMenu.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,15 @@ export const WorkspaceEntryOverflowMenu: FunctionComponent<WorkspaceEntryOverflo
6060

6161
const toggleShared = useCallback(() => {
6262
const newLevel =
63-
workspace.spec?.admission === AdmissionLevel.EVERYONE ? AdmissionLevel.OWNER_ONLY : AdmissionLevel.EVERYONE;
63+
workspace.status?.admission === AdmissionLevel.EVERYONE
64+
? AdmissionLevel.OWNER_ONLY
65+
: AdmissionLevel.EVERYONE;
6466

6567
toggleWorkspaceShared.mutate({
6668
workspaceId: workspace.id,
6769
level: newLevel,
6870
});
69-
}, [toggleWorkspaceShared, workspace.id, workspace.spec?.admission]);
71+
}, [toggleWorkspaceShared, workspace.id, workspace.status?.admission]);
7072

7173
const togglePinned = useCallback(() => {
7274
toggleWorkspacePinned.mutate({
@@ -127,12 +129,12 @@ export const WorkspaceEntryOverflowMenu: FunctionComponent<WorkspaceEntryOverflo
127129
menuEntries.push(
128130
{
129131
title: "Share",
130-
active: workspace.spec?.admission === AdmissionLevel.EVERYONE,
132+
active: workspace.status?.admission === AdmissionLevel.EVERYONE,
131133
onClick: toggleShared,
132134
},
133135
{
134136
title: "Pin",
135-
active: !!workspace.metadata?.pinned,
137+
active: !!workspace.pinned,
136138
separator: true,
137139
onClick: togglePinned,
138140
},

components/dashboard/src/workspaces/Workspaces.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,14 @@ const WorkspacesPage: FunctionComponent = () => {
4747
const { filteredActiveWorkspaces, filteredInactiveWorkspaces } = useMemo(() => {
4848
const filteredActiveWorkspaces = activeWorkspaces.filter(
4949
(info) =>
50-
`${info.metadata!.name}${info.id}${info.metadata!.originalContextUrl}${
51-
info.status?.gitStatus?.cloneUrl
52-
}${info.status?.gitStatus?.branch}`
50+
`${info.name}${info.id}${info.contextUrl}${info.status?.gitStatus?.cloneUrl}${info.status?.gitStatus?.branch}`
5351
.toLowerCase()
5452
.indexOf(searchTerm.toLowerCase()) !== -1,
5553
);
5654

5755
const filteredInactiveWorkspaces = inactiveWorkspaces.filter(
5856
(info) =>
59-
`${info.metadata!.name}${info.id}${info.metadata!.originalContextUrl}${
60-
info.status?.gitStatus?.cloneUrl
61-
}${info.status?.gitStatus?.branch}`
57+
`${info.name}${info.id}${info.contextUrl}${info.status?.gitStatus?.cloneUrl}${info.status?.gitStatus?.branch}`
6258
.toLowerCase()
6359
.indexOf(searchTerm.toLowerCase()) !== -1,
6460
);
@@ -205,5 +201,5 @@ function isWorkspaceActive(info: Workspace): boolean {
205201
const twentyfourHoursAgo = hoursBefore(new Date().toISOString(), 24);
206202

207203
const isStopped = info.status?.phase?.name === WorkspacePhase_Phase.STOPPED;
208-
return info.metadata!.pinned || !isStopped || isDateSmallerOrEqual(twentyfourHoursAgo, lastSessionStart);
204+
return info.pinned || !isStopped || isDateSmallerOrEqual(twentyfourHoursAgo, lastSessionStart);
209205
}

components/public-api/gitpod/v1/envvar.proto

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,9 @@ message ResolveWorkspaceEnvironmentVariablesRequest {
142142
}
143143

144144
message ResolveWorkspaceEnvironmentVariablesResponse {
145+
message EnvironmentVariable {
146+
string name = 1;
147+
string value = 2;
148+
}
145149
repeated EnvironmentVariable environment_variables = 1;
146150
}
147-
148-
message EnvironmentVariable {
149-
string name = 1;
150-
string value = 2;
151-
}

0 commit comments

Comments
 (0)