From 86058767a18e84ffe95db079b5973f54492e12c0 Mon Sep 17 00:00:00 2001 From: Oleh Omelchenko Date: Sun, 19 Jan 2025 14:12:54 +0200 Subject: [PATCH] fix: update hasUnsavedChanges logic for draft versions and improve visualization spec handling --- src/SnippetManager.js | 5 +++-- src/VisualizationManager.js | 9 ++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/SnippetManager.js b/src/SnippetManager.js index 48eb126..f2b6244 100644 --- a/src/SnippetManager.js +++ b/src/SnippetManager.js @@ -43,10 +43,11 @@ export class SnippetManager { snippet.content; this.editorManager.setValue(content); - this.hasUnsavedChanges = false; + // Set hasUnsavedChanges to true if we're viewing a draft version + this.hasUnsavedChanges = this.isDraftVersion; this.updateReadOnlyState(); this.uiManager.updateSaveButton(this.hasUnsavedChanges); - this.uiManager.updateVersionSwitch(this.currentSnippetId, this.isDraftVersion, this.hasDraftChanges(this.currentSnippetId)); + this.uiManager.updateVersionSwitch(this.currentSnippetId, this.isDraftVersion, hasChanges); this.uiManager.renderSnippetList(this.snippets, this.currentSnippetId); this.visualizationManager.updateVisualization(content); } diff --git a/src/VisualizationManager.js b/src/VisualizationManager.js index 690b666..02c746c 100644 --- a/src/VisualizationManager.js +++ b/src/VisualizationManager.js @@ -6,10 +6,13 @@ export class VisualizationManager { async updateVisualization(spec) { try { const parsedSpec = typeof spec === 'string' ? JSON.parse(spec) : spec; - parsedSpec.width = parsedSpec.width || 'container'; - parsedSpec.height = parsedSpec.height || 'container'; + const displaySpec = { + ...parsedSpec, + width: parsedSpec.width || 'container', + height: parsedSpec.height || 'container' + }; - await vegaEmbed(`#${this.containerId}`, parsedSpec, { + await vegaEmbed(`#${this.containerId}`, displaySpec, { actions: true, theme: 'light' });