mirror of
https://github.com/home-assistant/frontend.git
synced 2025-11-09 19:09:48 +00:00
Target picker fix entities count for labels (#27603)
This commit is contained in:
@@ -1,17 +1,15 @@
|
|||||||
import { mdiClose } from "@mdi/js";
|
import { html, LitElement, nothing } from "lit";
|
||||||
import { css, html, LitElement, nothing } from "lit";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { customElement, property, query, state } from "lit/decorators";
|
|
||||||
import { fireEvent } from "../../../common/dom/fire_event";
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
import type { HassDialog } from "../../../dialogs/make-dialog-manager";
|
import type { HassDialog } from "../../../dialogs/make-dialog-manager";
|
||||||
import type { HomeAssistant } from "../../../types";
|
import type { HomeAssistant } from "../../../types";
|
||||||
import "../../ha-dialog-header";
|
import "../../ha-dialog-header";
|
||||||
import "../../ha-icon-button";
|
import "../../ha-icon-button";
|
||||||
import "../../ha-icon-next";
|
import "../../ha-icon-next";
|
||||||
import "../../ha-md-dialog";
|
|
||||||
import type { HaMdDialog } from "../../ha-md-dialog";
|
|
||||||
import "../../ha-md-list";
|
import "../../ha-md-list";
|
||||||
import "../../ha-md-list-item";
|
import "../../ha-md-list-item";
|
||||||
import "../../ha-svg-icon";
|
import "../../ha-svg-icon";
|
||||||
|
import "../../ha-wa-dialog";
|
||||||
import "../ha-target-picker-item-row";
|
import "../ha-target-picker-item-row";
|
||||||
import type { TargetDetailsDialogParams } from "./show-dialog-target-details";
|
import type { TargetDetailsDialogParams } from "./show-dialog-target-details";
|
||||||
|
|
||||||
@@ -21,14 +19,15 @@ class DialogTargetDetails extends LitElement implements HassDialog {
|
|||||||
|
|
||||||
@state() private _params?: TargetDetailsDialogParams;
|
@state() private _params?: TargetDetailsDialogParams;
|
||||||
|
|
||||||
@query("ha-md-dialog") private _dialog?: HaMdDialog;
|
@state() private _opened = false;
|
||||||
|
|
||||||
public showDialog(params: TargetDetailsDialogParams): void {
|
public showDialog(params: TargetDetailsDialogParams): void {
|
||||||
this._params = params;
|
this._params = params;
|
||||||
|
this._opened = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public closeDialog() {
|
public closeDialog() {
|
||||||
this._dialog?.close();
|
this._opened = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,58 +42,31 @@ class DialogTargetDetails extends LitElement implements HassDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-md-dialog open @closed=${this._dialogClosed}>
|
<ha-wa-dialog
|
||||||
<ha-dialog-header slot="headline">
|
.hass=${this.hass}
|
||||||
<ha-icon-button
|
.open=${this._opened}
|
||||||
slot="navigationIcon"
|
header-title=${this.hass.localize(
|
||||||
@click=${this.closeDialog}
|
"ui.components.target-picker.target_details"
|
||||||
.label=${this.hass.localize("ui.common.close")}
|
)}
|
||||||
.path=${mdiClose}
|
header-subtitle=${`${this.hass.localize(
|
||||||
></ha-icon-button>
|
`ui.components.target-picker.type.${this._params.type}`
|
||||||
<span slot="title"
|
)}:
|
||||||
>${this.hass.localize(
|
${this._params.title}`}
|
||||||
"ui.components.target-picker.target_details"
|
@closed=${this._dialogClosed}
|
||||||
)}</span
|
>
|
||||||
>
|
<ha-target-picker-item-row
|
||||||
<span slot="subtitle"
|
.hass=${this.hass}
|
||||||
>${this.hass.localize(
|
.type=${this._params.type}
|
||||||
`ui.components.target-picker.type.${this._params.type}`
|
.itemId=${this._params.itemId}
|
||||||
)}:
|
.deviceFilter=${this._params.deviceFilter}
|
||||||
${this._params.title}</span
|
.entityFilter=${this._params.entityFilter}
|
||||||
>
|
.includeDomains=${this._params.includeDomains}
|
||||||
</ha-dialog-header>
|
.includeDeviceClasses=${this._params.includeDeviceClasses}
|
||||||
<div slot="content">
|
expand
|
||||||
<ha-target-picker-item-row
|
></ha-target-picker-item-row>
|
||||||
.hass=${this.hass}
|
</ha-wa-dialog>
|
||||||
.type=${this._params.type}
|
|
||||||
.itemId=${this._params.itemId}
|
|
||||||
.deviceFilter=${this._params.deviceFilter}
|
|
||||||
.entityFilter=${this._params.entityFilter}
|
|
||||||
.includeDomains=${this._params.includeDomains}
|
|
||||||
.includeDeviceClasses=${this._params.includeDeviceClasses}
|
|
||||||
expand
|
|
||||||
></ha-target-picker-item-row>
|
|
||||||
</div>
|
|
||||||
</ha-md-dialog>
|
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
static styles = css`
|
|
||||||
ha-md-dialog {
|
|
||||||
min-width: 400px;
|
|
||||||
max-height: 90%;
|
|
||||||
--dialog-content-padding: var(--ha-space-2) var(--ha-space-6)
|
|
||||||
max(var(--safe-area-inset-bottom, var(--ha-space-0)), var(--ha-space-8));
|
|
||||||
}
|
|
||||||
|
|
||||||
@media all and (max-width: 600px), all and (max-height: 500px) {
|
|
||||||
ha-md-dialog {
|
|
||||||
--md-dialog-container-shape: var(--ha-space-0);
|
|
||||||
min-width: 100%;
|
|
||||||
min-height: 100%;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|||||||
@@ -162,11 +162,12 @@ export class HaTargetPickerItemRow extends LitElement {
|
|||||||
<div slot="headline">${name}</div>
|
<div slot="headline">${name}</div>
|
||||||
${context && !this.hideContext
|
${context && !this.hideContext
|
||||||
? html`<span slot="supporting-text">${context}</span>`
|
? html`<span slot="supporting-text">${context}</span>`
|
||||||
: this._domainName && this.subEntry
|
: nothing}
|
||||||
? html`<span slot="supporting-text" class="domain"
|
${this._domainName && this.subEntry
|
||||||
>${this._domainName}</span
|
? html`<span slot="supporting-text" class="domain"
|
||||||
>`
|
>${this._domainName}</span
|
||||||
: nothing}
|
>`
|
||||||
|
: nothing}
|
||||||
${!this.subEntry && entries && showEntities
|
${!this.subEntry && entries && showEntities
|
||||||
? html`
|
? html`
|
||||||
<div slot="end" class="summary">
|
<div slot="end" class="summary">
|
||||||
@@ -231,9 +232,11 @@ export class HaTargetPickerItemRow extends LitElement {
|
|||||||
const rows1 =
|
const rows1 =
|
||||||
(nextType === "area"
|
(nextType === "area"
|
||||||
? entries?.referenced_areas
|
? entries?.referenced_areas
|
||||||
: nextType === "device"
|
: nextType === "device" && this.type !== "label"
|
||||||
? entries?.referenced_devices
|
? entries?.referenced_devices
|
||||||
: entries?.referenced_entities) || [];
|
: this.type !== "label"
|
||||||
|
? entries?.referenced_entities
|
||||||
|
: []) || [];
|
||||||
|
|
||||||
const devicesInAreas = [] as string[];
|
const devicesInAreas = [] as string[];
|
||||||
|
|
||||||
@@ -284,9 +287,13 @@ export class HaTargetPickerItemRow extends LitElement {
|
|||||||
|
|
||||||
const entityRows =
|
const entityRows =
|
||||||
this.type === "label" && entries
|
this.type === "label" && entries
|
||||||
? entries.referenced_entities.filter((entity_id) =>
|
? entries.referenced_entities.filter((entity_id) => {
|
||||||
this.hass.entities[entity_id].labels.includes(this.itemId)
|
const entity = this.hass.entities[entity_id];
|
||||||
)
|
return (
|
||||||
|
entity.labels.includes(this.itemId) &&
|
||||||
|
!entries.referenced_devices.includes(entity.device_id || "")
|
||||||
|
);
|
||||||
|
})
|
||||||
: nextType === "device" && entries
|
: nextType === "device" && entries
|
||||||
? entries.referenced_entities.filter(
|
? entries.referenced_entities.filter(
|
||||||
(entity_id) =>
|
(entity_id) =>
|
||||||
@@ -412,7 +419,6 @@ export class HaTargetPickerItemRow extends LitElement {
|
|||||||
const device = this.hass.devices[device_id];
|
const device = this.hass.devices[device_id];
|
||||||
if (
|
if (
|
||||||
!hiddenAreaIds.includes(device.area_id || "") &&
|
!hiddenAreaIds.includes(device.area_id || "") &&
|
||||||
(this.type !== "label" || device.labels.includes(this.itemId)) &&
|
|
||||||
deviceMeetsFilter(
|
deviceMeetsFilter(
|
||||||
device,
|
device,
|
||||||
this.hass.entities,
|
this.hass.entities,
|
||||||
@@ -669,6 +675,14 @@ export class HaTargetPickerItemRow extends LitElement {
|
|||||||
button.link:focus {
|
button.link:focus {
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.domain {
|
||||||
|
width: fit-content;
|
||||||
|
border-radius: var(--ha-border-radius-md);
|
||||||
|
background-color: var(--ha-color-fill-neutral-quiet-resting);
|
||||||
|
padding: var(--ha-space-1);
|
||||||
|
font-family: var(--ha-font-family-code);
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user