mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-22 12:43:32 +09:00
fix(dashboard): say the legend shows the latest sample
In the browser the legend's time still read "--" next to the latest values, and the data table repeated the same minute on every row at the one-hour range, whose step is 15 seconds. The legend's time now reads "latest" until a point is hovered, and the table shows seconds. Assisted-by: LLM Signed-off-by: ZverGuy <maximbel2003@gmail.com>
This commit is contained in:
1 parent
601c9ece3f
commit
046df7fe96
4 files changed
+14
-3
No files matched your search
+1
-1
@@ -32,6 +32,6 @@ describe("SeriesTable", () => {
|
||||
expect(rows).toHaveLength(2)
|
||||
expect(within(rows[0]).getAllByRole("cell").map((c) => c.textContent)).toEqual(["2 B", "3 B"])
|
||||
expect(within(rows[1]).getAllByRole("cell").map((c) => c.textContent)).toEqual(["1 B", "–"])
|
||||
expect(within(rows[0]).getByRole("rowheader")).toHaveTextContent(new Date(1_700_000_060_000).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }))
|
||||
expect(within(rows[0]).getByRole("rowheader")).toHaveTextContent(new Date(1_700_000_060_000).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", second: "2-digit" }))
|
||||
})
|
||||
})
|
||||
+1
-1
@@ -8,7 +8,7 @@ interface SeriesTableProps {
|
||||
}
|
||||
|
||||
const formatTime = (seconds: number) =>
|
||||
new Date(seconds * 1000).toLocaleString([], { month: "short", day: "numeric", hour: "2-digit", minute: "2-digit" })
|
||||
new Date(seconds * 1000).toLocaleString([], { month: "short", day: "numeric", hour: "2-digit", minute: "2-digit", second: "2-digit" })
|
||||
|
||||
export function SeriesTable({ id, title, data, format }: SeriesTableProps) {
|
||||
const newestFirst = data.timestamps.map((t, i) => ({ t, i })).reverse()
|
||||
|
||||
+10
@@ -13,6 +13,7 @@ vi.mock("uplot", () => ({
|
||||
created.push({ opts, data, destroy: this.destroy })
|
||||
}
|
||||
setSize() {}
|
||||
static fmtDate = () => (d: Date) => d.toISOString()
|
||||
},
|
||||
}))
|
||||
|
||||
@@ -49,6 +50,15 @@ describe("TimeSeriesChart", () => {
|
||||
expect(legend(null, null, 1, 2)).toBe("–")
|
||||
})
|
||||
|
||||
it("labels the legend's time as latest while nothing is hovered", () => {
|
||||
render(<TimeSeriesChart data={data} format={String} />)
|
||||
|
||||
const time = created[0].opts.series[0].value!
|
||||
|
||||
expect(time(null, null, 0, null)).toBe("latest")
|
||||
expect(time(null, 2, 0, 1)).toBe(new Date(2000).toISOString())
|
||||
})
|
||||
|
||||
it("destroys the chart on unmount", () => {
|
||||
const { unmount } = render(<TimeSeriesChart data={data} format={String} />)
|
||||
|
||||
|
||||
+2
-1
@@ -19,6 +19,7 @@ export function TimeSeriesChart({ data, format }: TimeSeriesChartProps) {
|
||||
if (!el) return
|
||||
const fmt = (v: number | null) => (v === null ? "–" : format(v))
|
||||
const latest = data.series.map((s) => s.values.findLast((v) => v !== null) ?? null)
|
||||
const stamp = uPlot.fmtDate("{M}/{D}/{YY} {h}:{mm}:{ss} {AA}")
|
||||
const chart = new uPlot(
|
||||
{
|
||||
width: el.clientWidth || 600,
|
||||
@@ -26,7 +27,7 @@ export function TimeSeriesChart({ data, format }: TimeSeriesChartProps) {
|
||||
scales: { x: { time: true } },
|
||||
legend: { live: true },
|
||||
series: [
|
||||
{},
|
||||
{ value: (_: uPlot, v: number | null, _sidx: number, idx: number | null) => (idx === null || v === null ? "latest" : stamp(new Date(v * 1000))) },
|
||||
...data.series.map((s, i) => ({
|
||||
label: s.label,
|
||||
stroke: COLORS[i % COLORS.length],
|
||||
|
||||
Reference in new issue
Block a user