mirror of
https://github.com/Unleash/unleash.git
synced 2025-10-13 11:17:26 +02:00
updated Orval and configured it to be compatible with v7. --------- Co-authored-by: Thomas Heartman <thomas@getunleash.io>
51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import useSWR, { mutate, type SWRConfiguration } from 'swr';
|
|
import { useCallback } from 'react';
|
|
import { formatApiPath } from 'utils/formatPath';
|
|
import handleErrorResponses from '../httpErrorResponseHandler.js';
|
|
import type {
|
|
InstanceInsightsSchema,
|
|
GetInstanceInsightsParams,
|
|
} from 'openapi';
|
|
|
|
export const useInsights = (
|
|
from: GetInstanceInsightsParams['from'] = '',
|
|
to: GetInstanceInsightsParams['to'] = '',
|
|
options?: SWRConfiguration,
|
|
) => {
|
|
const path = formatApiPath(`api/admin/insights?from=${from}&to=${to}`);
|
|
|
|
const { data, error } = useSWR<InstanceInsightsSchema>(
|
|
path,
|
|
fetchExecutiveDashboard,
|
|
options,
|
|
);
|
|
|
|
const refetchInsights = useCallback(() => {
|
|
mutate(path).catch(console.warn);
|
|
}, [path]);
|
|
|
|
return {
|
|
insights:
|
|
data ||
|
|
/* @ts-expect-error FIXME (lifecycleMetrics): lifecycle trends */
|
|
({
|
|
userTrends: [],
|
|
flagTrends: [],
|
|
projectFlagTrends: [],
|
|
metricsSummaryTrends: [],
|
|
environmentTypeTrends: [],
|
|
} as InstanceInsightsSchema),
|
|
refetchInsights,
|
|
loading: !error && !data,
|
|
error,
|
|
};
|
|
};
|
|
|
|
const fetchExecutiveDashboard = (
|
|
path: string,
|
|
): Promise<InstanceInsightsSchema> => {
|
|
return fetch(path)
|
|
.then(handleErrorResponses('Executive Dashboard Data'))
|
|
.then((res) => res.json());
|
|
};
|