-
Notifications
You must be signed in to change notification settings - Fork 201
fix: show aggregation errors in Chart.svelte instead of an infinite spinner
#9838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import Chart from "@rilldata/web-common/features/components/charts/Chart.svelte"; | ||
| import type { ChartDataResult } from "@rilldata/web-common/features/components/charts"; | ||
| import { render } from "@testing-library/svelte"; | ||
| import chroma from "chroma-js"; | ||
| import { readable } from "svelte/store"; | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| const measure = { name: "operation_jx_cnt", displayName: "JX count" }; | ||
|
|
||
| function chartData(partial: Partial<ChartDataResult>): ChartDataResult { | ||
| return { | ||
| data: [], | ||
| isFetching: false, | ||
| fields: {}, | ||
| isDarkMode: false, | ||
| hasComparison: false, | ||
| theme: { | ||
| primary: chroma("#1d4ed8"), | ||
| secondary: chroma("#7c3aed"), | ||
| }, | ||
| ...partial, | ||
| }; | ||
| } | ||
|
|
||
| const chartSpec = { | ||
| metrics_view: "ncar_jx_detail_metrics", | ||
| x: { field: "cal_date", type: "temporal" as const }, | ||
| y: { field: "operation_jx_cnt", type: "quantitative" as const }, | ||
| }; | ||
|
|
||
| function renderChart(data: ChartDataResult, measures = [measure]) { | ||
| return render(Chart, { | ||
| props: { | ||
| chartType: "line_chart", | ||
| chartSpec, | ||
| chartData: readable(data), | ||
| measures, | ||
| isCanvas: false, | ||
| view: undefined, | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| describe("Chart loading and error states", () => { | ||
| it("shows the query error instead of the spinner", () => { | ||
| const { container, queryByText } = renderChart( | ||
| chartData({ | ||
| isFetching: true, | ||
| error: new Error("time range has too many bins"), | ||
| }), | ||
| ); | ||
|
|
||
| expect(queryByText("time range has too many bins")).toBeInTheDocument(); | ||
| expect(container.querySelector(".status")).toBeNull(); | ||
| }); | ||
|
|
||
| it("shows the spinner while fetching without an error", () => { | ||
| const { container, queryByText } = renderChart( | ||
| chartData({ isFetching: true }), | ||
| ); | ||
|
|
||
| expect(container.querySelector(".status")).not.toBeNull(); | ||
| expect(queryByText("No Data to Display")).toBeNull(); | ||
| }); | ||
|
|
||
| it("shows an empty state when the query resolves with no rows", () => { | ||
| const { container, queryByText } = renderChart( | ||
| chartData({ isFetching: false, data: [] }), | ||
| ); | ||
|
|
||
| expect(queryByText("No Data to Display")).toBeInTheDocument(); | ||
| expect(container.querySelector(".status")).toBeNull(); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,40 @@ Object.defineProperty(window, "scrollTo", { | |
| value: vi.fn(), | ||
| }); | ||
|
|
||
| // Node 22+ exposes a global `localStorage` that is undefined unless | ||
| // --localstorage-file is set. Theme and other stores read the global at | ||
| // import time, so pin it to a memory-backed mock for jsdom tests. | ||
| if ( | ||
| typeof globalThis.localStorage === "undefined" || | ||
| typeof globalThis.localStorage?.getItem !== "function" | ||
| ) { | ||
| const memory = new Map<string, string>(); | ||
| const localStorageMock: Storage = { | ||
| get length() { | ||
| return memory.size; | ||
| }, | ||
| clear: () => memory.clear(), | ||
| getItem: (key: string) => memory.get(key) ?? null, | ||
| key: (index: number) => [...memory.keys()][index] ?? null, | ||
| removeItem: (key: string) => { | ||
| memory.delete(key); | ||
| }, | ||
| setItem: (key: string, value: string) => { | ||
| memory.set(key, value); | ||
| }, | ||
| }; | ||
| Object.defineProperty(globalThis, "localStorage", { | ||
| configurable: true, | ||
| writable: true, | ||
| value: localStorageMock, | ||
| }); | ||
| Object.defineProperty(window, "localStorage", { | ||
| configurable: true, | ||
| writable: true, | ||
| value: localStorageMock, | ||
| }); | ||
| } | ||
|
Comment on lines
+25
to
+57
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shim is unrelated to the branch reorder and is inert on the pinned toolchain: |
||
|
|
||
| Settings.defaultWeekSettings = { | ||
| minimalDays: 4, | ||
| firstDay: 1, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every case here passes
measures = [measure], so themeasures.length === 0half of the loading branch, which is what actually kept the chart spinning, is never exercised. With a non-emptymeasuresthe old{:else if error}branch was already reachable: the query client only retries network errors (web-common/src/lib/svelte-query/globalQueryClient.ts:13-14), so a failed aggregation settles withisFetching: falseanderrorset. The regression to pin ischartData({ isFetching: false, error })withmeasures: [], which is the state of a chart pointed at a missing or invalid metrics view, sincegetMeasuresForMetricViewreturns[]whenever there is novalidSpec(web-common/src/features/metrics-views/metrics-view-selectors.ts:100-105). The existingisFetching: truepluserrorcase only covers refetch-after-failure.