You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
portainer/app/react/nomad/DashboardView/useDashboard.ts

42 lines
988 B

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);
}
}