fix: change dirty strategy in check form #1037
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes: #1026 (comment)
Problem
When introducing the notify unsaved changes feature, an accidental bug was introduced where after using the test button the form was considered submitted and could no longer be saved.
Solution
The solution is to change the strategy in assessing whether the form is 'dirty' or not. Instead of utilizing React hook form's
isDirty
value in provided by theformState
, we are manually checking if the initial values match the current values. It is not the most optimal solution but it does work adequately.The desired solution proposed in the issue of not considering the test button a submit button has its own tradeoffs with the way
react-hook-form
works and the current set-up of the Synthetic Monitoring application. Because theFormLayout
component doesn't expose any of its inner workings (such as moving between steps and the validation invalid / valid triggers provided byreact-hook-form
'shandleSubmit
) it would require a larger re-work of these components and have the same UX.The
test
button is likely to evolve when we tackle phase 2 of the check creation flow so this solution is most appropriate right now.Last note, it is difficult to write tests for the 'test' button because JSDom doesn't expose the submitter element, which we rely upon to know if it is an ad-hoc test or saving the check.