1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-04 21:35:23 +02:00

refactor(edge/groups): migrate view to react [EE-4683] (#10592)

This commit is contained in:
Chaim Lev-Ari 2023-11-14 12:57:27 +02:00 committed by GitHub
parent 1f2f4525e3
commit 99b39da03d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 199 additions and 228 deletions

View file

@ -0,0 +1,35 @@
import { useMutation, useQueryClient } from 'react-query';
import { promiseSequence } from '@/portainer/helpers/promise-utils';
import axios, { parseAxiosError } from '@/portainer/services/axios';
import {
mutationOptions,
withError,
withInvalidate,
} from '@/react-tools/react-query';
import { EdgeGroup } from '../types';
import { buildUrl } from '../queries/build-url';
import { queryKeys } from '../queries/query-keys';
export function useDeleteEdgeGroupsMutation() {
const queryClient = useQueryClient();
return useMutation(
(edgeGroupIds: Array<EdgeGroup['Id']>) =>
promiseSequence(
edgeGroupIds.map((edgeGroupId) => () => deleteEdgeGroup(edgeGroupId))
),
mutationOptions(
withError('Unable to delete Edge Group(s)'),
withInvalidate(queryClient, [queryKeys.base()])
)
);
}
async function deleteEdgeGroup(id: EdgeGroup['Id']) {
try {
await axios.delete(buildUrl({ id }));
} catch (e) {
throw parseAxiosError(e, 'Unable to delete edge Group');
}
}