From 5b7655cf7212612f493b87b38470ad5f8b072640 Mon Sep 17 00:00:00 2001 From: karwosts <32912880+karwosts@users.noreply.github.com> Date: Mon, 16 Jun 2025 22:42:20 -0700 Subject: [PATCH] Fix automation drag&drop loses item (#25811) --- .../config/automation/action/ha-automation-action.ts | 12 ++++++++++-- .../automation/condition/ha-automation-condition.ts | 12 ++++++++++-- .../automation/trigger/ha-automation-trigger.ts | 12 ++++++++++-- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/panels/config/automation/action/ha-automation-action.ts b/src/panels/config/automation/action/ha-automation-action.ts index e41f9e500f..678f829bcb 100644 --- a/src/panels/config/automation/action/ha-automation-action.ts +++ b/src/panels/config/automation/action/ha-automation-action.ts @@ -235,7 +235,7 @@ export default class HaAutomationAction extends LitElement { private async _actionAdded(ev: CustomEvent): Promise { ev.stopPropagation(); const { index, data } = ev.detail; - const actions = [ + let actions = [ ...this.actions.slice(0, index), data, ...this.actions.slice(index), @@ -243,7 +243,15 @@ export default class HaAutomationAction extends LitElement { // Add action locally to avoid UI jump this.actions = actions; await nextRender(); - fireEvent(this, "value-changed", { value: this.actions }); + if (this.actions !== actions) { + // Ensure action is added even after update + actions = [ + ...this.actions.slice(0, index), + data, + ...this.actions.slice(index), + ]; + } + fireEvent(this, "value-changed", { value: actions }); } private async _actionRemoved(ev: CustomEvent): Promise { diff --git a/src/panels/config/automation/condition/ha-automation-condition.ts b/src/panels/config/automation/condition/ha-automation-condition.ts index f1557a7956..46e18ab00d 100644 --- a/src/panels/config/automation/condition/ha-automation-condition.ts +++ b/src/panels/config/automation/condition/ha-automation-condition.ts @@ -258,7 +258,7 @@ export default class HaAutomationCondition extends LitElement { private async _conditionAdded(ev: CustomEvent): Promise { ev.stopPropagation(); const { index, data } = ev.detail; - const conditions = [ + let conditions = [ ...this.conditions.slice(0, index), data, ...this.conditions.slice(index), @@ -266,7 +266,15 @@ export default class HaAutomationCondition extends LitElement { // Add condition locally to avoid UI jump this.conditions = conditions; await nextRender(); - fireEvent(this, "value-changed", { value: this.conditions }); + if (this.conditions !== conditions) { + // Ensure condition is added even after update + conditions = [ + ...this.conditions.slice(0, index), + data, + ...this.conditions.slice(index), + ]; + } + fireEvent(this, "value-changed", { value: conditions }); } private async _conditionRemoved(ev: CustomEvent): Promise { diff --git a/src/panels/config/automation/trigger/ha-automation-trigger.ts b/src/panels/config/automation/trigger/ha-automation-trigger.ts index cc6219d0cc..7e7fefd79e 100644 --- a/src/panels/config/automation/trigger/ha-automation-trigger.ts +++ b/src/panels/config/automation/trigger/ha-automation-trigger.ts @@ -220,7 +220,7 @@ export default class HaAutomationTrigger extends LitElement { private async _triggerAdded(ev: CustomEvent): Promise { ev.stopPropagation(); const { index, data } = ev.detail; - const triggers = [ + let triggers = [ ...this.triggers.slice(0, index), data, ...this.triggers.slice(index), @@ -228,7 +228,15 @@ export default class HaAutomationTrigger extends LitElement { // Add trigger locally to avoid UI jump this.triggers = triggers; await nextRender(); - fireEvent(this, "value-changed", { value: this.triggers }); + if (this.triggers !== triggers) { + // Ensure trigger is added even after update + triggers = [ + ...this.triggers.slice(0, index), + data, + ...this.triggers.slice(index), + ]; + } + fireEvent(this, "value-changed", { value: triggers }); } private async _triggerRemoved(ev: CustomEvent): Promise {