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

Resize card editor #21115

Merged
merged 14 commits into from
Jun 24, 2024
Merged

Resize card editor #21115

merged 14 commits into from
Jun 24, 2024

Conversation

piitaya
Copy link
Member

@piitaya piitaya commented Jun 19, 2024

Proposed change

Add layout editor on card to resize cards on grid sections.
NEEDS #21065

Some points to improve in future PR :

  • Add support for other views and sections. Each sections/views should be able to provide an editor.
  • Add restriction for resizing. For some cards like entities card, the height should not be editable.

CleanShot 2024-06-19 at 12 18 21

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 ha-grid-size-picker for customizing grid sizes with sliders.
    • Added ha-grid-layout-slider for numerical value control with enhanced accessibility.
    • Added a layout editing tab in the card element editor.
  • Enhancements

    • Improved layout and visibility configuration in Lovelace cards.
    • Added new translations for grid-size picker and layout options.
  • Bug Fixes

    • Updated event handling to use the new preventDefault function.
  • Style

    • Updated styling and rendering logic for visibility editor and layout editor.
  • Documentation

    • Added explanations for card visibility and layout configurations in translations.

@frenck frenck added the Noteworthy Marks a PR as noteworthy and should be in the release notes (in case it normally would not appear) label Jun 19, 2024
@piitaya piitaya marked this pull request as ready for review June 20, 2024 08:08
Copy link
Contributor

coderabbitai bot commented Jun 20, 2024

Walkthrough

Walkthrough

The changes introduce a customizable grid size picker for the Lovelace card editor in Home Assistant, alongside revisions to existing UI components and properties. Key updates include a new prevent default function, the addition of the preview property replacing editMode, a layout editor tab, and accessibility improvements. These enhance the user experience and editing capabilities within the Lovelace UI, making grid adjustments and layout configuration more intuitive.

Changes

File or Path Change Summary
src/common/dom/prevent_default.ts Added preventDefault function for event handling.
src/components/ha-grid-size-picker.ts, src/panels/lovelace/editor/card-editor/ha-grid-layout-slider.ts, src/panels/lovelace/editor/card-editor/hui-card-layout-editor.ts Introduced grid size picker and layout editor with sliders for rows and columns, default reset options, and visual grid layout.
src/data/lovelace.ts, src/panels/lovelace/cards/hui-card.ts, src/panels/lovelace/views/hui-view.ts, src/panels/lovelace/sections/hui-section.ts Added preview property, replacing editMode, updated initialization and usage.
src/panels/lovelace/editor/card-editor/hui-card-element-editor.ts Added a new layout tab in the card element editor, updated tab selection logic, and modified tab localization keys.
src/panels/lovelace/editor/card-editor/hui-card-visibility-editor.ts Updated intro text rendering with custom styling, replacing <ha-alert> with a <p> tag.
src/panels/lovelace/editor/card-editor/hui-dialog-edit-card.ts Added _shouldShowLayoutTab method for determining the visibility of the layout tab.
src/panels/lovelace/editor/conditions/ha-card-condition-editor.ts Changed preventDefault import source, impacting the module structure.
src/translations/en.json Added translations for grid-size picker, reset options, columns, rows, and explanation tags for visibility and layout configurations.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant HaGridSizeEditor as ha-grid-size-picker
    participant HuiCardElementEditor as hui-card-element-editor
    participant HuiDialogEditCard as hui-dialog-edit-card
    participant LovelaceCard

    User->>+HuiDialogEditCard: Opens card editor
    HuiDialogEditCard->>+HuiCardElementEditor: Initializes editor tabs
    HuiCardElementEditor-->>-User: Renders config, visibility, layout tabs
    
    User->>+HaGridSizeEditor: Adjusts grid size
    HaGridSizeEditor-->>-User: Updates grid layout
    
    User->>+LovelaceCard: Modifies layout
    LovelaceCard-->>-User: Applies changes and emits event

    User->>+HuiCardElementEditor: Switches to layout tab
    HuiCardElementEditor-->>-User: Renders layout options
Loading

Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between c6c0ca9 and 28d5609.

