Skip to content

Commit

Permalink
Add support for setting label description (#20421)
Browse files Browse the repository at this point in the history
* Add support for setting label description
  • Loading branch information
cgarwood authored Apr 12, 2024
1 parent 16de573 commit fb83121
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions gallery/src/pages/components/ha-selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,14 @@ const LABELS: LabelRegistryEntry[] = [
name: "Energy",
icon: null,
color: "yellow",
description: null,
},
{
label_id: "entertainment",
name: "Entertainment",
icon: "mdi:popcorn",
color: "blue",
description: null,
},
];

Expand Down
2 changes: 2 additions & 0 deletions src/components/ha-label-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ export class HaLabelPicker extends SubscribeMixin(LitElement) {
name: this.hass.localize("ui.components.label-picker.no_match"),
icon: null,
color: null,
description: null,
},
];
}
Expand All @@ -315,6 +316,7 @@ export class HaLabelPicker extends SubscribeMixin(LitElement) {
name: this.hass.localize("ui.components.label-picker.add_new"),
icon: "mdi:plus",
color: null,
description: null,
},
];
}
Expand Down
2 changes: 2 additions & 0 deletions src/data/label_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ export interface LabelRegistryEntry {
name: string;
icon: string | null;
color: string | null;
description: string | null;
}

export interface LabelRegistryEntryMutableParams {
name: string;
icon?: string | null;
color?: string | null;
description?: string | null;
}

export const fetchLabelRegistry = (conn: Connection) =>
Expand Down
18 changes: 17 additions & 1 deletion src/panels/config/labels/dialog-label-detail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { createCloseHeading } from "../../../components/ha-dialog";
import "../../../components/ha-formfield";
import "../../../components/ha-switch";
import "../../../components/ha-textfield";
import "../../../components/ha-textarea";
import "../../../components/ha-icon-picker";
import "../../../components/ha-color-picker";
import { HassDialog } from "../../../dialogs/make-dialog-manager";
Expand All @@ -31,6 +32,8 @@ class DialogLabelDetail

@state() private _color!: string;

@state() private _description!: string;

@state() private _error?: string;

@state() private _params?: LabelDetailDialogParams;
Expand All @@ -44,10 +47,12 @@ class DialogLabelDetail
this._name = this._params.entry.name || "";
this._icon = this._params.entry.icon || "";
this._color = this._params.entry.color || "";
this._description = this._params.entry.description || "";
} else {
this._name = this._params.suggestedName || "";
this._icon = "";
this._color = "";
this._description = "";
}
document.body.addEventListener("keydown", this._handleKeyPress);
}
Expand Down Expand Up @@ -118,6 +123,14 @@ class DialogLabelDetail
"ui.panel.config.labels.detail.color"
)}
></ha-color-picker>
<ha-textarea
.value=${this._description}
.configValue=${"description"}
@input=${this._input}
.label=${this.hass!.localize(
"ui.panel.config.labels.detail.description"
)}
></ha-textarea>
</div>
</div>
${this._params.entry && this._params.removeEntry
Expand Down Expand Up @@ -169,6 +182,7 @@ class DialogLabelDetail
name: this._name.trim(),
icon: this._icon.trim() || null,
color: this._color.trim() || null,
description: this._description.trim() || null,
};
if (this._params!.entry) {
newValue = await this._params!.updateEntry!(values);
Expand Down Expand Up @@ -202,12 +216,14 @@ class DialogLabelDetail
a {
color: var(--primary-color);
}
ha-textarea,
ha-textfield,
ha-icon-picker,
ha-color-picker {
display: block;
}
ha-color-picker {
ha-color-picker,
ha-textarea {
margin-top: 16px;
}
`,
Expand Down
6 changes: 6 additions & 0 deletions src/panels/config/labels/ha-config-labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ export class HaConfigLabels extends LitElement {
sortable: true,
filterable: true,
grows: true,
template: (label) => html`
<div>${label.name}</div>
${label.description
? html`<div class="secondary">${label.description}</div>`
: nothing}
`,
},
actions: {
title: "",
Expand Down

0 comments on commit fb83121

Please sign in to comment.