Fix navigation warnings on autotest manager and starter file manager pages, closes 7641#7968
Fix navigation warnings on autotest manager and starter file manager pages, closes 7641#7968philipkukulak wants to merge 1 commit into
Conversation
d1b46c7 to
cb56873
Compare
Coverage Report for CI Build 26658959313Coverage decreased (-0.1%) to 90.143%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats💛 - Coveralls |
cb56873 to
864b0a8
Compare
david-yz-liu
left a comment
There was a problem hiding this comment.
Nice work, @philipkukulak. I left one inline comment, and also it seems like you should now be able to remove the loading of the _navigation_warning.js.erb partial from this page.
Please go ahead and also make the same change to the starter files page.
| handleFormChange = data => { | ||
| this.setState({formData: data.formData}, () => this.toggleFormChanged(true)); | ||
| this.setState({formData: data.formData}); | ||
| if (!this._initializing) { |
There was a problem hiding this comment.
Overall I don't think this _initializing attribute is necessary. You can check the current value of this.state.formData before doing any updates, treating Object.keys(this.state.formData).length === 0 as the "initializing" condition.
There was a problem hiding this comment.
Wouldn't Object.keys(this.state.formData).length > 0 if any form data already exists, e.g. some tester is already configured? That would mark the page 'dirty' by default whenever there's persistent data. I'm thinking of 'initialization' as the initial fetch for page contents rather than the contents of the page itself.
There was a problem hiding this comment.
I'm also considering "initialization" as the initial fetch. The initial state of this component sets formData: {}. After the data is fetched this will change. (For a new assignment I suppose it's possible the fetched value may be {} as well, I'm not sure. If so, you can change the initial formData state to null instead to disambiguate it.)
There was a problem hiding this comment.
Ahhh okay I think I understand. I'll re-request review once I pushed these changes. Thanks David.
864b0a8 to
c42f884
Compare
…pages, closes 7641
c42f884 to
65c48bb
Compare
|
Removed the Note that overall test coverage has gone down because we've created a new test suite ( |
| <%= render partial: 'shared/navigation_warning', | ||
| formats: [:js], | ||
| handlers: [:erb] %> | ||
|
|
There was a problem hiding this comment.
Delete this blank line
| domContentLoadedCB() | ||
| } | ||
| })(); | ||
| $(document).on('click', 'input[type="submit"]', function () { |
There was a problem hiding this comment.
This change is quite different from the one for the autotest manager and not what I expected (this file is used by other views as well, so should not be changed).
The starter file page does use React, with the root component being StarterFileManager. Please make the same type of change you made for the AutotestManager in that component.
Proposed Changes
On the Settings > Automated Tests page, a warning should pop up if a user attempts to navigate away from the page after making changes and before saving them.
Currently, it appears even after the user has saved their changes. This happens because the Settings > Automated Tests page is rendered with
react, which is rendered after thejqueryclick handler in_navigation_warning.js.erbis registered:submit_clickedcan never be flipped totruebecause the submit button doesn't exist when that handler is registered.Furthermore, the
window.onbeforeunloadhandler as defined in the_navigation_warning.js.erbpartial has no awareness of the Automated Tests pagereactstructure. The page and the partial within it are tracking 'dirtiness' in separate state variables.With help from
claude, the cleanest fix is to override thewindow.onbeforeunloadhandler inautotest_manager.jsxand to gate the initialization of the page so thatfetchDatadoesn't instantly 'dirty' the page whenreactfiresonChangeupon first receipt of existing form data.The fix for the Settings -> Starter Files page is far simpler, since it is not rendered using
react: we bind the handler to.on('click', ...)instead.Screenshots of your changes (if applicable)
Screen.Recording.2026-05-29.at.10.56.39.AM.mov
Screen.Recording.2026-05-29.at.3.49.18.PM.mov
Associated documentation repository pull request (if applicable)
n/aType of Change
(Write an
Xor a brief description next to the type or types that best describe your changes.)Checklist
(Complete each of the following items for your pull request. Indicate that you have completed an item by changing the
[ ]into a[x]in the raw text, or by clicking on the checkbox in the rendered description on GitHub.)Before opening your pull request:
After opening your pull request:
Questions and Comments
I had the thought that we could also take this a step further and track changes to the page that are 'undone', e.g. checking a box and then unchecking it, and make sure the navigation warning doesn't pop up in that case. I came to the judgment that this would bloat the code more than we could justify an improvement so slight.
I also did not touch the Settings -> Starter Files page (on which this bug is also present) but if it is decided upon review that we'd like to bundle that fix into this PR, I would be happy to do so.Applied this fix to the Settings -> Starter Files page.