New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Justice Counts] Fix data entry form bug when navigating back from publish confirm page #148
Conversation
useEffect(() => { | ||
/** Runs validation of previously saved inputs on load */ | ||
if (reportMetrics) { | ||
formStore.validatePreviouslySavedInputs(reportID); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, we could also call this whenever a report is fetched? It could just be part of the process of fetching a report, storing it in the report store, and also storing inputs + validation in the form store?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes a lot of sense actually! I don't have strong feelings though -- if you feel that this solution is robust enough for now @terryttsai , I'm fine to merge this in as-is. Up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No strong feelings either - both make a lot of sense! I'm good with your solution here!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll go with this for now!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@terryttsai thank you so much for investigating this and for writing such a clear and well-explained PR description! This solution makes perfect sense to me. Curious what @mxosman thinks about your suggestion of moving this validation logic up to happen right after a report is fetched -- I'll leave it up to you both if you think that's worth doing now. I'm happy with this as-is though :)
useEffect(() => { | ||
/** Runs validation of previously saved inputs on load */ | ||
if (reportMetrics) { | ||
formStore.validatePreviouslySavedInputs(reportID); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes a lot of sense actually! I don't have strong feelings though -- if you feel that this solution is robust enough for now @terryttsai , I'm fine to merge this in as-is. Up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice debugging and solution, Terry!!
Description of the change
See video for reproducing the bug here: https://app.zenhub.com/workspaces/justice-counts--622109ea3bb6e0001d2d06ad/issues/recidiviz/recidiviz-data/16570
This bug is caused by
formStore.validatePreviouslySavedInputs
being called when the user is navigating from the Publish Confirm page back to the data entry page, which replaces all user inputs with what was originally fetched from the server when the data entry page was first loaded.The
DataEntryForm
component gets unmounted and remounted when navigating to and away from the Publish Confirm page, which causesformStore.validatePreviouslySavedInputs
to get triggered. I believeformStore.validatePreviouslySavedInputs
is intended to be triggered once on loading the data entry page and not when navigating from Publish Confirm back to the Data Entry Form.My solution is to move the
formStore.validatePreviouslySavedInputs
trigger out of theDataEntryForm
component and into the parentReportDataEntry
component. The parent component is loaded once when the data entry page is loaded, and callsformStore.validatePreviouslySavedInputs
. It doesn't get called again until the user navigates away from the data entry section entirely.Type of change
Related issues
Closes #152
Checklists
Development
This box MUST be checked by the submitter prior to merging:
These boxes should be checked by the submitter prior to merging:
Code review
These boxes should be checked by reviewers prior to merging: