Commit 0a3e8b8
fix: warn before discarding unsaved changes in waveconfig view (#3099)
Fixes #2890
## Changes
Add unsaved changes confirmation when navigating away in the Wave Config
view. Two navigation paths lose edits without warning:
1. **File sidebar selection**: `handleFileSelect` calls
`model.loadFile(file)` directly, which resets `hasEditedAtom` and
overwrites `fileContentAtom` — discarding edits silently.
2. **JSON→Visual tab switching**: `setActiveTab()` is called directly.
The visual component renders from saved config (not the editor buffer),
so edits appear lost.
### Fix
- Added `confirmDiscardChanges()` to `WaveConfigViewModel` — checks
`hasEditedAtom`, shows `window.confirm()` if there are unsaved changes.
- Guarded `handleFileSelect` with the confirmation check (skips if
already on the selected file).
- Guarded JSON→Visual tab switch with the confirmation check.
Only prompts when `hasEditedAtom` is true. Visual→JSON direction is safe
(editor loads from `fileContentAtom`). `window.confirm()` is synchronous
and works well in Electron.
## Test Plan
- Edit JSON, switch file in sidebar → confirmation dialog appears.
Cancel stays, confirm switches.
- Edit JSON, click Visual tab → confirmation dialog appears.
- Save changes first, then switch → no dialog.
- Switch without editing → no dialog.
- `npx tsc --noEmit` passes.
---------
Signed-off-by: majiayu000 <1835304752@qq.com>
Co-authored-by: sawka <mike@commandline.dev>1 parent 6a287e4 commit 0a3e8b8
File tree
2 files changed
+23
-1
lines changed- frontend/app/view/waveconfig
2 files changed
+23
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
263 | 263 | | |
264 | 264 | | |
265 | 265 | | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
266 | 281 | | |
267 | 282 | | |
268 | 283 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
| |||
231 | 233 | | |
232 | 234 | | |
233 | 235 | | |
234 | | - | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
235 | 241 | | |
236 | 242 | | |
237 | 243 | | |
| |||
241 | 247 | | |
242 | 248 | | |
243 | 249 | | |
| 250 | + | |
244 | 251 | | |
245 | 252 | | |
246 | 253 | | |
| |||
0 commit comments