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

Allow to hide and sort columns in data tables #21168

Merged
merged 3 commits into from
Jun 26, 2024
Merged

Conversation

bramkragten
Copy link
Member

@bramkragten bramkragten commented Jun 26, 2024

Proposed change

Allow to hide and sort columns in data tables, change the way mobile data rows are created to respect hiding and sorting on the secondary line of the main field there.

image

image

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 customizable column settings in various data tables, including options to hide, show, and reorder columns.
    • Introduced "Narrow mode" support for better visibility on smaller screens.
  • Enhancements

    • Improved column customization capabilities in multiple panels (Automation, Backup, Blueprint, Devices, Entities, Helpers, Labels, Lovelace Dashboards, Scene, Script, Tags, Users, Voice Assistants).
    • Enhanced data table rendering logic to support additional templates and properties for better user experience.
  • User Interface

    • Added new settings dialog for customizing table columns.
    • Included new fields such as "Path" in backup and "Entity ID" in various sections.
  • Translations

    • Updated English translations to reflect the new column customization settings and new fields.

Copy link
Contributor

coderabbitai bot commented Jun 26, 2024

Walkthrough

Walkthrough

The recent updates enhance the DataTable components by adding features such as column manipulation, visibility control, and customization options. These changes empower users to reorder columns, hide/show columns dynamically, and utilize additional templates for enhanced rendering. The updates also introduce storage for column configurations, ensuring persistent customizations. Furthermore, similar enhancements have been applied across various panels, improving the user interface and interaction consistency.

Changes

File(s) Summary of Changes
src/components/data-table/ha-data-table.ts Added properties for column manipulation, visibility, and templates; updated sorting and rendering logic.
.../layouts/hass-tabs-subpage-data-table.ts Enhanced data table component with column order, hidden columns, and settings dialog.
.../config/automation/ha-automation-picker.ts Added properties for column customization and modified templates.
.../config/backup/ha-config-backup.ts Adjusted templates and fields based on narrow condition.
.../config/blueprint/ha-blueprint-overview.ts Added storage for column settings; adjusted column properties and event handling.
.../config/devices/ha-config-devices-dashboard.ts Introduced storage for column settings; updated column definitions and handling.
.../config/entities/ha-config-entities.ts Added storage for column settings; enhanced column definitions and initialization.
.../config/helpers/ha-config-helpers.ts Added storage properties for column settings.
.../config/labels/ha-config-labels.ts Added storage for column settings; updated column properties.
.../config/lovelace/dashboards/... Enhanced column definitions with new properties; added storage for settings.
.../config/lovelace/resources/... Added properties for column settings and handling changes.
.../config/scene/ha-scene-dashboard.ts Introduced storage for column settings; updated properties and rendering.
.../config/script/ha-script-picker.ts Added storage properties and redefined column properties/templates.
.../config/tags/ha-config-tags.ts Modified _columns method; adjusted column properties and templates.
.../config/users/ha-config-users.ts Added storage for column settings; updated templates and event handling.
.../config/voice-assistants/ha-config-voice-assistants-expose.ts Added storage decorators and adjusted column properties.
src/translations/en.json Added translation entries for new settings and fields.

Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 8336f9d and 25b8993.

Files selected for processing (19)
  • src/components/data-table/dialog-data-table-settings.ts (1 hunks)
  • src/components/data-table/ha-data-table.ts (12 hunks)
  • src/components/data-table/show-dialog-data-table-settings.ts (1 hunks)
  • src/layouts/hass-tabs-subpage-data-table.ts (10 hunks)
  • src/panels/config/automation/ha-automation-picker.ts (8 hunks)
  • src/panels/config/backup/ha-config-backup.ts (3 hunks)
  • src/panels/config/blueprint/ha-blueprint-overview.ts (7 hunks)
  • src/panels/config/devices/ha-config-devices-dashboard.ts (6 hunks)
  • src/panels/config/entities/ha-config-entities.ts (8 hunks)
  • src/panels/config/helpers/ha-config-helpers.ts (7 hunks)
  • src/panels/config/labels/ha-config-labels.ts (4 hunks)
  • src/panels/config/lovelace/dashboards/ha-config-lovelace-dashboards.ts (5 hunks)
  • src/panels/config/lovelace/resources/ha-config-lovelace-resources.ts (3 hunks)
  • src/panels/config/scene/ha-scene-dashboard.ts (8 hunks)
  • src/panels/config/script/ha-script-picker.ts (8 hunks)
  • src/panels/config/tags/ha-config-tags.ts (2 hunks)
  • src/panels/config/users/ha-config-users.ts (7 hunks)
  • src/panels/config/voice-assistants/ha-config-voice-assistants-expose.ts (8 hunks)
  • src/translations/en.json (5 hunks)
Additional context used
Biome
src/panels/config/backup/ha-config-backup.ts

[error] 78-78: Template literals are preferred over string concatenation. (lint/style/useTemplate)

Unsafe fix: Use a template literal.

src/panels/config/lovelace/resources/ha-config-lovelace-resources.ts

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

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


[error] 199-199: 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] 211-211: Unexpected any. Specify a different type. (lint/suspicious/noExplicitAny)

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


[error] 213-213: 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)


[error] 227-227: 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] 228-228: 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] 230-230: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


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


[error] 233-233: 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] 234-234: 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] 237-237: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 242-242: 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] 245-245: 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] 247-247: 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] 249-249: 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] 250-250: 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] 258-258: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 258-258: 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] 259-259: 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/config/users/ha-config-users.ts

[error] 247-247: 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] 252-252: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 252-252: 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] 253-253: 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] 260-260: 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] 264-264: 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] 267-267: 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] 268-268: 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] 276-276: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 276-276: 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] 277-277: 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] 279-279: Unexpected any. Specify a different type. (lint/suspicious/noExplicitAny)

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

src/components/data-table/dialog-data-table-settings.ts

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

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


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

Unsafe fix: Change to an optional chain.


[error] 136-136: 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] 105-105: Excessive complexity detected. (lint/complexity/noExcessiveCognitiveComplexity)

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


[error] 180-180: 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] 212-212: 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] 213-213: 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] 223-223: 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] 230-230: 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/config/tags/ha-config-tags.ts

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

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


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

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


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

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


[error] 235-235: 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] 259-259: 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] 304-304: 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] 308-308: 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] 309-309: 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] 318-318: Unexpected any. Specify a different type. (lint/suspicious/noExplicitAny)

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

src/panels/config/labels/ha-config-labels.ts

[error] 278-278: 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] 284-284: 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] 285-285: 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] 297-297: Unexpected any. Specify a different type. (lint/suspicious/noExplicitAny)

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

src/panels/config/lovelace/dashboards/ha-config-lovelace-dashboards.ts

[error] 79-79: This type annotation is trivially inferred from its initialization. (lint/style/noInferrableTypes)

Safe fix: Remove the type annotation.


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

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


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


[error] 421-421: 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] 430-430: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


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


[error] 436-436: 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] 439-439: 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] 445-445: 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] 447-447: 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] 449-449: 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] 452-452: 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] 459-459: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 459-459: 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] 460-460: 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] 464-464: Unexpected any. Specify a different type. (lint/suspicious/noExplicitAny)

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

src/panels/config/blueprint/ha-blueprint-overview.ts

[error] 130-130: This type annotation is trivially inferred from its initialization. (lint/style/noInferrableTypes)

Safe fix: Remove the type annotation.


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

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


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


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


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


[error] 461-461: 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] 465-465: Unexpected any. Specify a different type. (lint/suspicious/noExplicitAny)

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


[error] 480-480: 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] 515-515: 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] 538-538: 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] 539-539: 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/config/voice-assistants/ha-config-voice-assistants-expose.ts

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


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


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

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


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

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


[error] 649-649: 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] 653-654: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 676-676: 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] 685-685: 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] 718-718: 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] 757-757: 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/layouts/hass-tabs-subpage-data-table.ts

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

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

src/panels/config/devices/ha-config-devices-dashboard.ts

[error] 369-369: 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] 395-395: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 395-395: 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] 528-529: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.


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

Unsafe fix: Change to an optional chain.


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

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


