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:
parent
020ecb740a
commit
a216a1e960
23 changed files with 482 additions and 298 deletions
36
app/react/edge/edge-stacks/queries/useEdgeStacks.ts
Normal file
36
app/react/edge/edge-stacks/queries/useEdgeStacks.ts
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue