Skip to content

Commit

Permalink
fixes, date adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
insmac committed Nov 26, 2024
1 parent 4ca8664 commit 6bedfcc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
26 changes: 14 additions & 12 deletions packages/web-console/src/scenes/Editor/Metrics/metric.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import React, { useEffect, useState, useContext, useCallback } from "react"
import React, {
useEffect,
useState,
useContext,
useCallback,
useRef,
} from "react"
import { Metric as MetricItem } from "../../../store/buffers"
import {
MetricDuration,
Expand Down Expand Up @@ -83,8 +89,8 @@ export const Metric = ({
const { quest } = useContext(QuestContext)
const [loading, setLoading] = useState(false)
const [data, setData] = useState<uPlot.AlignedData>()
const [lastMetric, setLastMetric] = useState<MetricItem>()
const [colorPickerOpen, setColorPickerOpen] = useState(false)
const metricDurationRef = useRef(metricDuration)

const tables = useSelector(selectors.query.getTables)

Expand All @@ -95,13 +101,15 @@ export const Metric = ({

const fetchLatency = async () => {
if (!metric.tableId) return Promise.reject()
return quest.query<Latency>(latencySQL(metric.tableId, metricDuration))
return quest.query<Latency>(
latencySQL(metric.tableId, metricDurationRef.current),
)
}

const fetchRowsApplied = async () => {
if (!metric.tableId) return Promise.reject()
return quest.query<RowsApplied>(
rowsAppliedSQL(metric.tableId, metricDuration),
rowsAppliedSQL(metric.tableId, metricDurationRef.current),
)
}

Expand Down Expand Up @@ -129,17 +137,11 @@ export const Metric = ({
}

useEffect(() => {
if (!isEqual(metric, lastMetric) && metric.tableId) {
fetchMetric()
setLastMetric(metric)
}
}, [metric])

useEffect(() => {
metricDurationRef.current = metricDuration
if (metric.tableId) {
fetchMetric()
}
}, [metricDuration])
}, [metricDuration, metric.tableId])

const focusListener = useCallback(() => {
if (focusListenerRef.current) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { utcToLocal } from "./../../../utils/dateTime"
import { uniq } from "./../../../utils/uniq"
import { subMinutes } from "date-fns"
import { useContext } from "react"
Expand Down Expand Up @@ -30,10 +31,10 @@ const valuePlugin = (
const x = idx !== null && idx !== undefined ? u.data[0][idx] : null
const y = idx !== null && idx !== undefined ? u.data[1][idx] : null
if ([y, x].every(Boolean)) {
const date = new Date(x as number)
timeRef.current!.textContent = `${date.toLocaleDateString(
navigator.language,
)} ${date.toLocaleTimeString(navigator.language)}:`
timeRef.current!.textContent = utcToLocal(
x as number,
"dd/MM/yyyy HH:mm:ss",
)
valueRef.current!.textContent = yValue(y as number)
} else {
timeRef.current!.textContent = null
Expand Down
10 changes: 2 additions & 8 deletions packages/web-console/src/scenes/Editor/Metrics/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,7 @@ export const xAxisFormat = {
[MetricDuration.TWENTY_FOUR_HOURS]: (rawValue: number) =>
utcToLocal(rawValue, "HH:mm"),
[MetricDuration.THREE_DAYS]: (rawValue: number) =>
new Date(rawValue).toLocaleDateString(navigator.language, {
day: "2-digit",
month: "2-digit",
}),
utcToLocal(rawValue, "dd/MM"),
[MetricDuration.SEVEN_DAYS]: (rawValue: number) =>
new Date(rawValue).toLocaleDateString(navigator.language, {
day: "2-digit",
month: "2-digit",
}),
utcToLocal(rawValue, "dd/MM"),
}

0 comments on commit 6bedfcc

Please sign in to comment.