[error] 727-727: 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] 727-727: 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] 581-581: Excessive complexity detected. (lint/complexity/noExcessiveCognitiveComplexity)

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


[error] 540-540: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead. (lint/suspicious/noGlobalIsNan)

See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.

src/panels/config/helpers/ha-config-helpers.ts

[error] 135-135: 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] 136-136: 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] 243-243: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 404-404: 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] 453-453: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 453-453: 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] 463-463: Excessive complexity detected. (lint/complexity/noExcessiveCognitiveComplexity)

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


[error] 775-775: 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] 798-798: 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] 809-809: 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] 823-823: 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] 762-762: Excessive complexity detected. (lint/complexity/noExcessiveCognitiveComplexity)

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


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

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


[error] 1021-1021: 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] 1040-1040: 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] 1051-1051: Forbidden non-null assertion. (lint/style/noNonNullAssertion)

src/components/data-table/ha-data-table.ts

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

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


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

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


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

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


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


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

Unsafe fix: Use an undefined assignment instead.


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

Unsafe fix: Use an undefined assignment instead.


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

Unsafe fix: Use an undefined assignment instead.


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

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


[error] 300-300: 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] 301-301: 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] 376-376: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.


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

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


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

Unsafe fix: Change to an optional chain.


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

Unsafe fix: Change to an optional chain.


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

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


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


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

Unsafe fix: Use an undefined assignment instead.


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

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


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

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


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

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

src/panels/config/scene/ha-scene-dashboard.ts

[error] 215-215: 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] 233-233: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 233-233: 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] 421-421: Excessive complexity detected. (lint/complexity/noExcessiveCognitiveComplexity)

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


[error] 843-843: 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] 854-854: 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] 867-867: 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] 890-890: 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] 830-830: Excessive complexity detected. (lint/complexity/noExcessiveCognitiveComplexity)

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


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

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


[error] 1086-1086: 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] 1089-1089: 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] 1093-1093: 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] 1094-1094: 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/config/script/ha-script-picker.ts

[error] 220-220: 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] 240-240: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 240-240: 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] 414-414: Excessive complexity detected. (lint/complexity/noExcessiveCognitiveComplexity)

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


[error] 857-857: 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] 868-868: 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] 881-881: 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] 904-904: 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] 844-844: Excessive complexity detected. (lint/complexity/noExcessiveCognitiveComplexity)

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


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

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


[error] 1162-1162: 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] 1163-1163: 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] 1169-1169: Unexpected any. Specify a different type. (lint/suspicious/noExplicitAny)

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

src/panels/config/entities/ha-config-entities.ts

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

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


[error] 516-516: 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] 537-537: 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] 466-466: Excessive complexity detected. (lint/complexity/noExcessiveCognitiveComplexity)

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


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


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


[error] 570-570: 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] 577-577: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


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

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


[error] 857-857: 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] 857-857: 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] 1017-1017: Excessive complexity detected. (lint/complexity/noExcessiveCognitiveComplexity)

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


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

src/panels/config/automation/ha-automation-picker.ts

[error] 230-230: 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] 251-251: Forbidden non-null assertion. (lint/style/noNonNullAssertion)


[error] 251-251: 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: Excessive complexity detected. (lint/complexity/noExcessiveCognitiveComplexity)

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


[error] 964-964: 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] 975-975: 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] 989-989: 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] 1012-1012: 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] 951-951: Excessive complexity detected. (lint/complexity/noExcessiveCognitiveComplexity)

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


[error] 1137-1137: 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] 1138-1138: 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] 1147-1147: Unexpected any. Specify a different type. (lint/suspicious/noExplicitAny)

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


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

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

Gitleaks
src/translations/en.json

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

Additional comments not posted (48)
src/components/data-table/show-dialog-data-table-settings.ts (3)

4-12: Ensure the interface is correctly utilized in the function.

The DataTableSettingsDialogParams interface is well-defined and matches the function parameters used in showDataTableSettingsDialog. This is a good practice as it ensures type safety and better documentation.


14-16: Approve the dynamic import function for dialog.

The loadDataTableSettingsDialog function uses dynamic import, which is an efficient way to load modules on demand. This can improve the loading time of the application by splitting the code into smaller chunks that are only loaded when necessary.


17-26: Check the implementation of the event dispatch.

The function showDataTableSettingsDialog correctly sets up and dispatches a custom event to show the dialog. The properties passed in the event are well-structured and match the expected types defined in DataTableSettingsDialogParams.

src/panels/config/backup/ha-config-backup.ts (1)

94-96: Confirm the column properties for actions.

The actions column has been set with showNarrow: true, hideable: false, and moveable: false. Ensure these settings align with the user requirements for column visibility and manipulation on narrow screens.

src/panels/config/lovelace/resources/ha-config-lovelace-resources.ts (3)

70-82: Approve the use of storage decorators for persisting user settings.

The storage decorators used for _activeColumnOrder and _activeHiddenColumns are correctly implemented to persist user settings across sessions. This is crucial for maintaining a consistent user experience.


163-165: Check the data binding in the render method.

The properties .columnOrder and .hiddenColumns are correctly bound to the data table component. This ensures that the user's preferences for column visibility and order are respected in the UI.


287-290: Ensure proper event handling for column changes.

The method _handleColumnsChanged is crucial for updating the state when the user changes the column order or visibility. It's important to verify that this method is correctly updating the state to reflect these changes.

src/panels/config/users/ha-config-users.ts (3)

49-61: Approve the implementation of storage decorators for user preferences.

The storage decorators for _activeColumnOrder and _activeHiddenColumns are correctly used to persist user preferences on column visibility and order. This is essential for a personalized user experience.


191-193: Confirm the data binding in the render method.

The properties .columnOrder and .hiddenColumns are properly bound to the data table component, ensuring that the UI reflects the user's column preferences.


312-315: Ensure proper event handling for column changes.

The method _handleColumnsChanged is critical for updating the state when the user changes the column order or visibility. Confirm that this method correctly updates the state to reflect these changes.

Verification successful

Proper event handling for column changes verified.

The _handleColumnsChanged method correctly updates the state by setting _activeColumnOrder and _activeHiddenColumns using the event details. This pattern is consistently implemented across multiple files in the codebase.

  • src/panels/config/users/ha-config-users.ts lines 312-315
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the column change handling is consistent and triggers the necessary state updates.
grep -rnw '_handleColumnsChanged' -A 10

Length of output: 24443

src/components/data-table/dialog-data-table-settings.ts (5)

18-37: Approve the basic structure of the dialog component.

The DialogDataTableSettings class is well-structured, with methods for showing and closing the dialog. The use of state properties to manage the dialog state is appropriate.


76-158: Check the rendering logic for the dialog.

The rendering logic uses conditional rendering based on the dialog parameters and correctly utilizes the sorted columns for displaying the settings. Ensure that all conditions and iterations are handled efficiently.

Tools
Biome

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

Unsafe fix: Change to an optional chain.


[error] 136-136: 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] 105-105: Excessive complexity detected. (lint/complexity/noExcessiveCognitiveComplexity)

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


226-232: Confirm the reset functionality in the dialog.

The _reset method resets the column order and visibility to their default states. Confirm that this method correctly resets the state and updates the UI accordingly.

Tools
Biome

[error] 230-230: 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


183-224: Check the toggle visibility logic for columns.

The _toggle method is responsible for toggling the visibility of columns. Ensure that it correctly updates the hidden columns state and handles all edge cases.

Verification successful

Check the toggle visibility logic for columns.

The _toggle method appears to handle the visibility toggling of columns correctly by updating the hidden columns state and invoking the onUpdate callback with the updated column order and hidden columns. The _params and _sortedColumns are defined and used appropriately within the method.

  • _params: The DataTableSettingsDialogParams interface includes columns, onUpdate, hiddenColumns, and columnOrder, which are used in the _toggle method.
  • _sortedColumns: This method, memoized with memoizeOne, filters and sorts columns based on their visibility and order.

The logic in _toggle ensures that columns are correctly added or removed from the hidden list and updates the column order if necessary.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the toggle visibility handling is robust and covers all scenarios.
grep -rnw '_toggle' -A 10

