mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Fix statistic-picker filter behavior (#17453)
This commit is contained in:
parent
788e48a5a6
commit
bde93c44bd
@ -1,5 +1,5 @@
|
|||||||
import { HassEntity } from "home-assistant-js-websocket";
|
import { HassEntity } from "home-assistant-js-websocket";
|
||||||
import { html, LitElement, PropertyValues, TemplateResult } from "lit";
|
import { html, LitElement, nothing, PropertyValues, TemplateResult } from "lit";
|
||||||
import { ComboBoxLitRenderer } from "@vaadin/combo-box/lit";
|
import { ComboBoxLitRenderer } from "@vaadin/combo-box/lit";
|
||||||
import { customElement, property, query, state } from "lit/decorators";
|
import { customElement, property, query, state } from "lit/decorators";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
@ -87,6 +87,8 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
|
|
||||||
private _statistics: StatisticItem[] = [];
|
private _statistics: StatisticItem[] = [];
|
||||||
|
|
||||||
|
@state() private _filteredItems?: StatisticItem[] = undefined;
|
||||||
|
|
||||||
private _rowRenderer: ComboBoxLitRenderer<StatisticItem> = (item) =>
|
private _rowRenderer: ComboBoxLitRenderer<StatisticItem> = (item) =>
|
||||||
html`<mwc-list-item graphic="avatar" twoline>
|
html`<mwc-list-item graphic="avatar" twoline>
|
||||||
${item.state
|
${item.state
|
||||||
@ -254,7 +256,11 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult | typeof nothing {
|
||||||
|
if (this._statistics.length === 0) {
|
||||||
|
return nothing;
|
||||||
|
}
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-combo-box
|
<ha-combo-box
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
@ -265,9 +271,8 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
.renderer=${this._rowRenderer}
|
.renderer=${this._rowRenderer}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
.allowCustomValue=${this.allowCustomEntity}
|
.allowCustomValue=${this.allowCustomEntity}
|
||||||
.filteredItems=${this.value && this._statistics.length === 0
|
.items=${this._statistics}
|
||||||
? undefined
|
.filteredItems=${this._filteredItems ?? this._statistics}
|
||||||
: this._statistics}
|
|
||||||
item-value-path="id"
|
item-value-path="id"
|
||||||
item-id-path="id"
|
item-id-path="id"
|
||||||
item-label-path="name"
|
item-label-path="name"
|
||||||
@ -303,11 +308,10 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _filterChanged(ev: CustomEvent): void {
|
private _filterChanged(ev: CustomEvent): void {
|
||||||
const target = ev.target as HaComboBox;
|
|
||||||
const filterString = ev.detail.value.toLowerCase();
|
const filterString = ev.detail.value.toLowerCase();
|
||||||
target.filteredItems = filterString.length
|
this._filteredItems = filterString.length
|
||||||
? fuzzyFilterSort<StatisticItem>(filterString, this._statistics)
|
? fuzzyFilterSort<StatisticItem>(filterString, this._statistics)
|
||||||
: this._statistics;
|
: undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _setValue(value: string) {
|
private _setValue(value: string) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user