Files selected for processing (14)
  • src/common/dom/prevent_default.ts (1 hunks)
  • src/components/ha-grid-size-picker.ts (1 hunks)
  • src/data/lovelace.ts (1 hunks)
  • src/panels/lovelace/cards/hui-card.ts (2 hunks)
  • src/panels/lovelace/editor/card-editor/ha-grid-layout-slider.ts (1 hunks)
  • src/panels/lovelace/editor/card-editor/hui-card-element-editor.ts (3 hunks)
  • src/panels/lovelace/editor/card-editor/hui-card-layout-editor.ts (1 hunks)
  • src/panels/lovelace/editor/card-editor/hui-card-visibility-editor.ts (3 hunks)
  • src/panels/lovelace/editor/card-editor/hui-dialog-edit-card.ts (2 hunks)
  • src/panels/lovelace/editor/conditions/ha-card-condition-editor.ts (1 hunks)
  • src/panels/lovelace/sections/hui-grid-section.ts (4 hunks)
  • src/panels/lovelace/sections/hui-section.ts (1 hunks)
  • src/panels/lovelace/views/hui-view.ts (1 hunks)
  • src/translations/en.json (2 hunks)
Additional context used
Biome
src/panels/lovelace/editor/card-editor/hui-card-visibility-editor.ts

[error] 41-41: Avoid the delete operator which can impact performance. (lint/performance/noDelete)

Unsafe fix: Use an undefined assignment instead.

src/panels/lovelace/editor/card-editor/hui-card-element-editor.ts

[error] 25-25: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 28-28: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.


[error] 36-36: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 39-39: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.

src/panels/lovelace/cards/hui-card.ts

[error] 98-98: Unexpected any. Specify a different type. (lint/suspicious/noExplicitAny)

any disables many type checking rules. Its use should be avoided.


[error] 140-140: Unexpected any. Specify a different type. (lint/suspicious/noExplicitAny)

any disables many type checking rules. Its use should be avoided.


[error] 148-148: Unexpected any. Specify a different type. (lint/suspicious/noExplicitAny)

any disables many type checking rules. Its use should be avoided.


[error] 149-149: Unexpected any. Specify a different type. (lint/suspicious/noExplicitAny)

any disables many type checking rules. Its use should be avoided.


[error] 160-160: Unexpected any. Specify a different type. (lint/suspicious/noExplicitAny)

any disables many type checking rules. Its use should be avoided.

src/panels/lovelace/sections/hui-grid-section.ts

[error] 58-58: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 100-100: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 158-158: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 162-162: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator

src/panels/lovelace/sections/hui-section.ts

[error] 171-171: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 192-192: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 193-193: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 194-194: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 195-195: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 196-196: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 197-197: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 260-260: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 260-260: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 262-262: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator

src/panels/lovelace/editor/card-editor/hui-card-layout-editor.ts

[error] 184-184: Avoid the delete operator which can impact performance. (lint/performance/noDelete)

Unsafe fix: Use an undefined assignment instead.


[error] 202-202: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 203-203: Avoid the delete operator which can impact performance. (lint/performance/noDelete)

Unsafe fix: Use an undefined assignment instead.


[error] 203-203: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 205-205: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 206-206: Avoid the delete operator which can impact performance. (lint/performance/noDelete)

Unsafe fix: Use an undefined assignment instead.


[error] 206-206: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 208-208: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 209-209: Avoid the delete operator which can impact performance. (lint/performance/noDelete)

Unsafe fix: Use an undefined assignment instead.

src/panels/lovelace/editor/conditions/ha-card-condition-editor.ts

[error] 56-56: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 56-56: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 169-169: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 187-187: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 188-188: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 191-191: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator

src/panels/lovelace/editor/card-editor/ha-grid-layout-slider.ts

[error] 141-141: This variable implicitly has the any type. (lint/suspicious/noImplicitAnyLet)

Variable declarations without type annotation and initialization implicitly have the any type. Declare a type or initialize the variable with some value.

src/panels/lovelace/views/hui-view.ts

[error] 92-92: Unexpected any. Specify a different type. (lint/suspicious/noExplicitAny)

any disables many type checking rules. Its use should be avoided.


[error] 117-117: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 173-173: Unexpected any. Specify a different type. (lint/suspicious/noExplicitAny)

any disables many type checking rules. Its use should be avoided.


[error] 185-185: Unexpected any. Specify a different type. (lint/suspicious/noExplicitAny)

any disables many type checking rules. Its use should be avoided.


[error] 214-214: Unexpected any. Specify a different type. (lint/suspicious/noExplicitAny)

any disables many type checking rules. Its use should be avoided.


[error] 261-261: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 283-283: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 284-284: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 285-285: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 286-286: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 287-287: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 288-288: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 289-289: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 290-290: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 299-299: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 325-325: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 325-325: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 327-327: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 339-339: Unexpected any. Specify a different type. (lint/suspicious/noExplicitAny)

any disables many type checking rules. Its use should be avoided.


[error] 344-344: Unexpected any. Specify a different type. (lint/suspicious/noExplicitAny)