Length of output: 16545



Script:

#!/bin/bash
# Find the definition and usage of _params in the file
ast-grep --lang typescript --pattern 'private _params: $_;' --json

# Find the definition and implementation of the _sortedColumns method in the file
ast-grep --lang typescript --pattern '_sortedColumns($_) { $$$ }' --json

Length of output: 1035



Script:

#!/bin/bash
# Find the definition and usage of _params in the file
ast-grep --lang typescript --pattern 'private _params: $_' --json

# Find the definition and implementation of the _sortedColumns method in the file
ast-grep --lang typescript --pattern '_sortedColumns($_) { $$$ }' --json

Length of output: 1033



Script:

#!/bin/bash
# Find the definition and usage of _params in the file
ast-grep --lang typescript --pattern 'private _params' --json

# Find the definition and implementation of the _sortedColumns method in the file
ast-grep --lang typescript --pattern '_sortedColumns' --json

Length of output: 565



Script:

#!/bin/bash
# Search for the definition and usage of _params in the file
rg '_params' src/components/data-table/dialog-data-table-settings.ts

# Search for the definition and implementation of the _sortedColumns method in the file
rg '_sortedColumns' src/components/data-table/dialog-data-table-settings.ts

Length of output: 831



Script:

#!/bin/bash
# Search for the definition of DataTableSettingsDialogParams
rg 'DataTableSettingsDialogParams' --type-add 'typescript:*.ts' --type typescript

# Search for the implementation of memoizeOne
rg 'memoizeOne' --type-add 'typescript:*.ts' --type typescript

Length of output: 55026



Script:

#!/bin/bash
# Extract the definition of DataTableSettingsDialogParams
rg 'export interface DataTableSettingsDialogParams' -A 20 src/components/data-table/show-dialog-data-table-settings.ts

# Extract the implementation of _sortedColumns
rg 'private _sortedColumns = memoizeOne' -A 20 src/components/data-table/dialog-data-table-settings.ts

Length of output: 1616

Tools
Biome

[error] 212-212: 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] 213-213: 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] 223-223: 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


160-181: Ensure correct handling of column movement events.

The _columnMoved method handles the reordering of columns based on user interactions. Verify that this method updates the column order state correctly and triggers the necessary updates.

Verification successful

Column movement handling is correctly implemented.

The _columnMoved method correctly updates the column order state and triggers the necessary updates using the _sortedColumns function. The _sortedColumns function properly handles the sorting and visibility of columns.

  • _columnMoved method: Verified to update column order state correctly.
  • _sortedColumns function: Verified to handle sorting and visibility of columns correctly.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that column movement handling is consistent and effective.
grep -rnw '_columnMoved' -A 10

Length of output: 2034



Script:

#!/bin/bash
# Search for the implementation of the _sortedColumns method
ast-grep --lang typescript --pattern 'private _sortedColumns($$$) { $$$ }'

# Search for the usage of the _params.onUpdate function
grep -rnw '_params.onUpdate'

Length of output: 563



Script:

#!/bin/bash
# Correct the ast-grep pattern for _sortedColumns method
ast-grep --lang typescript --pattern 'function _sortedColumns($_) { $$$ }'

# Search for the definition of _params to understand its structure
grep -rnw '_params'

Length of output: 91333



Script:

#!/bin/bash
# Correct the ast-grep pattern for _sortedColumns method
ast-grep --lang typescript --pattern 'private _sortedColumns($_, $_, $_) { $$$ }'

Length of output: 548



Script:

#!/bin/bash
# Search for the _sortedColumns method using grep
grep -rnw 'private _sortedColumns' --include \*.ts

# Correct the ast-grep pattern for _sortedColumns method
ast-grep --lang typescript --pattern 'method_definition (name: _sortedColumns) @method'

Length of output: 798



Script:

#!/bin/bash
# Display the implementation of _sortedColumns in src/components/data-table/dialog-data-table-settings.ts
sed -n '39,59p' src/components/data-table/dialog-data-table-settings.ts

Length of output: 845



Script:

#!/bin/bash
# Display more lines to capture the full implementation of _sortedColumns in src/components/data-table/dialog-data-table-settings.ts
sed -n '39,79p' src/components/data-table/dialog-data-table-settings.ts

Length of output: 1266

Tools
Biome

[error] 180-180: 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/config/tags/ha-config-tags.ts (1)

183-183: Enhance Accessibility in Rendering

Ensure that all interactive elements generated in the rendering process have appropriate ARIA labels and roles for better accessibility.

Consider adding role and aria-label attributes to interactive elements to enhance accessibility.

src/panels/config/labels/ha-config-labels.ts (2)

69-81: Optimize Storage Decorators Usage

The use of storage decorators for _activeColumnOrder and _activeHiddenColumns is correct, but ensure the storage keys are unique across different components to avoid conflicts.

Verify that the storage keys used ("labels-table-column-order" and "labels-table-hidden-columns") are unique across the application to avoid potential data conflicts.


190-192: Ensure Consistency in Event Handling

The @columns-changed event handler is correctly implemented, but ensure that all possible event properties are handled to maintain state consistency.

Verify that all properties from the event detail are being used or logged to ensure full handling of the event data.

src/panels/config/lovelace/dashboards/ha-config-lovelace-dashboards.ts (1)

88-100: Refine Storage Handling

The use of storage decorators for dashboard settings is well-implemented. Consider adding error handling for storage access to enhance robustness.

Add try-catch blocks around storage access to handle potential exceptions and ensure the application remains stable even if storage access fails.

src/panels/config/blueprint/ha-blueprint-overview.ts (5)

110-115: Proper use of storage for column order persistence.

The implementation of _activeColumnOrder with the @storage decorator correctly handles user preferences for column order across sessions.


117-122: Proper use of storage for hidden columns persistence.

The implementation of _activeHiddenColumns with the @storage decorator correctly handles user preferences for hidden columns across sessions.


Line range hint 290-321: Well-structured render method.

The render method is clearly structured, effectively uses lit-html for dynamic content, and handles different states (like no data) gracefully.


565-568: Effective handling of column changes.

The _handleColumnsChanged method effectively updates the column order and visibility settings based on user interactions.


Line range hint 250-260: Correct implementation of lifecycle method.

The firstUpdated method uses lifecycle hooks appropriately to handle initial routing and potential blueprint additions based on URL parameters.

src/panels/config/voice-assistants/ha-config-voice-assistants-expose.ts (5)

121-126: Proper use of storage for column order persistence.

The implementation of _activeColumnOrder with the @storage decorator correctly handles user preferences for column order across sessions.


128-133: Proper use of storage for hidden columns persistence.

The implementation of _activeHiddenColumns with the @storage decorator correctly handles user preferences for hidden columns across sessions.


Line range hint 500-575: Well-structured render method.

The render method is clearly structured, effectively uses lit-html for dynamic content, and handles different states (like no data) gracefully.


781-784: Effective handling of column changes.

The _handleColumnsChanged method effectively updates the column order and visibility settings based on user interactions.


Line range hint 450-460: Correct implementation of lifecycle method.

The firstUpdated method uses lifecycle hooks appropriately to handle initial routing and potential entity additions based on URL parameters.

src/layouts/hass-tabs-subpage-data-table.ts (3)

46-46: Proper use of new import for settings dialog functionality.


176-179: Proper implementation of properties for column customization.


628-642: Settings Dialog Functionality: Ensure robust event handling.

The _openSettings method triggers the settings dialog and handles updates to the column configuration. It's crucial to ensure that the event handling for columns-changed is robust and that it properly updates the component's state.

src/panels/config/devices/ha-config-devices-dashboard.ts (1)

1038-1041: Ensure proper handling of event details in _handleColumnsChanged

The method _handleColumnsChanged directly assigns properties from the event detail. Ensure that these properties exist on the event detail object to prevent runtime errors.

This script checks all dispatchEvent calls to ensure that when columns-changed is dispatched, it includes the necessary properties.

Verification successful

Event details are properly handled in _handleColumnsChanged

