Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/components/ha-selector/ha-selector-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,20 @@ export class HaObjectSelector extends LitElement {
.filter(Boolean)
.join(" · ");

const overviewLabels = this.selector.object!.overview_labels || false;

const labelField =
preferredLabel || Object.keys(this.selector.object!.fields!)[0];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The ! here is optimistic. fields may be undefined according to the type


const labelHeader = overviewLabels
? `${this._computeLabel({
name: labelField,
selector: fields[labelField]?.selector,
})}: `
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The : should really be part of the translation otherwise it won't work in all languages

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I was really trying to avoid another field needed to be translated and instead just have a bool saying if it should display in the overview or not.

I'd think this probably looks ok even to remove : so it would just say Uncompensated value 5?

: "";

let description = "";
let descriptionHeader = "";

const descriptionField = this.selector.object!.description_field;
if (descriptionField && descriptionField in fields) {
Expand All @@ -108,6 +121,12 @@ export class HaObjectSelector extends LitElement {
descriptionSelector
)
: "";
descriptionHeader = overviewLabels
? `${this._computeLabel({
name: descriptionField,
selector: descriptionSelector,
})}: `
: "";
}

const reorderable = this.selector.object!.multiple || false;
Expand All @@ -123,10 +142,10 @@ export class HaObjectSelector extends LitElement {
></ha-svg-icon>
`
: nothing}
<div slot="headline" class="label">${label}</div>
<div slot="headline" class="label">${labelHeader}${label}</div>
${description
? html`<div slot="supporting-text" class="description">
${description}
${descriptionHeader}${description}
</div>`
: nothing}
<ha-icon-button
Expand Down
1 change: 1 addition & 0 deletions src/data/selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ export interface ObjectSelector {
label_field?: string;
description_field?: string;
translation_key?: string;
overview_labels?: boolean;
fields?: Record<string, ObjectSelectorField>;
multiple?: boolean;
} | null;
Expand Down
Loading