Fix integration filter search (#20408)

This commit is contained in:
Bram Kragten 2024-04-04 13:26:26 +02:00 committed by GitHub
parent 61c9072a08
commit 72d1e37a23
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,4 +1,3 @@
import { SelectedDetail } from "@material/mwc-list";
import { mdiFilterVariantRemove } from "@mdi/js"; import { mdiFilterVariantRemove } from "@mdi/js";
import { css, CSSResultGroup, html, LitElement, nothing } from "lit"; import { css, CSSResultGroup, html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
@ -56,11 +55,7 @@ export class HaFilterIntegrations extends LitElement {
@value-changed=${this._handleSearchChange} @value-changed=${this._handleSearchChange}
> >
</search-input-outlined> </search-input-outlined>
<mwc-list <mwc-list class="ha-scrollbar" @click=${this._handleItemClick}>
@selected=${this._integrationsSelected}
multi
class="ha-scrollbar"
>
${repeat( ${repeat(
this._integrations(this._manifests, this._filter, this.value), this._integrations(this._manifests, this._filter, this.value),
(i) => i.domain, (i) => i.domain,
@ -131,34 +126,21 @@ export class HaFilterIntegrations extends LitElement {
) )
); );
private async _integrationsSelected( private _handleItemClick(ev) {
ev: CustomEvent<SelectedDetail<Set<number>>> const listItem = ev.target.closest("ha-check-list-item");
) { const value = listItem?.value;
const integrations = this._integrations( if (!value) {
this._manifests!,
this._filter,
this.value
);
if (!ev.detail.index.size) {
fireEvent(this, "data-table-filter-changed", {
value: [],
items: undefined,
});
this.value = [];
return; return;
} }
if (this.value?.includes(value)) {
const value: string[] = []; this.value = this.value?.filter((val) => val !== value);
} else {
for (const index of ev.detail.index) { this.value = [...(this.value || []), value];
const domain = integrations[index].domain;
value.push(domain);
} }
this.value = value; listItem.selected = this.value?.includes(value);
fireEvent(this, "data-table-filter-changed", { fireEvent(this, "data-table-filter-changed", {
value, value: this.value,
items: undefined, items: undefined,
}); });
} }