The columns-changed event includes the necessary properties columnOrder and hiddenColumns. Therefore, the _handleColumnsChanged method in ha-config-devices-dashboard.ts correctly handles the event details.

  • src/layouts/hass-tabs-subpage-data-table.ts: fireEvent(this, "columns-changed", { columnOrder, hiddenColumns });
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the event 'columns-changed' always includes 'columnOrder' and 'hiddenColumns'.

# Test: Search for the event dispatch logic. Expect: Proper properties being passed.
rg --type typescript $'this.dispatchEvent'

Length of output: 76



Script:

#!/bin/bash
# Description: Verify that the event 'columns-changed' always includes 'columnOrder' and 'hiddenColumns'.

# Test: Search for the event dispatch logic in TypeScript files. Expect: Proper properties being passed.
rg --type ts $'this.dispatchEvent(new CustomEvent("columns-changed", { detail: { columnOrder: $_, hiddenColumns: $_ } }))'

Length of output: 368



Script:

#!/bin/bash
# Description: Verify that the event 'columns-changed' always includes 'columnOrder' and 'hiddenColumns'.

# Test: Search for the event dispatch logic in TypeScript files. Expect: Proper properties being passed.
rg --type ts 'this.dispatchEvent\(new CustomEvent\("columns-changed", { detail: { columnOrder: .*, hiddenColumns: .* } }\)\)'

Length of output: 378



Script:

#!/bin/bash
# Description: Verify that the event 'columns-changed' always includes 'columnOrder' and 'hiddenColumns'.

# Test: Search for the event dispatch logic in TypeScript files. Expect: Proper properties being passed.
rg --type ts 'this.dispatchEvent\(new CustomEvent\("columns-changed", { detail: {.*columnOrder.*hiddenColumns.*} }\)\)'

Length of output: 366



Script:

#!/bin/bash
# Description: Verify that the event 'columns-changed' always includes 'columnOrder' and 'hiddenColumns'.

# Search for the event dispatch logic in TypeScript files.
rg --type ts 'columns-changed'

Length of output: 1529



Script:

#!/bin/bash
# Extract the relevant lines from the file where the 'columns-changed' event is dispatched.
rg --type ts 'fireEvent(this, "columns-changed", { columnOrder, hiddenColumns });' -A 5

Length of output: 276



Script:

#!/bin/bash
# Search for the 'fireEvent' calls related to 'columns-changed' event.
rg --type ts 'fireEvent'

Length of output: 188485

src/panels/config/helpers/ha-config-helpers.ts (2)

170-182: Approved: Implementation of storage for column preferences.

The use of the storage decorator for _activeColumnOrder and _activeHiddenColumns properties is correctly implemented to persist user preferences across sessions.


1100-1103: Approved: Column change handling is correctly implemented.

The method _handleColumnsChanged appropriately updates the column order and visibility based on user interactions, ensuring the UI reflects these changes immediately.

src/components/data-table/ha-data-table.ts (2)

Line range hint 113-158: New properties to support column sorting and hiding.

The properties narrow, hiddenColumns, and columnOrder are added to manage the visibility and order of columns. These are crucial for the feature allowing users to customize their view in the data table.


86-86: Consider specifying a more explicit type instead of any.

The extraTemplate function in DataTableColumnData interface uses any, which should be avoided to ensure type safety.

-  extraTemplate?: (row: T) => TemplateResult | string | typeof nothing;
+  extraTemplate?: (row: SpecificType) => TemplateResult | string | typeof nothing;

Replace SpecificType with the actual expected type of row.

Likely invalid or redundant comment.

src/panels/config/script/ha-script-picker.ts (3)

1269-1272: Column change handler is implemented correctly.

The _handleColumnsChanged method correctly updates the column order and visibility based on user interactions. Well done on maintaining clean and understandable event handling.


274-280: Enhanced UI with conditional rendering in column template.

The addition of an extraTemplate for labels in the script data table is a great enhancement. It smartly uses conditional rendering to improve information visibility without cluttering the UI.


327-329: Proper configuration of the actions column properties.

The actions column properties are well-configured to ensure visibility and fixed positioning, which is crucial for user interactions in a responsive environment.

src/panels/config/entities/ha-config-entities.ts (2)

1340-1343: Column change handler implemented correctly.

Verify that this method integrates well with other components and does not introduce side effects.

Verification successful

Column change handler implemented correctly.

The _handleColumnsChanged method is correctly linked to the @columns-changed event, ensuring it is triggered appropriately. No side effects or integration issues were found.

  • src/panels/config/entities/ha-config-entities.ts:
    • Line 1340: Event listener for @columns-changed uses _handleColumnsChanged.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the integration of `_handleColumnsChanged` with other components.

# Test: Search for the method usage and related event triggers.
rg --type typescript '_handleColumnsChanged' src/panels/config/entities/

Length of output: 107



Script:

#!/bin/bash
# Description: Verify the integration of `_handleColumnsChanged` with other components.

# Test: Search for the method usage and related event triggers.
rg --type ts '_handleColumnsChanged' src/panels/config/entities/

Length of output: 268


189-201: Storage properties implemented correctly.

Ensure that these properties are utilized correctly throughout the class to maintain user preferences across sessions.

Verification successful

Storage properties implemented and utilized correctly.

The properties _activeColumnOrder and _activeHiddenColumns are correctly integrated and used within the class to maintain user preferences for column order and hidden columns.

  • .columnOrder=${this._activeColumnOrder}
  • .hiddenColumns=${this._activeHiddenColumns}
  • this._activeColumnOrder = ev.detail.columnOrder;
  • this._activeHiddenColumns = ev.detail.hiddenColumns;
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of `_activeColumnOrder` and `_activeHiddenColumns` throughout the class.

# Test: Search for the properties usage.
rg --type typescript '_activeColumnOrder|_activeHiddenColumns' src/panels/config/entities/ha-config-entities.ts

Length of output: 148



Script:

#!/bin/bash
# Description: Verify the usage of `_activeColumnOrder` and `_activeHiddenColumns` throughout the class.

# Test: Search for the properties usage.
rg '_activeColumnOrder|_activeHiddenColumns' src/panels/config/entities/ha-config-entities.ts

Length of output: 389

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

195-208: Implementation of storage properties for column customization looks good.

The use of the @storage decorator with subscribe: false is appropriate for session-specific settings like column order and visibility, which do not require updates across sessions.


1422-1425: Proper handling of column changes in the automation picker.

The implementation of the _handleColumnsChanged method correctly updates and persists user settings for column order and visibility, ensuring a consistent user experience across sessions.

src/translations/en.json (4)

533-534: Translation keys added for table customization settings.

The new keys "select_none" and "settings" are added correctly under the appropriate section.


803-810: Detailed settings for column customization added.

The translation entries for "header", "hide", "show", "done", and "restore" are well-defined and correctly nested within the settings object.


2082-2082: New translation key for backup path.

The addition of the "path" key under the supervisor::backup section is appropriate and enhances the information available about backups.


2677-2677: Added translation key for entity ID in media browser.

The addition of "entity_id" under the media-browser headers is appropriate and aligns with the need for more descriptive headers.


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

Outside diff range comments (15)
src/panels/config/labels/ha-config-labels.ts (1)

[!TIP]
Codebase Verification

Non-null assertions are still present in the codebase and have not been universally replaced with optional chaining.

