Skip to content

Commit

Permalink
Fix E2E
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaHegde committed Dec 5, 2024
1 parent 491a9ff commit 5e662a4
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 5 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,21 @@ import {
const ExploreViewKeys: Record<V1ExploreWebView, (keyof V1ExplorePreset)[]> = {
[V1ExploreWebView.EXPLORE_WEB_VIEW_UNSPECIFIED]: [],
[V1ExploreWebView.EXPLORE_WEB_VIEW_EXPLORE]: [
"view",
"measures",
"dimensions",
"exploreExpandedDimension",
"exploreSortBy",
"exploreSortAsc",
"exploreSortType",
"comparisonDimension",
],
[V1ExploreWebView.EXPLORE_WEB_VIEW_TIME_DIMENSION]: [
"view",
"timeDimensionMeasure",
"timeDimensionChartType",
"timeDimensionPin",
"comparisonDimension",
],
[V1ExploreWebView.EXPLORE_WEB_VIEW_PIVOT]: [
"view",
"pivotCols",
"pivotRows",
"pivotSortAsc",
Expand All @@ -48,18 +47,33 @@ const ExploreViewOtherKeys: Record<
[V1ExploreWebView.EXPLORE_WEB_VIEW_PIVOT]: [],
[V1ExploreWebView.EXPLORE_WEB_VIEW_CANVAS]: [],
};
// Keys shared between views.
const ExploreViewSharedKeys = {} as Record<
V1ExploreWebView,
Record<V1ExploreWebView, (keyof V1ExplorePreset)[]>
>;
for (const webView in ExploreViewOtherKeys) {
const keys = new Set(ExploreViewKeys[webView]);
ExploreViewSharedKeys[webView] = {};
const otherKeys = new Set<keyof V1ExplorePreset>();

for (const otherWebView in ExploreViewKeys) {
if (webView === otherWebView) continue;
ExploreViewSharedKeys[webView][otherWebView] = [];

for (const key of ExploreViewKeys[otherWebView]) {
if (keys.has(key)) continue;
if (keys.has(key)) {
ExploreViewSharedKeys[webView][otherWebView].push(key);
continue;
}
otherKeys.add(key);
}
}
ExploreViewOtherKeys[webView] = [...otherKeys];
}
export const SharedStateStoreKey = "__common";
// Values shared across the views. Any keys not defined in ExploreViewKeys will fall under this.
// Having a catch-all like this will avoid issues where new fields added are not lost.
export const SharedStateStoreKey = "__shared";

export function getKeyForSessionStore(
exploreName: string,
Expand Down Expand Up @@ -99,6 +113,43 @@ export function updateExploreSessionStore(

sessionStorage.setItem(key, JSON.stringify(storedPreset));
sessionStorage.setItem(sharedKey, JSON.stringify(sharedPreset));

for (const otherView in ExploreViewSharedKeys[view]) {
const sharedKeys = ExploreViewSharedKeys[view][otherView];
if (!sharedKeys?.length) continue;

const otherViewKey = getKeyForSessionStore(exploreName, prefix, otherView);
const otherViewRawPreset = sessionStorage.getItem(otherViewKey);
if (!otherViewRawPreset) continue;

try {
const otherViewPreset = JSON.parse(otherViewRawPreset) as V1ExplorePreset;
for (const sharedKey of sharedKeys) {
if (!(sharedKey in storedPreset)) continue;
otherViewPreset[sharedKey] = storedPreset[sharedKey];
}
sessionStorage.setItem(otherViewKey, JSON.stringify(otherViewPreset));
} catch {
// ignore errors
}
}
}

export function clearExploreSessionStore(
exploreName: string,
prefix: string | undefined,
) {
for (const view in ExploreViewKeys) {
const key = getKeyForSessionStore(exploreName, prefix, view);
sessionStorage.removeItem(key);
}

const sharedKey = getKeyForSessionStore(
exploreName,
prefix,
SharedStateStoreKey,
);
sessionStorage.removeItem(sharedKey);
}

export function getExplorePresetForWebView(
Expand Down
2 changes: 2 additions & 0 deletions web-common/src/features/explores/ExploreEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { setLineStatuses } from "@rilldata/web-common/components/editor/line-status";
import { metricsExplorerStore } from "@rilldata/web-common/features/dashboards/stores/dashboard-stores";
import { createPersistentDashboardStore } from "@rilldata/web-common/features/dashboards/stores/persistent-dashboard-state";
import { clearExploreSessionStore } from "@rilldata/web-common/features/dashboards/url-state/explore-web-view-store";
import Editor from "@rilldata/web-common/features/editor/Editor.svelte";
import { FileArtifact } from "@rilldata/web-common/features/entity-management/file-artifact";
import { yaml } from "@codemirror/lang-yaml";
Expand All @@ -27,6 +28,7 @@
metricsExplorerStore.remove(exploreName);
// Reset local persisted dashboard state for the metrics view
createPersistentDashboardStore(exploreName).reset();
clearExploreSessionStore(exploreName, undefined);

if (!content?.length) {
setLineStatuses([], editor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { metricsPlusSQL } from "@rilldata/web-common/components/editor/presets/yamlWithJsonAndSql";
import { metricsExplorerStore } from "@rilldata/web-common/features/dashboards/stores/dashboard-stores";
import { createPersistentDashboardStore } from "@rilldata/web-common/features/dashboards/stores/persistent-dashboard-state";
import { clearExploreSessionStore } from "@rilldata/web-common/features/dashboards/url-state/explore-web-view-store";
import Editor from "@rilldata/web-common/features/editor/Editor.svelte";
import { FileArtifact } from "@rilldata/web-common/features/entity-management/file-artifact";
import { yamlSchema } from "codemirror-json-schema/yaml";
Expand Down Expand Up @@ -44,6 +45,7 @@
metricsExplorerStore.remove(metricsViewName);
// Reset local persisted dashboard state for the metrics view
createPersistentDashboardStore(metricsViewName).reset();
clearExploreSessionStore(metricsViewName, undefined);

if (!content?.length) {
setLineStatuses([], editor);
Expand Down

0 comments on commit 5e662a4

Please sign in to comment.