Skip to content

DT-340: Warn the user if they are leaving a story edit page with unsaved changes#334

Merged
JuanVqz merged 10 commits into
mainfrom
feature/DT-340-warn-user-unsaved-edits
Jul 21, 2026
Merged

DT-340: Warn the user if they are leaving a story edit page with unsaved changes#334
JuanVqz merged 10 commits into
mainfrom
feature/DT-340-warn-user-unsaved-edits

Conversation

@torresga

@torresga torresga commented Nov 7, 2024

Copy link
Copy Markdown
Contributor

Jira Ticket

https://ombulabs.atlassian.net/browse/DT-340

Motivation / Context

Currently if you leave the current page, you can lose information that was not saved. This feature warns you if you are leaving without saving information.

QA / Testing Instructions

  1. Go to the Edit Story page.
  2. Edit the story.
  3. Try to navigate off the page by reloading, pressing the back button in the browser, clicking the logo or the Back button on the page.
  4. Ensure that you get a popup asking you if are sure you want to reload/go back.

Screenshots:

Screenshot 2024-11-07 at 1 53 28 PM

I will abide by the code of conduct.

@torresga
torresga marked this pull request as ready for review November 7, 2024 20:30

@JuanVqz JuanVqz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestions are not a blocker.

Comment thread app/assets/javascripts/stories.js Outdated
Comment thread app/assets/javascripts/stories.js Outdated
@torresga
torresga requested a review from JuanVqz September 6, 2025 00:05
@JuanVqz

JuanVqz commented Sep 16, 2025

Copy link
Copy Markdown
Member

Hey @torresga, this looks good; however, maybe we can improve a little bit on the isDirty logic; for example, I tried the following, and the state was still dirty when it probably should not have been.

  1. Go to the edit page.
  2. Type 3 letters in the title.
  3. Click back, the logo, or any action that triggers the modal to alert us we left unsaved changes.
  4. The alert will pop up as expected; until here, all looks good.
  5. Then I removed the 3 letters to be in an unchanged state, and clicking any action to get out of the page does not allow me because it says I have unsaved changes when I really don't.

If you need help to follow the described steps, let me know, and we can check it together.

torresga and others added 8 commits July 21, 2026 09:46
…e form existed. Also created a function to add and remove the beforeunload event listener
Co-authored-by: Juan Vásquez <juan@ombulabs.com>
Co-authored-by: Juan Vásquez <juan@ombulabs.com>
- 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.
@JuanVqz
JuanVqz force-pushed the feature/DT-340-warn-user-unsaved-edits branch from c6d99df to 9b2da29 Compare July 21, 2026 18:08
JuanVqz added 2 commits July 21, 2026 12:26
- 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.
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.
@JuanVqz
JuanVqz merged commit c4a2ece into main Jul 21, 2026
2 checks passed
@JuanVqz
JuanVqz deleted the feature/DT-340-warn-user-unsaved-edits branch July 21, 2026 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants