Skip to content

Commit 0f316da

Browse files
authored
[dashboard] fix ws query invalidation (#17348)
1 parent 8cef174 commit 0f316da

6 files changed

+21
-6
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ import { useFeatureFlags } from "../../contexts/FeatureFlagContext";
99
import { workspacesService } from "../../service/public-api";
1010
import { getGitpodService } from "../../service/service";
1111
import { getListWorkspacesQueryKey, ListWorkspacesQueryResult } from "./list-workspaces-query";
12+
import { useCurrentOrg } from "../organizations/orgs-query";
1213

1314
type DeleteInactiveWorkspacesArgs = {
1415
workspaceIds: string[];
1516
};
1617
export const useDeleteInactiveWorkspacesMutation = () => {
1718
const queryClient = useQueryClient();
1819
const { usePublicApiWorkspacesService } = useFeatureFlags();
20+
const org = useCurrentOrg();
1921

2022
return useMutation({
2123
mutationFn: async ({ workspaceIds }: DeleteInactiveWorkspacesArgs) => {
@@ -37,7 +39,7 @@ export const useDeleteInactiveWorkspacesMutation = () => {
3739
return deletedWorkspaceIds;
3840
},
3941
onSuccess: (deletedWorkspaceIds) => {
40-
const queryKey = getListWorkspacesQueryKey();
42+
const queryKey = getListWorkspacesQueryKey(org.data?.id);
4143

4244
// Remove deleted workspaces from cache so it's reflected right away
4345
// Using the result of the mutationFn so we only remove workspaces that were delete

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { useFeatureFlags } from "../../contexts/FeatureFlagContext";
99
import { workspacesService } from "../../service/public-api";
1010
import { getGitpodService } from "../../service/service";
1111
import { getListWorkspacesQueryKey, ListWorkspacesQueryResult } from "./list-workspaces-query";
12+
import { useCurrentOrg } from "../organizations/orgs-query";
1213

1314
type DeleteWorkspaceArgs = {
1415
workspaceId: string;
@@ -17,6 +18,7 @@ type DeleteWorkspaceArgs = {
1718
export const useDeleteWorkspaceMutation = () => {
1819
const queryClient = useQueryClient();
1920
const { usePublicApiWorkspacesService } = useFeatureFlags();
21+
const org = useCurrentOrg();
2022

2123
return useMutation({
2224
mutationFn: async ({ workspaceId }: DeleteWorkspaceArgs) => {
@@ -25,7 +27,7 @@ export const useDeleteWorkspaceMutation = () => {
2527
: await getGitpodService().server.deleteWorkspace(workspaceId);
2628
},
2729
onSuccess: (_, { workspaceId }) => {
28-
const queryKey = getListWorkspacesQueryKey();
30+
const queryKey = getListWorkspacesQueryKey(org.data?.id);
2931

3032
// Remove workspace from cache so it's reflected right away
3133
queryClient.setQueryData<ListWorkspacesQueryResult>(queryKey, (oldWorkspacesData) => {

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,9 @@ export const useListWorkspacesQuery = ({ limit }: UseListWorkspacesQueryArgs) =>
5858
});
5959
};
6060

61-
export const getListWorkspacesQueryKey = (orgId?: string) => ["workspaces", "list", orgId || "noorg"];
61+
export function getListWorkspacesQueryKey(orgId?: string) {
62+
if (!orgId) {
63+
return ["workspaces", "list"];
64+
}
65+
return ["workspaces", "list", orgId];
66+
}

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,22 @@
77
import { useMutation, useQueryClient } from "@tanstack/react-query";
88
import { getGitpodService } from "../../service/service";
99
import { getListWorkspacesQueryKey, ListWorkspacesQueryResult } from "./list-workspaces-query";
10+
import { useCurrentOrg } from "../organizations/orgs-query";
1011

1112
type ToggleWorkspacePinnedArgs = {
1213
workspaceId: string;
1314
};
1415

1516
export const useToggleWorkspacedPinnedMutation = () => {
1617
const queryClient = useQueryClient();
18+
const org = useCurrentOrg();
1719

1820
return useMutation({
1921
mutationFn: async ({ workspaceId }: ToggleWorkspacePinnedArgs) => {
2022
return await getGitpodService().server.updateWorkspaceUserPin(workspaceId, "toggle");
2123
},
2224
onSuccess: (_, { workspaceId }) => {
23-
const queryKey = getListWorkspacesQueryKey();
25+
const queryKey = getListWorkspacesQueryKey(org.data?.id);
2426

2527
// Update workspace.pinned to account for the toggle so it's reflected immediately
2628
queryClient.setQueryData<ListWorkspacesQueryResult>(queryKey, (oldWorkspaceData) => {

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { GitpodServer } from "@gitpod/gitpod-protocol";
88
import { useMutation, useQueryClient } from "@tanstack/react-query";
99
import { getGitpodService } from "../../service/service";
1010
import { getListWorkspacesQueryKey, ListWorkspacesQueryResult } from "./list-workspaces-query";
11+
import { useCurrentOrg } from "../organizations/orgs-query";
1112

1213
type ToggleWorkspaceSharedArgs = {
1314
workspaceId: string;
@@ -16,13 +17,14 @@ type ToggleWorkspaceSharedArgs = {
1617

1718
export const useToggleWorkspaceSharedMutation = () => {
1819
const queryClient = useQueryClient();
20+
const org = useCurrentOrg();
1921

2022
return useMutation({
2123
mutationFn: async ({ workspaceId, level }: ToggleWorkspaceSharedArgs) => {
2224
return await getGitpodService().server.controlAdmission(workspaceId, level);
2325
},
2426
onSuccess: (_, { workspaceId, level }) => {
25-
const queryKey = getListWorkspacesQueryKey();
27+
const queryKey = getListWorkspacesQueryKey(org.data?.id);
2628

2729
// Update workspace.shareable to the level we set so it's reflected immediately
2830
queryClient.setQueryData<ListWorkspacesQueryResult>(queryKey, (oldWorkspacesData) => {

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,22 @@
77
import { useMutation, useQueryClient } from "@tanstack/react-query";
88
import { getGitpodService } from "../../service/service";
99
import { getListWorkspacesQueryKey, ListWorkspacesQueryResult } from "./list-workspaces-query";
10+
import { useCurrentOrg } from "../organizations/orgs-query";
1011

1112
type UpdateWorkspaceDescriptionArgs = {
1213
workspaceId: string;
1314
newDescription: string;
1415
};
1516
export const useUpdateWorkspaceDescriptionMutation = () => {
1617
const queryClient = useQueryClient();
18+
const org = useCurrentOrg();
1719

1820
return useMutation({
1921
mutationFn: async ({ workspaceId, newDescription }: UpdateWorkspaceDescriptionArgs) => {
2022
return await getGitpodService().server.setWorkspaceDescription(workspaceId, newDescription);
2123
},
2224
onSuccess: (_, { workspaceId, newDescription }) => {
23-
const queryKey = getListWorkspacesQueryKey();
25+
const queryKey = getListWorkspacesQueryKey(org.data?.id);
2426

2527
// pro-actively update workspace description rather than reload all workspaces
2628
queryClient.setQueryData<ListWorkspacesQueryResult>(queryKey, (oldWorkspacesData) => {

0 commit comments

Comments
 (0)