Skip to content
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

Merged
merged 2 commits into from
Jan 12, 2021

Conversation

ivokh
Copy link
Contributor

@ivokh ivokh commented Dec 30, 2020

PR Type

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

PR Checklist

  • - Latest master branch merged
  • - PR title descriptive (can be used in release notes)
  • - Passes Tests

Description

Only show the confirm dialog (prompt) when a value is changed inside the howto edit/create page

Git Issues

#766

Screenshots/Videos

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.
@cypress
Copy link

cypress bot commented Dec 30, 2020



Test summary

62 0 0 0


Run details

Project onearmy-community-platform
Status Passed
Commit c5c1867 ℹ️
Started Dec 30, 2020 9:06 AM
Ended Dec 30, 2020 9:11 AM
Duration 05:28 💡
OS Linux Ubuntu Linux - 16.04
Browser Multiple

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

@chrismclarke chrismclarke self-requested a review January 12, 2021 06:42

// 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 = {
Copy link
Member

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)
Copy link
Member

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}
Copy link
Member

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.

Copy link
Member

@chrismclarke chrismclarke left a 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.

1086-Testing-1.mp4

@chrismclarke chrismclarke merged commit fb4dff4 into ONEARMY:master Jan 12, 2021
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