Skip to content

Commit

Permalink
Use domain translation in filter for domain search
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbede committed May 9, 2024
1 parent 9c57c9f commit 4612acf
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions src/components/ha-filter-domains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import "./ha-domain-icon";
import "./search-input-outlined";
import { computeDomain } from "../common/entity/compute_domain";

type DomainTranslation = {
domain: string;
translation: string;
};

@customElement("ha-filter-domains")
export class HaFilterDomains extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
Expand Down Expand Up @@ -63,17 +68,17 @@ export class HaFilterDomains extends LitElement {
(i) => i,
(domain) =>
html`<ha-check-list-item
.value=${domain}
.selected=${(this.value || []).includes(domain)}
.value=${domain.domain}
.selected=${(this.value || []).includes(domain.domain)}
graphic="icon"
>
<ha-domain-icon
slot="graphic"
.hass=${this.hass}
.domain=${domain}
.domain=${domain.domain}
brandFallback
></ha-domain-icon>
${domainToName(this.hass.localize, domain)}
${domain.translation}
</ha-check-list-item>`
)}
</mwc-list> `
Expand All @@ -83,13 +88,22 @@ export class HaFilterDomains extends LitElement {
}

private _domains = memoizeOne((states, filter) => {
const domains = new Set<string>();
const domains = new Map<string, DomainTranslation>();
Object.keys(states).forEach((entityId) => {
domains.add(computeDomain(entityId));
const computedDomain = computeDomain(entityId);
domains.set(computedDomain, {
domain: computedDomain,
translation: domainToName(this.hass.localize, computedDomain),
});
});
return Array.from(domains)
.filter((domain) => !filter || domain.toLowerCase().includes(filter))
.sort((a, b) => stringCompare(a, b, this.hass.locale.language));

return Array.from(domains.values())
.filter(
(entry) => !filter || entry.translation.toLowerCase().includes(filter)
)
.sort((a, b) =>
stringCompare(a.translation, b.translation, this.hass.locale.language)
);
});

protected updated(changed) {
Expand Down

0 comments on commit 4612acf

Please sign in to comment.