Skip to content

Commit e5250bb

Browse files
committed
Migrate gRPC workspaceService other workspace related method
1 parent f9e6a63 commit e5250bb

24 files changed

+2625
-450
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
@@ -30,7 +30,7 @@ import * as SSHClasses from "@gitpod/public-api/lib/gitpod/v1/ssh_pb";
3030
// This is used to version the cache
3131
// If data we cache changes in a non-backwards compatible way, increment this version
3232
// That will bust any previous cache versions a client may have stored
33-
const CACHE_VERSION = "8";
33+
const CACHE_VERSION = "9";
3434

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

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/toggle-workspace-pinned-mutation.ts

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

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

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

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

Lines changed: 0 additions & 47 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,15 +4,16 @@
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 useWorkspaceClasses = () => {
12-
return useQuery<SupportedWorkspaceClass[]>({
12+
return useQuery<WorkspaceClass[]>({
1313
queryKey: ["workspace-classes"],
1414
queryFn: async () => {
15-
return getGitpodService().server.getSupportedWorkspaceClasses();
15+
const response = await workspaceClient.listWorkspaceClasses({});
16+
return response.workspaceClasses;
1617
},
1718
cacheTime: 1000 * 60 * 60, // 1h
1819
staleTime: 1000 * 60 * 60, // 1h

0 commit comments

Comments
 (0)