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:
parent
1f2f4525e3
commit
99b39da03d
18 changed files with 199 additions and 228 deletions
|
@ -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');
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue