diff --git a/web-common/src/features/dashboards/proto-state/dashboard-url-state.spec.ts b/web-common/src/features/dashboards/proto-state/dashboard-url-state.spec.ts index 9cca3fb1241..cb9a2fcfc2d 100644 --- a/web-common/src/features/dashboards/proto-state/dashboard-url-state.spec.ts +++ b/web-common/src/features/dashboards/proto-state/dashboard-url-state.spec.ts @@ -3,7 +3,6 @@ import { useDashboardDefaultProto, useDashboardUrlSync, } from "@rilldata/web-common/features/dashboards/proto-state/dashboard-url-state"; -import { getDashboardStateFromUrl } from "@rilldata/web-common/features/dashboards/proto-state/fromProto"; import { getProtoFromDashboardState } from "@rilldata/web-common/features/dashboards/proto-state/toProto"; import { metricsExplorerStore } from "@rilldata/web-common/features/dashboards/stores/dashboard-stores"; import { @@ -79,7 +78,7 @@ describe("useDashboardUrlSync", () => { beforeEach(() => { resetDashboardStore(); - pageMock.goto("/dashboard/AdBids"); + pageMock.goto(`/explore/${AD_BIDS_EXPLORE_NAME}`); pageMock.gotoSpy.mockClear(); }); @@ -222,8 +221,8 @@ type PageMock = Readable & { }; function createPageMock() { const { update, subscribe } = writable({ - url: new URL("http://localhost/dashboard/AdBids"), - params: { name: "AdBids" }, + url: new URL("http://localhost/explore/AdBids_explore"), + params: { name: "AdBids_explore" }, } as any); pageMock.subscribe = subscribe; @@ -231,12 +230,12 @@ function createPageMock() { update((page) => { if (state) { page.url = new URL( - `http://localhost/dashboard/AdBids?state=${encodeURIComponent( + `http://localhost/explore/AdBids_explore?state=${encodeURIComponent( state, )}`, ); } else { - page.url = new URL("http://localhost/dashboard/AdBids"); + page.url = new URL("http://localhost/explore/AdBids_explore"); } return page; }); diff --git a/web-common/src/features/dashboards/proto-state/sparse-proto.spec.ts b/web-common/src/features/dashboards/proto-state/sparse-proto.spec.ts index 3d2b2b6514d..8661ac2ffa6 100644 --- a/web-common/src/features/dashboards/proto-state/sparse-proto.spec.ts +++ b/web-common/src/features/dashboards/proto-state/sparse-proto.spec.ts @@ -5,7 +5,6 @@ import { AD_BIDS_EXPLORE_INIT, AD_BIDS_EXPLORE_NAME, AD_BIDS_METRICS_INIT, - AD_BIDS_NAME, AD_BIDS_SCHEMA, AD_BIDS_TIME_RANGE_SUMMARY, } from "@rilldata/web-common/features/dashboards/stores/test-data/data"; diff --git a/web-common/src/features/dashboards/state-managers/state-managers.ts b/web-common/src/features/dashboards/state-managers/state-managers.ts index 3f650cd29c5..0943cf87df7 100644 --- a/web-common/src/features/dashboards/state-managers/state-managers.ts +++ b/web-common/src/features/dashboards/state-managers/state-managers.ts @@ -96,7 +96,7 @@ export function createStateManagers({ const validSpecStore: Readable< QueryObserverResult > = derived([runtime, exploreNameStore], ([r, exploreName], set) => - useValidExplore(r.instanceId, exploreName).subscribe(set), + useValidExplore(r.instanceId, exploreName, { queryClient }).subscribe(set), ); const timeRangeSummaryStore: Readable< @@ -110,7 +110,7 @@ export function createStateManagers({ {}, { query: { - queryClient: queryClient, + queryClient, enabled: !!validSpec?.data?.metricsView?.timeDimension, }, }, diff --git a/web-common/src/features/dashboards/time-controls/time-control-store.spec.ts b/web-common/src/features/dashboards/time-controls/time-control-store.spec.ts index 7e1ceb7a70c..64409ee9650 100644 --- a/web-common/src/features/dashboards/time-controls/time-control-store.spec.ts +++ b/web-common/src/features/dashboards/time-controls/time-control-store.spec.ts @@ -365,6 +365,7 @@ describe("time-control-store", () => { "2022-04-01T00:00:00.000Z", ); + console.log("refetch"); dashboardFetchMocks.mockMetricsExplore( AD_BIDS_EXPLORE_NAME, AD_BIDS_METRICS_INIT_WITH_TIME, diff --git a/web-common/src/features/explores/selectors.ts b/web-common/src/features/explores/selectors.ts index 45a10c6ba29..7bbe3f4889c 100644 --- a/web-common/src/features/explores/selectors.ts +++ b/web-common/src/features/explores/selectors.ts @@ -5,6 +5,7 @@ import { RpcStatus, V1ExploreSpec, V1GetExploreResponse, + V1GetResourceResponse, type V1MetricsViewSpec, } from "@rilldata/web-common/runtime-client"; import { ErrorType } from "@rilldata/web-common/runtime-client/http-client"; @@ -31,19 +32,35 @@ export type ValidExploreResponse = { explore: V1ExploreSpec | undefined; metricsView: V1MetricsViewSpec | undefined; }; -export function useValidExplore(instanceId: string, exploreName: string) { +export function useValidExplore( + instanceId: string, + exploreName: string, + queryOptions?: CreateQueryOptions< + V1GetExploreResponse, + ErrorType, + ValidExploreResponse + >, +) { + const defaultQueryOptions: CreateQueryOptions< + V1GetExploreResponse, + ErrorType, + ValidExploreResponse + > = { + select: (data) => + { + explore: data.explore?.explore?.state?.validSpec, + metricsView: data.metricsView?.metricsView?.state?.validSpec, + }, + queryClient, + enabled: !!exploreName, + }; return createRuntimeServiceGetExplore( instanceId, { name: exploreName }, { query: { - select: (data) => - { - explore: data.explore?.explore?.state?.validSpec, - metricsView: data.metricsView?.metricsView?.state?.validSpec, - }, - queryClient, - enabled: !!exploreName, + ...defaultQueryOptions, + ...queryOptions, }, }, );