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

Change take control of blueprint UX #21254

Merged
merged 2 commits into from
Jul 2, 2024
Merged

Conversation

bramkragten
Copy link
Member

@bramkragten bramkragten commented Jul 2, 2024

Proposed change

CleanShot 2024-07-02 at 18 37 35@2x

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

    • Introduced blueprint configuration handling in automation and script editors, allowing users to take control, revert changes, and save modifications.
  • Bug Fixes

    • Various UI adjustments to improve the rendering logic and user experience within different editor components.
  • Style

    • Reformatted HTML templates and updated CSS styles for a more consistent appearance across the application.
  • Translation

    • Updated confirmation messages for taking control of automation and script configurations in the English translation file.

Copy link
Contributor

coderabbitai bot commented Jul 2, 2024

Walkthrough

Walkthrough

The updates revolve around enhancing automation and script editors by introducing or modifying blueprint handling features. This includes supporting blueprint configurations, enabling users to take control of blueprints, revert to original configurations, and save changes. Various UI elements and methods related to alerts and disabled states have been removed for cleaner and more intuitive user interactions.

Changes

File(s) Change Summary
src/.../blueprint-automation-editor.ts Removed conditional rendering of a warning alert in HaBlueprintAutomationEditor.
src/.../ha-automation-editor.ts Added _blueprintConfig state, methods for taking control of blueprints, reverting, saving changes.
src/.../manual-automation-editor.ts Removed a section handling disabled state and duplicate method.
src/.../blueprint-generic-editor.ts Adjusted HTML formatting, removed _duplicate method, reordered styling for ha-alert.
src/.../blueprint-script-editor.ts Removed display of a warning message and migration button when disabled.
src/.../ha-script-editor.ts Introduced _blueprintConfig, methods for blueprint handling, updated control flow and CSS.
src/.../manual-script-editor.ts Removed a section handling disabled state and duplicate method.
src/translations/en.json Updated key for control confirmation in English translation.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant HaAutomationEditor
    participant BlueprintService
    participant UIServices
    
    User->>HaAutomationEditor: Interact with blueprint
    HaAutomationEditor->>BlueprintService: Get blueprint config
    BlueprintService-->>HaAutomationEditor: Return blueprint config
    HaAutomationEditor->>UIServices: Display config (read-only)
    
    User->>HaAutomationEditor: Take control of blueprint
    HaAutomationEditor->>BlueprintService: Set new config
    BlueprintService-->>HaAutomationEditor: Confirm update
    HaAutomationEditor->>UIServices: Update to editable mode
    
    User->>HaAutomationEditor: Save changes after edit
    HaAutomationEditor->>BlueprintService: Save new config
    BlueprintService-->>HaAutomationEditor: Confirm save
    HaAutomationEditor->>UIServices: Notify save success
Loading

Tip

AI model upgrade

gpt-4o model for reviews and chat is now live

OpenAI claims that this model is better at understanding and generating code than the previous models. Please join our Discord Community to provide any feedback or to report any issues.


Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between e0c5203 and 2800a04.

Files selected for processing (1)
  • src/panels/config/blueprint/blueprint-generic-editor.ts (4 hunks)
Additional comments not posted (2)
src/panels/config/blueprint/blueprint-generic-editor.ts (2)

128-128: Ensure ha-expansion-panel is imported.

The ha-expansion-panel component is used here, but there is no import statement for it. Ensure it is imported to avoid runtime errors.

+ import "../../../components/ha-expansion-panel";

323-326: LGTM!

The added styling for ha-alert follows the existing CSS conventions.


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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 do a full 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 configuration to show the current CodeRabbit configuration for the repository.
  • @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.

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: 10

"text": "This script is based on a blueprint. You are about to take control, which will separate it from the blueprint and give you the ability to fully edit the script. Would you like to proceed?",
"action": "[%key:ui::panel::config::automation::editor::take_control_confirmation::action%]"
},
"confirm_take_control": "Your are viewing a preview of the script config, do you want to take control?",
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix typo in confirmation message.

There is a typo in the confirmation message: "Your are" should be "You are".

-  "confirm_take_control": "Your are viewing a preview of the script config, do you want to take control?"
+  "confirm_take_control": "You are viewing a preview of the script config, do you want to take control?"
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"confirm_take_control": "Your are viewing a preview of the script config, do you want to take control?",
"confirm_take_control": "You are viewing a preview of the script config, do you want to take control?"

