-
-
Notifications
You must be signed in to change notification settings - Fork 407
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
#766 Show prompt only if form value changed #1086
Conversation
When leaving the howto edit page a confirmation dialog is shown to warn the user that he/she might loose the changes. This commit changes this logic so that the dialog is only shown when there are actual changes that would be lost. The dirty state of the form is used for this. A big part of the added logic is for correctly marking a field (and thus the form) as dirty.
Add the display of a confirm dialog on a complete page refresh/reload not only on a React Router change.
Test summaryRun details
View run in Cypress Dashboard ➡️ This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard |
|
||
// Functions used to give as callback to the isEqual prop of a form fields. | ||
// The isEqual callback is used to determine if a field is dirty. | ||
export const COMPARISONS = { |
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.
Really nice to have these defined in a reusable way, will come in handy elsewhere for sure
it('[Warning on leaving page]', () => { | ||
const stub = cy.stub() | ||
stub.returns(false); | ||
cy.on('window:confirm', stub) |
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 idea to stub this, wouldn't have thought of that!
@@ -228,6 +251,7 @@ export class HowtoForm extends React.PureComponent<IProps, IState> { | |||
? this.validateTitle(value) | |||
: false | |||
} | |||
isEqual={COMPARISONS.textInput} |
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 feel like adding comparisons to every field might be a bit time-intensive to manage if this form were to change or if we want to apply the same to other forms (e.g. creating events). Although I'm guessing processing at the form level is then computationally quite a bit more intensive (checking every field any time anything changes).... So I think probably the best solution is using a better form library that has more native support for this, and for now we have the option to apply at the form level if we want.
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 added a few inline comments and a bit more context to the discussion on #766 , but overall I think the additions are great and my own testing seemed to work well. Merging.
PR Type
PR Checklist
master
branch mergedDescription
Only show the confirm dialog (prompt) when a value is changed inside the howto edit/create page
Git Issues
#766
Screenshots/Videos