Skip to content

Commit 36f91e0

Browse files
Merge pull request #56 from agentevals-dev/fix/slow-metrics-config-load
Fix metrics panel render problem
2 parents 630a641 + 234114b commit 36f91e0

1 file changed

Lines changed: 16 additions & 24 deletions

File tree

ui/src/components/upload/MetricSelector.tsx

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useState, useEffect } from 'react';
2-
import { Checkbox, Button, Spin } from 'antd';
2+
import { Checkbox, Button } from 'antd';
33
import { css } from '@emotion/react';
44
import { AVAILABLE_METRICS, type MetricMetadata } from '../../lib/types';
55
import { listMetrics } from '../../api/client';
@@ -125,29 +125,29 @@ const selectorStyle = css`
125125
}
126126
`;
127127

128+
let cachedMetrics: MetricMetadata[] | null = null;
129+
128130
export const MetricSelector: React.FC<MetricSelectorProps> = ({
129131
selectedMetrics,
130132
onToggleMetric,
131133
loadFromAPI = false,
132134
}) => {
133-
const [metrics, setMetrics] = useState<MetricMetadata[]>(AVAILABLE_METRICS);
134-
const [loading, setLoading] = useState(false);
135+
const [metrics, setMetrics] = useState<MetricMetadata[]>(cachedMetrics ?? AVAILABLE_METRICS);
135136

136137
useEffect(() => {
137-
if (loadFromAPI) {
138-
setLoading(true);
139-
listMetrics()
140-
.then((apiMetrics) => {
138+
if (!loadFromAPI || cachedMetrics) return;
139+
let cancelled = false;
140+
listMetrics()
141+
.then((apiMetrics) => {
142+
if (!cancelled) {
143+
cachedMetrics = apiMetrics;
141144
setMetrics(apiMetrics);
142-
})
143-
.catch((error) => {
144-
console.error('Failed to load metrics from API, using fallback:', error);
145-
setMetrics(AVAILABLE_METRICS);
146-
})
147-
.finally(() => {
148-
setLoading(false);
149-
});
150-
}
145+
}
146+
})
147+
.catch((error) => {
148+
console.error('Failed to load metrics from API, using fallback:', error);
149+
});
150+
return () => { cancelled = true; };
151151
}, [loadFromAPI]);
152152

153153
const categorizedMetrics = metrics.reduce(
@@ -175,14 +175,6 @@ export const MetricSelector: React.FC<MetricSelectorProps> = ({
175175
});
176176
};
177177

178-
if (loading) {
179-
return (
180-
<div css={selectorStyle} style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: '200px' }}>
181-
<Spin tip="Loading metrics..." />
182-
</div>
183-
);
184-
}
185-
186178
return (
187179
<div css={selectorStyle}>
188180
<div className="metric-categories">

0 commit comments

Comments
 (0)