Occurrences of non-null assertions (!) were found in the following files:

  • cast/src/receiver/layout/hc-main.ts
  • cast/src/receiver/layout/hc-lovelace.ts
  • src/util/toast-saved-success.ts
  • src/util/toast-deleted-success.ts
  • src/util/launch-screen.ts
  • src/state/translations-mixin.ts
  • src/state/themes-mixin.ts
  • src/state/haptic-mixin.ts
  • src/state/disconnect-toast-mixin.ts
  • src/state/context-mixin.ts
  • src/state/connection-mixin.ts
  • src/state/auth-mixin.ts
  • src/state-summary/state-card-script.ts
  • src/state-summary/state-card-number.ts
  • src/state-summary/state-card-input_number.ts
  • src/state-control/water_heater/ha-state-control-water_heater-temperature.ts
  • src/state-control/valve/ha-state-control-valve-position.ts
  • src/state-control/valve/ha-state-control-valve-buttons.ts
  • src/state-control/light/ha-state-control-light-brightness.ts
  • src/state-control/humidifier/ha-state-control-humidifier-humidity.ts
  • src/state-control/fan/ha-state-control-fan-speed.ts
  • src/state-control/cover/ha-state-control-cover-tilt-position.ts
  • src/state-control/cover/ha-state-control-cover-position.ts
  • src/state-control/cover/ha-state-control-cover-buttons.ts
  • src/state-control/climate/ha-state-control-climate-temperature.ts
  • src/state-control/climate/ha-state-control-climate-humidity.ts
  • src/state-control/alarm_control_panel/ha-state-control-alarm_control_panel-modes.ts
  • src/panels/todo/ha-panel-todo.ts
  • src/panels/todo/dialog-todo-item-editor.ts
  • src/panels/profile/ha-profile-section-security.ts
  • src/panels/profile/ha-profile-section-general.ts
  • src/panels/profile/ha-pick-dashboard-row.ts
  • src/panels/profile/ha-long-lived-access-tokens-card.ts
  • src/panels/profile/ha-long-lived-access-token-dialog.ts
  • src/panels/my/ha-panel-my.ts
  • src/panels/profile/dialog-ha-mfa-module-setup-flow.ts
  • src/panels/media-browser/ha-bar-media-player.ts
  • src/panels/logbook/ha-panel-logbook.ts
  • src/panels/map/ha-panel-map.ts
  • src/panels/mailbox/ha-dialog-show-audio-message.ts
  • src/panels/lovelace/views/hui-sidebar-view.ts
  • src/panels/lovelace/views/hui-view.ts
  • src/panels/lovelace/views/hui-sections-view.ts
  • src/panels/lovelace/hui-root.ts
  • src/panels/lovelace/special-rows/hui-cast-row.ts
  • src/panels/lovelace/hui-editor.ts
  • src/panels/lovelace/editor/view-editor/hui-dialog-edit-view.ts
  • src/panels/lovelace/editor/config-elements/hui-entities-card-row-editor.ts
  • src/panels/lovelace/editor/config-elements/hui-statistics-graph-card-editor.ts
  • src/panels/lovelace/editor/config-elements/hui-gauge-card-editor.ts
  • src/panels/lovelace/editor/config-elements/hui-select-options-card-feature-editor.ts
  • src/panels/lovelace/editor/config-elements/hui-tile-card-editor.ts
  • src/panels/lovelace/editor/config-elements/hui-thermostat-card-editor.ts
  • src/panels/lovelace/editor/config-elements/hui-sensor-card-editor.ts
  • src/panels/lovelace/editor/config-elements/hui-light-card-editor.ts
  • src/panels/lovelace/editor/config-elements/hui-iframe-card-editor.ts
  • src/panels/lovelace/editor/config-elements/hui-climate-preset-modes-card-feature-editor.ts
  • src/panels/lovelace/editor/config-elements/hui-conditional-card-editor.ts
  • src/panels/lovelace/editor/config-elements/hui-entities-card-editor.ts
  • src/panels/lovelace/editor/config-elements/hui-area-card-editor.ts
  • src/panels/lovelace/editor/config-elements/hui-logbook-card-editor.ts
  • src/panels/lovelace/editor/config-elements/hui-alarm-panel-card-editor.ts
  • src/panels/lovelace/entity-rows/hui-weather-entity-row.ts
  • src/panels/lovelace/entity-rows/hui-scene-entity-row.ts
  • src/panels/lovelace/entity-rows/hui-media-player-entity-row.ts
  • src/panels/lovelace/editor/card-editor/hui-dialog-edit-card.ts
  • src/panels/lovelace/editor/card-editor/hui-card-picker.ts
  • src/panels/lovelace/editor/card-editor/hui-entity-picker-table.ts
  • src/panels/lovelace/editor/card-editor/hui-dialog-create-card.ts
  • src/panels/lovelace/editor/card-editor/hui-dialog-suggest-card.ts
  • src/panels/lovelace/entity-rows/hui-lock-entity-row.ts
  • src/panels/lovelace/entity-rows/hui-input-select-entity-row.ts
  • src/panels/lovelace/entity-rows/hui-input-datetime-entity-row.ts
  • src/panels/lovelace/entity-rows/hui-button-entity-row.ts
  • src/panels/lovelace/elements/hui-state-icon-element.ts
  • src/panels/lovelace/elements/hui-state-label-element.ts
  • src/panels/lovelace/cards/hui-calendar-card.ts
  • src/panels/lovelace/cards/hui-light-card.ts
  • src/panels/lovelace/cards/hui-thermostat-card.ts
  • src/panels/lovelace/cards/hui-plant-status-card.ts
  • src/panels/lovelace/cards/hui-media-control-card.ts
  • src/panels/lovelace/cards/hui-statistics-graph-card.ts
  • src/panels/lovelace/cards/hui-tile-card.ts
  • src/panels/lovelace/cards/hui-glance-card.ts
  • src/panels/lovelace/cards/hui-starting-card.ts
  • src/panels/lovelace/cards/hui-logbook-card.ts
  • src/panels/lovelace/cards/hui-map-card.ts
  • src/panels/lovelace/cards/hui-button-card.ts
  • src/panels/lovelace/cards/hui-weather-forecast-card.ts
  • src/panels/lovelace/cards/hui-picture-glance-card.ts
  • src/panels/lovelace/cards/hui-picture-entity-card.ts
  • src/panels/lovelace/cards/hui-picture-elements-card.ts
  • src/panels/lovelace/cards/hui-recovery-mode-card.ts
  • src/panels/lovelace/cards/hui-humidifier-card.ts
  • src/panels/lovelace/cards/hui-shopping-list-card.ts
  • src/panels/lovelace/cards/hui-statistic-card.ts
  • src/panels/lovelace/cards/hui-cover-tilt-card-feature.ts
  • src/panels/lovelace/card-features/hui-alarm-modes-card-feature.ts
  • src/panels/lovelace/card-features/hui-light-brightness-card-feature.ts
  • src/panels/lovelace/card-features/hui-light-color-temp-card-feature.ts
  • src/panels/lovelace/card-features/hui-target-temperature-card-feature.ts
  • src/panels/lovelace/card-features/hui-target-humidity-card-feature.ts
  • src/panels/lovelace/card-features/hui-select-options-card-feature.ts
  • src/panels/lovelace/card-features/hui-fan-speed-card-feature.ts
  • src/panels/lovelace/card-features/hui-fan-preset-modes-card-feature.ts
  • src/panels/lovelace/card-features/hui-climate-preset-modes-card-feature.ts
  • src/panels/lovelace/card-features/hui-climate-hvac-modes-card-feature.ts
  • src/panels/lovelace/card-features/hui-climate-swing-modes-card-feature.ts
  • src/panels/lovelace/card-features/hui-humidifier-modes-card-feature.ts
  • src/panels/lovelace/card-features/hui-humidifier-toggle-card-feature.ts
  • src/panels/lovelace/card-features/hui-water-heater-operation-modes-card-feature.ts
  • src/panels/lovelace/card-features/hui-cover-open-close-card-feature.ts
  • src/panels/lovelace/card-features/hui-cover-position-card-feature.ts
  • src/panels/lovelace/card-features/hui-cover-tilt-position-card-feature.ts
  • src/panels/lovelace/card-features/hui-lawn-mower-commands-card-feature.ts
  • src/panels/lovelace/card-features/hui-vacuum-commands-card-feature.ts
  • src/panels/lovelace/card-features/hui-update-actions-card-feature.ts
  • src/panels/lovelace/card-features/hui-numeric-input-card-feature.ts
  • src/panels/lovelace/card-features/hui-humidifier-modes-card-feature.ts
  • src/panels/lovelace/card-features/hui-humidifier-modes-card-feature.ts
  • src/panels/lovelace/card-features/hui-humidifier-modes-card-feature.ts
  • src/panels/lovelace/card-features/hui-humidifier-modes-card-feature.ts
  • src/panels/lovelace/card-features/hui-humidifier-modes-card-feature.ts
  • src/panels/lovelace/card-features/hui-humidifier-modes-card-feature.ts
  • src/panels/lovelace/card-features/hui-humidifier-modes-card-feature.ts
  • src/panels/lovelace/card-features/hui-humidifier-modes-card-feature.ts
  • src/panels/lovelace/card-features/hui-humidifier-modes-card-feature.ts
  • src/panels/lovelace/card-features/hui-humidifier-modes-card-feature.ts
  • src/panels/lovelace/card-features/hui-humidifier-modes-card-feature.ts
  • src/panels/lovelace/card-features/hui-humidifier-modes-card-feature.ts
  • src/panels/lovelace/card-features/hui-humidifier-modes-card-feature.ts
  • src/panels/lovelace/card-features/hui-humidifier-modes-card-feature.ts
  • src/panels/lovelace/card-features/hui-humidifier-modes-card-feature.ts
  • src/panels/lovelace/card-features/hui-humidifier-modes-card-feature.ts
  • src/panels/lovelace/card-features/hui-humidifier-modes-card-feature.ts
  • src/panels/lovelace/card-features/hui-humidifier-modes-card-feature.ts
  • src/panels/lovelace/card-features/hui-humidifier-modes-card-feature.ts
  • src/panels/lovelace/card-features/hui-humidifier-modes-card-feature.ts
  • src/panels/lovelace/card-features/hui-humidifier-modes-card-feature.ts
  • src/panels/lovelace/card-features/hui-humidifier-modes-card-feature.ts
  • src/panels/lovelace/card-features/hui-humidifier-modes-card-feature.ts
  • src/panels/lovelace/card-features/hui-humidifier-modes-card-feature.ts

