diff --git a/packages/web-console/src/scenes/Editor/Metrics/index.tsx b/packages/web-console/src/scenes/Editor/Metrics/index.tsx index e4bf595d9..014f66852 100644 --- a/packages/web-console/src/scenes/Editor/Metrics/index.tsx +++ b/packages/web-console/src/scenes/Editor/Metrics/index.tsx @@ -99,11 +99,11 @@ export const Metrics = () => { const [dialogOpen, setDialogOpen] = useState(false) const [metrics, setMetrics] = useState([]) const telemetryConfig = useSelector(selectors.telemetry.getConfig) - const [fetchMode, setFetchMode] = useState(FetchMode.OVERWRITE) const tabInFocusRef = React.useRef(true) const refreshRateRef = React.useRef() const intervalRef = React.useRef() + const fetchModeRef = React.useRef(FetchMode.OVERWRITE) const { autoRefreshTables } = useLocalStorage() @@ -136,6 +136,7 @@ export const Metrics = () => { eventBus.publish(EventType.METRICS_REFRESH_DATA, { dateFrom, dateTo, + overwrite: fetchModeRef.current === FetchMode.OVERWRITE, }) } @@ -170,20 +171,20 @@ export const Metrics = () => { } const handleDateFromToChange = (dateFrom: string, dateTo: string) => { - setFetchMode(FetchMode.OVERWRITE) + fetchModeRef.current = FetchMode.OVERWRITE setDateFrom(dateFrom) setDateTo(dateTo) } const handleFullRefresh = () => { - setFetchMode(FetchMode.OVERWRITE) + fetchModeRef.current = FetchMode.OVERWRITE refreshMetricsData() } const focusListener = useCallback(() => { tabInFocusRef.current = true if (refreshRateRef.current !== RefreshRate.OFF) { - setFetchMode(FetchMode.OVERWRITE) + fetchModeRef.current = FetchMode.OVERWRITE refreshMetricsData() } }, [refreshRateRef.current]) @@ -200,7 +201,7 @@ export const Metrics = () => { intervalRef.current = setInterval( () => { if (!tabInFocusRef.current) return - setFetchMode(FetchMode.ROLLING_APPEND) + fetchModeRef.current = FetchMode.ROLLING_APPEND refreshMetricsData() }, refreshRateInSec > 0 ? refreshRateInSec * 1000 : 0, @@ -261,7 +262,7 @@ export const Metrics = () => { } if (dateFrom && dateTo && refreshRate && metricViewMode) { updateBuffer(buffer.id, merged) - setFetchMode(FetchMode.OVERWRITE) + fetchModeRef.current = FetchMode.OVERWRITE refreshMetricsData() } } @@ -417,7 +418,7 @@ export const Metrics = () => { onRemove={handleRemoveMetric} onTableChange={handleTableChange} onColorChange={handleColorChange} - fetchMode={fetchMode} + fetchMode={fetchModeRef.current} rollingAppendLimit={rollingAppendLimit} /> ))} diff --git a/packages/web-console/src/scenes/Editor/Metrics/metric.tsx b/packages/web-console/src/scenes/Editor/Metrics/metric.tsx index e79837967..b5102807a 100644 --- a/packages/web-console/src/scenes/Editor/Metrics/metric.tsx +++ b/packages/web-console/src/scenes/Editor/Metrics/metric.tsx @@ -10,6 +10,7 @@ import { getTimeFilter, getSamplingRateForPeriod, durationTokenToDate, + MetricsRefreshPayload, } from "./utils" import { widgets } from "./widgets" import { QuestContext } from "../../../providers" @@ -138,8 +139,8 @@ export const Metric = ({ } } - const refreshMetricsData = () => { - fetchMetric() + const refreshMetricsData = (payload?: MetricsRefreshPayload) => { + fetchMetric(payload?.overwrite) } useEffect(() => { @@ -152,7 +153,10 @@ export const Metric = ({ }, [metric.tableId]) useEffect(() => { - eventBus.subscribe(EventType.METRICS_REFRESH_DATA, refreshMetricsData) + eventBus.subscribe( + EventType.METRICS_REFRESH_DATA, + refreshMetricsData, + ) return () => { eventBus.unsubscribe(EventType.METRICS_REFRESH_DATA, refreshMetricsData) diff --git a/packages/web-console/src/scenes/Editor/Metrics/utils.ts b/packages/web-console/src/scenes/Editor/Metrics/utils.ts index 5a56f8c70..2ca0498a4 100644 --- a/packages/web-console/src/scenes/Editor/Metrics/utils.ts +++ b/packages/web-console/src/scenes/Editor/Metrics/utils.ts @@ -37,6 +37,7 @@ export type Widget = { export type MetricsRefreshPayload = { dateFrom: string dateTo: string + overwrite?: boolean } export type Duration = {