"text": "This automation is based on a blueprint. You are about to take control, which will separate it from the blueprint and give you the ability to fully edit the automation. Would you like to proceed?",
"action": "Take control"
},
"confirm_take_control": "Your are viewing a preview of the automation config, do you want to take control?",
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix typo in confirmation message.

There is a typo in the confirmation message: "Your are" should be "You are".

-  "confirm_take_control": "Your are viewing a preview of the automation config, do you want to take control?"
+  "confirm_take_control": "You are viewing a preview of the automation config, do you want to take control?"
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"confirm_take_control": "Your are viewing a preview of the automation config, do you want to take control?",
"confirm_take_control": "You are viewing a preview of the automation config, do you want to take control?",

Comment on lines +835 to +836
blueprint-script-editor,
:not(.yaml-mode) > ha-alert {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure blueprint-script-editor and manual-script-editor are imported.

The blueprint-script-editor and manual-script-editor components are used here, but there is no import statement for them. Ensure they are imported to avoid runtime errors.

+ import "./blueprint-script-editor";
+ import "./manual-script-editor";

Committable suggestion was skipped due to low confidence.

@@ -653,14 +654,33 @@
description: config.description,
};

this._blueprintConfig = config;
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid using any type.

Replace the any type with a more specific type to improve type safety.

- } catch (err: any) {
+ } catch (err: Error) {

Committable suggestion was skipped due to low confidence.

Comment on lines +659 to +662
if (this._mode === "yaml") {
this.renderRoot.querySelector("ha-yaml-editor")?.setValue(this._config);
}
this._readOnly = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix read-only state logic.

The read-only state should be set to false after taking control of the blueprint.

- this._readOnly = true;
+ this._readOnly = false;
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (this._mode === "yaml") {
this.renderRoot.querySelector("ha-yaml-editor")?.setValue(this._config);
}
this._readOnly = true;
if (this._mode === "yaml") {
this.renderRoot.querySelector("ha-yaml-editor")?.setValue(this._config);
}
this._readOnly = false;

src/panels/config/script/ha-script-editor.ts Show resolved Hide resolved
Comment on lines +845 to +846
blueprint-automation-editor,
:not(.yaml-mode) > ha-alert {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure blueprint-automation-editor and manual-automation-editor are imported.

The blueprint-automation-editor and manual-automation-editor components are used here, but there is no import statement for them. Ensure they are imported to avoid runtime errors.

+ import "./blueprint-automation-editor";
+ import "./manual-automation-editor";

Committable suggestion was skipped due to low confidence.

Comment on lines +686 to +691
this._blueprintConfig = config;
this._config = newConfig;
this._dirty = true;
if (this._mode === "yaml") {
this.renderRoot.querySelector("ha-yaml-editor")?.setValue(this._config);
}
this._readOnly = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix read-only state logic.

The read-only state should be set to false after taking control of the blueprint.

- this._readOnly = true;
+ this._readOnly = false;
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
this._blueprintConfig = config;
this._config = newConfig;
this._dirty = true;
if (this._mode === "yaml") {
this.renderRoot.querySelector("ha-yaml-editor")?.setValue(this._config);
}
this._readOnly = true;
this._blueprintConfig = config;
this._config = newConfig;
if (this._mode === "yaml") {
this.renderRoot.querySelector("ha-yaml-editor")?.setValue(this._config);
}
this._readOnly = false;

Comment on lines +231 to +232
.disabled=${this._blueprintConfig ||
(!this._readOnly && !this.automationId)}
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix conditional logic for disabling the duplicate button.

The current logic might not cover all cases. Ensure that the button is correctly disabled based on the blueprint configuration and read-only state.

- .disabled=${this._blueprintConfig || (!this._readOnly && !this.automationId)}
+ .disabled=${!this._blueprintConfig && (!this._readOnly || !this.automationId)}

Committable suggestion was skipped due to low confidence.

@bramkragten bramkragten added this to the 2024.7 milestone Jul 2, 2024
@bramkragten bramkragten merged commit 9a2051a into dev Jul 2, 2024
8 of 9 checks passed
@bramkragten bramkragten deleted the ux-take-control-blueprint branch July 2, 2024 19:19
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