From fab5e8a65611e351b0f301e0867907a7d51d5b75 Mon Sep 17 00:00:00 2001 From: xiaomiku01 Date: Sat, 11 Apr 2026 01:14:47 +0800 Subject: [PATCH] fix(ui): filter deleted probes from latency chart stats Stats records in the DB contain historical data for all probes including deleted ones. Now filters stats by active probe keys and clears state when all probes are removed. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../routes/system/network-probes.tsx | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/internal/site/src/components/routes/system/network-probes.tsx b/internal/site/src/components/routes/system/network-probes.tsx index de01e52e..74e2f78f 100644 --- a/internal/site/src/components/routes/system/network-probes.tsx +++ b/internal/site/src/components/routes/system/network-probes.tsx @@ -47,9 +47,16 @@ export default function NetworkProbes({ fetchProbes() }, [fetchProbes]) + // Build set of current probe keys to filter out deleted probes from stats + const activeProbeKeys = useMemo(() => new Set(probes.map(probeKey)), [probes]) + // Fetch probe stats based on chart time useEffect(() => { - if (probes.length === 0) return + if (probes.length === 0) { + setStats([]) + setLatestResults({}) + return + } const controller = new AbortController() const statsType = chartTimeData[chartTime]?.type ?? "1m" @@ -58,10 +65,16 @@ export default function NetworkProbes({ signal: controller.signal, }) .then((raw) => { - const data: NetworkProbeStatsRecord[] = raw.map((r) => ({ - stats: r.stats, - created: new Date(r.created).getTime(), - })) + // Filter stats to only include currently active probes + const data: NetworkProbeStatsRecord[] = raw.map((r) => { + const filtered: NetworkProbeStatsRecord["stats"] = {} + for (const [key, val] of Object.entries(r.stats)) { + if (activeProbeKeys.has(key)) { + filtered[key] = val + } + } + return { stats: filtered, created: new Date(r.created).getTime() } + }) setStats(data) if (data.length > 0) { const last = data[data.length - 1].stats @@ -75,7 +88,7 @@ export default function NetworkProbes({ .catch(() => setStats([])) return () => controller.abort() - }, [systemId, chartTime, probes]) + }, [systemId, chartTime, probes, activeProbeKeys]) const deleteProbe = async (id: string) => { try {