Skip to content

Commit

Permalink
Migrate gRPC workspaceService other workspace related method
Browse files Browse the repository at this point in the history
  • Loading branch information
mustard-mh committed Dec 4, 2023
1 parent 5a55a7a commit 62860ec
Show file tree
Hide file tree
Showing 20 changed files with 1,608 additions and 413 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
* See License.AGPL.txt in the project root for license information.
*/

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

interface SelectWorkspaceClassProps {
selectedWorkspaceClass?: string;
Expand Down Expand Up @@ -78,7 +78,7 @@ export default function SelectWorkspaceClassComponent({
}

type WorkspaceClassDropDownElementSelectedProps = {
wsClass?: SupportedWorkspaceClass;
wsClass?: WorkspaceClass;
loading?: boolean;
};

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

return (
<ComboboxSelectedItem
icon={WorkspaceClass}
icon={WorkspaceClassIcon}
loading={loading}
htmlTitle={title}
title={<div className="truncate">{title}</div>}
Expand All @@ -106,7 +106,7 @@ const WorkspaceClassDropDownElementSelected: FC<WorkspaceClassDropDownElementSel
);
};

function WorkspaceClassDropDownElement(props: { wsClass: SupportedWorkspaceClass }): JSX.Element {
function WorkspaceClassDropDownElement(props: { wsClass: WorkspaceClass }): JSX.Element {
const c = props.wsClass;
return (
<div className="flex ml-1 mt-1 flex-grow">
Expand Down
2 changes: 1 addition & 1 deletion components/dashboard/src/data/setup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import * as SSHClasses from "@gitpod/public-api/lib/gitpod/v1/ssh_pb";
// This is used to version the cache
// If data we cache changes in a non-backwards compatible way, increment this version
// That will bust any previous cache versions a client may have stored
const CACHE_VERSION = "14";
const CACHE_VERSION = "16";

export function noPersistence(queryKey: QueryKey): QueryKey {
return [...queryKey, "no-persistence"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* See License.AGPL.txt in the project root for license information.
*/

import { useQuery } from "@tanstack/react-query";
import { useQuery, useQueryClient } from "@tanstack/react-query";
import { useCurrentOrg } from "../organizations/orgs-query";
import { workspaceClient } from "../../service/public-api";
import { Workspace } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
Expand Down Expand Up @@ -57,3 +57,19 @@ export function getListWorkspacesQueryKey(orgId?: string) {
}
return ["workspaces", "list", orgId];
}

export const useUpdateWorkspaceInCache = () => {
const queryClient = useQueryClient();
const org = useCurrentOrg();
return (newWorkspace: Workspace) => {
const queryKey = getListWorkspacesQueryKey(org.data?.id);
queryClient.setQueryData<ListWorkspacesQueryResult>(queryKey, (oldWorkspacesData) => {
return oldWorkspacesData?.map((info) => {
if (info.id !== newWorkspace.id) {
return info;
}
return newWorkspace;
});
});
};
};

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License.AGPL.txt in the project root for license information.
*/

import { useMutation } from "@tanstack/react-query";
import { useUpdateWorkspaceInCache } from "./list-workspaces-query";
import { UpdateWorkspaceRequest } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
import { PartialMessage } from "@bufbuild/protobuf";
import { workspaceClient } from "../../service/public-api";

export const useUpdateWorkspaceMutation = () => {
const updateWorkspace = useUpdateWorkspaceInCache();

return useMutation({
mutationFn: async (data: PartialMessage<UpdateWorkspaceRequest>) => {
return await workspaceClient.updateWorkspace(data);
},
onSuccess: (data) => {
if (data.workspace) {
updateWorkspace(data.workspace);
}
},
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
* See License.AGPL.txt in the project root for license information.
*/

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

export const useWorkspaceClasses = () => {
return useQuery<SupportedWorkspaceClass[]>({
return useQuery<WorkspaceClass[]>({
queryKey: ["workspace-classes"],
queryFn: async () => {
return getGitpodService().server.getSupportedWorkspaceClasses();
const response = await workspaceClient.listWorkspaceClasses({});
return response.workspaceClasses;
},
cacheTime: 1000 * 60 * 60, // 1h
staleTime: 1000 * 60 * 60, // 1h
Expand Down
Loading

0 comments on commit 62860ec

Please sign in to comment.