Fix automation drag&drop loses item (#25811)

This commit is contained in:
karwosts 2025-06-16 22:42:20 -07:00 committed by GitHub
parent 634e1dbde8
commit 5b7655cf72
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 30 additions and 6 deletions

View File

@ -235,7 +235,7 @@ export default class HaAutomationAction extends LitElement {
private async _actionAdded(ev: CustomEvent): Promise<void> {
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<void> {

View File

@ -258,7 +258,7 @@ export default class HaAutomationCondition extends LitElement {
private async _conditionAdded(ev: CustomEvent): Promise<void> {
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<void> {

View File

@ -220,7 +220,7 @@ export default class HaAutomationTrigger extends LitElement {
private async _triggerAdded(ev: CustomEvent): Promise<void> {
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<void> {