Fix pickers (#20315)

* Fix not found area picker

* Fix no match for categories
This commit is contained in:
Paul Bottein 2024-04-02 12:45:13 +02:00 committed by GitHub
parent bc8012dcc9
commit db59e138e9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 39 additions and 32 deletions

View File

@ -136,20 +136,6 @@ export class HaAreaPicker extends LitElement {
noAdd: this["noAdd"], noAdd: this["noAdd"],
excludeAreas: this["excludeAreas"] excludeAreas: this["excludeAreas"]
): AreaRegistryEntry[] => { ): AreaRegistryEntry[] => {
if (!areas.length) {
return [
{
area_id: NO_ITEMS_ID,
floor_id: null,
name: this.hass.localize("ui.components.area-picker.no_areas"),
picture: null,
icon: null,
aliases: [],
labels: [],
},
];
}
let deviceEntityLookup: DeviceEntityDisplayLookup = {}; let deviceEntityLookup: DeviceEntityDisplayLookup = {};
let inputDevices: DeviceRegistryEntry[] | undefined; let inputDevices: DeviceRegistryEntry[] | undefined;
let inputEntities: EntityRegistryDisplayEntry[] | undefined; let inputEntities: EntityRegistryDisplayEntry[] | undefined;
@ -288,7 +274,7 @@ export class HaAreaPicker extends LitElement {
{ {
area_id: NO_ITEMS_ID, area_id: NO_ITEMS_ID,
floor_id: null, floor_id: null,
name: this.hass.localize("ui.components.area-picker.no_match"), name: this.hass.localize("ui.components.area-picker.no_areas"),
picture: null, picture: null,
icon: null, icon: null,
aliases: [], aliases: [],
@ -376,20 +362,40 @@ export class HaAreaPicker extends LitElement {
const filteredItems = fuzzyFilterSort<ScorableAreaRegistryEntry>( const filteredItems = fuzzyFilterSort<ScorableAreaRegistryEntry>(
filterString, filterString,
target.items || [] target.items?.filter(
(item) => ![NO_ITEMS_ID, ADD_NEW_ID].includes(item.label_id)
) || []
); );
if (!this.noAdd && filteredItems?.length === 0) { if (filteredItems.length === 0) {
this._suggestion = filterString; if (!this.noAdd) {
this.comboBox.filteredItems = [ this.comboBox.filteredItems = [
{ {
area_id: ADD_NEW_SUGGESTION_ID, area_id: NO_ITEMS_ID,
name: this.hass.localize( floor_id: null,
"ui.components.area-picker.add_new_sugestion", name: this.hass.localize("ui.components.area-picker.no_match"),
{ name: this._suggestion } icon: null,
), picture: null,
picture: null, labels: [],
}, aliases: [],
]; },
] as AreaRegistryEntry[];
} else {
this._suggestion = filterString;
this.comboBox.filteredItems = [
{
area_id: ADD_NEW_SUGGESTION_ID,
floor_id: null,
name: this.hass.localize(
"ui.components.area-picker.add_new_sugestion",
{ name: this._suggestion }
),
icon: "mdi:plus",
picture: null,
labels: [],
aliases: [],
},
] as AreaRegistryEntry[];
}
} else { } else {
this.comboBox.filteredItems = filteredItems; this.comboBox.filteredItems = filteredItems;
} }
@ -409,6 +415,8 @@ export class HaAreaPicker extends LitElement {
if (newValue === NO_ITEMS_ID) { if (newValue === NO_ITEMS_ID) {
newValue = ""; newValue = "";
this.comboBox.setInputValue("");
return;
} }
if (![ADD_NEW_SUGGESTION_ID, ADD_NEW_ID].includes(newValue)) { if (![ADD_NEW_SUGGESTION_ID, ADD_NEW_ID].includes(newValue)) {

View File

@ -384,7 +384,7 @@ export class HaFloorPicker extends SubscribeMixin(LitElement) {
this.comboBox.filteredItems = [ this.comboBox.filteredItems = [
{ {
floor_id: NO_FLOORS_ID, floor_id: NO_FLOORS_ID,
name: this.hass.localize("ui.components.floor-picker.no_floors"), name: this.hass.localize("ui.components.floor-picker.no_match"),
icon: null, icon: null,
level: null, level: null,
aliases: [], aliases: [],

View File

@ -188,9 +188,7 @@ export class HaCategoryPicker extends SubscribeMixin(LitElement) {
this.comboBox.filteredItems = [ this.comboBox.filteredItems = [
{ {
category_id: NO_CATEGORIES_ID, category_id: NO_CATEGORIES_ID,
name: this.hass.localize( name: this.hass.localize("ui.components.category-picker.no_match"),
"ui.components.category-picker.no_categories"
),
icon: null, icon: null,
}, },
] as ScorableCategoryRegistryEntry[]; ] as ScorableCategoryRegistryEntry[];

View File

@ -571,6 +571,7 @@
"add_new_sugestion": "Add new category ''{name}''", "add_new_sugestion": "Add new category ''{name}''",
"add_new": "Add new category…", "add_new": "Add new category…",
"no_categories": "You don't have any categories", "no_categories": "You don't have any categories",
"no_match": "No matching categories found",
"add_dialog": { "add_dialog": {
"title": "Add new category", "title": "Add new category",
"text": "Enter the name of the new category.", "text": "Enter the name of the new category.",