Fix metrics API response structure
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>
This commit is contained in:
@@ -44,8 +44,8 @@ export default async function ComparePage({ searchParams }: ComparePageProps) {
|
|||||||
// Fetch available metrics
|
// Fetch available metrics
|
||||||
const metricsResponse = await fetchMetrics();
|
const metricsResponse = await fetchMetrics();
|
||||||
|
|
||||||
// Convert metrics object to array
|
// Metrics is already an array
|
||||||
const metricsArray = Object.values(metricsResponse?.metrics || {});
|
const metricsArray = metricsResponse?.metrics || [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ComparisonView
|
<ComparisonView
|
||||||
|
|||||||
@@ -43,8 +43,8 @@ export default async function RankingsPage({ searchParams }: RankingsPageProps)
|
|||||||
fetchMetrics(),
|
fetchMetrics(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Convert metrics object to array
|
// Metrics is already an array
|
||||||
const metricsArray = Object.values(metricsResponse?.metrics || {});
|
const metricsArray = metricsResponse?.metrics || [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RankingsView
|
<RankingsView
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ export function useMetrics() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
metrics: data?.metrics || {},
|
metrics: data?.metrics || [],
|
||||||
metricsList: data?.metrics ? Object.values(data.metrics) : [],
|
metricsList: data?.metrics || [],
|
||||||
getMetric: (key: string) => data?.metrics?.[key],
|
getMetric: (key: string) => data?.metrics?.find(m => m.key === key),
|
||||||
isLoading,
|
isLoading,
|
||||||
error,
|
error,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -194,8 +194,9 @@ export interface MetricDefinition {
|
|||||||
hasNationalAverage?: boolean;
|
hasNationalAverage?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Backend returns metrics as an array, not an object
|
||||||
export interface MetricsResponse {
|
export interface MetricsResponse {
|
||||||
metrics: Record<string, MetricDefinition>;
|
metrics: MetricDefinition[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DataInfoResponse {
|
export interface DataInfoResponse {
|
||||||
|
|||||||
Reference in New Issue
Block a user