Skip to content

Commit 861385c

Browse files
committed
Disable local storage in emebd (#7382)
1 parent 48e328c commit 861385c

File tree

5 files changed

+60
-23
lines changed

5 files changed

+60
-23
lines changed

web-admin/src/features/embeds/ExploreEmbed.svelte

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
<script context="module">
2+
export let EmbedStorageNamespacePrefix = "__rill_embed";
3+
</script>
4+
15
<script lang="ts">
26
import { Dashboard } from "@rilldata/web-common/features/dashboards";
37
import DashboardThemeProvider from "@rilldata/web-common/features/dashboards/DashboardThemeProvider.svelte";
@@ -38,7 +42,11 @@
3842
{:else if data}
3943
{#key exploreName}
4044
<StateManagersProvider {exploreName} {metricsViewName}>
41-
<DashboardStateManager {exploreName}>
45+
<DashboardStateManager
46+
{exploreName}
47+
storageNamespacePrefix={EmbedStorageNamespacePrefix}
48+
disableMostRecentDashboardState
49+
>
4250
<DashboardThemeProvider>
4351
<Dashboard {exploreName} {metricsViewName} isEmbedded />
4452
</DashboardThemeProvider>

web-admin/src/routes/-/embed/+page.svelte

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
import ContentContainer from "@rilldata/web-admin/components/layout/ContentContainer.svelte";
55
import DashboardsTable from "@rilldata/web-admin/features/dashboards/listing/DashboardsTable.svelte";
66
import CanvasEmbed from "@rilldata/web-admin/features/embeds/CanvasEmbed.svelte";
7-
import ExploreEmbed from "@rilldata/web-admin/features/embeds/ExploreEmbed.svelte";
7+
import ExploreEmbed, {
8+
EmbedStorageNamespacePrefix,
9+
} from "@rilldata/web-admin/features/embeds/ExploreEmbed.svelte";
810
import TopNavigationBarEmbed from "@rilldata/web-admin/features/embeds/TopNavigationBarEmbed.svelte";
911
import UnsupportedKind from "@rilldata/web-admin/features/embeds/UnsupportedKind.svelte";
12+
import { clearExploreSessionStore } from "@rilldata/web-common/features/dashboards/state-managers/loaders/explore-web-view-store";
1013
import { ResourceKind } from "@rilldata/web-common/features/entity-management/resource-selectors";
1114
import { featureFlags } from "@rilldata/web-common/features/feature-flags";
1215
import type { V1ResourceName } from "@rilldata/web-common/runtime-client";
@@ -27,6 +30,7 @@
2730
// Manage active resource
2831
let activeResource: V1ResourceName | null = null;
2932
$: if (resourceName && resourceType) {
33+
cleanSessionStorageForResource(resourceType, resourceName);
3034
activeResource = {
3135
name: resourceName,
3236
kind: resourceType,
@@ -39,6 +43,18 @@
3943
// TODO: move to a route based approach to avoid this issues.
4044
}
4145
46+
const resourcesSeen = new Set<string>();
47+
// Clean session storage for dashboards that are navigated to for the 1st time.
48+
// This way once the page is loaded, the dashboard state is persisted.
49+
// But the moment the user moves away to another page within the parent page, then it will be cleared next time the user comes back to the dashboard.
50+
function cleanSessionStorageForResource(type: string, name: string) {
51+
if (type !== ResourceKind.Explore.toString()) return;
52+
53+
if (resourcesSeen.has(name)) return;
54+
clearExploreSessionStore(name, EmbedStorageNamespacePrefix);
55+
resourcesSeen.add(name);
56+
}
57+
4258
function handleSelectResource(event: CustomEvent<V1ResourceName>) {
4359
const newUrl = new URL($page.url);
4460
newUrl.search = `resource=${event.detail.name}&type=${event.detail.kind}`;

web-common/src/features/dashboards/state-managers/loaders/DashboardStateDataLoader.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ export class DashboardStateDataLoader {
5858
instanceId: string,
5959
private readonly exploreName: string,
6060
private readonly storageNamespacePrefix: string | undefined,
61-
private readonly bookmarkOrTokenExploreState?: CompoundQueryResult<Partial<ExploreState> | null>,
61+
private readonly bookmarkOrTokenExploreState:
62+
| CompoundQueryResult<Partial<ExploreState> | null>
63+
| undefined,
64+
public readonly disableMostRecentDashboardState: boolean,
6265
) {
6366
this.validSpecQuery = useExploreValidSpec(instanceId, exploreName);
6467
this.fullTimeRangeQuery = this.useFullTimeRangeQuery(
@@ -334,7 +337,9 @@ export class DashboardStateDataLoader {
334337
exploreStateFromSessionStorage ??
335338
(urlSearchParams.size > 0 ? partialExploreStateFromUrl : null),
336339
// Next priority is the most recent state user had visited. This is a small subset of the full state.
337-
shouldSkipOtherSources ? null : mostRecentPartialExploreState,
340+
shouldSkipOtherSources || this.disableMostRecentDashboardState
341+
? null
342+
: mostRecentPartialExploreState,
338343
// Next priority is one of the other source defined.
339344
// For cloud dashboard it would be home bookmark if present.
340345
// For shared url it would be the saved state in token

web-common/src/features/dashboards/state-managers/loaders/DashboardStateManager.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
export let bookmarkOrTokenExploreState:
1818
| CompoundQueryResult<Partial<ExploreState> | null>
1919
| undefined = undefined;
20+
export let disableMostRecentDashboardState: boolean = false;
2021
2122
$: ({ instanceId } = $runtime);
2223
$: exploreSpecQuery = useExploreValidSpec(instanceId, exploreName);
@@ -29,6 +30,7 @@
2930
exploreName,
3031
storageNamespacePrefix,
3132
bookmarkOrTokenExploreState,
33+
disableMostRecentDashboardState,
3234
);
3335
3436
let stateSync: DashboardStateSync | undefined;

web-common/src/features/dashboards/state-managers/loaders/DashboardStateSync.ts

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,14 @@ export class DashboardStateSync {
122122
exploreSpec,
123123
timeControlsState,
124124
);
125-
// Update "most recent explore state" with the initial state
126-
saveMostRecentPartialExploreState(
127-
this.exploreName,
128-
this.extraPrefix,
129-
initExploreState,
130-
);
125+
if (!this.dataLoader.disableMostRecentDashboardState) {
126+
// Update "most recent explore state" with the initial state
127+
saveMostRecentPartialExploreState(
128+
this.exploreName,
129+
this.extraPrefix,
130+
initExploreState,
131+
);
132+
}
131133

132134
// If the current url same as the new url then there is no need to do anything
133135
if (redirectUrl.search === pageState.url.search) {
@@ -208,12 +210,14 @@ export class DashboardStateSync {
208210
exploreSpec,
209211
timeControlsState,
210212
);
211-
// Update "most recent explore state" with updated state from url
212-
saveMostRecentPartialExploreState(
213-
this.exploreName,
214-
this.extraPrefix,
215-
updatedExploreState,
216-
);
213+
if (!this.dataLoader.disableMostRecentDashboardState) {
214+
// Update "most recent explore state" with updated state from url
215+
saveMostRecentPartialExploreState(
216+
this.exploreName,
217+
this.extraPrefix,
218+
updatedExploreState,
219+
);
220+
}
217221

218222
this.updating = false;
219223
// If the url doesn't need to be changed further then we can skip the goto
@@ -271,13 +275,15 @@ export class DashboardStateSync {
271275
exploreSpec,
272276
timeControlsState,
273277
);
274-
// Update "most recent explore state" with updated state.
275-
// Since we do not update the state per action we do it here as blanket update.
276-
saveMostRecentPartialExploreState(
277-
this.exploreName,
278-
this.extraPrefix,
279-
exploreState,
280-
);
278+
if (!this.dataLoader.disableMostRecentDashboardState) {
279+
// Update "most recent explore state" with updated state.
280+
// Since we do not update the state per action we do it here as blanket update.
281+
saveMostRecentPartialExploreState(
282+
this.exploreName,
283+
this.extraPrefix,
284+
exploreState,
285+
);
286+
}
281287

282288
this.updating = false;
283289
// If the state didnt result in a new url then skip goto.

0 commit comments

Comments
 (0)