2026-02-02 20:34:35 +00:00
|
|
|
/**
|
|
|
|
|
* Custom hook for fetching metric definitions with SWR
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
import useSWR from 'swr';
|
|
|
|
|
import { fetcher } from '@/lib/api';
|
|
|
|
|
import type { MetricsResponse } from '@/lib/types';
|
|
|
|
|
|
|
|
|
|
export function useMetrics() {
|
|
|
|
|
const { data, error, isLoading } = useSWR<MetricsResponse>(
|
|
|
|
|
'/metrics',
|
|
|
|
|
fetcher,
|
|
|
|
|
{
|
|
|
|
|
revalidateOnFocus: false,
|
|
|
|
|
dedupingInterval: 60000, // 1 minute
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return {
|
2026-02-02 22:00:07 +00:00
|
|
|
metrics: data?.metrics || [],
|
|
|
|
|
metricsList: data?.metrics || [],
|
|
|
|
|
getMetric: (key: string) => data?.metrics?.find(m => m.key === key),
|
2026-02-02 20:34:35 +00:00
|
|
|
isLoading,
|
|
|
|
|
error,
|
|
|
|
|
};
|
|
|
|
|
}
|