Skip to content

Commit

Permalink
Fix missing home bookmark while siwtching using breadcrumbs
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaHegde committed Dec 13, 2024
1 parent c9b0fe9 commit 9cafbd1
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<DashboardURLStateSync
metricsViewName={explore.metricsView.meta.name.name}
exploreName={resourceName}
extraKeyPrefix={`${organization}__${project}__`}
{defaultExplorePreset}
{initExploreState}
{exploreStateFromYAMLConfig}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { afterNavigate, onNavigate } from "$app/navigation";
import { onNavigate } from "$app/navigation";
import { page } from "$app/stores";
import DashboardBuilding from "@rilldata/web-admin/features/dashboards/DashboardBuilding.svelte";
import DashboardErrored from "@rilldata/web-admin/features/dashboards/DashboardErrored.svelte";
Expand All @@ -12,7 +12,6 @@
import { useExplore } from "@rilldata/web-common/features/explores/selectors";
import { eventBus } from "@rilldata/web-common/lib/event-bus/event-bus";
import { runtime } from "@rilldata/web-common/runtime-client/runtime-store";
import type { AfterNavigate } from "@sveltejs/kit";
import type { PageData } from "./$types";
const PollIntervalWhenDashboardFirstReconciling = 1000;
Expand Down Expand Up @@ -83,12 +82,6 @@
});
}
let previousNavigationType: AfterNavigate["type"];
afterNavigate(({ from, type }) => {
if (from !== null && !from.url) return;
previousNavigationType = type;
});
onNavigate(() => {
// Temporary: clear the mocked user when navigating away.
// In the future, we should be able to handle the mocked user on all project pages.
Expand All @@ -112,12 +105,12 @@
<DashboardURLStateSync
{metricsViewName}
{exploreName}
extraKeyPrefix={`${orgName}__${projectName}__`}
{defaultExplorePreset}
{initExploreState}
{exploreStateFromYAMLConfig}
{partialExploreStateFromUrl}
{exploreStateFromSessionStorage}
{previousNavigationType}
>
<DashboardThemeProvider>
<Dashboard {metricsViewName} {exploreName} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { page } from "$app/stores";
import { onMount, setContext } from "svelte";
import { setContext } from "svelte";
import { useQueryClient } from "@tanstack/svelte-query";
import { createStateManagers, DEFAULT_STORE_KEY } from "./state-managers";
Expand All @@ -21,8 +21,6 @@
});
setContext(DEFAULT_STORE_KEY, stateManagers);
onMount(() => () => stateManagers.cleanup());
// Our state management was not built around the ability to arbitrarily change the explore or metrics view name
// This needs to change, but this is a workaround for now
$: if (visualEditing) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
contextColWidthDefaults,
} from "@rilldata/web-common/features/dashboards/stores/metrics-explorer-entity";
import { createPersistentDashboardStore } from "@rilldata/web-common/features/dashboards/stores/persistent-dashboard-state";
import { updateExploreSessionStore } from "@rilldata/web-common/features/dashboards/url-state/explore-web-view-store";
import { getDefaultExplorePreset } from "@rilldata/web-common/features/dashboards/url-state/getDefaultExplorePreset";
import { initLocalUserPreferenceStore } from "@rilldata/web-common/features/dashboards/user-preferences";
import {
Expand Down Expand Up @@ -71,8 +70,6 @@ export type StateManagers = {
*/
contextColumnWidths: Writable<ContextColWidths>;
defaultExploreState: Readable<V1ExplorePreset>;

cleanup: () => void;
};

export const DEFAULT_STORE_KEY = Symbol("state-managers");
Expand Down Expand Up @@ -155,17 +152,6 @@ export function createStateManagers({
);
},
);
const unsub = dashboardStore.subscribe((dashState) => {
const exploreState = get(validSpecStore).data?.explore;
if (!dashState || !exploreState || dashState.name !== get(exploreNameStore))
return;
updateExploreSessionStore(
get(exploreNameStore),
extraKeyPrefix,
dashState,
exploreState,
);
});

const persistentDashboardStore = createPersistentDashboardStore(
(extraKeyPrefix || "") + exploreName,
Expand Down Expand Up @@ -201,9 +187,5 @@ export function createStateManagers({
}),
contextColumnWidths,
defaultExploreState,

cleanup: () => {
unsub();
},
};
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
<script lang="ts">
import { afterNavigate, goto } from "$app/navigation";
import { afterNavigate, goto, replaceState } from "$app/navigation";
import { page } from "$app/stores";
import ErrorPage from "@rilldata/web-common/components/ErrorPage.svelte";
import { getStateManagers } from "@rilldata/web-common/features/dashboards/state-managers/state-managers";
import { metricsExplorerStore } from "@rilldata/web-common/features/dashboards/stores/dashboard-stores";
import type { MetricsExplorerEntity } from "@rilldata/web-common/features/dashboards/stores/metrics-explorer-entity";
import { convertExploreStateToURLSearchParams } from "@rilldata/web-common/features/dashboards/url-state/convertExploreStateToURLSearchParams";
import { updateExploreSessionStore } from "@rilldata/web-common/features/dashboards/url-state/explore-web-view-store";
import { getUpdatedUrlForExploreState } from "@rilldata/web-common/features/dashboards/url-state/getUpdatedUrlForExploreState";
import {
createQueryServiceMetricsViewSchema,
type V1ExplorePreset,
} from "@rilldata/web-common/runtime-client";
import type { HTTPError } from "@rilldata/web-common/runtime-client/fetchWrapper";
import { runtime } from "@rilldata/web-common/runtime-client/runtime-store";
import type { AfterNavigate } from "@sveltejs/kit";
import { onMount } from "svelte";
export let metricsViewName: string;
export let exploreName: string;
export let extraKeyPrefix: string | undefined = undefined;
export let defaultExplorePreset: V1ExplorePreset;
export let exploreStateFromYAMLConfig: Partial<MetricsExplorerEntity>;
export let initExploreState: Partial<MetricsExplorerEntity> | undefined =
Expand All @@ -26,7 +27,6 @@
export let exploreStateFromSessionStorage:
| Partial<MetricsExplorerEntity>
| undefined;
export let previousNavigationType: AfterNavigate["type"];
const { dashboardStore, validSpecStore, timeRangeSummaryStore } =
getStateManagers();
Expand All @@ -46,9 +46,9 @@
// null checks
!metricsSpec ||
!exploreSpec ||
!to ||
// seems like a sveltekit bug where an additional afterNavigate is triggered with invalid fields
(from !== null && !from.url) ||
!to
(from !== null && !from.url)
) {
return;
}
Expand All @@ -61,7 +61,7 @@
let partialExplore = partialExploreStateFromUrl;
let shouldUpdateUrl = false;
if (exploreStateFromSessionStorage && type !== "popstate") {
if (exploreStateFromSessionStorage) {
partialExplore = exploreStateFromSessionStorage;
shouldUpdateUrl = true;
}
Expand All @@ -80,14 +80,11 @@
);
prevUrl = redirectUrl.toString();
if (!shouldUpdateUrl || redirectUrl.search === $page.url.search) {
if (!shouldUpdateUrl || redirectUrl.search === to.url.toString()) {
return;
}
void goto(redirectUrl, {
replaceState: true,
state: $page.state,
});
replaceState(redirectUrl, $page.state);
});
let prevUrl = "";
Expand Down Expand Up @@ -130,10 +127,13 @@
return;
}
void goto(redirectUrl, {
replaceState: true,
state: $page.state,
});
replaceState(redirectUrl, $page.state);
updateExploreSessionStore(
exploreName,
extraKeyPrefix,
$dashboardStore,
exploreSpec!,
);
}
function gotoNewState() {
Expand All @@ -148,9 +148,15 @@
defaultExplorePreset,
);
const newUrl = u.toString();
if (prevUrl !== newUrl) {
void goto(newUrl);
}
if (!prevUrl || prevUrl === newUrl) return;
void goto(newUrl);
updateExploreSessionStore(
exploreName,
extraKeyPrefix,
$dashboardStore,
exploreSpec,
);
}
// reactive to only dashboardStore
Expand All @@ -160,10 +166,11 @@
}
onMount(() => {
// safeguard to make sure we initialize the explore state in case afterNavigate is missed
if (!$dashboardStore) {
handleExploreInit(previousNavigationType === "enter");
}
setTimeout(() => {
if (!$dashboardStore) {
handleExploreInit(true);
}
});
});
</script>

Expand Down

0 comments on commit 9cafbd1

Please sign in to comment.