mirror of
https://github.com/portainer/portainer.git
synced 2025-08-02 20:35:25 +02:00
feat(waiting-room): choose relations when associated endpoint [EE-5187] (#8720)
This commit is contained in:
parent
511adabce2
commit
365316971b
53 changed files with 1712 additions and 303 deletions
3
app/react/edge/edge-groups/queries/build-url.ts
Normal file
3
app/react/edge/edge-groups/queries/build-url.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
export function buildUrl() {
|
||||
return '/edge_groups';
|
||||
}
|
3
app/react/edge/edge-groups/queries/query-keys.ts
Normal file
3
app/react/edge/edge-groups/queries/query-keys.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
export const queryKeys = {
|
||||
base: () => ['edge', 'groups'] as const,
|
||||
};
|
|
@ -0,0 +1,47 @@
|
|||
import { useMutation, useQueryClient } from 'react-query';
|
||||
|
||||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
import { TagId } from '@/portainer/tags/types';
|
||||
import {
|
||||
mutationOptions,
|
||||
withError,
|
||||
withInvalidate,
|
||||
} from '@/react-tools/react-query';
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
|
||||
import { EdgeGroup } from '../types';
|
||||
|
||||
import { buildUrl } from './build-url';
|
||||
import { queryKeys } from './query-keys';
|
||||
|
||||
interface CreateGroupPayload {
|
||||
name: string;
|
||||
dynamic: boolean;
|
||||
tagIds?: TagId[];
|
||||
endpoints?: EnvironmentId[];
|
||||
partialMatch?: boolean;
|
||||
}
|
||||
|
||||
export async function createEdgeGroup(requestPayload: CreateGroupPayload) {
|
||||
try {
|
||||
const { data: group } = await axios.post<EdgeGroup>(
|
||||
buildUrl(),
|
||||
requestPayload
|
||||
);
|
||||
return group;
|
||||
} catch (e) {
|
||||
throw parseAxiosError(e as Error, 'Failed to create Edge group');
|
||||
}
|
||||
}
|
||||
|
||||
export function useCreateGroupMutation() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation(
|
||||
createEdgeGroup,
|
||||
mutationOptions(
|
||||
withError('Failed to create Edge group'),
|
||||
withInvalidate(queryClient, [queryKeys.base()])
|
||||
)
|
||||
);
|
||||
}
|
|
@ -5,15 +5,16 @@ import { EnvironmentType } from '@/react/portainer/environments/types';
|
|||
|
||||
import { EdgeGroup } from '../types';
|
||||
|
||||
import { queryKeys } from './query-keys';
|
||||
import { buildUrl } from './build-url';
|
||||
|
||||
interface EdgeGroupListItemResponse extends EdgeGroup {
|
||||
EndpointTypes: Array<EnvironmentType>;
|
||||
}
|
||||
|
||||
async function getEdgeGroups() {
|
||||
try {
|
||||
const { data } = await axios.get<EdgeGroupListItemResponse[]>(
|
||||
'/edge_groups'
|
||||
);
|
||||
const { data } = await axios.get<EdgeGroupListItemResponse[]>(buildUrl());
|
||||
return data;
|
||||
} catch (err) {
|
||||
throw parseAxiosError(err as Error, 'Failed fetching edge groups');
|
||||
|
@ -25,5 +26,5 @@ export function useEdgeGroups<T = EdgeGroupListItemResponse[]>({
|
|||
}: {
|
||||
select?: (groups: EdgeGroupListItemResponse[]) => T;
|
||||
} = {}) {
|
||||
return useQuery(['edge', 'groups'], getEdgeGroups, { select });
|
||||
return useQuery(queryKeys.base(), getEdgeGroups, { select });
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue