2022-09-13 13:56:38 +00:00
|
|
|
import { useQuery } from 'react-query';
|
|
|
|
|
|
|
|
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
|
|
|
|
|
|
|
import { EdgeGroup } from '../types';
|
|
|
|
|
|
|
|
async function getEdgeGroups() {
|
|
|
|
try {
|
|
|
|
const { data } = await axios.get<EdgeGroup[]>('/edge_groups');
|
|
|
|
return data;
|
|
|
|
} catch (err) {
|
|
|
|
throw parseAxiosError(err as Error, 'Failed fetching edge groups');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-18 11:42:18 +00:00
|
|
|
export function useEdgeGroups<T = EdgeGroup[]>({
|
|
|
|
select,
|
|
|
|
}: {
|
|
|
|
select?: (groups: EdgeGroup[]) => T;
|
|
|
|
} = {}) {
|
|
|
|
return useQuery(['edge', 'groups'], getEdgeGroups, { select });
|
2022-09-13 13:56:38 +00:00
|
|
|
}
|