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

Script editor updates (match automation editor) #20791

Merged
merged 4 commits into from
May 21, 2024

Conversation

karwosts
Copy link
Contributor

@karwosts karwosts commented May 13, 2024

Proposed change

Updates the script editor to match the style of the automation editor:

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

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:

@karwosts
Copy link
Contributor Author

@piitaya - Since you asked, here's my attempt at bringing automation editor style to the script editor.

I might have gone a little overboard doing refactoring trying to make the script editor and automation editor look more line-by-line equivalent, though when I got done I realized maybe this has become unreviewable 😅 .

I almost didn't want to put it up for that reason, but if you were planning on tackling this, I'll leave it up to you if you'd rather fight through this review, or if you can do a cleaner job yourself, I'm happy to just close this and let you drive it, I didn't know this was on your todo list.

Thanks!

@karwosts karwosts requested a review from piitaya May 13, 2024 12:57
},
},
{
name: "icon",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we drop icon from the UI? It's not clear to me how this interacts with icon from the entity registry, if one is considered priority over the other, or if this is just vestigial.

If we want to keep it I guess could fork the rename dialog (or share it with automations) and add it there.

Copy link
Member

Choose a reason for hiding this comment

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

I think we should drop it to be aligned with automation editor.
Currently, automation editor save name (as alias key) and description to yaml and icon to entity registry. You can also override the name in the entity registry.

IMO, name, description and icon should be editable without opening the more info settings dialog.
name and icon should be stored in the entity registry as it can be used everywhere (dashboard, automation list). description should be stored in the yaml as it's only used in the editor.

I will discuss this point with the rest of the UX/UI team so we can discuss how we manage the migration if we do changes (if it's needed).

},
},
{
name: "icon",
Copy link
Member

Choose a reason for hiding this comment

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

I think we should drop it to be aligned with automation editor.
Currently, automation editor save name (as alias key) and description to yaml and icon to entity registry. You can also override the name in the entity registry.

IMO, name, description and icon should be editable without opening the more info settings dialog.
name and icon should be stored in the entity registry as it can be used everywhere (dashboard, automation list). description should be stored in the yaml as it's only used in the editor.

I will discuss this point with the rest of the UX/UI team so we can discuss how we manage the migration if we do changes (if it's needed).

src/panels/config/script/ha-script-editor.ts Outdated Show resolved Hide resolved
@karwosts
Copy link
Contributor Author

If you're spending time thinking about scripts & names, I'll also point out that I think the use of unique_id for scripts also seems to cause a lot of confusion.

I believe when the script is first created, the unique_id is assigned (this is its key in scripts.yaml), and that id is forever used for the name of the service that is created to run this script, and no amount of renaming can change that. I think that cause a lot of user confusion why when they change alias/friendly_names/entity_ids the script services are not updated with the new name.

I'm not sure if that can be improved in some way. I know the duplicate button is used to migrate services from readonly to services.yaml, maybe we can have some kind of similar pattern for "migrating" a script to a new unique_id, if user wants that to be changed.

@piitaya
Copy link
Member

piitaya commented May 21, 2024

@karwosts I approved the PR. I will open another PR to add the icon to the rename dialog so user can edit the icon without opening the more info settings dialog. We will look if we can sync the name between yaml and entity registry to avoid confusion.

I wonder if we can use the entity_id for service call instead of unique_id...
I will discuss that with the core team... But it has the downside to break service call if you rename the entity id of the script (but at least, it's consistent with entity_id as a target in service calls. And it will be a breaking change so... 🤷‍♂️ So you have an idea of we can solve this issue?

@piitaya piitaya merged commit 9b28c7c into home-assistant:dev May 21, 2024
13 checks passed
@karwosts karwosts deleted the new-script-editor branch May 24, 2024 13:11
@piitaya piitaya mentioned this pull request May 27, 2024
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Creating a new script may overwrite an old script without warning
2 participants