Commit c4a2ece
DT-340: Warn the user if they are leaving a story edit page with unsaved changes (#334)
* Adds event listeners to listen for unsaved edits and alerting the user if there are unsaved edits
* Adds spec to test for presence of alert when we try to navigate away from an unsaved edited story
* Refactored the code to only add the event listeners on the form if the form existed. Also created a function to add and remove the beforeunload event listener
* DT-340: Edit tests so that it tests all scenarios
* Update app/assets/javascripts/stories.js
Co-authored-by: Juan Vásquez <juan@ombulabs.com>
* Update app/assets/javascripts/stories.js
Co-authored-by: Juan Vásquez <juan@ombulabs.com>
* Fix method name
* Fix unsaved-changes detection to compare against initial form state
- Track dirtiness by comparing the current form serialization to a snapshot
taken on load, so reverting an edit (typing then deleting it) correctly
clears the warning instead of leaving the form permanently 'dirty'.
- Also listen for 'change' so status-select edits are detected, and guard the
back/logo click handlers against missing elements on non-edit pages.
- Add a feature spec covering the revert-to-original case.
* Unify unsaved-changes wording and init on turbolinks:load
- Route every in-app link that leaves the edit page through one confirm with a
single shared message constant, instead of hard-coding only Back and the
logo. The native beforeunload prompt (reload / tab close) still uses the
browser's own text, since browsers ignore custom strings there.
- Initialize on turbolinks:load instead of DOMContentLoaded, matching
project.js, so the guard (and the markdown preview) also initialize on
Turbolinks visits. Module-scoped state lets the delegated click handler be
added by reference and de-duplicated across visits.
* Fix flaky clone sub-projects spec ordering
Assert the cloned sub-projects by set of titles (contain_exactly) instead of
positional index. The projects association has no default order, so indexing
into it was order-dependent and failed on the build-rails-next lane when the
database returned the rows in a different order.
---------
Co-authored-by: Juan Vásquez <juan@ombulabs.com>1 parent 355315f commit c4a2ece
3 files changed
Lines changed: 140 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
2 | 18 | | |
3 | 19 | | |
4 | 20 | | |
| |||
25 | 41 | | |
26 | 42 | | |
27 | 43 | | |
| 44 | + | |
| 45 | + | |
28 | 46 | | |
29 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 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 | + | |
30 | 126 | | |
31 | 127 | | |
32 | 128 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
266 | 266 | | |
267 | 267 | | |
268 | 268 | | |
269 | | - | |
270 | | - | |
271 | | - | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
272 | 272 | | |
273 | 273 | | |
274 | 274 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
71 | 111 | | |
72 | 112 | | |
73 | 113 | | |
| |||
0 commit comments