Please address these occurrences by replacing non-null assertions with optional chaining where appropriate.

Analysis chain

Line range hint 73-113: Enhancements to column properties improve interactivity and user experience.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify removal of non-null assertions and replacement with optional chaining.

# Test: Search for non-null assertions. Expect: No occurrences.
rg --type typescript '!'

Length of output: 61



Script:

#!/bin/bash
# Description: Verify removal of non-null assertions and replacement with optional chaining.

# Test: Search for non-null assertions. Expect: No occurrences.
rg '!\.' --glob '*.ts'

Length of output: 273458

src/panels/config/blueprint/ha-blueprint-overview.ts (4)

Line range hint 116-116: Remove unnecessary type annotation.

The type annotation on this line is inferred by TypeScript and is therefore redundant.

- private _filter: string = "";
+ private _filter = "";

Line range hint 123-123: Specify a more explicit type instead of any.

Using any can disable TypeScript's type checking, reducing the benefits of static type checking. If possible, replace any with a more specific type to enhance code reliability and maintainability.


Line range hint 376-379: Replace non-null assertions with optional chaining.

Non-null assertions can lead to runtime errors if not handled carefully. It's safer to use optional chaining (?.) which includes runtime checks.

- this.hass!.localize
+ this.hass?.localize

- result!.blueprint.metadata.name
+ result?.blueprint.metadata.name

- this._activeSorting!.detail
+ this._activeSorting?.detail

- this._activeGrouping!.value
+ this._activeGrouping?.value

- this._activeCollapsed!.value
+ this._activeCollapsed?.value

Also applies to: 407-407, 435-435, 450-450, 469-469, 504-504, 527-527, 528-528


Line range hint 157-157: Remove or utilize the unused variable narrow.

The variable narrow is declared but not used within the scope of its declaration. If it's not needed, consider removing it to clean up the codebase.

- narrow,
src/panels/config/voice-assistants/ha-config-voice-assistants-expose.ts (2)

Line range hint 298-298: Refactor to reduce complexity.

The _filteredEntities function is complex, making it hard to understand and maintain. Consider breaking it down into smaller, more focused functions or using more descriptive variable names to improve readability.


Line range hint 361-361: Replace non-null assertions with optional chaining for safety.

Using non-null assertions can lead to runtime errors if the objects are actually null. Use optional chaining (?.) to safely access properties and methods.

- this.hass!.localize
+ this.hass?.localize

- this.exposedEntities![entityId]
+ this.exposedEntities?.[entityId]

- this._extEntities![entityId]
+ this._extEntities?.[entityId]

- this.cloudStatus!.prefs.alexa_enabled
+ this.cloudStatus?.prefs.alexa_enabled

- this._searchParms!.get("assistants")!.split(",")
+ this._searchParms?.get("assistants")?.split(",")

Also applies to: 414-414, 632-632, 636-637, 659-659, 668-668, 701-701, 740-740

src/layouts/hass-tabs-subpage-data-table.ts (1)

Line range hint 223-223: Refactor Required Due to High Complexity.

The function around line 223 is flagged for excessive complexity. Consider breaking it down into smaller, more manageable functions to improve readability and maintainability.

- [Original complex function code]
+ [Refactored code with smaller functions]
src/panels/config/devices/ha-config-devices-dashboard.ts (1)

Line range hint 451-570: Enhanced data table columns configuration.

The modifications to the _columns method introduce significant improvements in terms of interactivity and data representation. Properties like sortable, filterable, and groupable are crucial for a dynamic user experience.

Consider refactoring for better readability.

