-
-
Notifications
You must be signed in to change notification settings - Fork 247
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
show confirmation dialog on changes #887
Conversation
I actually started experimenting on this last year but didn't finish, I still have the code below in a git stash... So as you can see while I don't like the I extracted the beforeLeave logic into a function to avoid repeating code for every route, I'd suggest you do that as well. Having a reliable "dirtyness" flag is also a complex problem, I wanted to add Thanks a lot for looking into it!
|
I also thought about that, but as it seems you old "stash" missed something I also didn't realize at first: the router's
I'll look into this.
Well, for "Pages" the JSONs are not required at all, I only had to add them for Rules :-). I also didn't like the unnecessary JSON overhead, I just found it to be the common way to deep copy javascript objects. With some more research I found that it actually shouldn't be too hard to create a recursive cloning function that will be a few times faster than using JSON. I could imagine that by using the deep watch approach it's much easier to really catch all changes to an object.
You're welcome. Though your comment doesn't really reveal if I should continue looking into this and which approach to choose 😉 . |
Ah right, maybe only don't do it if routeTo's URL starts with routeFrom's, then? (meaning we are going "below" the current URL so no need to save then because it's probably a modal being opened)
I'm happy with the JSON approach for rules, and very happy that you decide to tackle this, as this was rather high in my priority list. |
Hm, I can't reproduce this. Due to
Egg of Columbus! Sometimes things can be just so easy ... 🤦
Assuming this means that I can go on implementing the 'watch' approach wherever suitable, including the adjustments mentioned. 😉 |
So, as discussed the commit now includes a mixin and is much cleaner. I tried to cover all sites where you can save your data and generalized the confirmation dialog. NotesAfter I was finished I realized that "Unsaved changes. Save now? -> Yes / No"-like dialog would actually be much more convenient, but that would require to rewrite all In "Rules" I replaced the JSON stuff with supposedly faster library functions. Originally, I didn't want to import libraries for this. But these are 1. already present as dependencies of other libraries, 2. actually tiny, so I think the overall performance boost might be worth it. Even though present, I still added them to |
Ah, and I updated blockly, as their current docs didn't match. I found there has been a breaking change in the events with the latest release. |
@hubsif are you finished with this PR? If so could you rebase and I'll have a closer look, thanks! |
Yes, I think this was ready to be reviewed. |
I checked it out and could reproduce it - I should have pointed out that this doesn't happen when you use the Back buttons on the pages, but it does when you use the native "back" feature of the browser to go back (I do that very often), or a physical "back" key on your device or mouse... |
@hubsif if you could rebase and apply ghys@c021806 that would be great. I tested it and it works okay, hope there won't be any adverse side effects but in any case it's better than having nothing at all! LGTM, nice work! |
Signed-off-by: Hubert Nusser <[email protected]>
Signed-off-by: Yannick Schaus <[email protected]>
done. |
Very nice, another major issue closed! |
I've spent some time looking into issue #367.
I think I have come up with an acceptable solution. It doesn't address all editable pages yet, since I wanted to get some feedback before attending the possibly more complicated parts (e.g. Things). Yet, it might provide some kind of "jump start" for this issue.
Notes
While it was easy to watch for changes in Pages, it was a little more difficult for Rules, which dynamically change their status through the eventsource.
The approach in Rules of storing the server-saved object and comparing changes to it has the advantage that "undone changes" can be detected. Perhaps that's generally desired?
In `routes.js`:
This definitely doesn't seem too clean, but it works nicely and I couldn't find another solution. More experienced developers might find a better way.
The
beforeLeave
method could also be put into a mixin (to be more DRY), though that probably means that only a generalized message can be displayed (right now it shows e.g. "Rule has not been saved").Once agreed on a certain approach, I can continue working on this if desired.