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 change icon #20885

Merged
merged 3 commits into from
May 29, 2024
Merged

Script change icon #20885

merged 3 commits into from
May 29, 2024

Conversation

piitaya
Copy link
Member

@piitaya piitaya commented May 27, 2024

Proposed change

Following #20791, add script icon to the rename dialog.
We should find a way to sync yaml alias, icon and script with entity registry in the future.

CleanShot 2024-05-27 at 17 59 38

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:

Summary by CodeRabbit

  • New Features

    • Added support for renaming scripts in addition to automations.
    • Introduced a new icon picker for scripts.
  • Enhancements

    • Updated script and automation rename dialog to handle script-specific properties.
    • Improved script editing logic in the script editor.
  • Localization

    • Added new translation key for "icon" in the English language file.

Copy link
Contributor

coderabbitai bot commented May 27, 2024

Walkthrough

Walkthrough

The recent changes introduce support for renaming both automations and scripts, including an icon picker for scripts. Updates include modifications to method signatures, parameter types, and the addition of new properties and imports to handle the specific requirements of scripts. These enhancements ensure a more unified and flexible approach to managing automations and scripts within the application.

Changes

File Path Change Summary
src/panels/config/automation/automation-rename-dialog/dialog-automation-rename.ts Added support for renaming scripts, introduced an icon picker, updated method signatures, and added new properties.
src/panels/config/automation/automation-rename-dialog/show-dialog-automation-rename.ts Renamed interfaces, added a domain property, and updated parameter types in the showAutomationRenameDialog function.
src/panels/config/automation/ha-automation-editor.ts Added imports for ha-icon and ha-list-item, and included a domain parameter in the updateConfig function.
src/panels/config/script/ha-script-editor.ts Updated import for showMoreInfoDialog, added a domain parameter to showAutomationRenameDialog, and updated script editing logic.
src/translations/en.json Added a new key-value pair "icon": "Icon" under a specific section.

Recent Review Details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits Files that changed from the base of the PR and between 05aecaa and 05f084b.
Files selected for processing (5)
  • src/panels/config/automation/automation-rename-dialog/dialog-automation-rename.ts (6 hunks)
  • src/panels/config/automation/automation-rename-dialog/show-dialog-automation-rename.ts (1 hunks)
  • src/panels/config/automation/ha-automation-editor.ts (2 hunks)
  • src/panels/config/script/ha-script-editor.ts (4 hunks)
  • src/translations/en.json (1 hunks)
Additional Context Used
Biome (43)
src/panels/config/automation/automation-rename-dialog/dialog-automation-rename.ts (3)

149-149: Unexpected any. Specify a different type.


1-2: Some named imports are only used as types.


11-12: All these imports are only used as types.

src/panels/config/automation/ha-automation-editor.ts (20)

181-181: Forbidden non-null assertion.


248-248: Do not use template literals if interpolation and special-character handling are not needed.


258-258: Do not use template literals if interpolation and special-character handling are not needed.


461-463: Prefer for...of instead of forEach.


522-522: Unexpected any. Specify a different type.


603-603: Avoid the delete operator which can impact performance.


620-620: Forbidden non-null assertion.


623-623: Forbidden non-null assertion.


626-626: Forbidden non-null assertion.


627-627: Forbidden non-null assertion.


666-666: Forbidden non-null assertion.


668-668: Forbidden non-null assertion.


691-691: Forbidden non-null assertion.


707-707: Forbidden non-null assertion.


730-730: Forbidden non-null assertion.


731-731: Unexpected any. Specify a different type.


16-17: All these imports are only used as types.


17-26: Some named imports are only used as types.


39-50: Some named imports are only used as types.


60-61: All these imports are only used as types.

src/panels/config/script/ha-script-editor.ts (20)

241-241: Do not use template literals if interpolation and special-character handling are not needed.


251-251: Do not use template literals if interpolation and special-character handling are not needed.


458-458: Forbidden non-null assertion.


503-503: Forbidden non-null assertion.


505-505: Forbidden non-null assertion.


510-510: Forbidden non-null assertion.


513-513: Forbidden non-null assertion.


559-559: Forbidden non-null assertion.


583-583: Forbidden non-null assertion.


