2022-09-13 13:56:38 +00:00
|
|
|
import { useQuery } from 'react-query';
|
|
|
|
|
|
|
|
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
2023-03-06 20:25:04 +00:00
|
|
|
import { EnvironmentType } from '@/react/portainer/environments/types';
|
2022-09-13 13:56:38 +00:00
|
|
|
|
|
|
|
import { EdgeGroup } from '../types';
|
|
|
|
|
2023-03-06 20:25:04 +00:00
|
|
|
interface EdgeGroupListItemResponse extends EdgeGroup {
|
|
|
|
EndpointTypes: Array<EnvironmentType>;
|
|
|
|
}
|
|
|
|
|
2022-09-13 13:56:38 +00:00
|
|
|
async function getEdgeGroups() {
|
|
|
|
try {
|
2023-03-06 20:25:04 +00:00
|
|
|
const { data } = await axios.get<EdgeGroupListItemResponse[]>(
|
|
|
|
'/edge_groups'
|
|
|
|
);
|
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
|
|
|
} = {}) {
|
|
|
|
return useQuery(['edge', 'groups'], getEdgeGroups, { select });
|
2022-09-13 13:56:38 +00:00
|
|
|
}
|