any disables many type checking rules. Its use should be avoided.

src/panels/lovelace/editor/card-editor/hui-dialog-edit-card.ts

[error] 146-146: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 149-149: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 154-154: Unexpected any. Specify a different type. (lint/suspicious/noExplicitAny)

any disables many type checking rules. Its use should be avoided.


[error] 170-170: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.


[error] 182-182: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 186-186: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 192-192: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 196-196: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 198-198: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 226-226: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 286-286: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 296-296: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 312-312: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 164-164: Excessive complexity detected. (lint/complexity/noExcessiveCognitiveComplexity)

Please refactor this function to reduce its complexity score from 30 to the max allowed complexity 15.


[error] 353-353: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 387-387: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.


[error] 399-399: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 402-402: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 405-405: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


[error] 406-406: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator

Gitleaks
src/translations/en.json

6490-6491: Identified a HashiCorp Terraform password field, risking unauthorized infrastructure configuration and security breaches. (hashicorp-tf-password)

Additional comments not posted (8)
src/common/dom/prevent_default.ts (1)

1-1: Proper use of arrow function for event handling.

The preventDefault function correctly uses an arrow function to ensure that this context is not bound unnecessarily. It's concise and effectively prevents the default action on events.

src/data/lovelace.ts (1)

33-33: Good addition of preview property to the interface.

Adding the preview property to the LovelaceSectionElement interface is a thoughtful change that supports the new features related to card layout previewing.

src/panels/lovelace/editor/card-editor/hui-card-element-editor.ts (1)

Line range hint 9-101: Refactor to use optional chaining for better safety and readability.

There are several places in the code where non-null assertions are used, which could lead to runtime errors if not handled properly. Consider using optional chaining to make the code more robust and easier to read.
[REFACTOR_SUGGESTion]

- const elClass = await getCardElementClass(this.configElementType!);
+ const elClass = await getCardElementClass(this.configElementType);
- return elClass && elClass.getConfigElement;
+ return elClass?.getConfigElement();
- return elClass && elClass.getConfigForm;
+ return elClass?.getConfigForm();
src/panels/lovelace/cards/hui-card.ts (1)

162-162: Ensure visibility update logic is correct.

The method willUpdate contains logic to update visibility but does not handle all potential changes that might affect the visibility state. Ensure that all relevant properties are checked and handled appropriately.

src/components/ha-grid-size-picker.ts (1)

137-155: Ensure proper event handling in value change methods.

The _valueChanged and _reset methods stop event propagation which might interfere with other components that rely on these events. Verify that stopping propagation is necessary and document why it's required in the code.

src/panels/lovelace/editor/conditions/ha-card-condition-editor.ts (1)

8-8: Good practice to use event prevention utilities.

Using preventDefault and stopPropagation from shared utility modules promotes reusability and consistency across the project. This is a good practice as it centralizes common event handling behaviors which can be optimized and maintained in one place.

src/panels/lovelace/editor/card-editor/hui-dialog-edit-card.ts (1)

356-365: Clarify the logic behind the condition for showing the layout tab.

The method _shouldShowLayoutTab() determines the visibility of the layout tab based on whether the card is in a grid section. While the logic is clear, adding a comment explaining why only grid sections are considered could enhance maintainability and understandability for other developers or future modifications.

src/translations/en.json (1)

744-748: Translations for grid-size-picker are appropriate and well-formatted.

These translations align with the new feature allowing users to adjust grid sizes, enhancing user experience by providing clear instructions.


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

Outside diff range comments (8)
src/panels/lovelace/cards/hui-error-card.ts (1)

Line range hint 35-35: Consider replacing any with a more specific error type to enhance type safety.

