diff --git a/web-local/src/routes/(viz)/explore/[name]/+layout.ts b/web-local/src/routes/(viz)/explore/[name]/+layout.ts index f391f8a192e..2e68e233ef4 100644 --- a/web-local/src/routes/(viz)/explore/[name]/+layout.ts +++ b/web-local/src/routes/(viz)/explore/[name]/+layout.ts @@ -1,3 +1,4 @@ +import { getUpdatedUrlForExploreState } from "@rilldata/web-common/features/dashboards/url-state/getUpdatedUrlForExploreState"; import { fetchExploreSpec } from "@rilldata/web-common/features/explores/selectors"; import { runtime } from "@rilldata/web-common/runtime-client/runtime-store"; import { error } from "@sveltejs/kit"; @@ -11,13 +12,28 @@ export const load = async ({ params, depends }) => { depends(exploreName, "explore"); try { - const { explore, metricsView, defaultExplorePreset } = - await fetchExploreSpec(instanceId, exploreName); + const { + explore, + metricsView, + defaultExplorePreset, + initExploreState, + initLoadedOutsideOfURL, + } = await fetchExploreSpec(instanceId, exploreName); + const initUrlSearch = initLoadedOutsideOfURL + ? getUpdatedUrlForExploreState( + explore.explore?.state?.validSpec ?? {}, + defaultExplorePreset, + initExploreState, + new URLSearchParams(), + ) + : ""; return { explore, metricsView, defaultExplorePreset, + initExploreState, + initUrlSearch, }; } catch (e) { console.error(e); diff --git a/web-local/src/routes/(viz)/explore/[name]/+page.svelte b/web-local/src/routes/(viz)/explore/[name]/+page.svelte index 03a70bca552..7a8e2cd6f3d 100644 --- a/web-local/src/routes/(viz)/explore/[name]/+page.svelte +++ b/web-local/src/routes/(viz)/explore/[name]/+page.svelte @@ -18,9 +18,12 @@ metricsView, explore, defaultExplorePreset, + initExploreState, + initUrlSearch, partialExploreState, - loaded, + urlSearchForPartial, errors, + exploreName, } = data); $: if (errors?.length) { setTimeout(() => { @@ -36,7 +39,6 @@ resetSelectedMockUserAfterNavigate(queryClient); - $: exploreName = explore.meta?.name?.name as string; $: metricsViewName = metricsView?.meta?.name?.name as string; $: ({ instanceId } = $runtime); @@ -85,9 +87,13 @@ {#key exploreName} diff --git a/web-local/src/routes/(viz)/explore/[name]/+page.ts b/web-local/src/routes/(viz)/explore/[name]/+page.ts index d8b02962669..bd8003db3e6 100644 --- a/web-local/src/routes/(viz)/explore/[name]/+page.ts +++ b/web-local/src/routes/(viz)/explore/[name]/+page.ts @@ -1,4 +1,5 @@ import { convertURLToExploreState } from "@rilldata/web-common/features/dashboards/url-state/convertPresetToExploreState"; +import { getUpdatedUrlForExploreState } from "@rilldata/web-common/features/dashboards/url-state/getUpdatedUrlForExploreState"; export const load = async ({ url, parent, params }) => { const { explore, metricsView, defaultExplorePreset } = await parent(); @@ -6,18 +7,28 @@ export const load = async ({ url, parent, params }) => { const metricsViewSpec = metricsView.metricsView?.state?.validSpec; const exploreSpec = explore.explore?.state?.validSpec; - const { partialExploreState, loaded, errors } = convertURLToExploreState( - exploreName, - undefined, - url.searchParams, - metricsViewSpec, - exploreSpec, - defaultExplorePreset, - ); + const { partialExploreState, loadedOutsideOfURL, errors } = + convertURLToExploreState( + exploreName, + undefined, + url.searchParams, + metricsViewSpec, + exploreSpec, + defaultExplorePreset, + ); + const urlSearchForPartial = loadedOutsideOfURL + ? getUpdatedUrlForExploreState( + exploreSpec, + defaultExplorePreset, + partialExploreState, + url.searchParams, + ) + : url.searchParams.toString(); return { partialExploreState, - loaded, + urlSearchForPartial, errors, + exploreName, }; };