1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-19 21:39:40 +02:00
portainer/app/react/edge/edge-stacks/queries/useEdgeStacks.ts

40 lines
994 B
TypeScript
Raw Normal View History

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);
}
}