1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-10-13 11:17:26 +02:00
unleash.unleash/frontend/src/hooks/api/getters/useApplicationOverview/useApplicationOverview.ts
Christopher Kolstad 53354224fc
chore: Bump biome and configure husky (#6589)
Upgrades biome to 1.6.1, and updates husky pre-commit hook.

Most changes here are making type imports explicit.
2024-03-18 13:58:05 +01:00

41 lines
1.1 KiB
TypeScript

import useSWR, { type SWRConfiguration } from 'swr';
import { formatApiPath } from 'utils/formatPath';
import handleErrorResponses from '../httpErrorResponseHandler';
import type { ApplicationOverviewSchema } from 'openapi';
const placeHolderApplication: ApplicationOverviewSchema = {
environments: [],
featureCount: 0,
projects: [],
issues: {
missingStrategies: [],
},
};
export const useApplicationOverview = (
application: string,
options: SWRConfiguration = {},
) => {
const path = formatApiPath(
`api/admin/metrics/applications/${application}/overview`,
);
const { data, error } = useSWR<ApplicationOverviewSchema>(
path,
fetcher,
options,
);
return {
data: data || placeHolderApplication,
error,
loading: !error && !data,
};
};
const fetcher = async (path: string): Promise<ApplicationOverviewSchema> => {
const res = await fetch(path).then(
handleErrorResponses('Application overview'),
);
const data = await res.json();
return data;
};