fix(netflow): подтверждать выбранный срез перед запросами

This commit is contained in:
Denozordec committed 2026-10-11 18:16:29 +07:00
1 parent 64df472202
commit 0c14da190b
13 files changed
+338 -21

No files matched your search

+11 -4
View File
@@ -832,7 +832,14 @@ export default function TrafficPage() {
serverId: selectedId,
iface: selectedIface,
})
const flowLiveEnabled = isLive && effectiveMode === "flows" && Boolean(selectedId) && range === "5m"
const confirmedFlowSelection = isLive && Boolean(currentFlows) && !liveError && (
range === "30d"
? /^[1-9]\d*$/.test(selectedId) && Number.isSafeInteger(Number(selectedId)) && Boolean(currentFlows?.monthlyServers?.some(server => String(server.id) === selectedId))
: flowScope === "servers"
? /^[1-9]\d*$/.test(selectedId) && Number.isSafeInteger(Number(selectedId)) && flowExporters.some(card => card.id === selectedId)
: Boolean(selectedId) && flowClients.some(card => card.id === selectedId)
)
const flowLiveEnabled = confirmedFlowSelection && effectiveMode === "flows" && range === "5m"
const { sample: flowLiveSample, error: flowLiveError, receivedAt: flowLiveReceivedAt } = useFlowLive({
enabled: flowLiveEnabled,
backendUrl,
@@ -914,9 +921,9 @@ export default function TrafficPage() {
const analyticsKey = JSON.stringify([flowKey, selectedId, flowIface, flowDedup, flowExcludeMesh, flowExcludeOverlay, analyticsRetry, range === "30d" ? flowMonth : null])
const currentAnalytics = analyticsResult?.key === analyticsKey ? analyticsResult : null
const analyticsLoading = isLive && effectiveMode === "flows" && Boolean(selectedId) && (range !== "30d" || flowMonthValid) && !currentAnalytics
const analyticsLoading = confirmedFlowSelection && effectiveMode === "flows" && (range !== "30d" || flowMonthValid) && !currentAnalytics
useEffect(() => {
if (!isLive || effectiveMode !== "flows" || !selectedId || (range === "30d" && !flowMonthValid)) return
if (!confirmedFlowSelection || effectiveMode !== "flows" || (range === "30d" && !flowMonthValid)) return
let cancelled = false
const request = range === "30d"
? getFlowMonthly(backendUrl, { month: flowMonth, serverId: flowScope === "servers" ? selectedId : undefined }).then(monthly => ({ monthly }))
@@ -931,7 +938,7 @@ export default function TrafficPage() {
if (!cancelled) setAnalyticsResult({ key: analyticsKey, error: e instanceof Error ? e.message : "Не удалось загрузить аналитику" })
})
return () => { cancelled = true }
}, [isLive, effectiveMode, selectedId, range, flowScope, flowIface, flowDedup, flowExcludeMesh, flowExcludeOverlay, backendUrl, analyticsKey, flowMonth, flowMonthValid])
}, [confirmedFlowSelection, isLive, effectiveMode, selectedId, range, flowScope, flowIface, flowDedup, flowExcludeMesh, flowExcludeOverlay, backendUrl, analyticsKey, flowMonth, flowMonthValid])
useEffect(() => {
if (!isLive) return