From 9845f0b47cf94bedfe3fe877ff54663d82cfdaec Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Mon, 1 Sep 2025 18:12:08 +0200 Subject: [PATCH] Don't use ha-automation-row-selected to know if the item was selected (#26812) --- src/components/ha-sortable.ts | 13 ++----------- .../automation/action/ha-automation-action.ts | 15 ++------------- .../condition/ha-automation-condition.ts | 15 ++------------- .../automation/option/ha-automation-option.ts | 15 ++------------- .../automation/trigger/ha-automation-trigger.ts | 15 ++------------- 5 files changed, 10 insertions(+), 63 deletions(-) diff --git a/src/components/ha-sortable.ts b/src/components/ha-sortable.ts index 64fd388724..c7219e7cbe 100644 --- a/src/components/ha-sortable.ts +++ b/src/components/ha-sortable.ts @@ -15,21 +15,16 @@ declare global { "item-added": { index: number; data: any; + item: any; }; "item-removed": { index: number; }; "drag-start": undefined; "drag-end": undefined; - "item-cloned": HaSortableClonedEventData; } } -export interface HaSortableClonedEventData { - item: any; - clone: any; -} - export type HaSortableOptions = Omit< SortableInstance.SortableOptions, "onStart" | "onChoose" | "onEnd" | "onUpdate" | "onAdd" | "onRemove" @@ -154,7 +149,6 @@ export class HaSortable extends LitElement { onUpdate: this._handleUpdate, onAdd: this._handleAdd, onRemove: this._handleRemove, - onClone: this._handleClone, }; if (this.draggableSelector) { @@ -187,6 +181,7 @@ export class HaSortable extends LitElement { fireEvent(this, "item-added", { index: evt.newIndex, data: evt.item.sortableData, + item: evt.item, }); }; @@ -194,10 +189,6 @@ export class HaSortable extends LitElement { fireEvent(this, "item-removed", { index: evt.oldIndex }); }; - private _handleClone = (evt) => { - fireEvent(this, "item-cloned", evt); - }; - private _handleEnd = async (evt) => { fireEvent(this, "drag-end"); // put back in original location diff --git a/src/panels/config/automation/action/ha-automation-action.ts b/src/panels/config/automation/action/ha-automation-action.ts index f23cfaf414..f0e9d57c3d 100644 --- a/src/panels/config/automation/action/ha-automation-action.ts +++ b/src/panels/config/automation/action/ha-automation-action.ts @@ -9,7 +9,6 @@ import { fireEvent } from "../../../../common/dom/fire_event"; import { nextRender } from "../../../../common/util/render-status"; import "../../../../components/ha-button"; import "../../../../components/ha-sortable"; -import type { HaSortableClonedEventData } from "../../../../components/ha-sortable"; import "../../../../components/ha-svg-icon"; import { ACTION_BUILDING_BLOCKS, @@ -76,7 +75,6 @@ export default class HaAutomationAction extends LitElement { @item-moved=${this._actionMoved} @item-added=${this._actionAdded} @item-removed=${this._actionRemoved} - @item-cloned=${this._actionCloned} >
${repeat( @@ -301,11 +299,8 @@ export default class HaAutomationAction extends LitElement { private async _actionAdded(ev: CustomEvent): Promise { ev.stopPropagation(); const { index, data } = ev.detail; - let selected = false; - if (data?.["ha-automation-row-selected"]) { - selected = true; - delete data["ha-automation-row-selected"]; - } + const item = ev.detail.item as HaAutomationActionRow; + const selected = item.isSelected(); let actions = [ ...this.actions.slice(0, index), @@ -363,12 +358,6 @@ export default class HaAutomationAction extends LitElement { fireEvent(this, "value-changed", { value: actions }); } - private _actionCloned(ev: CustomEvent) { - if (ev.detail.item.action && ev.detail.item.isSelected()) { - ev.detail.item.action["ha-automation-row-selected"] = true; - } - } - private _duplicateAction(ev: CustomEvent) { ev.stopPropagation(); const index = (ev.target as any).index; diff --git a/src/panels/config/automation/condition/ha-automation-condition.ts b/src/panels/config/automation/condition/ha-automation-condition.ts index 98e1df7a0f..5a60c5b70b 100644 --- a/src/panels/config/automation/condition/ha-automation-condition.ts +++ b/src/panels/config/automation/condition/ha-automation-condition.ts @@ -10,7 +10,6 @@ import { nextRender } from "../../../../common/util/render-status"; import "../../../../components/ha-button"; import "../../../../components/ha-button-menu"; import "../../../../components/ha-sortable"; -import type { HaSortableClonedEventData } from "../../../../components/ha-sortable"; import "../../../../components/ha-svg-icon"; import type { AutomationClipboard, @@ -153,7 +152,6 @@ export default class HaAutomationCondition extends LitElement { @item-moved=${this._conditionMoved} @item-added=${this._conditionAdded} @item-removed=${this._conditionRemoved} - @item-cloned=${this._conditionCloned} >
${repeat( @@ -319,11 +317,8 @@ export default class HaAutomationCondition extends LitElement { private async _conditionAdded(ev: CustomEvent): Promise { ev.stopPropagation(); const { index, data } = ev.detail; - let selected = false; - if (data?.["ha-automation-row-selected"]) { - selected = true; - delete data["ha-automation-row-selected"]; - } + const item = ev.detail.item as HaAutomationConditionRow; + const selected = item.isSelected(); let conditions = [ ...this.conditions.slice(0, index), data, @@ -361,12 +356,6 @@ export default class HaAutomationCondition extends LitElement { fireEvent(this, "value-changed", { value: conditions }); } - private _conditionCloned(ev: CustomEvent) { - if (ev.detail.item.isSelected()) { - ev.detail.item.condition["ha-automation-row-selected"] = true; - } - } - private _conditionChanged(ev: CustomEvent) { ev.stopPropagation(); const conditions = [...this.conditions]; diff --git a/src/panels/config/automation/option/ha-automation-option.ts b/src/panels/config/automation/option/ha-automation-option.ts index 31a1a7a5e6..9f72fecc03 100644 --- a/src/panels/config/automation/option/ha-automation-option.ts +++ b/src/panels/config/automation/option/ha-automation-option.ts @@ -9,7 +9,6 @@ import { fireEvent } from "../../../../common/dom/fire_event"; import { nextRender } from "../../../../common/util/render-status"; import "../../../../components/ha-button"; import "../../../../components/ha-sortable"; -import type { HaSortableClonedEventData } from "../../../../components/ha-sortable"; import "../../../../components/ha-svg-icon"; import type { AutomationClipboard } from "../../../../data/automation"; import type { Option } from "../../../../data/script"; @@ -65,7 +64,6 @@ export default class HaAutomationOption extends LitElement { @item-moved=${this._optionMoved} @item-added=${this._optionAdded} @item-removed=${this._optionRemoved} - @item-cloned=${this._optionCloned} >
${repeat( @@ -241,11 +239,8 @@ export default class HaAutomationOption extends LitElement { private async _optionAdded(ev: CustomEvent): Promise { ev.stopPropagation(); const { index, data } = ev.detail; - let selected = false; - if (data?.["ha-automation-row-selected"]) { - selected = true; - delete data["ha-automation-row-selected"]; - } + const item = ev.detail.item as HaAutomationOptionRow; + const selected = item.isSelected(); const options = [ ...this.options.slice(0, index), @@ -273,12 +268,6 @@ export default class HaAutomationOption extends LitElement { fireEvent(this, "value-changed", { value: options }); } - private _optionCloned(ev: CustomEvent) { - if (ev.detail.item.isSelected()) { - ev.detail.item.option["ha-automation-row-selected"] = true; - } - } - private _optionChanged(ev: CustomEvent) { ev.stopPropagation(); const options = [...this.options]; diff --git a/src/panels/config/automation/trigger/ha-automation-trigger.ts b/src/panels/config/automation/trigger/ha-automation-trigger.ts index bcc3e7ff5d..f4e2548876 100644 --- a/src/panels/config/automation/trigger/ha-automation-trigger.ts +++ b/src/panels/config/automation/trigger/ha-automation-trigger.ts @@ -10,7 +10,6 @@ import { nextRender } from "../../../../common/util/render-status"; import "../../../../components/ha-button"; import "../../../../components/ha-button-menu"; import "../../../../components/ha-sortable"; -import type { HaSortableClonedEventData } from "../../../../components/ha-sortable"; import "../../../../components/ha-svg-icon"; import type { AutomationClipboard, @@ -72,7 +71,6 @@ export default class HaAutomationTrigger extends LitElement { @item-moved=${this._triggerMoved} @item-added=${this._triggerAdded} @item-removed=${this._triggerRemoved} - @item-cloned=${this._triggerCloned} >
${repeat( @@ -260,11 +258,8 @@ export default class HaAutomationTrigger extends LitElement { private async _triggerAdded(ev: CustomEvent): Promise { ev.stopPropagation(); const { index, data } = ev.detail; - let selected = false; - if (data?.["ha-automation-row-selected"]) { - selected = true; - delete data["ha-automation-row-selected"]; - } + const item = ev.detail.item as HaAutomationTriggerRow; + const selected = item.isSelected(); let triggers = [ ...this.triggers.slice(0, index), @@ -303,12 +298,6 @@ export default class HaAutomationTrigger extends LitElement { fireEvent(this, "value-changed", { value: triggers }); } - private _triggerCloned(ev: CustomEvent) { - if (ev.detail.item.isSelected()) { - ev.detail.item.trigger["ha-automation-row-selected"] = true; - } - } - private _triggerChanged(ev: CustomEvent) { ev.stopPropagation(); const triggers = [...this.triggers];