fix(dashboard): suggest a longer metrics range only when there is one

With the longest range already picked, the empty panel still told the
reader to try a longer range, which the picker cannot offer.

Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
This commit is contained in:
ZverGuy committed 2026-11-04 18:56:01 +07:00
1 parent 554dad87bb
commit c9a15cb8ae
2 files changed
+15 -2

No files matched your search

@@ -87,6 +87,17 @@ describe("MetricsView", () => {
for (const status of screen.getAllByRole("status")) expect(status).toHaveClass("h-[230px]")
})
it("suggests a longer range only while one exists", async () => {
const { client } = clientWith(() => Response.json({ status: "success", data: { resultType: "matrix", result: [] } }))
renderWithK8sProvider(<MetricsView scope={scope} />, { client })
await waitFor(() => expect(screen.getAllByText("Try a longer range.")).toHaveLength(3))
await userEvent.click(screen.getByRole("button", { name: "7d" }))
await waitFor(() => expect(screen.getAllByText("No data for this range.")).toHaveLength(3))
expect(screen.queryByText("Try a longer range.")).toBeNull()
})
it("holds each chart's place while it loads", () => {
const { client } = clientWith(() => new Promise<Response>(() => {}))
@@ -23,6 +23,8 @@ export function MetricsView({ scope }: { scope: ObservabilityScope }) {
const client = useK8sClient()
const root = metricsRoot(scope)
const [range, setRange] = useState<RangeKey>("1h")
const rangeKeys = Object.keys(RANGES) as RangeKey[]
const longestRange = range === rangeKeys[rangeKeys.length - 1]
const results = useQueries({
queries: METRIC_PANELS.map((panel) => ({
@@ -48,7 +50,7 @@ export function MetricsView({ scope }: { scope: ObservabilityScope }) {
<div className="space-y-4 p-6">
<div className="flex items-center justify-between">
<h2 className="text-sm font-semibold text-slate-900">Resource consumption</h2>
<RangePicker options={Object.keys(RANGES) as RangeKey[]} value={range} onChange={setRange} />
<RangePicker options={rangeKeys} value={range} onChange={setRange} />
</div>
{wide ? (
<ProxyNotice what="Metrics" error={wide} />
@@ -62,7 +64,7 @@ export function MetricsView({ scope }: { scope: ObservabilityScope }) {
) : isLoading || !data ? (
<EmptyState busy title="Loading…" className={CHART_SLOT} />
) : data.series.length === 0 ? (
<EmptyState title="No data for this range." hint="Try a longer range." className={CHART_SLOT} />
<EmptyState title="No data for this range." hint={longestRange ? undefined : "Try a longer range."} className={CHART_SLOT} />
) : (
<TimeSeriesChart data={data} format={panel.format} />
)}