Skip to content

Conversation

@seyfeb
Copy link
Collaborator

@seyfeb seyfeb commented Dec 30, 2020

When changes in the recipe form are done by the user, the form is marked dirty. When navigating away from a dirty form, the user is prompted for confirmation.

Closes #310

@sam-19 If you‘d like to share your opinion, you‘re welcome!

@seyfeb seyfeb changed the title Earn before leaving recipe editor with changes Warn before leaving recipe editor with changes Dec 30, 2020
Signed-off-by: Sebastian Fey <[email protected]>
@seyfeb seyfeb force-pushed the feature/warnBeforeLeavingRecipeEdit branch from 43fad70 to 3d12202 Compare December 30, 2020 20:04
@codecov
Copy link

codecov bot commented Dec 30, 2020

Codecov Report

Merging #464 (6023d95) into master (538a91c) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff            @@
##             master    #464   +/-   ##
========================================
  Coverage      0.91%   0.91%           
  Complexity      414     414           
========================================
  Files            13      13           
  Lines          1307    1307           
========================================
  Hits             12      12           
  Misses         1295    1295           
Flag Coverage Δ Complexity Δ
integration 0.00% <ø> (ø) 0.00 <ø> (ø)
unittests 0.91% <ø> (ø) 0.00 <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Copy link
Collaborator

@christianlupus christianlupus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am considering if it would be more clear to set the saving flag inside the save function. Also, we could reset it on the done()/fail() functions in order to have a clear idea if an operation is in progress at the moment.

One case I am thinking a bit but that might be off: What happens on a slow network connection when a user clicks save but does not wait for at least the termination of the HTTP request. As the saving flag allows to reload/navigate to another URL, the changes might get lost if the user is too fast. Or am I getting things here wrong?

return window.confirm('You have unsaved changes! Do you still want to leave?')
},
confirmStayInEditedForm() {
return !this.savingRecipe && this.formDirty && !this.confirmLeavingPage()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will continue to new URL when a saving action is just running, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea was: If the user clicked the save button (saving is running), the browser continues to the new URL without checking if the form is dirty (this.formDirty) and (if it is dirty) asking for confirmation (!this.confirmLeavingPage())

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I see that. This is more related to the overall comment below about the abort of a saving action.

}
},
setup: function() {
let $this = this
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May I ask, mainly out of curiosity, why we need a $this variable when we have the this one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot :o I introduced it for the $nextTick callback. But actually it’s not necessary since $nextTick is invoked in the this context

@seyfeb
Copy link
Collaborator Author

seyfeb commented Jan 2, 2021

One case I am thinking a bit but that might be off: What happens on a slow network connection when a user clicks save but does not wait for at least the termination of the HTTP request. As the saving flag allows to reload/navigate to another URL, the changes might get lost if the user is too fast. Or am I getting things here wrong?

Actually I’m not sure about this. I tried to provoke this problem but wasn’t successful.

@christianlupus
Copy link
Collaborator

I tried to provoke this behavior as well but was neither successful. Either one is online and the save is possible or one is offline and one cannot navigate elsewhere. So it should be save to merge this,

@christianlupus christianlupus merged commit 42d9ad5 into nextcloud:master Jan 3, 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.

Show warning when navigating away from recipe editing window

2 participants