Skip to content

Commit

Permalink
Reset expore state when metrics view is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaHegde committed Dec 10, 2024
1 parent 30b0075 commit d88e4ba
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions web-common/src/features/entity-management/file-artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export class FileArtifact {
readonly fileName: string;
readonly disableAutoSave: boolean;
readonly autoSave: Writable<boolean>;
lastSeenResource: V1Resource;

private remoteCallbacks = new Set<(content: string, force?: true) => void>();
private localCallbacks = new Set<(content: string | null) => void>();
Expand Down Expand Up @@ -231,6 +232,7 @@ export class FileArtifact {
resource.meta?.reconcileStatus ===
V1ReconcileStatus.RECONCILE_STATUS_RUNNING,
);
this.lastSeenResource = resource;
}

hardDeleteResource() {
Expand Down
7 changes: 7 additions & 0 deletions web-common/src/features/entity-management/file-artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ export class FileArtifacts {
.map((artifact) => get(artifact.resourceName)?.name ?? "");
}

getResourcesForKind(kind: ResourceKind): V1Resource[] {
return Array.from(this.artifacts.values())
.filter((artifact) => get(artifact.resourceName)?.kind === kind)
.map((artifact) => artifact.lastSeenResource)
.filter(Boolean);
}

async saveAll() {
await Promise.all(
Array.from(this.artifacts.values()).map((artifact) =>
Expand Down
18 changes: 18 additions & 0 deletions web-common/src/features/metrics-views/editor/MetricsEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
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 { fileArtifacts } from "@rilldata/web-common/features/entity-management/file-artifacts";
import { ResourceKind } from "@rilldata/web-common/features/entity-management/resource-selectors";
import { yamlSchema } from "codemirror-json-schema/yaml";
import type { JSONSchema7 } from "json-schema";
import MetricsEditorContainer from "./MetricsEditorContainer.svelte";
Expand Down Expand Up @@ -47,6 +49,22 @@
createPersistentDashboardStore(metricsViewName).reset();
clearExploreSessionStore(metricsViewName, undefined);

// Reset local persisted explore state derived from this metrics view
fileArtifacts
.getResourcesForKind(ResourceKind.Explore)
.forEach((exploreResource) => {
const exploreName = exploreResource?.meta?.name?.name;
if (
!exploreName ||
!exploreResource?.explore?.state?.validSpec?.metricsView ||
exploreResource?.explore?.state?.validSpec?.metricsView !==
metricsViewName
)
return;
createPersistentDashboardStore(exploreName).reset();
clearExploreSessionStore(exploreName, undefined);
});

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

0 comments on commit d88e4ba

Please sign in to comment.