1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-24 15:59:41 +02:00

refactor(edge/stacks): migrate list view to react [EE-2237] (#9186)

This commit is contained in:
Chaim Lev-Ari 2023-07-12 18:26:52 +04:00 committed by GitHub
parent 020ecb740a
commit a216a1e960
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 482 additions and 298 deletions

View file

@ -0,0 +1,36 @@
import { useQuery } from 'react-query';
import { withError } from '@/react-tools/react-query';
import axios, { parseAxiosError } from '@/portainer/services/axios';
import { EdgeStack } from '../types';
import { buildUrl } from './buildUrl';
export function useEdgeStacks<T = Array<EdgeStack>>({
select,
/**
* If set to a number, the query will continuously refetch at this frequency in milliseconds.
* If set to a function, the function will be executed with the latest data and query to compute a frequency
* Defaults to `false`.
*/
refetchInterval,
}: {
select?: (stacks: EdgeStack[]) => T;
refetchInterval?: number | false | ((data?: T) => false | number);
} = {}) {
return useQuery(['edge_stacks'], () => getEdgeStacks(), {
...withError('Failed loading Edge stack'),
select,
refetchInterval,
});
}
export async function getEdgeStacks() {
try {
const { data } = await axios.get<EdgeStack[]>(buildUrl());
return data;
} catch (e) {
throw parseAxiosError(e as Error);
}
}