mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-20 07:46:37 +00:00
Filter fixes (#11664)
This commit is contained in:
parent
fb66d224ae
commit
e1c07f109c
@ -4,6 +4,7 @@ import { mdiFilterVariant } from "@mdi/js";
|
|||||||
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
|
import { stopPropagation } from "../common/dom/stop_propagation";
|
||||||
import { computeStateName } from "../common/entity/compute_state_name";
|
import { computeStateName } from "../common/entity/compute_state_name";
|
||||||
import { computeDeviceName } from "../data/device_registry";
|
import { computeDeviceName } from "../data/device_registry";
|
||||||
import { findRelated, RelatedResult } from "../data/search";
|
import { findRelated, RelatedResult } from "../data/search";
|
||||||
@ -65,6 +66,7 @@ export class HaRelatedFilterButtonMenu extends LitElement {
|
|||||||
.fullwidth=${this.narrow}
|
.fullwidth=${this.narrow}
|
||||||
.corner=${this.corner}
|
.corner=${this.corner}
|
||||||
@closed=${this._onClosed}
|
@closed=${this._onClosed}
|
||||||
|
@input=${stopPropagation}
|
||||||
>
|
>
|
||||||
<ha-area-picker
|
<ha-area-picker
|
||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
@ -75,6 +77,7 @@ export class HaRelatedFilterButtonMenu extends LitElement {
|
|||||||
no-add
|
no-add
|
||||||
.excludeDomains=${this.excludeDomains}
|
.excludeDomains=${this.excludeDomains}
|
||||||
@value-changed=${this._areaPicked}
|
@value-changed=${this._areaPicked}
|
||||||
|
@click=${this._preventDefault}
|
||||||
></ha-area-picker>
|
></ha-area-picker>
|
||||||
<ha-device-picker
|
<ha-device-picker
|
||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
@ -84,6 +87,7 @@ export class HaRelatedFilterButtonMenu extends LitElement {
|
|||||||
.value=${this.value?.device}
|
.value=${this.value?.device}
|
||||||
.excludeDomains=${this.excludeDomains}
|
.excludeDomains=${this.excludeDomains}
|
||||||
@value-changed=${this._devicePicked}
|
@value-changed=${this._devicePicked}
|
||||||
|
@click=${this._preventDefault}
|
||||||
></ha-device-picker>
|
></ha-device-picker>
|
||||||
<ha-entity-picker
|
<ha-entity-picker
|
||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
@ -93,6 +97,7 @@ export class HaRelatedFilterButtonMenu extends LitElement {
|
|||||||
.value=${this.value?.entity}
|
.value=${this.value?.entity}
|
||||||
.excludeDomains=${this.excludeDomains}
|
.excludeDomains=${this.excludeDomains}
|
||||||
@value-changed=${this._entityPicked}
|
@value-changed=${this._entityPicked}
|
||||||
|
@click=${this._preventDefault}
|
||||||
></ha-entity-picker>
|
></ha-entity-picker>
|
||||||
</mwc-menu-surface>
|
</mwc-menu-surface>
|
||||||
`;
|
`;
|
||||||
@ -110,7 +115,12 @@ export class HaRelatedFilterButtonMenu extends LitElement {
|
|||||||
this._open = false;
|
this._open = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _preventDefault(ev) {
|
||||||
|
ev.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
private async _entityPicked(ev: CustomEvent) {
|
private async _entityPicked(ev: CustomEvent) {
|
||||||
|
ev.stopPropagation();
|
||||||
const entityId = ev.detail.value;
|
const entityId = ev.detail.value;
|
||||||
if (!entityId) {
|
if (!entityId) {
|
||||||
fireEvent(this, "related-changed", { value: undefined });
|
fireEvent(this, "related-changed", { value: undefined });
|
||||||
@ -130,6 +140,7 @@ export class HaRelatedFilterButtonMenu extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _devicePicked(ev: CustomEvent) {
|
private async _devicePicked(ev: CustomEvent) {
|
||||||
|
ev.stopPropagation();
|
||||||
const deviceId = ev.detail.value;
|
const deviceId = ev.detail.value;
|
||||||
if (!deviceId) {
|
if (!deviceId) {
|
||||||
fireEvent(this, "related-changed", { value: undefined });
|
fireEvent(this, "related-changed", { value: undefined });
|
||||||
@ -153,6 +164,7 @@ export class HaRelatedFilterButtonMenu extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _areaPicked(ev: CustomEvent) {
|
private async _areaPicked(ev: CustomEvent) {
|
||||||
|
ev.stopPropagation();
|
||||||
const areaId = ev.detail.value;
|
const areaId = ev.detail.value;
|
||||||
if (!areaId) {
|
if (!areaId) {
|
||||||
fireEvent(this, "related-changed", { value: undefined });
|
fireEvent(this, "related-changed", { value: undefined });
|
||||||
@ -176,7 +188,7 @@ export class HaRelatedFilterButtonMenu extends LitElement {
|
|||||||
:host {
|
:host {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
position: relative;
|
position: relative;
|
||||||
--mdc-menu-min-width: 200px;
|
--mdc-menu-min-width: 250px;
|
||||||
}
|
}
|
||||||
ha-area-picker,
|
ha-area-picker,
|
||||||
ha-device-picker,
|
ha-device-picker,
|
||||||
@ -186,6 +198,12 @@ export class HaRelatedFilterButtonMenu extends LitElement {
|
|||||||
padding: 4px 16px;
|
padding: 4px 16px;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
ha-area-picker {
|
||||||
|
padding-top: 16px;
|
||||||
|
}
|
||||||
|
ha-entity-picker {
|
||||||
|
padding-bottom: 16px;
|
||||||
|
}
|
||||||
:host([narrow]) ha-area-picker,
|
:host([narrow]) ha-area-picker,
|
||||||
:host([narrow]) ha-device-picker,
|
:host([narrow]) ha-device-picker,
|
||||||
:host([narrow]) ha-entity-picker {
|
:host([narrow]) ha-entity-picker {
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import "@material/mwc-list/mwc-list";
|
||||||
import "@material/mwc-list/mwc-list-item";
|
import "@material/mwc-list/mwc-list-item";
|
||||||
import Fuse from "fuse.js";
|
import Fuse from "fuse.js";
|
||||||
import {
|
import {
|
||||||
@ -5,8 +6,8 @@ import {
|
|||||||
CSSResultGroup,
|
CSSResultGroup,
|
||||||
html,
|
html,
|
||||||
LitElement,
|
LitElement,
|
||||||
TemplateResult,
|
|
||||||
PropertyValues,
|
PropertyValues,
|
||||||
|
TemplateResult,
|
||||||
} from "lit";
|
} from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { styleMap } from "lit/directives/style-map";
|
import { styleMap } from "lit/directives/style-map";
|
||||||
@ -102,8 +103,7 @@ class StepFlowPickHandler extends LitElement {
|
|||||||
.label=${this.hass.localize("ui.panel.config.integrations.search")}
|
.label=${this.hass.localize("ui.panel.config.integrations.search")}
|
||||||
@keypress=${this._maybeSubmit}
|
@keypress=${this._maybeSubmit}
|
||||||
></search-input>
|
></search-input>
|
||||||
<div
|
<mwc-list
|
||||||
class="container"
|
|
||||||
style=${styleMap({
|
style=${styleMap({
|
||||||
width: `${this._width}px`,
|
width: `${this._width}px`,
|
||||||
height: `${this._height}px`,
|
height: `${this._height}px`,
|
||||||
@ -112,7 +112,7 @@ class StepFlowPickHandler extends LitElement {
|
|||||||
${addDeviceRows.length
|
${addDeviceRows.length
|
||||||
? html`
|
? html`
|
||||||
${addDeviceRows.map((handler) => this._renderRow(handler))}
|
${addDeviceRows.map((handler) => this._renderRow(handler))}
|
||||||
<div class="divider"></div>
|
<li divider padded class="divider" role="separator"></li>
|
||||||
`
|
`
|
||||||
: ""}
|
: ""}
|
||||||
${handlers.length
|
${handlers.length
|
||||||
@ -139,7 +139,7 @@ class StepFlowPickHandler extends LitElement {
|
|||||||
>.
|
>.
|
||||||
</p>
|
</p>
|
||||||
`}
|
`}
|
||||||
</div>
|
</mwc-list>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,10 +169,26 @@ class StepFlowPickHandler extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public willUpdate(changedProps: PropertyValues): void {
|
public willUpdate(changedProps: PropertyValues): void {
|
||||||
|
super.willUpdate(changedProps);
|
||||||
if (this._filter === undefined && this.initialFilter !== undefined) {
|
if (this._filter === undefined && this.initialFilter !== undefined) {
|
||||||
this._filter = this.initialFilter;
|
this._filter = this.initialFilter;
|
||||||
}
|
}
|
||||||
super.willUpdate(changedProps);
|
if (this.initialFilter !== undefined && this._filter === "") {
|
||||||
|
this.initialFilter = undefined;
|
||||||
|
this._filter = "";
|
||||||
|
this._width = undefined;
|
||||||
|
this._height = undefined;
|
||||||
|
} else if (
|
||||||
|
this.hasUpdated &&
|
||||||
|
changedProps.has("_filter") &&
|
||||||
|
(!this._width || !this._height)
|
||||||
|
) {
|
||||||
|
// Store the width and height so that when we search, box doesn't jump
|
||||||
|
const boundingRect =
|
||||||
|
this.shadowRoot!.querySelector("mwc-list")!.getBoundingClientRect();
|
||||||
|
this._width = boundingRect.width;
|
||||||
|
this._height = boundingRect.height;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected firstUpdated(changedProps) {
|
protected firstUpdated(changedProps) {
|
||||||
@ -183,21 +199,6 @@ class StepFlowPickHandler extends LitElement {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected updated(changedProps) {
|
|
||||||
super.updated(changedProps);
|
|
||||||
if (!changedProps.has("handlers")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Wait until list item initialized
|
|
||||||
const firstListItem = this.shadowRoot!.querySelector("mwc-list-item")!;
|
|
||||||
firstListItem.updateComplete.then(() => {
|
|
||||||
// Store the width and height so that when we search, box doesn't jump
|
|
||||||
const div = this.shadowRoot!.querySelector("div.container")!;
|
|
||||||
this._width = div.clientWidth;
|
|
||||||
this._height = div.clientHeight;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private _getHandlers() {
|
private _getHandlers() {
|
||||||
return this._filterHandlers(
|
return this._filterHandlers(
|
||||||
this.handlers,
|
this.handlers,
|
||||||
@ -263,31 +264,26 @@ class StepFlowPickHandler extends LitElement {
|
|||||||
}
|
}
|
||||||
search-input {
|
search-input {
|
||||||
display: block;
|
display: block;
|
||||||
margin-top: 8px;
|
margin: 16px 16px 0;
|
||||||
}
|
|
||||||
.divider {
|
|
||||||
margin: 8px 0;
|
|
||||||
border-top: 1px solid var(--divider-color);
|
|
||||||
}
|
}
|
||||||
ha-icon-next {
|
ha-icon-next {
|
||||||
margin-right: 8px;
|
margin-right: 8px;
|
||||||
}
|
}
|
||||||
div {
|
mwc-list {
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
max-height: 600px;
|
max-height: 600px;
|
||||||
}
|
}
|
||||||
|
.divider {
|
||||||
|
border-bottom-color: var(--divider-color);
|
||||||
|
}
|
||||||
h2 {
|
h2 {
|
||||||
padding-right: 66px;
|
padding-right: 66px;
|
||||||
}
|
}
|
||||||
@media all and (max-height: 900px) {
|
@media all and (max-height: 900px) {
|
||||||
div {
|
mwc-list {
|
||||||
max-height: calc(100vh - 134px);
|
max-height: calc(100vh - 134px);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
paper-icon-item {
|
|
||||||
cursor: pointer;
|
|
||||||
margin-bottom: 4px;
|
|
||||||
}
|
|
||||||
p {
|
p {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
padding: 16px;
|
padding: 16px;
|
||||||
|
@ -338,7 +338,9 @@ export class MoreInfoDialog extends LitElement {
|
|||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
.content {
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
@media all and (max-width: 450px), all and (max-height: 500px) {
|
@media all and (max-width: 450px), all and (max-height: 500px) {
|
||||||
ha-header-bar {
|
ha-header-bar {
|
||||||
--mdc-theme-primary: var(--app-header-background-color);
|
--mdc-theme-primary: var(--app-header-background-color);
|
||||||
|
@ -164,7 +164,11 @@ export class HaTabsSubpageDataTable extends LitElement {
|
|||||||
this.hass.localize("ui.components.data-table.search")}
|
this.hass.localize("ui.components.data-table.search")}
|
||||||
>
|
>
|
||||||
${!this.narrow
|
${!this.narrow
|
||||||
? html`<div class="filters" slot="suffix">
|
? html`<div
|
||||||
|
class="filters"
|
||||||
|
slot="suffix"
|
||||||
|
@click=${this._preventDefault}
|
||||||
|
>
|
||||||
${filterInfo
|
${filterInfo
|
||||||
? html`<div class="active-filters">
|
? html`<div class="active-filters">
|
||||||
${filterInfo}
|
${filterInfo}
|
||||||
@ -194,10 +198,10 @@ export class HaTabsSubpageDataTable extends LitElement {
|
|||||||
<div slot="toolbar-icon">
|
<div slot="toolbar-icon">
|
||||||
${this.narrow
|
${this.narrow
|
||||||
? html`<div class="filter-menu">
|
? html`<div class="filter-menu">
|
||||||
<slot name="filter-menu"></slot>${this.numHidden ||
|
${this.numHidden || this.activeFilters
|
||||||
this.activeFilters
|
|
||||||
? html`<span class="badge">${this.numHidden || "!"}</span>`
|
? html`<span class="badge">${this.numHidden || "!"}</span>`
|
||||||
: ""}
|
: ""}
|
||||||
|
<slot name="filter-menu"></slot>
|
||||||
</div>`
|
</div>`
|
||||||
: ""}<slot name="toolbar-icon"></slot>
|
: ""}<slot name="toolbar-icon"></slot>
|
||||||
</div>
|
</div>
|
||||||
@ -238,6 +242,10 @@ export class HaTabsSubpageDataTable extends LitElement {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _preventDefault(ev) {
|
||||||
|
ev.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
private _handleSearchChange(ev: CustomEvent) {
|
private _handleSearchChange(ev: CustomEvent) {
|
||||||
if (this.filter === ev.detail.value) {
|
if (this.filter === ev.detail.value) {
|
||||||
return;
|
return;
|
||||||
@ -292,12 +300,14 @@ export class HaTabsSubpageDataTable extends LitElement {
|
|||||||
--mdc-ripple-color: transparant;
|
--mdc-ripple-color: transparant;
|
||||||
}
|
}
|
||||||
.filters {
|
.filters {
|
||||||
--mdc-text-field-fill-color: initial;
|
--mdc-text-field-fill-color: var(--input-fill-color);
|
||||||
--mdc-text-field-idle-line-color: initial;
|
--mdc-text-field-idle-line-color: var(--input-idle-line-color);
|
||||||
|
--mdc-shape-small: 4px;
|
||||||
--text-field-overflow: initial;
|
--text-field-overflow: initial;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
margin-right: 8px;
|
margin-right: 8px;
|
||||||
|
color: var(--primary-text-color);
|
||||||
}
|
}
|
||||||
.active-filters {
|
.active-filters {
|
||||||
color: var(--primary-text-color);
|
color: var(--primary-text-color);
|
||||||
@ -308,6 +318,7 @@ export class HaTabsSubpageDataTable extends LitElement {
|
|||||||
margin-left: 4px;
|
margin-left: 4px;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
width: max-content;
|
width: max-content;
|
||||||
|
cursor: initial;
|
||||||
}
|
}
|
||||||
.active-filters ha-svg-icon {
|
.active-filters ha-svg-icon {
|
||||||
color: var(--primary-color);
|
color: var(--primary-color);
|
||||||
|
@ -300,10 +300,14 @@ class HaConfigIntegrations extends SubscribeMixin(LitElement) {
|
|||||||
const filterMenu = html`<div
|
const filterMenu = html`<div
|
||||||
slot=${ifDefined(this.narrow ? "toolbar-icon" : "suffix")}
|
slot=${ifDefined(this.narrow ? "toolbar-icon" : "suffix")}
|
||||||
>
|
>
|
||||||
|
${!this._showDisabled && this.narrow && disabledCount
|
||||||
|
? html`<span class="badge">${disabledCount}</span>`
|
||||||
|
: ""}
|
||||||
<ha-button-menu
|
<ha-button-menu
|
||||||
corner="BOTTOM_START"
|
corner="BOTTOM_START"
|
||||||
multi
|
multi
|
||||||
@action=${this._handleMenuAction}
|
@action=${this._handleMenuAction}
|
||||||
|
@click=${this._preventDefault}
|
||||||
>
|
>
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
slot="trigger"
|
slot="trigger"
|
||||||
@ -322,9 +326,6 @@ class HaConfigIntegrations extends SubscribeMixin(LitElement) {
|
|||||||
)}
|
)}
|
||||||
</ha-check-list-item>
|
</ha-check-list-item>
|
||||||
</ha-button-menu>
|
</ha-button-menu>
|
||||||
${!this._showDisabled && this.narrow && disabledCount
|
|
||||||
? html`<span class="badge">${disabledCount}</span>`
|
|
||||||
: ""}
|
|
||||||
</div>`;
|
</div>`;
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
@ -362,7 +363,11 @@ class HaConfigIntegrations extends SubscribeMixin(LitElement) {
|
|||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
${!this._showDisabled && disabledCount
|
${!this._showDisabled && disabledCount
|
||||||
? html`<div class="active-filters" slot="suffix">
|
? html`<div
|
||||||
|
class="active-filters"
|
||||||
|
slot="suffix"
|
||||||
|
@click=${this._preventDefault}
|
||||||
|
>
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.integrations.disable.disabled_integrations",
|
"ui.panel.config.integrations.disable.disabled_integrations",
|
||||||
{ number: disabledCount }
|
{ number: disabledCount }
|
||||||
@ -507,6 +512,10 @@ class HaConfigIntegrations extends SubscribeMixin(LitElement) {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _preventDefault(ev) {
|
||||||
|
ev.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
private _loadConfigEntries() {
|
private _loadConfigEntries() {
|
||||||
getConfigEntries(this.hass).then((configEntries) => {
|
getConfigEntries(this.hass).then((configEntries) => {
|
||||||
this._configEntries = configEntries
|
this._configEntries = configEntries
|
||||||
@ -724,6 +733,7 @@ class HaConfigIntegrations extends SubscribeMixin(LitElement) {
|
|||||||
padding: 2px 2px 2px 8px;
|
padding: 2px 2px 2px 8px;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
width: max-content;
|
width: max-content;
|
||||||
|
cursor: initial;
|
||||||
}
|
}
|
||||||
.active-filters mwc-button {
|
.active-filters mwc-button {
|
||||||
margin-left: 8px;
|
margin-left: 8px;
|
||||||
@ -754,6 +764,9 @@ class HaConfigIntegrations extends SubscribeMixin(LitElement) {
|
|||||||
top: 8px;
|
top: 8px;
|
||||||
font-size: 0.65em;
|
font-size: 0.65em;
|
||||||
}
|
}
|
||||||
|
ha-button-menu {
|
||||||
|
color: var(--primary-text-color);
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user