Skip to content

Commit 0152b84

Browse files
authored
Migrate gRPC workspaceService other workspace related method (#19118)
* Migrate gRPC workspaceService other workspace related method * Use shim and gRPC everywhere * fix update
1 parent 2b5a36e commit 0152b84

25 files changed

+1626
-428
lines changed

components/dashboard/src/components/SelectWorkspaceClassComponent.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
* See License.AGPL.txt in the project root for license information.
55
*/
66

7-
import { SupportedWorkspaceClass } from "@gitpod/gitpod-protocol/lib/workspace-class";
87
import { FC, useCallback, useEffect, useMemo } from "react";
9-
import WorkspaceClass from "../icons/WorkspaceClass.svg";
8+
import WorkspaceClassIcon from "../icons/WorkspaceClass.svg";
109
import { Combobox, ComboboxElement, ComboboxSelectedItem } from "./podkit/combobox/Combobox";
1110
import { useWorkspaceClasses } from "../data/workspaces/workspace-classes-query";
11+
import { WorkspaceClass } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
1212

1313
interface SelectWorkspaceClassProps {
1414
selectedWorkspaceClass?: string;
@@ -78,7 +78,7 @@ export default function SelectWorkspaceClassComponent({
7878
}
7979

8080
type WorkspaceClassDropDownElementSelectedProps = {
81-
wsClass?: SupportedWorkspaceClass;
81+
wsClass?: WorkspaceClass;
8282
loading?: boolean;
8383
};
8484

@@ -90,7 +90,7 @@ const WorkspaceClassDropDownElementSelected: FC<WorkspaceClassDropDownElementSel
9090

9191
return (
9292
<ComboboxSelectedItem
93-
icon={WorkspaceClass}
93+
icon={WorkspaceClassIcon}
9494
loading={loading}
9595
htmlTitle={title}
9696
title={<div className="truncate">{title}</div>}
@@ -106,7 +106,7 @@ const WorkspaceClassDropDownElementSelected: FC<WorkspaceClassDropDownElementSel
106106
);
107107
};
108108

109-
function WorkspaceClassDropDownElement(props: { wsClass: SupportedWorkspaceClass }): JSX.Element {
109+
function WorkspaceClassDropDownElement(props: { wsClass: WorkspaceClass }): JSX.Element {
110110
const c = props.wsClass;
111111
return (
112112
<div className="flex ml-1 mt-1 flex-grow">

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 = "14";
35+
const CACHE_VERSION = "16";
3636

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

components/dashboard/src/data/workspaces/delete-inactive-workspaces-mutation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
import { useMutation, useQueryClient } from "@tanstack/react-query";
8-
import { workspacesService } from "../../service/public-api";
8+
import { workspaceClient } from "../../service/public-api";
99
import { getListWorkspacesQueryKey, ListWorkspacesQueryResult } from "./list-workspaces-query";
1010
import { useCurrentOrg } from "../organizations/orgs-query";
1111

@@ -22,7 +22,7 @@ export const useDeleteInactiveWorkspacesMutation = () => {
2222

2323
for (const workspaceId of workspaceIds) {
2424
try {
25-
await workspacesService.deleteWorkspace({ workspaceId });
25+
await workspaceClient.deleteWorkspace({ workspaceId });
2626

2727
deletedWorkspaceIds.push(workspaceId);
2828
} catch (e) {

components/dashboard/src/data/workspaces/delete-workspace-mutation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
import { useMutation, useQueryClient } from "@tanstack/react-query";
8-
import { workspacesService } from "../../service/public-api";
8+
import { workspaceClient } from "../../service/public-api";
99
import { getListWorkspacesQueryKey, ListWorkspacesQueryResult } from "./list-workspaces-query";
1010
import { useCurrentOrg } from "../organizations/orgs-query";
1111

@@ -19,7 +19,7 @@ export const useDeleteWorkspaceMutation = () => {
1919

2020
return useMutation({
2121
mutationFn: async ({ workspaceId }: DeleteWorkspaceArgs) => {
22-
return await workspacesService.deleteWorkspace({ workspaceId });
22+
return await workspaceClient.deleteWorkspace({ workspaceId });
2323
},
2424
onSuccess: (_, { workspaceId }) => {
2525
const queryKey = getListWorkspacesQueryKey(org.data?.id);

components/dashboard/src/data/workspaces/list-workspaces-query.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* See License.AGPL.txt in the project root for license information.
55
*/
66

7-
import { useQuery } from "@tanstack/react-query";
7+
import { useQuery, useQueryClient } from "@tanstack/react-query";
88
import { useCurrentOrg } from "../organizations/orgs-query";
99
import { workspaceClient } from "../../service/public-api";
1010
import { Workspace } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
@@ -57,3 +57,19 @@ export function getListWorkspacesQueryKey(orgId?: string) {
5757
}
5858
return ["workspaces", "list", orgId];
5959
}
60+
61+
export const useUpdateWorkspaceInCache = () => {
62+
const queryClient = useQueryClient();
63+
const org = useCurrentOrg();
64+
return (newWorkspace: Workspace) => {
65+
const queryKey = getListWorkspacesQueryKey(org.data?.id);
66+
queryClient.setQueryData<ListWorkspacesQueryResult>(queryKey, (oldWorkspacesData) => {
67+
return oldWorkspacesData?.map((info) => {
68+
if (info.id !== newWorkspace.id) {
69+
return info;
70+
}
71+
return newWorkspace;
72+
});
73+
});
74+
};
75+
};

components/dashboard/src/data/workspaces/stop-workspace-mutation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
import { useMutation } from "@tanstack/react-query";
8-
import { workspacesService } from "../../service/public-api";
8+
import { workspaceClient } from "../../service/public-api";
99

1010
type StopWorkspaceArgs = {
1111
workspaceId: string;
@@ -15,7 +15,7 @@ export const useStopWorkspaceMutation = () => {
1515
// No need to manually update workspace in cache here, we'll receive messages over the ws that will update it
1616
return useMutation({
1717
mutationFn: async ({ workspaceId }: StopWorkspaceArgs) => {
18-
return workspacesService.stopWorkspace({ workspaceId });
18+
return workspaceClient.stopWorkspace({ workspaceId });
1919
},
2020
});
2121
};

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

Lines changed: 0 additions & 47 deletions
This file was deleted.

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

Lines changed: 0 additions & 58 deletions
This file was deleted.

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

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3+
* Licensed under the GNU Affero General Public License (AGPL).
4+
* See License.AGPL.txt in the project root for license information.
5+
*/
6+
7+
import { useMutation } from "@tanstack/react-query";
8+
import { useUpdateWorkspaceInCache } from "./list-workspaces-query";
9+
import { UpdateWorkspaceRequest } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
10+
import { PartialMessage } from "@bufbuild/protobuf";
11+
import { workspaceClient } from "../../service/public-api";
12+
13+
export const useUpdateWorkspaceMutation = () => {
14+
const updateWorkspace = useUpdateWorkspaceInCache();
15+
16+
return useMutation({
17+
mutationFn: async (data: PartialMessage<UpdateWorkspaceRequest>) => {
18+
return await workspaceClient.updateWorkspace(data);
19+
},
20+
onSuccess: (data) => {
21+
if (data.workspace) {
22+
updateWorkspace(data.workspace);
23+
}
24+
},
25+
});
26+
};

components/dashboard/src/data/workspaces/workspace-classes-query.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44
* See License.AGPL.txt in the project root for license information.
55
*/
66

7-
import { SupportedWorkspaceClass } from "@gitpod/gitpod-protocol/lib/workspace-class";
87
import { useQuery } from "@tanstack/react-query";
9-
import { getGitpodService } from "../../service/service";
8+
import { workspaceClient } from "../../service/public-api";
9+
import { WorkspaceClass } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
1010

1111
export const DEFAULT_WS_CLASS = "g1-standard";
1212

1313
export const useWorkspaceClasses = () => {
14-
return useQuery<SupportedWorkspaceClass[]>({
14+
return useQuery<WorkspaceClass[]>({
1515
queryKey: ["workspace-classes"],
1616
queryFn: async () => {
17-
return getGitpodService().server.getSupportedWorkspaceClasses();
17+
const response = await workspaceClient.listWorkspaceClasses({});
18+
return response.workspaceClasses;
1819
},
1920
cacheTime: 1000 * 60 * 60, // 1h
2021
staleTime: 1000 * 60 * 60, // 1h

0 commit comments

Comments
 (0)