-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Add color option to heading entities #22068
Conversation
Warning Rate limit exceeded@piitaya has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 25 minutes and 46 seconds before requesting another review. How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughWalkthroughThe pull request introduces several modifications to the Changes
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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 using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Outside diff range and nitpick comments (5)
src/components/ha-selector/ha-selector-ui-color.ts (1)
27-28
: LGTM! Consider a minor improvement for consistency.The addition of
includeUncolored
andincludeState
properties enhances the customization options for the color picker, aligning well with the PR objectives. The implementation is correct and uses proper optional chaining.For consistency with other properties, consider using the spread operator to conditionally include these new properties:
- .includeUncolored=${this.selector.ui_color?.include_uncolored} - .includeState=${this.selector.ui_color?.include_state} + ...(this.selector.ui_color?.include_uncolored && { includeUncolored: true }) + ...(this.selector.ui_color?.include_state && { includeState: true })This approach would make the new properties consistent with how
defaultColor
is handled, only including them when they are explicitly set.src/panels/lovelace/editor/heading-entity/hui-heading-entity-editor.ts (1)
48-79
: LGTM: New "appearance" section added to schema.The addition of the "appearance" section with icon and color selectors improves the organization of the UI. The color selector options align well with the PR objectives.
Consider adding a comment explaining the purpose and structure of the new "appearance" section for better code maintainability.
src/panels/lovelace/editor/config-elements/hui-entity-badge-editor.ts (1)
95-97
: LGTM! Consider adding a comment for clarity.The addition of
include_state: true
to theui_color
selector is a good enhancement. It allows the color picker to consider the entity's state when selecting colors, which aligns with the PR objectives and improves customization options.Consider adding a brief comment explaining the purpose of
include_state: true
for future maintainers. For example:selector: { ui_color: { include_state: true, // Allow color selection based on entity state }, },src/panels/lovelace/editor/config-elements/hui-tile-card-editor.ts (1)
98-101
: LGTM! Consider minor formatting adjustment.The changes to the
color
selector align well with the PR objective of adding a color option to heading entities. The newui_color
selector withdefault_color: "state"
andinclude_state: true
options enhance the customization capabilities, allowing users to select colors based on entity states.Consider adjusting the indentation of the new properties to match the parent object:
selector: { ui_color: { - default_color: "state", - include_state: true, + default_color: "state", + include_state: true, }, },This minor change would improve code readability and maintain consistent formatting.
src/panels/lovelace/cards/types.ts (1)
510-510
: LGTM! Consider adding a JSDoc comment for clarity.The addition of the optional
color
property to theHeadingEntityConfig
interface is well-implemented and aligns with the PR objective. It allows for customization of heading entity colors without breaking existing configurations.Consider adding a JSDoc comment to provide more context about the
color
property. For example:/** Custom color for the heading entity. Can be any valid CSS color value. */ color?: string;This addition would improve code documentation and help developers understand the expected values for this property.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (9)
- src/components/ha-color-picker.ts (3 hunks)
- src/components/ha-selector/ha-selector-ui-color.ts (1 hunks)
- src/data/selector.ts (1 hunks)
- src/panels/lovelace/cards/heading/hui-heading-entity.ts (4 hunks)
- src/panels/lovelace/cards/types.ts (1 hunks)
- src/panels/lovelace/editor/config-elements/hui-entity-badge-editor.ts (1 hunks)
- src/panels/lovelace/editor/config-elements/hui-tile-card-editor.ts (1 hunks)
- src/panels/lovelace/editor/heading-entity/hui-heading-entity-editor.ts (4 hunks)
- src/translations/en.json (2 hunks)
Additional comments not posted (16)
src/panels/lovelace/editor/heading-entity/hui-heading-entity-editor.ts (5)
1-1
: LGTM: New import for color-related icon.The addition of
mdiPalette
import is appropriate for the new color feature being implemented.
22-22
: LGTM: New color property added to entityConfigStruct.The addition of the optional
color
property of type string toentityConfigStruct
is consistent with the PR objective of adding a color option to heading entities.
134-134
: LGTM: New case for "appearance" added to _computeLabelCallback.The addition of the "appearance" case in the
_computeLabelCallback
method is consistent with the new schema structure and follows the existing localization pattern.
Line range hint
1-165
: Overall assessment: Well-implemented color option for heading entities.The changes in this file successfully implement the color option for heading entities as described in the PR objectives. The new "appearance" section in the schema improves the organization of the UI, and the color selector includes appropriate options. The code is consistent with the existing style and patterns.
A few minor suggestions:
- Consider adding a comment explaining the purpose and structure of the new "appearance" section for better code maintainability.
- Ensure that the new localization key for the "appearance" section is defined in the appropriate localization files.
Great job on implementing this new feature!
Line range hint
134-138
: Verify new localization keys.Please ensure that the new localization key
ui.panel.lovelace.editor.card.heading.entity_config.appearance
is defined in the appropriate localization files.Run the following script to check for the new localization key:
src/data/selector.ts (2)
Line range hint
1-1000
: Verify usage of UiColorSelector in componentsWhile the changes to the
UiColorSelector
interface are well-implemented and backwards-compatible, it's important to ensure that any components or functions using this interface are updated to handle the new properties effectively.Please run the following script to identify components that might need updating:
#!/bin/bash # Search for components using UiColorSelector rg --type typescript "UiColorSelector" -C 10 src/componentsReview the results and update the relevant components to take advantage of the new color selection options if necessary.
457-461
: LGTM! Consider updating documentation.The changes to the
UiColorSelector
interface enhance the color selection capabilities, aligning well with the PR objectives. The new optional properties provide more flexibility and customization options.To ensure consistency across the codebase, please run the following script to check for any other occurrences of
UiColorSelector
that might need updating:Additionally, consider updating the relevant documentation to reflect these new options for color selection.
Verification successful
Verification Successful!
All occurrences of
UiColorSelector
are confined tosrc/data/selector.ts
andsrc/components/ha-selector/ha-selector-ui-color.ts
. The changes are properly contained, and no additional updates are necessary.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for other occurrences of UiColorSelector rg --type typescript "UiColorSelector" -C 5Length of output: 94
Script:
#!/bin/bash # Search for other occurrences of UiColorSelector without specifying file type rg "UiColorSelector" -C 5Length of output: 2427
src/translations/en.json (2)
702-704
: New color picker options added: ApprovedThe addition of "default", "state", and "uncolored" options to the color picker enhances user flexibility in color selection. These new options provide more granular control and should improve the overall user experience when working with colors in the interface.
6012-6013
: Entity configuration options improved: ApprovedThe addition of "content" and "appearance" keys under "entity_config" provides a clear separation of configuration options for entities. This organization improves the user experience by making it easier to distinguish between content-related and appearance-related settings when configuring entities.
src/components/ha-color-picker.ts (6)
36-39
: Confirm value assignment logic in_valueSelected
methodThe line
this.value = value === this.defaultColor ? undefined : value;
setsthis.value
toundefined
when the selectedvalue
matchesthis.defaultColor
. Ensure this logic correctly handles the cases wheredefaultColor
is a string and that the component behaves as expected when the default color is selected.Consider testing the color selection to ensure that the default color functionality works correctly, and selecting the default color resets
this.value
appropriately.
61-67
: Validate conditional icon rendering logicIn the render method, the conditional logic for displaying icons based on the selected
value
seems correct. However, double-check that all possiblevalue
cases ("uncolored"
,"state"
, and color strings) are handled appropriately and that the correct icons are displayed.
128-132
: Ensure CSS styles are consistentThe CSS changes for
.circle-color
appear to be correct. Verify that the styling is consistent across different themes and that the--circle-color
variable is appropriately defined in all cases where the component is used.
71-94
: Review inclusion of "uncolored" and "state" optionsThe inclusion of "uncolored" and "state" options in the color picker is controlled by
includeUncolored
andincludeState
. Ensure that these options are needed and that their localization keys (ui.components.color-picker.uncolored
andui.components.color-picker.state
) are correctly defined in the translation files.You might want to verify that the localization keys are present:
#!/bin/bash # Description: Check for localization keys for uncolored and state rg --type json '"ui\.components\.color-picker\.(uncolored|state)"' src/translations/Also, confirm that the inclusion of these options aligns with the intended user experience.
26-30
: Ensure new properties are utilized appropriatelyYou've added
includeState
andincludeUncolored
properties toha-color-picker
. Verify that any components that should expose these options are updated to set these properties accordingly.Run the following script to locate all instances of
ha-color-picker
and check if they need to include the new properties:#!/bin/bash # Description: Find all usages of ha-color-picker in the codebase rg --type js --type ts '<ha-color-picker' --multiline
23-24
: Update dependent components fordefaultColor
type changeChanging
defaultColor
from aBoolean
to aString
type may affect other components that useha-color-picker
. Ensure that all instances whereha-color-picker
is used are updated to pass the correctdefault_color
attribute value.Run the following script to find usages of
ha-color-picker
with thedefault_color
attribute:src/panels/lovelace/cards/heading/hui-heading-entity.ts (1)
60-95
: Efficient implementation of color computation with memoizationThe newly added
_computeStateColor
method effectively computes the color based on the entity's state and configuration. UtilizingmemoizeOne
enhances performance by avoiding redundant computations for the same inputs.
I think we should align the off state color with the no color option personally. |
bf4464e
to
5ce0cd1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Outside diff range and nitpick comments (2)
src/panels/lovelace/editor/config-elements/hui-entity-badge-editor.ts (2)
95-97
: LGTM! Consider adding a comment for clarity.The update to include the entity's state color as an option in the color selector is a good improvement. It aligns well with the PR objectives and enhances the user interface as described in the summary.
Consider adding a brief comment explaining the purpose of
include_state: true
for future maintainers:selector: { ui_color: { + // Include the entity's state color as an option in the color picker include_state: true, }, },
256-267
: LGTM! Consider future extensibility.The addition of the
_computeHelperCallback
method is a good improvement. It enhances the user interface by providing contextual help for the color property, which aligns well with the PR objectives.For future extensibility, consider using a switch statement instead of an if-else chain. This will make it easier to add help text for other properties in the future:
private _computeHelperCallback = ( schema: SchemaUnion<ReturnType<typeof this._schema>> ) => { switch (schema.name) { case "color": return this.hass!.localize( `ui.panel.lovelace.editor.badge.entity.${schema.name}_helper` ); default: return undefined; } };
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (8)
- src/components/ha-color-picker.ts (3 hunks)
- src/components/ha-selector/ha-selector-ui-color.ts (1 hunks)
- src/data/selector.ts (1 hunks)
- src/panels/lovelace/cards/heading/hui-heading-entity.ts (5 hunks)
- src/panels/lovelace/editor/config-elements/hui-entity-badge-editor.ts (3 hunks)
- src/panels/lovelace/editor/config-elements/hui-tile-card-editor.ts (3 hunks)
- src/panels/lovelace/editor/heading-entity/hui-heading-entity-editor.ts (6 hunks)
- src/translations/en.json (4 hunks)
Files skipped from review as they are similar to previous changes (7)
- src/components/ha-color-picker.ts
- src/components/ha-selector/ha-selector-ui-color.ts
- src/data/selector.ts
- src/panels/lovelace/cards/heading/hui-heading-entity.ts
- src/panels/lovelace/editor/config-elements/hui-tile-card-editor.ts
- src/panels/lovelace/editor/heading-entity/hui-heading-entity-editor.ts
- src/translations/en.json
Additional comments not posted (1)
src/panels/lovelace/editor/config-elements/hui-entity-badge-editor.ts (1)
208-208
: LGTM! Good integration of the helper callback.The addition of the
computeHelpText
property to theha-form
component is a good integration of the newly added_computeHelperCallback
method. This change enables the display of contextual help text for form fields, which enhances the user experience and supports the PR objectives.
0066ff1
to
1ec1083
Compare
1ec1083
to
2c68b5e
Compare
Proposed change
Color editor
Colored icons
Type of change
Example configuration
Additional information
Checklist
If user exposed functionality or configuration variables are added/changed:
Summary by CodeRabbit
Release Notes
New Features
HaColorPicker
component with new properties for better customization:includeState
andincludeNone
.Bug Fixes
Documentation