Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions apps/webapp/app/components/code/QueryResultsChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -889,13 +889,15 @@ export const QueryResultsChart = memo(function QueryResultsChart({
const cfg: ChartConfig = {};
sortedSeries.forEach((s, i) => {
const statusColor = groupByIsRunStatus ? getRunStatusHexColor(s) : undefined;
const originalIndex = config.yAxisColumns.indexOf(s);
const colorIndex = originalIndex >= 0 ? originalIndex : i;
cfg[s] = {
label: s,
color: statusColor ?? config.seriesColors?.[s] ?? getSeriesColor(i),
color: statusColor ?? config.seriesColors?.[s] ?? getSeriesColor(colorIndex),
};
});
return cfg;
}, [sortedSeries, groupByIsRunStatus, config.seriesColors]);
}, [sortedSeries, groupByIsRunStatus, config.seriesColors, config.yAxisColumns]);

// Custom tooltip label formatter for better date display
const tooltipLabelFormatter = useMemo(() => {
Expand Down
10 changes: 7 additions & 3 deletions apps/webapp/app/routes/resources.metric.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,19 @@ export function MetricWidget({
const [response, setResponse] = useState<MetricWidgetActionResponse | null>(null);
const [isLoading, setIsLoading] = useState(false);
const abortControllerRef = useRef<AbortController | null>(null);
const isDirtyRef = useRef(false);

// Track the latest props so the submit callback always uses fresh values
// without needing to be recreated (which would cause useInterval to re-register listeners).
const propsRef = useRef(props);
propsRef.current = props;

const submit = useCallback(() => {
// Skip fetching if the widget is not visible on screen
if (!isVisibleRef.current) return;
if (!isVisibleRef.current) {
isDirtyRef.current = true;
return;
}
isDirtyRef.current = false;

// Abort any in-flight request for this widget
abortControllerRef.current?.abort();
Expand Down Expand Up @@ -225,7 +229,7 @@ export function MetricWidget({
// When a widget scrolls into view and has no data yet, trigger a load.
const { ref: visibilityRef, isVisibleRef } = useElementVisibility({
onVisibilityChange: (visible) => {
if (visible && !response) {
if (visible && (!response || isDirtyRef.current)) {
submit();
}
},
Expand Down
Loading