586-586: Forbidden non-null assertion.


589-589: Forbidden non-null assertion.


590-590: Forbidden non-null assertion.


633-633: Forbidden non-null assertion.


635-635: Forbidden non-null assertion.


641-641: Forbidden non-null assertion.


656-656: Forbidden non-null assertion.


672-672: Forbidden non-null assertion.


705-705: Forbidden non-null assertion.


711-711: Forbidden non-null assertion.


713-713: Template literals are preferred over string concatenation.

Additional comments not posted (13)
src/panels/config/automation/automation-rename-dialog/show-dialog-automation-rename.ts (3)

8-10: Ensure consistent use of domain types.

The explicit setting of the domain property to "automation" in the AutomationRenameDialogParams interface ensures that the type is strictly enforced, which is good for maintainability and avoiding runtime errors.


15-17: Ensure consistent use of domain types.

Similarly, setting the domain property to "script" in the ScriptRenameDialogParams interface is a good practice for type safety and clarity in the codebase.


24-24: Review the integration of the showAutomationRenameDialog function.

The function now accepts a union type of AutomationRenameDialogParams | ScriptRenameDialogParams, which is a flexible approach to handle both automation and script dialogs through a single function. This change enhances the function's versatility.

src/panels/config/automation/automation-rename-dialog/dialog-automation-rename.ts (5)

28-28: Check the type safety of _params.

The change to allow _params to be of type AutomationRenameDialogParams | ScriptRenameDialogParams is appropriate given the context of handling both automation and script dialogs. This is a good use of TypeScript's union types to enforce flexibility while maintaining type safety.


32-32: Review the handling of icon changes.

The addition of _newIcon and the _iconChanged method to handle icon updates is a good enhancement. It allows dynamic updates to the icon based on user interactions, which improves the UI's responsiveness and functionality.

Also applies to: 142-145


36-41: Ensure correct initialization of dialog parameters.

The showDialog method correctly initializes the internal state with the provided parameters, including handling the optional icon property. This ensures that the dialog reflects the current state of the automation or script being edited.


96-114: Review conditional rendering logic for the icon picker.

The conditional rendering of the ha-icon-picker component based on the domain type is a smart way to customize the UI based on the context (automation vs script). This makes the UI more intuitive and tailored to the user's current task.


162-175: Check the update logic in the _save method.

The method correctly handles the saving of different properties based on the domain. This includes a conditional check to ensure that the icon is only updated for scripts, aligning with the functional requirements specified.

src/panels/config/script/ha-script-editor.ts (2)

36-36: Review the addition of new imports.

The new imports for ha-list-item, ha-svg-icon, and showMoreInfoDialog are used appropriately within the file to enhance the script editor's functionality, such as displaying list items and handling more info dialogs.

Also applies to: 53-53


657-657: Check the domain specification in the showAutomationRenameDialog call.

Specifying the domain as "script" when calling showAutomationRenameDialog ensures that the dialog behaves correctly for script entities. This is a crucial detail that aligns with the new functionality to handle both scripts and automations.

src/panels/config/automation/ha-automation-editor.ts (2)

35-37: Review the addition of new imports.

The imports for ha-icon, ha-icon-button, ha-list-item, and ha-svg-icon are correctly added to support the UI components used in the automation editor. These components are essential for providing a rich user interface.


692-692: Check the domain specification in the showAutomationRenameDialog call.

The explicit setting of the domain to "automation" ensures that the rename dialog is correctly configured for automation entities. This is important for maintaining consistent behavior across different parts of the application.

src/translations/en.json (1)

2769-2769: The addition of the "icon": "Icon" key-value pair aligns with the PR's objectives and enhances localization support for the new icon picker feature.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to full the review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@piitaya
Copy link
Member Author

piitaya commented May 27, 2024

@karwosts I added back the icon to the rename dialog so user can edit the icon from config using the UI.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

@bramkragten
Copy link
Member

Should we rename dialog-automation-rename to something more generic?

@bramkragten bramkragten merged commit e059ca1 into dev May 29, 2024
13 checks passed
@bramkragten bramkragten deleted the script_change_icon branch May 29, 2024 11:57
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.

2 participants