mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-22 12:43:32 +09:00
fix(dashboard): hold each metrics chart's place while empty or loading
A metrics panel with no series, or still loading, shrank to one line of small text or a bare spinner, so the tab jumped by the chart's height when data arrived and an empty range looked like a broken panel. Both states now fill the chart's slot and say what is going on, the same way the log console does. Assisted-by: LLM Signed-off-by: ZverGuy <maximbel2003@gmail.com>
This commit is contained in:
1 parent
f5ebb43c4b
commit
05b0ea0c45
2 files changed
+21
-4
No files matched your search
+15
-1
@@ -22,7 +22,7 @@ function matrix(pod: string) {
|
||||
})
|
||||
}
|
||||
|
||||
function clientWith(handler: (url: URL) => Response) {
|
||||
function clientWith(handler: (url: URL) => Response | Promise<Response>) {
|
||||
const client = new K8sClient()
|
||||
const raw = vi.spyOn(client, "raw").mockImplementation(async (path) => handler(new URL(path, "http://x")))
|
||||
return { client, raw }
|
||||
@@ -84,5 +84,19 @@ describe("MetricsView", () => {
|
||||
renderWithK8sProvider(<MetricsView scope={scope} />, { client })
|
||||
|
||||
await waitFor(() => expect(screen.getAllByText("No data for this range.")).toHaveLength(3))
|
||||
for (const status of screen.getAllByRole("status")) expect(status).toHaveClass("h-[230px]")
|
||||
})
|
||||
|
||||
it("holds each chart's place while it loads", () => {
|
||||
const { client } = clientWith(() => new Promise<Response>(() => {}))
|
||||
|
||||
renderWithK8sProvider(<MetricsView scope={scope} />, { client })
|
||||
|
||||
const statuses = screen.getAllByRole("status")
|
||||
expect(statuses).toHaveLength(3)
|
||||
for (const status of statuses) {
|
||||
expect(status).toHaveAttribute("aria-busy", "true")
|
||||
expect(status).toHaveClass("h-[230px]")
|
||||
}
|
||||
})
|
||||
})
|
||||
+6
-3
@@ -1,7 +1,7 @@
|
||||
import { useState } from "react"
|
||||
import { useQueries } from "@tanstack/react-query"
|
||||
import { useK8sClient } from "@cozystack/k8s-client"
|
||||
import { Section, Spinner } from "@cozystack/ui"
|
||||
import { Section } from "@cozystack/ui"
|
||||
import {
|
||||
METRIC_PANELS,
|
||||
RANGES,
|
||||
@@ -13,8 +13,11 @@ import { isScopeWide, metricsRoot, queryRange, type ObservabilityScope } from ".
|
||||
import { ProxyNotice } from "./ProxyNotice.tsx"
|
||||
import { TimeSeriesChart } from "./TimeSeriesChart.tsx"
|
||||
import { RangePicker } from "./RangePicker.tsx"
|
||||
import { EmptyState } from "./EmptyState.tsx"
|
||||
|
||||
const REFRESH_MS = 60_000
|
||||
// The uPlot canvas plus its one-row legend, so a placeholder takes the chart's place without a jump.
|
||||
const CHART_SLOT = "h-[230px] rounded-md border border-dashed border-slate-200 bg-slate-50"
|
||||
|
||||
export function MetricsView({ scope }: { scope: ObservabilityScope }) {
|
||||
const client = useK8sClient()
|
||||
@@ -57,9 +60,9 @@ export function MetricsView({ scope }: { scope: ObservabilityScope }) {
|
||||
{error ? (
|
||||
<ProxyNotice what="Metrics" error={error} />
|
||||
) : isLoading || !data ? (
|
||||
<Spinner />
|
||||
<EmptyState busy title="Loading…" className={CHART_SLOT} />
|
||||
) : data.series.length === 0 ? (
|
||||
<p className="text-sm text-slate-500">No data for this range.</p>
|
||||
<EmptyState title="No data for this range." hint="Nothing was recorded in the selected range." className={CHART_SLOT} />
|
||||
) : (
|
||||
<TimeSeriesChart data={data} format={panel.format} />
|
||||
)}
|
||||
|
||||
Reference in new issue
Block a user