- const columnsConfig = {
+ const iconColumn = {
+   ...
+ };
+ const nameColumn = {
+   ...
+ };
+ return { iconColumn, nameColumn, ... };

This refactoring breaks down the complex method into smaller, more manageable parts, improving readability and maintainability.

Tools
Biome

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

Unsafe fix: Change to an optional chain.


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

Unsafe fix: Change to an optional chain.


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

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


[error] 540-540: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead. (lint/suspicious/noGlobalIsNan)

See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.

src/panels/config/scene/ha-scene-dashboard.ts (3)

Line range hint 407-407: Refactor _applyFilters to reduce complexity.

This method has a high cognitive complexity due to multiple nested conditions and loops. Consider breaking it down into smaller, more manageable functions. Each filter type could potentially be handled in its own method, improving readability and maintainability.

- private _applyFilters() {
+ private _applyFilters() {
+   this._applyCategoryFilters();
+   this._applyLabelFilters();
+   // Additional filter methods
+ }

Line range hint 813-813: Refactor _bulkCreateCategory to reduce complexity.

This method handles multiple operations related to category creation and bulk update. Consider separating the creation logic from the bulk update logic into separate methods. This can make the code easier to understand and maintain.

- private async _bulkCreateCategory() {
+ private async _createCategory() {
+   // Category creation logic
+ }
+ private async _bulkUpdateCategory(categoryId: string) {
+   // Bulk update logic
+ }

Line range hint 1025-1025: Specify a more accurate type than any.

The use of any type for the event parameter in _handleSortingChanged reduces type safety. Specify a more accurate type to enhance code quality and maintainability.

- private _handleSortingChanged(ev: CustomEvent) {
+ private _handleSortingChanged(ev: HASSDomEvent<SortingChangedEvent>) {
src/panels/config/automation/ha-automation-picker.ts (3)

Line range hint 216-216: Replace non-null assertions with optional chaining for safety.

Using non-null assertions can lead to runtime errors if the object is indeed null or undefined. It's safer to use optional chaining (?.) which will gracefully handle these cases.

- this._overflowMenu!.open
+ this._overflowMenu?.open

- this._overflowMenu!.close()
+ this._overflowMenu?.close()

- this._overflowAutomation!.state
+ this._overflowAutomation?.state

- this._overflowAutomation!.category
+ this._overflowAutomation?.category

Also applies to: 237-237, 947-947, 958-958, 972-972, 995-995, 1120-1120, 1121-1121


Line range hint 388-388: Refactor functions to reduce complexity.

The functions _applyFilters and _bulkLabel are flagged for excessive complexity. Consider breaking these functions into smaller, more manageable parts or simplifying the logic to enhance maintainability and readability.

Also applies to: 934-934


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

Using any disables TypeScript's type checking, which can lead to potential bugs. It's better to specify explicit types for better code safety and clarity.

Also applies to: 1154-1154

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

Outside diff range comments (2)
src/panels/config/tags/ha-config-tags.ts (2)

Line range hint 209-223: Specify more precise types instead of any.

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

- private _handleWriteClick = (ev: Event) => this._openWrite((ev.currentTarget as any).tag);
+ private _handleWriteClick = (ev: Event) => this._openWrite((ev.currentTarget as HTMLElement).tag);  // Specify HTMLElement or a more appropriate type

Line range hint 235-309: Replace non-null assertions with safer alternatives.

Using non-null assertions can lead to runtime errors if the assumptions about non-nullability are incorrect. Use optional chaining or explicit null checks instead.

- this.hass.auth.external!.fireMessage({ type: "tag/write", payload: { name: tag.name || null, tag: tag.id } });
+ this.hass.auth.external?.fireMessage({ type: "tag/write", payload: { name: tag.name || null, tag: tag.id } });  // Use optional chaining

piitaya
piitaya previously approved these changes Jun 26, 2024
@bramkragten bramkragten merged commit 7d28f3f into dev Jun 26, 2024
9 checks passed
@bramkragten bramkragten deleted the column-settings branch June 26, 2024 09:51
@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 26, 2024
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: 15

Outside diff range comments (11)
src/panels/config/labels/ha-config-labels.ts (1)

Line range hint 87-127: Refactor Template Code for Clarity

The template code for rendering icons and overflow menus is complex and repeated across different columns. Consider extracting this into a dedicated method or using a custom component.

- template: (label) => html`<ha-icon .icon=${label.icon}></ha-icon>`
+ template: this._renderIcon

And define _renderIcon as:

_renderIcon(label) {
  return html`<ha-icon .icon=${label.icon}></ha-icon>`;
}
src/panels/config/lovelace/dashboards/ha-config-lovelace-dashboards.ts (1)

Line range hint 118-215: Improve Template Readability and Performance

The templates for dashboard items are complex and could be optimized for better readability and performance. Consider breaking down complex templates into simpler, reusable components.

- template: (dashboard) => html`...`
+ template: this._renderDashboardItem

And define _renderDashboardItem as:

_renderDashboardItem(dashboard) {
  return html`...`;  // Simplified version of the original template
}
src/layouts/hass-tabs-subpage-data-table.ts (1)

Line range hint 223-223: Reduce cognitive complexity as indicated by static analysis.

Consider refactoring the code to simplify complex logic, possibly by breaking down large methods or simplifying conditional statements.

src/components/data-table/ha-data-table.ts (2)

Line range hint 461-576: Improve code readability and maintainability in row rendering.

The method _renderRow uses deeply nested conditions and loops, making it hard to read and maintain.

Refactor to use helper functions to handle specific parts of the row rendering, such as handling templates or conditional rendering.

Tools
Biome

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

Unsafe fix: Change to an optional chain.


Line range hint 511-570: Reduce complexity in cell rendering logic.

The cell rendering logic in the data table is overly complex and could benefit from simplification or breaking down into smaller components.

Consider extracting parts of this logic into separate, well-named functions or methods to improve readability and testability.

Tools
Biome

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

Unsafe fix: Change to an optional chain.

src/panels/config/scene/ha-scene-dashboard.ts (4)

Line range hint 242-338: Ensure consistency and add documentation for column properties.

The properties moveable, showNarrow, and hideable have been added to various columns. It's important to maintain consistency across the implementation of these properties and add inline documentation to explain their behavior and impact on the user interface.


Line range hint 215-215: Replace non-null assertions with safer alternatives.

Several parts of the code use non-null assertions (!). These can lead to runtime errors if the values are actually null or undefined. Consider using optional chaining (?.) or adding checks to ensure the values are not null before accessing them.

- const labels = labelReg && entityRegEntry?.labels;
+ const labels = labelReg && entityRegEntry?.labels ? entityRegEntry.labels : undefined;

Also applies to: 233-233, 843-843, 854-854, 867-867, 890-890, 1086-1086, 1089-1089, 1093-1093, 1094-1094


Line range hint 421-421: Reduce complexity in complex functions.

The functions handling bulk actions have excessive cognitive complexity. Consider breaking them down into smaller, more manageable functions or using simpler logic to improve readability and maintainability.

Also applies to: 830-830


Line range hint 1042-1042: Specify a type instead of using any.

The use of any type can lead to potential type-safety issues. Consider specifying a more explicit type to enhance type safety and clarity of the code.

src/panels/config/entities/ha-config-entities.ts (2)

Line range hint 439-439: Reduce complexity of the render method.

The complexity of this method exceeds the recommended limit, which could impact maintainability. Consider refactoring to simplify the logic, possibly by breaking it down into smaller, more manageable functions.

-  protected render() {
+  protected render() {
+    // Refactor suggestion: Break down into smaller methods
+  }

Line range hint 516-516: Replace non-null assertions with optional chaining.

Non-null assertions are unsafe as they bypass TypeScript's strict null checks. Replace them with optional chaining to ensure runtime safety.

-  this.hass!
+  this.hass?
-  this._entries!
+  this._entries?
-  this._labels!
+  this._labels?
-  this._entitySources!
+  this._entitySources?
-  this._filters.config_entry!.value![0]
+  this._filters.config_entry?.value?[0]
-  this._filters.config_entry!.value![0]
+  this._filters.config_entry?.value?[0]
-  this._searchParms!
+  this._searchParms?

Also applies to: 537-537, 546-546, 570-570, 577-577, 857-857, 857-857, 1304-1305

Comment on lines +292 to +317
private _sortedColumns = memoizeOne(
(columns: DataTableColumnContainer, columnOrder?: string[]) => {
if (!columnOrder || !columnOrder.length) {
return columns;
}

return Object.keys(columns)
.sort((a, b) => {
const orderA = columnOrder!.indexOf(a);
const orderB = columnOrder!.indexOf(b);
if (orderA !== orderB) {
if (orderA === -1) {
return 1;
}
if (orderB === -1) {
return -1;
}
}
return orderA - orderB;
})
.reduce((obj, key) => {
obj[key] = columns[key];
return obj;
}, {}) as DataTableColumnContainer;
}
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor to reduce complexity and improve maintainability.

The method _sortedColumns has a complex sorting logic that could be simplified or broken down into smaller functions.

Consider breaking down the sorting logic into more manageable functions or utilizing built-in JavaScript sorting capabilities with custom comparators.

Tools
Biome

[error] 300-300: 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] 301-301: 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

Comment on lines +373 to +380
${Object.entries(columns).map(([key, column]) => {
if (
column.hidden ||
(this.columnOrder && this.columnOrder.includes(key)
? this.hiddenColumns?.includes(key) ?? column.defaultHidden
: column.defaultHidden)
) {
return nothing;
Copy link
Contributor

Choose a reason for hiding this comment

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

Complex conditional logic in rendering headers.

The rendering logic in the header uses complex conditional statements to determine visibility. This could be refactored for clarity.

Consider using a helper function to determine if a column should be hidden based on the various conditions.

Tools
Biome

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

Unsafe fix: Change to an optional chain.


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

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

@@ -235,6 +246,7 @@
(column: ClonedDataTableColumnData) => {
delete column.title;
delete column.template;
delete column.extraTemplate;
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 the delete operator for performance reasons.

Using delete on properties can lead to performance issues due to changes in object shape, which can affect optimization.

- delete column.extraTemplate;
+ column.extraTemplate = undefined;
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
delete column.extraTemplate;
column.extraTemplate = undefined;
Tools
Biome

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

Unsafe fix: Use an undefined assignment instead.

Comment on lines +164 to +169
@storage({
key: "devices-table-hidden-columns",
state: false,
subscribe: false,
})
private _activeHiddenColumns?: string[];
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider initializing _activeHiddenColumns with a default value

Similar to _activeColumnOrder, initializing _activeHiddenColumns with a default value could improve the robustness of the component.

- private _activeHiddenColumns?: string[];
+ private _activeHiddenColumns: string[] = [];

This ensures that the property is always in a defined state, potentially simplifying checks and operations on this array.

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
@storage({
key: "devices-table-hidden-columns",
state: false,
subscribe: false,
})
private _activeHiddenColumns?: string[];
@storage({
key: "devices-table-hidden-columns",
state: false,
subscribe: false,
})
private _activeHiddenColumns: string[] = [];

Comment on lines +68 to +71
moveable?: boolean;
hideable?: boolean;
defaultHidden?: boolean;
showNarrow?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

Add type annotations instead of any to enhance type safety.

The interface DataTableSortColumnData uses any for the generic type T. Using any can lead to potential bugs and less maintainable code by bypassing TypeScript's type checking.

- export interface DataTableSortColumnData<T = any> {
+ export interface DataTableSortColumnData<T = unknown> {

Committable suggestion was skipped due to low confidence.

Comment on lines +299 to +306
const settingsButton = html`<ha-assist-chip
class="has-dropdown select-mode-chip"
@click=${this._openSettings}
.title=${localize("ui.components.subpage-data-table.settings")}
>
<ha-svg-icon slot="icon" .path=${mdiCog}></ha-svg-icon>
</ha-assist-chip>`;

Copy link
Contributor

Choose a reason for hiding this comment

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

Enhance accessibility of the settings button.

Consider adding an aria-label attribute to improve accessibility for screen readers.

-      <ha-assist-chip
+      <ha-assist-chip aria-label=${localize("ui.components.subpage-data-table.settings")}
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
const settingsButton = html`<ha-assist-chip
class="has-dropdown select-mode-chip"
@click=${this._openSettings}
.title=${localize("ui.components.subpage-data-table.settings")}
>
<ha-svg-icon slot="icon" .path=${mdiCog}></ha-svg-icon>
</ha-assist-chip>`;
const settingsButton = html`<ha-assist-chip
class="has-dropdown select-mode-chip"
@click=${this._openSettings}
.title=${localize("ui.components.subpage-data-table.settings")}
aria-label=${localize("ui.components.subpage-data-table.settings")}
>
<ha-svg-icon slot="icon" .path=${mdiCog}></ha-svg-icon>
</ha-assist-chip>`;

this.hass.language,
this.hass.localize
)}
.columns=${this._columns(this.hass.localize)}
Copy link
Contributor

Choose a reason for hiding this comment

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

Optimize Event Subscription Handling

Consider unsubscribing from events when the component is disconnected to prevent potential memory leaks.

+ disconnectedCallback() {
+   if (this._tagScannedUnsub) {
+     this._tagScannedUnsub();
+     this._tagScannedUnsub = null;
+   }
+ }
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
.columns=${this._columns(this.hass.localize)}
.columns=${this._columns(this.hass.localize)}
+ disconnectedCallback() {
+ if (this._tagScannedUnsub) {
+ this._tagScannedUnsub();
+ this._tagScannedUnsub = null;
+ }
+ }

Comment on lines +69 to +144
private _columns = memoizeOne((localize: LocalizeFunc) => {
const columns: DataTableColumnContainer<TagRowData> = {
icon: {
title: "",
type: "icon-button",
template: (tag) =>
html` <ha-icon-button
.tag=${tag}
@click=${this._handleAutomationClick}
.label=${this.hass.localize(
"ui.panel.config.tag.create_automation"
)}
.path=${mdiRobot}
></ha-icon-button>`,
};
columns.edit = {
moveable: false,
showNarrow: true,
label: localize("ui.panel.config.tag.headers.icon"),
type: "icon",
template: (tag) => html`<tag-image .tag=${tag}></tag-image>`,
},
display_name: {
title: localize("ui.panel.config.tag.headers.name"),
main: true,
sortable: true,
filterable: true,
grows: true,
},
last_scanned_datetime: {
title: localize("ui.panel.config.tag.headers.last_scanned"),
sortable: true,
direction: "desc",
width: "20%",
template: (tag) => html`
${tag.last_scanned_datetime
? html`<ha-relative-time
.hass=${this.hass}
.datetime=${tag.last_scanned_datetime}
capitalize
></ha-relative-time>`
: this.hass.localize("ui.panel.config.tag.never_scanned")}
`,
},
};
if (this._canWriteTags) {
columns.write = {
title: "",
label: localize("ui.panel.config.tag.headers.write"),
type: "icon-button",
showNarrow: true,
template: (tag) =>
html` <ha-icon-button
html`<ha-icon-button
.tag=${tag}
@click=${this._handleEditClick}
.label=${this.hass.localize("ui.panel.config.tag.edit")}
.path=${mdiCog}
@click=${this._handleWriteClick}
.label=${this.hass.localize("ui.panel.config.tag.write")}
.path=${mdiContentDuplicate}
></ha-icon-button>`,
};
return columns;
}
);
columns.automation = {
title: "",
type: "icon-button",
showNarrow: true,
template: (tag) =>
html`<ha-icon-button
.tag=${tag}
@click=${this._handleAutomationClick}
.label=${this.hass.localize("ui.panel.config.tag.create_automation")}
.path=${mdiRobot}
></ha-icon-button>`,
};
columns.edit = {
title: "",
type: "icon-button",
showNarrow: true,
hideable: false,
moveable: false,
template: (tag) =>
html`<ha-icon-button
.tag=${tag}
@click=${this._handleEditClick}
.label=${this.hass.localize("ui.panel.config.tag.edit")}
.path=${mdiCog}
></ha-icon-button>`,
};
return columns;
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor Column Definitions for Clarity and Maintainability

The column definitions are well-structured but could benefit from splitting into smaller, more manageable functions or methods, especially since some columns have complex templates. This will improve readability and maintainability.

- private _columns = memoizeOne((localize: LocalizeFunc) => { ... });
+ private _defineIconColumn(localize) { ... }
+ private _defineDisplayNameColumn(localize) { ... }
+ private _defineLastScannedColumn(localize) { ... }
+ private _columns = memoizeOne((localize: LocalizeFunc) => {
+   return {
+     icon: this._defineIconColumn(localize),
+     display_name: this._defineDisplayNameColumn(localize),
+     last_scanned_datetime: this._defineLastScannedColumn(localize),
+   };
+ });

Committable suggestion was skipped due to low confidence.

Comment on lines +63 to +71
template: narrow
? undefined
: (backup) =>
html`${backup.name}
<div class="secondary">${backup.path}</div>`,
},
path: {
title: localize("ui.panel.config.backup.path"),
hidden: !narrow,
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor to use template literals for better readability and performance.

The template rendering logic in the name column can be improved by using template literals instead of the ternary operator for conditional rendering. This aligns with best practices and improves code readability.

- template: narrow ? undefined : (backup) => html`${backup.name}<div class="secondary">${backup.path}</div>`,
+ template: (backup) => narrow ? undefined : html`${backup.name}<div class="secondary">${backup.path}</div>`,
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
template: narrow
? undefined
: (backup) =>
html`${backup.name}
<div class="secondary">${backup.path}</div>`,
},
path: {
title: localize("ui.panel.config.backup.path"),
hidden: !narrow,
template: (backup) => narrow
? undefined
: html`${backup.name}
<div class="secondary">${backup.path}</div>`,

Comment on lines +39 to +74
private _sortedColumns = memoizeOne(
(
columns: DataTableColumnContainer,
columnOrder: string[] | undefined,
hiddenColumns: string[] | undefined
) =>
Object.keys(columns)
.filter((col) => !columns[col].hidden)
.sort((a, b) => {
const orderA = columnOrder?.indexOf(a) ?? -1;
const orderB = columnOrder?.indexOf(b) ?? -1;
const hiddenA =
hiddenColumns?.includes(a) ?? Boolean(columns[a].defaultHidden);
const hiddenB =
hiddenColumns?.includes(b) ?? Boolean(columns[b].defaultHidden);
if (hiddenA !== hiddenB) {
return hiddenA ? 1 : -1;
}
if (orderA !== orderB) {
if (orderA === -1) {
return 1;
}
if (orderB === -1) {
return -1;
}
}
return orderA - orderB;
})
.reduce(
(arr, key) => {
arr.push({ key, ...columns[key] });
return arr;
},
[] as (DataTableColumnData & { key: string })[]
)
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor to simplify the column sorting logic.

The _sortedColumns method has a complex logic for sorting columns based on order and visibility. Consider refactoring to reduce complexity and improve maintainability.

- // Existing complex sorting logic
+ // Simplified sorting logic using modern JavaScript features

Committable suggestion was skipped due to low confidence.

Tools
Biome

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

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

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.

3 participants