Skip to content

Commit

Permalink
Refactor configuration deletion queries
Browse files Browse the repository at this point in the history
Co-authored-by: Brad Harris <[email protected]>
  • Loading branch information
filiptronicek and selfcontained committed Nov 10, 2023
1 parent 5d6151b commit 4c921cf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import { FunctionComponent, useCallback, useState } from "react";
import ConfirmationModal from "../../components/ConfirmationModal";
import { useDeleteConfiguration } from "../../data/configurations/delete-configuration-mutation";
import type { Configuration } from "@gitpod/public-api/lib/gitpod/v1/configuration_pb";
import { useDeleteConfiguration } from "../../data/configurations/configuration-queries";

type RemoveProjectModalProps = {
configuration: Configuration;
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 { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { useCurrentOrg } from "../organizations/orgs-query";
import { configurationClient } from "../../service/public-api";
import type { Configuration } from "@gitpod/public-api/lib/gitpod/v1/configuration_pb";
Expand Down Expand Up @@ -60,6 +60,23 @@ export const useConfiguration = (configurationId: string) => {
});
};

export const useDeleteConfiguration = (configurationId: string) => {
const queryClient = useQueryClient();

return useMutation<void, Error>({
mutationKey: getConfigurationQueryKey(configurationId),
mutationFn: async () => {
await configurationClient.deleteConfiguration({
configurationId,
});
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["configurations", "list"] });
queryClient.invalidateQueries({ queryKey: getConfigurationQueryKey(configurationId) });
},
});
};

export const getConfigurationQueryKey = (configurationId: string) => {
const key: any[] = [BASE_KEY, { configurationId }];

Expand Down

This file was deleted.

0 comments on commit 4c921cf

Please sign in to comment.