Fix metrics API response structure
All checks were successful
Build and Push Docker Images / Build Backend (FastAPI) (push) Successful in 35s
Build and Push Docker Images / Build Frontend (Next.js) (push) Successful in 1m10s
Build and Push Docker Images / Trigger Portainer Update (push) Successful in 1s

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:
Tudor
2026-02-02 22:00:07 +00:00
parent d90661f2c2
commit 4dc0c10c9d
4 changed files with 9 additions and 8 deletions

View File

@@ -44,8 +44,8 @@ export default async function ComparePage({ searchParams }: ComparePageProps) {
// Fetch available metrics
const metricsResponse = await fetchMetrics();
// Convert metrics object to array
const metricsArray = Object.values(metricsResponse?.metrics || {});
// Metrics is already an array
const metricsArray = metricsResponse?.metrics || [];
return (
<ComparisonView

View File

@@ -43,8 +43,8 @@ export default async function RankingsPage({ searchParams }: RankingsPageProps)
fetchMetrics(),
]);
// Convert metrics object to array
const metricsArray = Object.values(metricsResponse?.metrics || {});
// Metrics is already an array
const metricsArray = metricsResponse?.metrics || [];
return (
<RankingsView

View File

@@ -19,9 +19,9 @@ export function useMetrics() {
);
return {
metrics: data?.metrics || {},
metricsList: data?.metrics ? Object.values(data.metrics) : [],
getMetric: (key: string) => data?.metrics?.[key],
metrics: data?.metrics || [],
metricsList: data?.metrics || [],
getMetric: (key: string) => data?.metrics?.find(m => m.key === key),
isLoading,
error,
};

View File

@@ -194,8 +194,9 @@ export interface MetricDefinition {
hasNationalAverage?: boolean;
}
// Backend returns metrics as an array, not an object
export interface MetricsResponse {
metrics: Record<string, MetricDefinition>;
metrics: MetricDefinition[];
}
export interface DataInfoResponse {