Skip to content

Commit

Permalink
fix: refresh after table drops
Browse files Browse the repository at this point in the history
  • Loading branch information
insmac committed Jan 10, 2025
1 parent ba41c1d commit 9ffd680
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions packages/web-console/src/scenes/Editor/Metrics/metric.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,20 @@ export const Metric = ({
const [loading, setLoading] = useState(metric.tableId !== undefined)
const [lastNotNull, setLastNotNull] = useState<number>()
const [colorPickerOpen, setColorPickerOpen] = useState(false)
const [lastTableId, setLastTableId] = useState<number | undefined>(
metric.tableId,
)
const tableIdRef = React.useRef(metric.tableId)
const dateFromRef = React.useRef(dateFrom)
const dateToRef = React.useRef(dateTo)
const dataRef = React.useRef<uPlot.AlignedData>([[], []])
const tableIdRef = React.useRef(metric.tableId)
const tableNameRef = React.useRef<string | undefined>()

dateFromRef.current = dateFrom
dateToRef.current = dateTo

const tables = useSelector(selectors.query.getTables)

const tableName = tables.find((t) => t.id === metric.tableId)?.table_name
tableNameRef.current = tableName

const widgetConfig = widgets[metric.metricType]

const isRollingAppendEnabled =
Expand Down Expand Up @@ -141,17 +142,22 @@ export const Metric = ({
}

const refreshMetricsData = (payload?: MetricsRefreshPayload) => {
fetchMetric(payload?.overwrite)
if (tableNameRef.current) {
fetchMetric(payload?.overwrite)
} else {
dataRef.current = [[], []]
setLoading(false)
}
}

useEffect(() => {
if (metric.tableId && metric.tableId !== lastTableId) {
if (tableName) {
tableNameRef.current = tableName
tableIdRef.current = metric.tableId
dataRef.current = [[], []]
setLastTableId(metric.tableId)
fetchMetric(true)
}
}, [metric.tableId])
}, [tableName])

useEffect(() => {
eventBus.subscribe<MetricsRefreshPayload>(
Expand All @@ -172,8 +178,6 @@ export const Metric = ({
</MetricInfoRoot>
)

const tableName = tables.find((t) => t.id === metric.tableId)?.table_name

// const canZoomToData = tableName !== undefined && lastNotNull !== undefined
const canZoomToData = false

Expand Down

0 comments on commit 9ffd680

Please sign in to comment.