fix: warn before discarding unsaved changes in waveconfig view#3099
fix: warn before discarding unsaved changes in waveconfig view#3099majiayu000 wants to merge 4 commits intowavetermdev:mainfrom
Conversation
Add confirmation dialog when navigating away from unsaved changes in the Wave Config editor. Guards both file sidebar selection and JSON-to-Visual tab switching with a window.confirm() prompt. No-ops when there are no pending changes. Fixes wavetermdev#2890 Signed-off-by: majiayu000 <1835304752@qq.com>
- Simplify Visual tab guard by removing redundant activeTab check (confirmDiscardChanges already returns true when no changes exist) - Document intentional asymmetry: JSON tab button has no guard because visual tab saves changes immediately via RPC Signed-off-by: majiayu000 <1835304752@qq.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughAdds two methods to WaveConfigViewModel: Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Code Review SummaryStatus: No Issues Found | Recommendation: Merge The existing comment at line 237 has been addressed - the PR now properly calls
Files Reviewed (2 files)
Reviewed by minimax-m2.5-20260211 · 195,457 tokens |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@frontend/app/view/waveconfig/waveconfig.tsx`:
- Around line 233-236: The click handler currently only switches tabs
(setActiveTab("visual")) after model.confirmDiscardChanges() and does not
actually clear the pending JSON edits, leaving the "Unsaved changes" flag set;
update the handler so that when model.confirmDiscardChanges() returns true you
also reset the JSON editor state—either by calling an existing discard/reset
method on the model (e.g., model.discardChanges() or model.resetDraft()) or by
invoking the component state setter that holds the draft JSON (e.g.,
setEditedJson(originalJson) or setPendingJson(undefined)) before calling
setActiveTab("visual"), ensuring the unsaved/dirty flag is cleared; if no reset
helper exists add one to the model to centralize discard logic and call it here.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: f5ee4912-0d13-44c8-a6c6-57081cb47c24
📒 Files selected for processing (2)
frontend/app/view/waveconfig/waveconfig-model.tsfrontend/app/view/waveconfig/waveconfig.tsx
When switching from JSON to Visual tab after confirming discard, also reset fileContent back to original and clear the dirty flag so the editor doesn't retain stale edits. Signed-off-by: majiayu000 <1835304752@qq.com>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
frontend/app/view/waveconfig/waveconfig-model.ts (1)
284-288: Consider clearing validation/error state on discard.
discardChanges()resets content and dirty state, but stalevalidationErrorAtom/errorMessageAtomcan survive after a discard and confuse users when they return to JSON.Suggested patch
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); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@frontend/app/view/waveconfig/waveconfig-model.ts` around lines 284 - 288, discardChanges() currently restores content and resets hasEditedAtom but leaves validationErrorAtom and errorMessageAtom stale; update discardChanges() to also clear validation state by calling globalStore.set on validationErrorAtom (e.g., to null or false) and on errorMessageAtom (e.g., to empty string or null) so any previous JSON errors are removed when content is discarded; ensure you reference the same atoms (validationErrorAtom, errorMessageAtom, fileContentAtom, hasEditedAtom, originalContentAtom) and use globalStore.set consistently.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@frontend/app/view/waveconfig/waveconfig-model.ts`:
- Around line 284-288: discardChanges() currently restores content and resets
hasEditedAtom but leaves validationErrorAtom and errorMessageAtom stale; update
discardChanges() to also clear validation state by calling globalStore.set on
validationErrorAtom (e.g., to null or false) and on errorMessageAtom (e.g., to
empty string or null) so any previous JSON errors are removed when content is
discarded; ensure you reference the same atoms (validationErrorAtom,
errorMessageAtom, fileContentAtom, hasEditedAtom, originalContentAtom) and use
globalStore.set consistently.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: a81eadc5-2052-45e6-b254-d74b298a1133
📒 Files selected for processing (2)
frontend/app/view/waveconfig/waveconfig-model.tsfrontend/app/view/waveconfig/waveconfig.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
- frontend/app/view/waveconfig/waveconfig.tsx
Clear validationErrorAtom and errorMessageAtom in discardChanges() so stale error messages don't persist after discarding edits. Signed-off-by: majiayu000 <1835304752@qq.com>
Fixes #2890
Changes
Add unsaved changes confirmation when navigating away in the Wave Config view. Two navigation paths lose edits without warning:
File sidebar selection:
handleFileSelectcallsmodel.loadFile(file)directly, which resetshasEditedAtomand overwritesfileContentAtom— discarding edits silently.JSON→Visual tab switching:
setActiveTab()is called directly. The visual component renders from saved config (not the editor buffer), so edits appear lost.Fix
confirmDiscardChanges()toWaveConfigViewModel— checkshasEditedAtom, showswindow.confirm()if there are unsaved changes.handleFileSelectwith the confirmation check (skips if already on the selected file).Only prompts when
hasEditedAtomis true. Visual→JSON direction is safe (editor loads fromfileContentAtom).window.confirm()is synchronous and works well in Electron.Test Plan
npx tsc --noEmitpasses.