Commit bb320db
fix(app): confirm before discarding unsaved changes when closing filter editor (#3005)
## Summary
In the Edit Dashboard Filters modal, clicking outside the modal or pressing ESC while editing a filter closed the editor immediately, silently discarding any pending form changes. This mirrors the fix already in place for the tile editor.
The filter edit form (`DashboardFilterEditForm`) now prompts for confirmation before closing when the form has pending edits:
- Uses `react-hook-form`'s `formState.isDirty` to detect pending changes — no confirm is shown for a clean form.
- Reuses the shared `useConfirm` dialog ("You have unsaved changes. Discard them and close the editor?" / **Discard**), same pattern and copy as the tile editor.
- Guards against re-entrancy (`isConfirmingRef`) so Mantine's focus management can't stack a second confirm dialog.
- Sets the edit-form modal's `zIndex` via `useZIndex()` so the root confirm dialog reliably layers on top — the same z-index handling the tile editor uses. Without this the two default-z-index modals stacked unpredictably.
The confirm applies to ESC, click-outside, and the modal's X. The in-form **Cancel** button (which returns to the filters list) is unchanged, since that is an explicit user action.
### Screenshots or video
| After |
| :---- |
| [Confirmation dialog shown when closing the filter editor with unsaved changes](https://cursor.com/agents/bc-c7e04f97-bd8f-49d4-b41f-55bf763048a5/artifacts?path=%2Fopt%2Fcursor%2Fartifacts%2Ffilter_editor_discard_confirmation.png) |
### How to test on Vercel preview
**Preview routes:** /dashboards
**Steps:**
1. Open /dashboards and create a new dashboard.
2. Click the filter icon in the dashboard header (data-testid `edit-filters-button`) to open the filters editor.
3. Click "Add new filter" (data-testid `add-filter-button`).
4. Type any text into the "Display name" field (data-testid `filter-name-input`).
5. Press ESC. Verify a confirmation dialog appears reading "You have unsaved changes. Discard them and close the editor?" with Cancel and Discard buttons.
6. Click Cancel. Verify the filter form is still open with the typed name intact.
7. Press ESC again, then click Discard. Verify the editor closes and no filter was saved.
### References
- Linear Issue: HDX-5167
- Related PRs: #2963
### Testing
- Added Playwright E2E cases in `dashboard.spec.ts`: one asserting the confirm-on-close (Cancel keeps edits, Discard closes) and one asserting a clean form closes without a prompt. Both pass in full-stack mode.
- `tsc --noEmit` and `eslint` pass (no new warnings).
<sub>To show artifacts inline, <a href="https://cursor.com/dashboard/cloud-agents#team-pull-requests">enable</a> in settings.</sub>
Linear Issue: [HDX-5167](https://linear.app/clickhouse/issue/HDX-5167/add-confirmation-dialog-when-closing-filter-editing-modal)
<div><a href="https://cursor.com/agents/bc-c7e04f97-bd8f-49d4-b41f-55bf763048a5?cursor_ref=pr_footer&cursor_cta=open_in_web"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/open-in-web-light.png"><img alt="Open in Web" width="114" height="28" src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a> <a href="https://cursor.com/background-agent?bcId=bc-c7e04f97-bd8f-49d4-b41f-55bf763048a5&cursor_ref=pr_footer&cursor_cta=open_in_cursor"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/open-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/open-in-cursor-light.png"><img alt="Open in Cursor" width="131" height="28" src="https://cursor.com/assets/images/open-in-cursor-dark.png"></picture></a> </div>
Co-authored-by: Cursor Agent <199161495+cursoragent@users.noreply.github.com>1 parent 8f3126f commit bb320db
4 files changed
Lines changed: 99 additions & 2 deletions
File tree
- .changeset
- packages/app
- src/components/DashboardFiltersModal
- tests/e2e
- features
- page-objects
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
Lines changed: 37 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
41 | 42 | | |
| 43 | + | |
42 | 44 | | |
43 | 45 | | |
44 | 46 | | |
| |||
96 | 98 | | |
97 | 99 | | |
98 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
99 | 133 | | |
100 | 134 | | |
101 | 135 | | |
| |||
213 | 247 | | |
214 | 248 | | |
215 | 249 | | |
216 | | - | |
| 250 | + | |
217 | 251 | | |
| 252 | + | |
218 | 253 | | |
219 | 254 | | |
220 | 255 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
446 | 446 | | |
447 | 447 | | |
448 | 448 | | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
449 | 488 | | |
450 | 489 | | |
451 | 490 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
844 | 844 | | |
845 | 845 | | |
846 | 846 | | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
847 | 865 | | |
848 | 866 | | |
849 | 867 | | |
| |||
0 commit comments