2022-09-13 13:56:38 +00:00
|
|
|
import { useQuery } from 'react-query';
|
|
|
|
|
|
|
|
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
2023-11-14 10:57:27 +00:00
|
|
|
import {
|
|
|
|
EnvironmentId,
|
|
|
|
EnvironmentType,
|
|
|
|
} from '@/react/portainer/environments/types';
|
2022-09-13 13:56:38 +00:00
|
|
|
|
|
|
|
import { EdgeGroup } from '../types';
|
|
|
|
|
2023-05-14 02:26:11 +00:00
|
|
|
import { queryKeys } from './query-keys';
|
|
|
|
import { buildUrl } from './build-url';
|
|
|
|
|
2023-11-14 10:57:27 +00:00
|
|
|
export interface EdgeGroupListItemResponse extends EdgeGroup {
|
2023-03-06 20:25:04 +00:00
|
|
|
EndpointTypes: Array<EnvironmentType>;
|
2023-11-14 10:57:27 +00:00
|
|
|
HasEdgeStack?: boolean;
|
|
|
|
HasEdgeJob?: boolean;
|
|
|
|
HasEdgeConfig?: boolean;
|
|
|
|
TrustedEndpoints: Array<EnvironmentId>;
|
2023-03-06 20:25:04 +00:00
|
|
|
}
|
|
|
|
|
2022-09-13 13:56:38 +00:00
|
|
|
async function getEdgeGroups() {
|
|
|
|
try {
|
2023-05-14 02:26:11 +00:00
|
|
|
const { data } = await axios.get<EdgeGroupListItemResponse[]>(buildUrl());
|
2022-09-13 13:56:38 +00:00
|
|
|
return data;
|
|
|
|
} catch (err) {
|
|
|
|
throw parseAxiosError(err as Error, 'Failed fetching edge groups');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-06 20:25:04 +00:00
|
|
|
export function useEdgeGroups<T = EdgeGroupListItemResponse[]>({
|
2022-09-18 11:42:18 +00:00
|
|
|
select,
|
|
|
|
}: {
|
2023-03-06 20:25:04 +00:00
|
|
|
select?: (groups: EdgeGroupListItemResponse[]) => T;
|
2022-09-18 11:42:18 +00:00
|
|
|
} = {}) {
|
2023-05-14 02:26:11 +00:00
|
|
|
return useQuery(queryKeys.base(), getEdgeGroups, { select });
|
2022-09-13 13:56:38 +00:00
|
|
|
}
|