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

fix(frontend): Prevent users from navigating to child with unsaved changes #468

Merged
merged 3 commits into from
Apr 11, 2024

Conversation

Piv94165
Copy link
Contributor

@Piv94165 Piv94165 commented Mar 27, 2024

What

Currently, users can navigate to a child node while editing a parent node without saving changes, resulting in a potential 404 error if the child node is newly created.
Additionally, clicking on a child node before saving changes can lead to the loss of unsaved modifications.

To prevent this, I have disabled the ability to navigate to a child node if this node has been newly created without saving.
Furthermore, I have implemented a warning message to inform users about why they cannot proceed to the child node : "You've just created a new child. To navigate to it, please ensure your changes are saved first."

There is another warning massage when whatever changes have not been saved : "Changes are pending and have not been saved. Please save your changes before navigating to any child node. If you prefer not to save your pending changes but wish to avoid losing them, you can navigate to a child node in a new window."

What can be added :

  • a button which enables user to discard changes

Screenshot

The child node has been added whithout saving :
image

A change has not been saved :
image

Copy link
Contributor

@perierc perierc left a comment

Choose a reason for hiding this comment

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

Good idea to add an Alert, but I don't think we should remove the href for all children (see comments)

Comment on lines 148 to 152
to={
hasChanges
? "#"
: `${urlPrefix}/entry/${relationObject["child"]}`
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The Alert is a wonderful idea, but I don't think we should change the link: imagine a user wants to open an existing child node in a new tab with a ctrl+click or right-click+open in new tab.

I think we should only remove the link for newly created children.

Copy link
Member

Choose a reason for hiding this comment

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

The loss of changes is however a big deal @perierc

As we have hasChanges I think there is a way to handle that by warning the user if he tries to close the page (or navigate away):
see https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event

It might be in another PR though.

Copy link
Member

Choose a reason for hiding this comment

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

Created: #474

@Piv94165 Piv94165 marked this pull request as ready for review March 28, 2024 07:36
@Piv94165 Piv94165 requested a review from a team as a code owner March 28, 2024 07:36
@teolemon teolemon requested a review from alexgarel April 10, 2024 19:49
Copy link
Member

@alexgarel alexgarel left a comment

Choose a reason for hiding this comment

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

Great !

Tested on my side.

I stumbled on another bug while testing, see

@alexgarel alexgarel merged commit 6391abb into main Apr 11, 2024
8 checks passed
@alexgarel alexgarel deleted the piv94165/prevent-click-on-new-child-before-creation branch April 11, 2024 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

[QW] Disable click on new child if not created yet (changes not saved)
4 participants