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

Prevent page exit on the create page when there are unsaved changes #6566

Merged
merged 5 commits into from
Dec 22, 2021
Merged

Prevent page exit on the create page when there are unsaved changes #6566

merged 5 commits into from
Dec 22, 2021

Conversation

avinashupadhya99
Copy link
Contributor

@avinashupadhya99 avinashupadhya99 commented Oct 23, 2021

Closes #3567

Changes -

  • Created a canDeactivate route guard for the create route
  • Added a listener for reload in the create page that asks for confirmation if there are unsaved changes
  • No confirmation asked for rerouting after submit but confirmation asked for manual rerouting after submit if the form values are invalid

Included a short video explaining how the changes look like -

Kubernetes.Dashboard.changes.demo.mp4

Missed mentioning that there is no confirmation dialog if there are no changes to any of the forms or if the changes are reversed.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Oct 23, 2021
@k8s-ci-robot
Copy link
Contributor

Welcome @avinashupadhya99!

It looks like this is your first PR to kubernetes/dashboard 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/dashboard has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Oct 23, 2021
@avinashupadhya99
Copy link
Contributor Author

/assign @maciaszczykm

@floreks
Copy link
Member

floreks commented Oct 25, 2021

I'd prefer to use a custom dialog that matches our UI design here.

@avinashupadhya99
Copy link
Contributor Author

avinashupadhya99 commented Oct 25, 2021

I'd prefer to use a custom dialog that matches our UI design here.

Is there an example I can look at? Thanks

@maciaszczykm
Copy link
Member

@floreks meant a dialog like the one that shows up when the namespace already exists. It's in the video.

@avinashupadhya99
Copy link
Contributor Author

We'll need to prevent the page reload in the browser when the reload button is clicked and display the dialog and do a manual reload if necessary but it looks like we cannot prevent the reload. I tried out a simple experiement and as far as I know, there is no way to prevent the reload of a page without the browser confirmation dialog. I tried inserting $event.preventDefault(); in

instead of $event.returnValue = true; but that did not prevent the page from reloading. Please correct me if I am wrong. I came across this SO answer which also states the same - https://stackoverflow.com/a/34415095.

@floreks
Copy link
Member

floreks commented Oct 26, 2021

I am not sure if you will be able to hijack and stop the browser refresh this way. I'd have to check to confirm. Will try to spend some time tomorrow on this.

@floreks
Copy link
Member

floreks commented Oct 27, 2021

It is indeed not possible to hijack the dialog that appears before unloading the page. It's not even possible to update the text that is displayed there and it was an intentional change done by the browser devs to avoid malicious usage of such popups.

I have refactored the code to match our style and used a custom dialog for the internal view change. The overall solution was good and I liked it.

Thanks!

@codecov
Copy link

codecov bot commented Oct 27, 2021

Codecov Report

Merging #6566 (2fec5e1) into master (5106f87) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master    #6566   +/-   ##
=======================================
  Coverage   42.55%   42.55%           
=======================================
  Files         217      217           
  Lines       10644    10644           
  Branches      177      177           
=======================================
  Hits         4530     4530           
  Misses       5851     5851           
  Partials      263      263           

@floreks
Copy link
Member

floreks commented Dec 22, 2021

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 22, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: avinashupadhya99, floreks

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 22, 2021
@k8s-ci-robot k8s-ci-robot merged commit 254b752 into kubernetes:master Dec 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prevent page exit on the create page when there are unsaved changes
4 participants