mirror of
https://github.com/portainer/portainer.git
synced 2025-07-23 07:19:41 +02:00
feat(dashboard): dashboard api [EE-7111] (#11843)
This commit is contained in:
parent
659abe553d
commit
9cef912c44
11 changed files with 695 additions and 69 deletions
43
app/react/kubernetes/dashboard/queries/getDashboardQuery.ts
Normal file
43
app/react/kubernetes/dashboard/queries/getDashboardQuery.ts
Normal file
|
@ -0,0 +1,43 @@
|
|||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { withError } from '@/react-tools/react-query';
|
||||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
|
||||
import { K8sDashboard } from '../types';
|
||||
|
||||
const queryKeys = {
|
||||
list: (environmentId: EnvironmentId) =>
|
||||
['environments', environmentId, 'dashboard'] as const,
|
||||
};
|
||||
|
||||
export function useGetDashboardQuery(
|
||||
environmentId: EnvironmentId,
|
||||
options?: { autoRefreshRate?: number }
|
||||
) {
|
||||
return useQuery(
|
||||
queryKeys.list(environmentId),
|
||||
async () => getDashboard(environmentId),
|
||||
{
|
||||
...withError('Unable to get dashboard stats'),
|
||||
refetchInterval() {
|
||||
return options?.autoRefreshRate ?? false;
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
async function getDashboard(environmentId: EnvironmentId) {
|
||||
try {
|
||||
const { data: dashboard } = await axios.get<K8sDashboard>(
|
||||
`kubernetes/${environmentId}/dashboard`
|
||||
);
|
||||
|
||||
return dashboard;
|
||||
} catch (e) {
|
||||
throw parseAxiosError(
|
||||
e,
|
||||
'Unable to get dashboard stats. Some counts may be inaccurate.'
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue