Skip to content
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

Migrate gRPC workspaceService other workspace related method #19118

Merged
merged 3 commits into from
Dec 6, 2023
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
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 @@ -5,7 +5,7 @@
*/

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

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

for (const workspaceId of workspaceIds) {
try {
await workspacesService.deleteWorkspace({ workspaceId });
await workspaceClient.deleteWorkspace({ workspaceId });

deletedWorkspaceIds.push(workspaceId);
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

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

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

return useMutation({
mutationFn: async ({ workspaceId }: DeleteWorkspaceArgs) => {
return await workspacesService.deleteWorkspace({ workspaceId });
return await workspaceClient.deleteWorkspace({ workspaceId });
},
onSuccess: (_, { workspaceId }) => {
const queryKey = getListWorkspacesQueryKey(org.data?.id);
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;
});
});
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

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

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

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
Loading