- catch (err: any) {
+ catch (err: Error) {
src/panels/lovelace/editor/card-editor/hui-card-visibility-editor.ts (1)

Line range hint 41-41: Consider avoiding the delete operator to enhance performance. Set the property to undefined instead.

- delete newConfig.visibility;
+ newConfig.visibility = undefined;
src/panels/lovelace/editor/card-editor/hui-dialog-delete-card.ts (1)

Line range hint 62-62: Consider replacing the non-null assertion operators with optional chaining to ensure safer code.

- ${this.hass!.localize("ui.common.cancel")}
+ ${this.hass?.localize("ui.common.cancel")}

- ${this.hass!.localize("ui.common.delete")}
+ ${this.hass?.localize("ui.common.delete")}

Also applies to: 65-65

src/panels/lovelace/editor/card-editor/hui-dialog-suggest-card.ts (1)

Line range hint 66-66: Several non-null assertion operators are used throughout the file. Consider replacing these with optional chaining to prevent potential runtime errors.

- this.hass!
+ this.hass?
- this._cardConfig!
+ this._cardConfig?
- this._sectionConfig!
+ this._sectionConfig?
- this._yamlEditor!
+ this._yamlEditor?
- this.lovelace!
+ this.lovelace?

Also applies to: 110-110, 133-134, 141-141, 160-160, 221-222, 223-224

src/panels/lovelace/sections/hui-grid-section.ts (1)

Line range hint 58-58: Several non-null assertion operators are used. It's recommended to replace these with optional chaining for safer code.

- this.lovelace!.config
+ this.lovelace?.config
- this.cards![idx]
+ this.cards?[idx]
- [...oldPath, oldIndex] as [number, number, number]
+ [...(oldPath ?? []), oldIndex] as [number, number, number]
- this._layoutElement!.cards = this._cards
+ this._layoutElement?.cards = this._cards

Also applies to: 100-100, 158-158, 162-162

src/panels/lovelace/sections/hui-section.ts (1)

Line range hint 171-171: Several non-null assertion operators are used. Consider replacing these with optional chaining to enhance code safety and maintainability.

- this.hass!
+ this.hass?
- this.lovelace!
+ this.lovelace?
- this._layoutElement!
+ this._layoutElement?

Also applies to: 192-192, 193-193, 194-194, 195-195, 196-196, 197-197, 260-260, 262-262

src/panels/lovelace/views/hui-masonry-view.ts (1)

Line range hint 71-71: Avoid using non-null assertion operators to prevent runtime errors.

Consider replacing non-null assertions with optional chaining or proper checks to ensure the object properties are defined before accessing them.

Also applies to: 91-91, 119-119, 134-134, 153-154, 165-165, 239-239, 260-260, 276-276

Tools
Biome

[error] 260-260: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

src/panels/lovelace/editor/conditions/ha-card-condition-editor.ts (1)

Line range hint 56-56: Non-null assertion operators are used, which could lead to potential runtime errors if the assumptions fail.

Consider replacing non-null assertions with optional chaining or proper existence checks to ensure robustness.

Also applies to: 169-169, 187-188, 191-191

src/panels/lovelace/views/hui-view.ts Outdated Show resolved Hide resolved
src/panels/lovelace/views/hui-view.ts Outdated Show resolved Hide resolved
src/panels/lovelace/views/hui-view.ts Outdated Show resolved Hide resolved
src/panels/lovelace/views/hui-sidebar-view.ts Outdated Show resolved Hide resolved
src/panels/lovelace/cards/hui-entity-filter-card.ts Outdated Show resolved Hide resolved
src/panels/lovelace/cards/hui-entity-filter-card.ts Outdated Show resolved Hide resolved
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: 1

Outside diff range comments (1)
src/panels/lovelace/editor/card-editor/hui-dialog-edit-card.ts (1)

Line range hint 239-267: Enhance the conditional rendering logic for layout and visibility tabs.

- .showLayoutTab=${this._shouldShowLayoutTab()}
+ .showLayoutTab=${this._params?.path.length === 2 && (!this._containerConfig.type || this._containerConfig.type === "grid")}
- .showVisibilityTab=${this._cardConfig?.type !== "conditional"}
+ .showVisibilityTab=${this._cardConfig && this._cardConfig.type !== "conditional"}

This change simplifies the conditional checks directly in the template rendering, making the code more concise and potentially easier to understand at a glance. It removes the need for separate methods that only contribute minimal logic, thus streamlining the component.

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

Outside diff range comments (8)
src/panels/lovelace/editor/card-editor/hui-card-visibility-editor.ts (1)

Line range hint 1-52: Consider optimizing property deletion for performance.

The method _valueChanged uses the delete operator, which can impact performance. Consider setting the property to undefined instead to potentially enhance performance.

- delete newConfig.visibility;
+ newConfig.visibility = undefined;
src/panels/lovelace/sections/hui-grid-section.ts (2)

Line range hint 26-229: Refactor the render method to improve CSS handling and readability.

The render method contains complex CSS and HTML structures that are difficult to read and maintain. Consider extracting CSS to external stylesheets or using CSS-in-JS solutions to improve maintainability and separation of concerns.

-  static get styles(): CSSResultGroup {
+  static get styles(): CSSResultGroup {
+    // Move CSS to external stylesheet or CSS-in-JS solution
+  }
Tools
Biome

[error] 100-100: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator


Line range hint 26-229: Improve accessibility and user interaction in the _addCard method.

The _addCard method could be improved by adding keyboard accessibility features and providing feedback to the user when an action is taken. Consider adding keyboard shortcuts and visual indicators for successful card addition.

Tools
Biome

[error] 100-100: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator

src/panels/lovelace/views/hui-view.ts (2)

Line range hint 92-92: Specify explicit types instead of using any.

Using any disables TypeScript's type checking, which can lead to bugs that are hard to detect. Specify explicit types to enhance type safety and maintainability.

- catch (e: any) {
+ catch (e: Error) {

This change should be applied wherever any is used for error handling in this file.

Also applies to: 117-117, 173-173, 185-185, 214-214, 339-339, 344-344

Tools
Biome

[error] 214-214: Unexpected any. Specify a different type. (lint/suspicious/noExplicitAny)

any disables many type checking rules. Its use should be avoided.


Line range hint 261-261: Avoid non-null assertions; use optional chaining and default values where applicable.

Non-null assertions can lead to runtime errors if the object is null. Replace these with optional chaining and provide default values to ensure robustness.

- this.hass!;
+ this.hass?.;

Apply this change across all instances where non-null assertions are used.

Also applies to: 283-283, 284-284, 285-285, 286-286, 287-287, 288-288, 289-289, 290-290, 299-299, 325-325, 327-327

Tools
Biome

[error] 214-214: Unexpected any. Specify a different type. (lint/suspicious/noExplicitAny)

any disables many type checking rules. Its use should be avoided.

src/panels/lovelace/editor/card-editor/hui-dialog-edit-card.ts (3)

Line range hint 146-146: Consider replacing non-null assertions with safer alternatives.

The use of non-null assertions (!) is detected in multiple lines. While these may be intended to suppress nullability checks, they can lead to runtime errors if assumptions about non-nullability prove incorrect. Consider using optional chaining (?.) or additional runtime checks to ensure safety.

- this._containerConfig!
+ this._containerConfig?. // Apply this pattern to similar instances

Also applies to: 149-149, 154-154, 170-170, 182-182, 186-186, 192-192, 196-196, 198-198, 226-226, 286-286, 296-296, 312-312, 353-353, 387-387, 399-399, 402-402, 405-405, 406-406


Line range hint 164-164: Reduce complexity in the _save method.

The _save method has been flagged for excessive cognitive complexity. Consider refactoring this method by breaking it down into smaller, more manageable functions, each handling a specific part of the save process. This will enhance readability and maintainability.


Line range hint 154-154: Specify a more precise type instead of any.

The use of any for the event parameter in the method _enableEscapeKeyClose can lead to potential issues as it bypasses TypeScript's static type checking. Consider specifying a more precise type to enhance type safety and code clarity.

- private _enableEscapeKeyClose = (ev: any) => {
+ private _enableEscapeKeyClose = (ev: KeyboardEvent) => {

src/translations/en.json Show resolved Hide resolved
src/panels/lovelace/views/hui-view.ts Show resolved Hide resolved
src/panels/lovelace/cards/hui-card.ts Show resolved Hide resolved
src/components/ha-grid-size-picker.ts Show resolved Hide resolved
src/panels/lovelace/sections/hui-section.ts Show resolved Hide resolved
@bramkragten
Copy link
Member

I think we should tweak the responsive rules a bit, on some screen sizes it looks like this:

CleanShot 2024-06-24 at 20 23 20@2x

protected firstUpdated(changedProps: PropertyValues<this>): void {
super.firstUpdated(changedProps);
try {
this._cardElement = document.createElement("hui-card");
Copy link
Member

Choose a reason for hiding this comment

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

Instead of creating another card element, can we hook into the preview element we already display?

Copy link
Member Author

@piitaya piitaya Jun 24, 2024

Choose a reason for hiding this comment

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

Not really because the card is wrapped into a section component.

}

private _boundedValue(value: number) {
return Math.min(Math.max(value, this.min), this.max);
Copy link
Member

Choose a reason for hiding this comment

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

export const clamp = (value: number, min: number, max: number) =>

data-row=${row}
data-column=${column}
?disabled=${disabled}
@click=${this._cellClick}
Copy link
Member

Choose a reason for hiding this comment

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

Move the click listener to the div above, so we only have 1 listener for all cells.

@piitaya
Copy link
Member Author

piitaya commented Jun 24, 2024

@bramkragten Oh right for the responsive part. I thought I added a max width but no 😅

@bramkragten bramkragten merged commit 321a085 into dev Jun 24, 2024
13 checks passed
@bramkragten bramkragten deleted the resize_card_editor branch June 24, 2024 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed Noteworthy Marks a PR as noteworthy and should be in the release notes (in case it normally would not appear)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants