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 leaving the editor if there are unsaved changes #23170

Merged

Conversation

jpbede
Copy link
Member

@jpbede jpbede commented Dec 5, 2024

Proposed change

Prevent (accidentally) exiting the automation/script/scene editor by navigating in the sidebar if you have unsaved changes. You will now be asked if you are sure you want to leave the editor.

WTH: https://community.home-assistant.io/t/wth-doesnt-ha-ask-if-i-want-to-save-automations/804030

Bildschirmaufnahme.2024-12-05.um.19.50.50.mov

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue or discussion:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

@home-assistant home-assistant bot added cla-signed WTH Issues & PRs generated from the "Month of What the Heck?" labels Dec 5, 2024
@jpbede jpbede changed the title Revert translation change for device quick bar Prevent leaving the editor if there are unsaved changes Dec 5, 2024
@silamon
Copy link
Contributor

silamon commented Dec 5, 2024

There's a similar PR here: #20161

@bramkragten
Copy link
Member

I like it! Nice work!

@jpbede jpbede force-pushed the automation-editor-prevent-navigate branch from ec49f08 to 59bb2e9 Compare December 6, 2024 11:46
silamon
silamon previously approved these changes Dec 11, 2024
Copy link
Contributor

@silamon silamon left a comment

Choose a reason for hiding this comment

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

Tested, works pretty solid.

@bramkragten
Copy link
Member

There are a few cases that are not handled by this solution, as it only works for anchor links. Like if you open the more info in the automation editor and then go to the device from the overflow your will still navigate away while losing your changes. I wonder if we can go 1 step deeper and intercept the navigate call...

@bramkragten
Copy link
Member

There are a few cases that are not handled by this solution, as it only works for anchor links. Like if you open the more info in the automation editor and then go to the device from the overflow your will still navigate away while losing your changes. I wonder if we can go 1 step deeper and intercept the navigate call...

Actually looks like this is not really an issue atm, as an automation is not part of a device and the other related items and history and logbook do use anchors...

@silamon
Copy link
Contributor

silamon commented Dec 11, 2024

There are a few cases that are not handled by this solution, as it only works for anchor links. Like if you open the more info in the automation editor and then go to the device from the overflow your will still navigate away while losing your changes. I wonder if we can go 1 step deeper and intercept the navigate call...

2 options I could think of (not easy ones :D)

  • Catch it in the custom router, although this is after navigate is already called, the url already been changed, so pushing back there is a little too late since you need to modify the history again at that point if you want to remain on the page.
  • Implement something similar like how we handle dialogs, being done in the navigate call, so before history is modified.

Neither one of the solutions allows to access the component to ask if it's dirty, so it will need to be a static piece of memory somewhere.

@bramkragten bramkragten merged commit c8f58c7 into home-assistant:dev Dec 11, 2024
15 checks passed
@jpbede jpbede deleted the automation-editor-prevent-navigate branch December 11, 2024 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed WTH Issues & PRs generated from the "Month of What the Heck?"
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants