From 736afe2530b79e1a1d1d480226e1025a37e778e1 Mon Sep 17 00:00:00 2001 From: Wendelin <12148533+wendevlin@users.noreply.github.com> Date: Wed, 17 Dec 2025 12:49:23 +0100 Subject: [PATCH] Migrate config-entry-picker to generic-picker (#28568) * Use generic-picker for config-entry-picker * Apply suggestion from @MindFreeze Co-authored-by: Petar Petrov * Apply suggestion from @MindFreeze Co-authored-by: Petar Petrov --------- Co-authored-by: Petar Petrov --- src/components/ha-config-entry-picker.ts | 142 +++++++++++------------ 1 file changed, 66 insertions(+), 76 deletions(-) diff --git a/src/components/ha-config-entry-picker.ts b/src/components/ha-config-entry-picker.ts index 2ead4e03ed..ce84582052 100644 --- a/src/components/ha-config-entry-picker.ts +++ b/src/components/ha-config-entry-picker.ts @@ -1,20 +1,22 @@ -import type { ComboBoxLitRenderer } from "@vaadin/combo-box/lit"; +import type { RenderItemFunction } from "@lit-labs/virtualizer/virtualize"; import { html, LitElement, nothing } from "lit"; import { customElement, property, query, state } from "lit/decorators"; import { fireEvent } from "../common/dom/fire_event"; -import { caseInsensitiveStringCompare } from "../common/string/compare"; import type { ConfigEntry } from "../data/config_entries"; import { getConfigEntries } from "../data/config_entries"; import { domainToName } from "../data/integration"; -import type { ValueChangedEvent, HomeAssistant } from "../types"; -import { brandsUrl } from "../util/brands-url"; -import "./ha-combo-box"; -import type { HaComboBox } from "./ha-combo-box"; +import type { HomeAssistant, ValueChangedEvent } from "../types"; import "./ha-combo-box-item"; +import "./ha-domain-icon"; +import "./ha-generic-picker"; +import type { HaGenericPicker } from "./ha-generic-picker"; +import type { PickerComboBoxItem } from "./ha-picker-combo-box"; -export interface ConfigEntryExtended extends ConfigEntry { - localized_domain_name?: string; -} +const SEARCH_KEYS = [ + { name: "primary", weight: 10 }, + { name: "secondary", weight: 8 }, + { name: "icon", weight: 5 }, +]; @customElement("ha-config-entry-picker") class HaConfigEntryPicker extends LitElement { @@ -28,119 +30,107 @@ class HaConfigEntryPicker extends LitElement { @property() public helper?: string; - @state() private _configEntries?: ConfigEntryExtended[]; + @state() private _configEntries?: PickerComboBoxItem[]; @property({ type: Boolean }) public disabled = false; @property({ type: Boolean }) public required = false; - @query("ha-combo-box") private _comboBox!: HaComboBox; + @query("ha-generic-picker") private _picker!: HaGenericPicker; public open() { - this._comboBox?.open(); + this._picker?.open(); } public focus() { - this._comboBox?.focus(); + this._picker?.focus(); } protected firstUpdated() { this._getConfigEntries(); } - private _rowRenderer: ComboBoxLitRenderer = ( - item - ) => html` - - - ${item.title || - this.hass.localize( - "ui.panel.config.integrations.config_entry.unnamed_entry" - )} - - ${item.localized_domain_name} - - - `; - protected render() { if (!this._configEntries) { return nothing; } return html` - + > `; } - private _onImageLoad(ev) { - ev.target.style.visibility = "initial"; - } - - private _onImageError(ev) { - ev.target.style.visibility = "hidden"; - } + private _rowRenderer: RenderItemFunction = (item) => html` + + ${item.primary} + ${item.secondary} + + + `; private async _getConfigEntries() { getConfigEntries(this.hass, { type: ["device", "hub", "service"], domain: this.integration, }).then((configEntries) => { - this._configEntries = configEntries - .map( - (entry: ConfigEntry): ConfigEntryExtended => ({ - ...entry, - localized_domain_name: domainToName( - this.hass.localize, - entry.domain + this._configEntries = configEntries.map((entry: ConfigEntry) => { + const domainName = domainToName(this.hass.localize, entry.domain); + return { + id: entry.entry_id, + icon: entry.domain, + primary: + entry.title || + this.hass.localize( + "ui.panel.config.integrations.config_entry.unnamed_entry" ), - }) - ) - .sort((conf1, conf2) => - caseInsensitiveStringCompare( - conf1.localized_domain_name + conf1.title, - conf2.localized_domain_name + conf2.title, - this.hass.locale.language - ) - ); + secondary: domainName, + sorting_label: [entry.title, domainName].filter(Boolean).join("_"), + }; + }); }); } - private get _value() { - return this.value || ""; - } + private _valueRenderer = (itemId: string) => { + const item = this._configEntries!.find((entry) => entry.id === itemId); + return html`${item?.icon + ? html`` + : nothing}${item?.primary || "Unknown"}`; + }; + + private _getItems = () => this._configEntries!; private _valueChanged(ev: ValueChangedEvent) { ev.stopPropagation(); const newValue = ev.detail.value; - if (newValue !== this._value) { + if (newValue !== this.value) { this._setValue(newValue); } }