Backend returns metrics as an array, not an object. - Update MetricsResponse type to use MetricDefinition[] instead of Record - Remove Object.values() conversion in compare and rankings pages - Fix useMetrics hook to handle array instead of object - Fix getMetric to use array.find() instead of object indexing Fixes empty metric dropdown on compare page. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
29 lines
600 B
TypeScript
29 lines
600 B
TypeScript
/**
|
|
* 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 {
|
|
metrics: data?.metrics || [],
|
|
metricsList: data?.metrics || [],
|
|
getMetric: (key: string) => data?.metrics?.find(m => m.key === key),
|
|
isLoading,
|
|
error,
|
|
};
|
|
}
|