mirror of
https://github.com/portainer/portainer.git
synced 2025-07-18 21:09:40 +02:00
39 lines
994 B
TypeScript
39 lines
994 B
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
|
|
import { withGlobalError } from '@/react-tools/react-query';
|
|
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
|
|
|
import { EdgeStack } from '../types';
|
|
|
|
import { buildUrl } from './buildUrl';
|
|
import { queryKeys } from './query-keys';
|
|
|
|
type QueryParams = {
|
|
summarizeStatuses?: boolean;
|
|
};
|
|
|
|
export function useEdgeStacks<T extends EdgeStack[] = EdgeStack[]>({
|
|
params,
|
|
refetchInterval,
|
|
}: {
|
|
params?: QueryParams;
|
|
refetchInterval?: number | false | ((data?: T) => false | number);
|
|
} = {}) {
|
|
return useQuery({
|
|
queryKey: queryKeys.base(),
|
|
queryFn: () => getEdgeStacks<T>(params),
|
|
refetchInterval,
|
|
...withGlobalError('Failed loading Edge stack'),
|
|
});
|
|
}
|
|
|
|
async function getEdgeStacks<T extends EdgeStack[] = EdgeStack[]>(
|
|
params: QueryParams = {}
|
|
) {
|
|
try {
|
|
const { data } = await axios.get<T>(buildUrl(), { params });
|
|
return data;
|
|
} catch (e) {
|
|
throw parseAxiosError(e as Error);
|
|
}
|
|
}
|