mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 07:49:41 +02:00
feat(app/edge-stacks): summarize the edge stack statuses in the backend (#818)
This commit is contained in:
parent
363a62d885
commit
e1c480d3c3
21 changed files with 645 additions and 312 deletions
|
@ -1,6 +1,6 @@
|
|||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { withError } from '@/react-tools/react-query';
|
||||
import { withGlobalError } from '@/react-tools/react-query';
|
||||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
|
||||
import { EdgeStack } from '../types';
|
||||
|
@ -8,28 +8,30 @@ import { EdgeStack } from '../types';
|
|||
import { buildUrl } from './buildUrl';
|
||||
import { queryKeys } from './query-keys';
|
||||
|
||||
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`.
|
||||
*/
|
||||
type QueryParams = {
|
||||
summarizeStatuses?: boolean;
|
||||
};
|
||||
|
||||
export function useEdgeStacks<T extends EdgeStack[] = EdgeStack[]>({
|
||||
params,
|
||||
refetchInterval,
|
||||
}: {
|
||||
select?: (stacks: EdgeStack[]) => T;
|
||||
params?: QueryParams;
|
||||
refetchInterval?: number | false | ((data?: T) => false | number);
|
||||
} = {}) {
|
||||
return useQuery(queryKeys.base(), () => getEdgeStacks(), {
|
||||
...withError('Failed loading Edge stack'),
|
||||
select,
|
||||
return useQuery({
|
||||
queryKey: queryKeys.base(),
|
||||
queryFn: () => getEdgeStacks<T>(params),
|
||||
refetchInterval,
|
||||
...withGlobalError('Failed loading Edge stack'),
|
||||
});
|
||||
}
|
||||
|
||||
export async function getEdgeStacks() {
|
||||
async function getEdgeStacks<T extends EdgeStack[] = EdgeStack[]>(
|
||||
params: QueryParams = {}
|
||||
) {
|
||||
try {
|
||||
const { data } = await axios.get<EdgeStack[]>(buildUrl());
|
||||
const { data } = await axios.get<T>(buildUrl(), { params });
|
||||
return data;
|
||||
} catch (e) {
|
||||
throw parseAxiosError(e as Error);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue