From 29fefa1d602c2c1912a2e02afbaed9f80010cca9 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Wed, 3 Jan 2024 12:20:11 +0100 Subject: [PATCH] Revert conditional rendering of condition (#19257) * Fix conditionally showing `triggered by` * revert conditional rendering * Update add-automation-element-dialog.ts * Update add-automation-element-dialog.ts --- src/data/condition.ts | 1 + .../add-automation-element-dialog.ts | 43 ++++++++----------- .../condition/ha-automation-condition.ts | 1 - .../show-add-automation-element-dialog.ts | 1 - 4 files changed, 20 insertions(+), 26 deletions(-) diff --git a/src/data/condition.ts b/src/data/condition.ts index d8c7af44fecc..44a0e218609c 100644 --- a/src/data/condition.ts +++ b/src/data/condition.ts @@ -46,6 +46,7 @@ export const CONDITION_GROUPS: AutomationElementGroup = { icon: mdiDotsHorizontal, members: { template: {}, + trigger: {}, }, }, } as const; diff --git a/src/panels/config/automation/add-automation-element-dialog.ts b/src/panels/config/automation/add-automation-element-dialog.ts index f8be65baf183..cf5874f80cd8 100644 --- a/src/panels/config/automation/add-automation-element-dialog.ts +++ b/src/panels/config/automation/add-automation-element-dialog.ts @@ -143,6 +143,16 @@ class DialogAddAutomationElement extends LitElement implements HassDialog { this._domains = undefined; } + private _getGroups = ( + type: AddAutomationElementDialogParams["type"], + group: string | undefined + ): AutomationElementGroup => + group + ? isService(group) + ? {} + : TYPES[type].groups[group].members! + : TYPES[type].groups; + private _convertToItem = ( key: string, options, @@ -169,22 +179,13 @@ class DialogAddAutomationElement extends LitElement implements HassDialog { private _getFilteredItems = memoizeOne( ( type: AddAutomationElementDialogParams["type"], - root: AddAutomationElementDialogParams["root"], group: string | undefined, filter: string, localize: LocalizeFunc, services: HomeAssistant["services"], manifests?: DomainManifestLookup ): ListItem[] => { - const groups: AutomationElementGroup = group - ? isService(group) - ? {} - : TYPES[type].groups[group].members! - : TYPES[type].groups; - - if (type === "condition" && group === "other" && !root) { - groups.trigger = {}; - } + const groups = this._getGroups(type, group); const flattenGroups = (grp: AutomationElementGroup) => Object.entries(grp).map(([key, options]) => @@ -213,7 +214,6 @@ class DialogAddAutomationElement extends LitElement implements HassDialog { private _getGroupItems = memoizeOne( ( type: AddAutomationElementDialogParams["type"], - root: AddAutomationElementDialogParams["root"], group: string | undefined, domains: Set | undefined, localize: LocalizeFunc, @@ -221,20 +221,17 @@ class DialogAddAutomationElement extends LitElement implements HassDialog { manifests?: DomainManifestLookup ): ListItem[] => { if (type === "action" && isService(group)) { - const result = this._services(localize, services, manifests, group); + let result = this._services(localize, services, manifests, group); if (group === `${SERVICE_PREFIX}media_player`) { - result.unshift(this._convertToItem("play_media", {}, type, localize)); + result = [ + this._convertToItem("play_media", {}, type, localize), + ...result, + ]; } return result; } - const groups: AutomationElementGroup = group - ? TYPES[type].groups[group].members! - : TYPES[type].groups; - - if (type === "condition" && group === "other" && !root) { - groups.trigger = {}; - } + const groups = this._getGroups(type, group); const result = Object.entries(groups).map(([key, options]) => this._convertToItem(key, options, type, localize) @@ -459,7 +456,6 @@ class DialogAddAutomationElement extends LitElement implements HassDialog { const items = this._filter ? this._getFilteredItems( this._params.type, - this._params.root, this._group, this._filter, this.hass.localize, @@ -468,7 +464,6 @@ class DialogAddAutomationElement extends LitElement implements HassDialog { ) : this._getGroupItems( this._params.type, - this._params.root, this._group, this._domains, this.hass.localize, @@ -537,7 +532,7 @@ class DialogAddAutomationElement extends LitElement implements HassDialog { rootTabbable style=${styleMap({ width: this._width ? `${this._width}px` : "auto", - height: this._height ? `${Math.min(670, this._height)}px` : "auto", + height: this._height ? `${Math.min(468, this._height)}px` : "auto", })} > ${this._params.clipboardItem && @@ -660,7 +655,7 @@ class DialogAddAutomationElement extends LitElement implements HassDialog { width: 24px; } mwc-list { - max-height: 670px; + max-height: 468px; max-width: 100vw; } search-input { diff --git a/src/panels/config/automation/condition/ha-automation-condition.ts b/src/panels/config/automation/condition/ha-automation-condition.ts index ecf4f8823770..27364b92a3ed 100644 --- a/src/panels/config/automation/condition/ha-automation-condition.ts +++ b/src/panels/config/automation/condition/ha-automation-condition.ts @@ -203,7 +203,6 @@ export default class HaAutomationCondition extends LitElement { showAddAutomationElementDialog(this, { type: "condition", add: this._addCondition, - root: !this.nested, clipboardItem: this._clipboard?.condition?.condition, }); } diff --git a/src/panels/config/automation/show-add-automation-element-dialog.ts b/src/panels/config/automation/show-add-automation-element-dialog.ts index 55453505121d..c497ca85c620 100644 --- a/src/panels/config/automation/show-add-automation-element-dialog.ts +++ b/src/panels/config/automation/show-add-automation-element-dialog.ts @@ -6,7 +6,6 @@ export interface AddAutomationElementDialogParams { type: "trigger" | "condition" | "action"; add: (key: string) => void; clipboardItem: string | undefined; - root?: boolean; group?: string; } const loadDialog = () => import("./add-automation-element-dialog");