From 273a675338b8bf3f696f42ade7320a98de0ac364 Mon Sep 17 00:00:00 2001 From: Aditya Hegde Date: Mon, 16 Dec 2024 22:37:01 +0530 Subject: [PATCH] Add schema requests --- .../BookmarksDropdownMenuContent.svelte | 7 +++- .../[project]/-/share/[token]/+layout.ts | 11 +++++-- .../[project]/explore/[dashboard]/+layout.ts | 33 ++++++++++++++----- .../url-state/DashboardURLStateSync.svelte | 5 ++- web-common/src/features/explores/selectors.ts | 16 +++++++++ 5 files changed, 59 insertions(+), 13 deletions(-) diff --git a/web-admin/src/features/bookmarks/BookmarksDropdownMenuContent.svelte b/web-admin/src/features/bookmarks/BookmarksDropdownMenuContent.svelte index 660e7e26ccd..e0cfbe739a5 100644 --- a/web-admin/src/features/bookmarks/BookmarksDropdownMenuContent.svelte +++ b/web-admin/src/features/bookmarks/BookmarksDropdownMenuContent.svelte @@ -27,6 +27,7 @@ import { getDefaultExplorePreset } from "@rilldata/web-common/features/dashboards/url-state/getDefaultExplorePreset"; import { ResourceKind } from "@rilldata/web-common/features/entity-management/resource-selectors"; import { useExploreValidSpec } from "@rilldata/web-common/features/explores/selectors"; + import { createQueryServiceMetricsViewSchema } from "@rilldata/web-common/runtime-client"; import { runtime } from "@rilldata/web-common/runtime-client/runtime-store"; import { BookmarkPlusIcon } from "lucide-svelte"; import { createEventDispatcher } from "svelte"; @@ -51,6 +52,10 @@ exploreSpec, $metricsViewTimeRange.data, ); + $: schemaResp = createQueryServiceMetricsViewSchema( + $runtime.instanceId, + metricsViewName, + ); $: projectIdResp = useProjectId(organization, project); const userResp = createAdminServiceGetCurrentUser(); @@ -72,7 +77,7 @@ $bookamrksResp.data?.bookmarks ?? [], metricsViewSpec, exploreSpec, - {}, + $schemaResp.data?.schema, $exploreState, defaultExplorePreset, ); diff --git a/web-admin/src/routes/[organization]/[project]/-/share/[token]/+layout.ts b/web-admin/src/routes/[organization]/[project]/-/share/[token]/+layout.ts index b4039b4974b..d350f688cca 100644 --- a/web-admin/src/routes/[organization]/[project]/-/share/[token]/+layout.ts +++ b/web-admin/src/routes/[organization]/[project]/-/share/[token]/+layout.ts @@ -1,7 +1,10 @@ import { fetchMagicAuthToken } from "@rilldata/web-admin/features/projects/selectors"; import { getDashboardStateFromUrl } from "@rilldata/web-common/features/dashboards/proto-state/fromProto"; import type { MetricsExplorerEntity } from "@rilldata/web-common/features/dashboards/stores/metrics-explorer-entity"; -import { fetchExploreSpec } from "@rilldata/web-common/features/explores/selectors"; +import { + fetchExploreSpec, + fetchMetricsViewSchema, +} from "@rilldata/web-common/features/explores/selectors"; import { error } from "@sveltejs/kit"; export const load = async ({ params: { token }, parent }) => { @@ -28,11 +31,15 @@ export const load = async ({ params: { token }, parent }) => { let tokenExploreState: Partial | undefined = undefined; if (tokenData.token?.state) { + const schema = await fetchMetricsViewSchema( + runtime?.instanceId, + exploreSpec.metricsView ?? "", + ); tokenExploreState = getDashboardStateFromUrl( tokenData.token?.state, metricsViewSpec, exploreSpec, - {}, // TODO + schema, ); } diff --git a/web-admin/src/routes/[organization]/[project]/explore/[dashboard]/+layout.ts b/web-admin/src/routes/[organization]/[project]/explore/[dashboard]/+layout.ts index fa148958cb6..b905022109c 100644 --- a/web-admin/src/routes/[organization]/[project]/explore/[dashboard]/+layout.ts +++ b/web-admin/src/routes/[organization]/[project]/explore/[dashboard]/+layout.ts @@ -1,10 +1,14 @@ +import type { V1Bookmark } from "@rilldata/web-admin/client"; import { fetchBookmarks, isHomeBookmark, } from "@rilldata/web-admin/features/bookmarks/selectors"; import { getDashboardStateFromUrl } from "@rilldata/web-common/features/dashboards/proto-state/fromProto"; import type { MetricsExplorerEntity } from "@rilldata/web-common/features/dashboards/stores/metrics-explorer-entity"; -import { fetchExploreSpec } from "@rilldata/web-common/features/explores/selectors"; +import { + fetchExploreSpec, + fetchMetricsViewSchema, +} from "@rilldata/web-common/features/explores/selectors"; import { type V1ExplorePreset, type V1Resource, @@ -21,13 +25,21 @@ export const load = async ({ params, depends, parent }) => { let metricsView: V1Resource | undefined; let defaultExplorePreset: V1ExplorePreset | undefined; let exploreStateFromYAMLConfig: Partial = {}; + let bookmarks: V1Bookmark[] | undefined; + try { - ({ - explore, - metricsView, - defaultExplorePreset, - exploreStateFromYAMLConfig, - } = await fetchExploreSpec(runtime?.instanceId, exploreName)); + [ + { + explore, + metricsView, + defaultExplorePreset, + exploreStateFromYAMLConfig, + }, + bookmarks, + ] = await Promise.all([ + fetchExploreSpec(runtime?.instanceId, exploreName), + fetchBookmarks(project.id, exploreName), + ]); } catch { // error handled in +page.svelte for now // TODO: move it here @@ -45,15 +57,18 @@ export const load = async ({ params, depends, parent }) => { let homeBookmarkExploreState: Partial | undefined = undefined; try { - const bookmarks = await fetchBookmarks(project.id, exploreName); const homeBookmark = bookmarks.find(isHomeBookmark); + const schema = await fetchMetricsViewSchema( + runtime?.instanceId, + exploreSpec.metricsView ?? "", + ); if (homeBookmark) { homeBookmarkExploreState = getDashboardStateFromUrl( homeBookmark.data ?? "", metricsViewSpec, exploreSpec, - {}, // TODO + schema, ); } } catch { diff --git a/web-common/src/features/dashboards/url-state/DashboardURLStateSync.svelte b/web-common/src/features/dashboards/url-state/DashboardURLStateSync.svelte index 327eb6a5f3b..fd3abb51220 100644 --- a/web-common/src/features/dashboards/url-state/DashboardURLStateSync.svelte +++ b/web-common/src/features/dashboards/url-state/DashboardURLStateSync.svelte @@ -55,7 +55,10 @@ const isInit = !$dashboardStore; if (isInit) { - handleExploreInit(type === "enter"); + // When a user changes url manually and clears the params the `type` will be "enter" + // This signal is used in handleExploreInit to make sure we do not use sessionStorage + const isManualUrlChange = type === "enter"; + handleExploreInit(isManualUrlChange); return; } diff --git a/web-common/src/features/explores/selectors.ts b/web-common/src/features/explores/selectors.ts index 67fdd1cf5b6..7f942f1d9f2 100644 --- a/web-common/src/features/explores/selectors.ts +++ b/web-common/src/features/explores/selectors.ts @@ -19,6 +19,8 @@ import { type V1MetricsViewSpec, type V1MetricsViewTimeRangeResponse, type V1ExplorePreset, + getQueryServiceMetricsViewSchemaQueryKey, + queryServiceMetricsViewSchema, } from "@rilldata/web-common/runtime-client"; import type { ErrorType } from "@rilldata/web-common/runtime-client/http-client"; import { error } from "@sveltejs/kit"; @@ -147,6 +149,20 @@ export async function fetchExploreSpec( }; } +export async function fetchMetricsViewSchema( + instanceId: string, + metricsViewName: string, +) { + const schemaResp = await queryClient.fetchQuery({ + queryKey: getQueryServiceMetricsViewSchemaQueryKey( + instanceId, + metricsViewName, + ), + queryFn: () => queryServiceMetricsViewSchema(instanceId, metricsViewName), + }); + return schemaResp.schema ?? {}; +} + export function getExploreStores( exploreName: string, prefix: string | undefined,