Fix drag and drop when using action and trigger selector (#22291)

* Fix drag and drop when using action selector

* Fix drag and drop when using trigger selector
This commit is contained in:
Paul Bottein 2024-10-08 21:04:45 +02:00 committed by GitHub
parent 1b441a7eec
commit 99035cea8f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 14 deletions

View File

@ -4,7 +4,7 @@ import memoizeOne from "memoize-one";
import { Action, migrateAutomationAction } from "../../data/script"; import { Action, migrateAutomationAction } from "../../data/script";
import { ActionSelector } from "../../data/selector"; import { ActionSelector } from "../../data/selector";
import "../../panels/config/automation/action/ha-automation-action"; import "../../panels/config/automation/action/ha-automation-action";
import { HomeAssistant } from "../../types"; import { HomeAssistant, ItemPath } from "../../types";
@customElement("ha-selector-action") @customElement("ha-selector-action")
export class HaActionSelector extends LitElement { export class HaActionSelector extends LitElement {
@ -18,19 +18,22 @@ export class HaActionSelector extends LitElement {
@property({ type: Boolean, reflect: true }) public disabled = false; @property({ type: Boolean, reflect: true }) public disabled = false;
private _actions = memoizeOne((action: Action | undefined) => { // Add path here to ignore memoize if the path changes
if (!action) { private _actions = memoizeOne(
return []; (action: Action | undefined, _path?: ItemPath) => {
if (!action) {
return [];
}
return migrateAutomationAction(action);
} }
return migrateAutomationAction(action); );
});
protected render() { protected render() {
return html` return html`
${this.label ? html`<label>${this.label}</label>` : nothing} ${this.label ? html`<label>${this.label}</label>` : nothing}
<ha-automation-action <ha-automation-action
.disabled=${this.disabled} .disabled=${this.disabled}
.actions=${this._actions(this.value)} .actions=${this._actions(this.value, this.selector.action?.path)}
.hass=${this.hass} .hass=${this.hass}
.path=${this.selector.action?.path} .path=${this.selector.action?.path}
></ha-automation-action> ></ha-automation-action>

View File

@ -4,7 +4,7 @@ import memoizeOne from "memoize-one";
import { migrateAutomationTrigger, Trigger } from "../../data/automation"; import { migrateAutomationTrigger, Trigger } from "../../data/automation";
import { TriggerSelector } from "../../data/selector"; import { TriggerSelector } from "../../data/selector";
import "../../panels/config/automation/trigger/ha-automation-trigger"; import "../../panels/config/automation/trigger/ha-automation-trigger";
import { HomeAssistant } from "../../types"; import { HomeAssistant, ItemPath } from "../../types";
@customElement("ha-selector-trigger") @customElement("ha-selector-trigger")
export class HaTriggerSelector extends LitElement { export class HaTriggerSelector extends LitElement {
@ -18,19 +18,22 @@ export class HaTriggerSelector extends LitElement {
@property({ type: Boolean, reflect: true }) public disabled = false; @property({ type: Boolean, reflect: true }) public disabled = false;
private _triggers = memoizeOne((trigger: Trigger | undefined) => { // Add path here to ignore memoize if the path changes
if (!trigger) { private _triggers = memoizeOne(
return []; (trigger: Trigger | undefined, _path?: ItemPath) => {
if (!trigger) {
return [];
}
return migrateAutomationTrigger(trigger);
} }
return migrateAutomationTrigger(trigger); );
});
protected render() { protected render() {
return html` return html`
${this.label ? html`<label>${this.label}</label>` : nothing} ${this.label ? html`<label>${this.label}</label>` : nothing}
<ha-automation-trigger <ha-automation-trigger
.disabled=${this.disabled} .disabled=${this.disabled}
.triggers=${this._triggers(this.value)} .triggers=${this._triggers(this.value, this.selector.trigger?.path)}
.hass=${this.hass} .hass=${this.hass}
.path=${this.selector.trigger?.path} .path=${this.selector.trigger?.path}
></ha-automation-trigger> ></ha-automation-trigger>