mirror of
https://github.com/portainer/portainer.git
synced 2025-08-02 20:35:25 +02:00
refactor(nomad): sync frontend with EE [EE-3353] (#7758)
This commit is contained in:
parent
78dcba614d
commit
881e99df53
68 changed files with 1799 additions and 17 deletions
41
app/react/nomad/DashboardView/useDashboard.ts
Normal file
41
app/react/nomad/DashboardView/useDashboard.ts
Normal file
|
@ -0,0 +1,41 @@
|
|||
import { useQuery } from 'react-query';
|
||||
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
|
||||
export type DashboardResponse = {
|
||||
JobCount: number;
|
||||
GroupCount: number;
|
||||
TaskCount: number;
|
||||
RunningTaskCount: number;
|
||||
NodeCount: number;
|
||||
};
|
||||
|
||||
export function useDashboard(environmentId: EnvironmentId) {
|
||||
return useQuery(
|
||||
['environments', environmentId, 'nomad', 'dashboard'],
|
||||
() => getDashboard(environmentId),
|
||||
{
|
||||
meta: {
|
||||
error: {
|
||||
title: 'Failure',
|
||||
message: 'Unable to get dashboard information',
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export async function getDashboard(environmentId: EnvironmentId) {
|
||||
try {
|
||||
const { data: dashboard } = await axios.get<DashboardResponse>(
|
||||
`/nomad/endpoints/${environmentId}/dashboard`,
|
||||
{
|
||||
params: {},
|
||||
}
|
||||
);
|
||||
return dashboard;
|
||||
} catch (e) {
|
||||
throw parseAxiosError(e as Error);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue