Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions frontend/app/view/waveconfig/waveconfig-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,21 @@ export class WaveConfigViewModel implements ViewModel {
return globalStore.get(this.hasEditedAtom);
}

confirmDiscardChanges(): boolean {
if (!this.hasChanges()) {
return true;
}
return window.confirm("You have unsaved changes. Discard and continue?");
}

discardChanges() {
const originalContent = globalStore.get(this.originalContentAtom);
globalStore.set(this.fileContentAtom, originalContent);
globalStore.set(this.hasEditedAtom, false);
globalStore.set(this.validationErrorAtom, null);
globalStore.set(this.errorMessageAtom, null);
}

markAsEdited() {
globalStore.set(this.hasEditedAtom, true);
}
Expand Down
9 changes: 8 additions & 1 deletion frontend/app/view/waveconfig/waveconfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const ConfigSidebar = memo(({ model }: ConfigSidebarProps) => {
const configErrorFiles = useAtomValue(model.configErrorFilesAtom);

const handleFileSelect = (file: ConfigFile) => {
if (selectedFile?.path === file.path) return;
if (!model.confirmDiscardChanges()) return;
model.loadFile(file);
setIsMenuOpen(false);
};
Expand Down Expand Up @@ -228,7 +230,11 @@ const WaveConfigView = memo(({ blockId, model }: ViewComponentProps<WaveConfigVi
{selectedFile.visualComponent && selectedFile.hasJsonView && (
<div className="flex gap-0 border-b border-border">
<button
onClick={() => setActiveTab("visual")}
onClick={() => {
if (!model.confirmDiscardChanges()) return;
model.discardChanges();
setActiveTab("visual");
}}
className={cn(
"px-4 pt-1 pb-1.5 cursor-pointer transition-colors text-secondary",
activeTab === "visual"
Expand All @@ -238,6 +244,7 @@ const WaveConfigView = memo(({ blockId, model }: ViewComponentProps<WaveConfigVi
>
Visual
</button>
{/* No guard needed: visual tab saves changes immediately via RPC */}
<button
onClick={() => setActiveTab("json")}
className={cn(
Expand Down