mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-29 12:16:39 +00:00
Fix moving actions with data (#4438)
This commit is contained in:
parent
7e7da26543
commit
a33cf97e2c
@ -7,6 +7,9 @@ import { afterNextRender } from "../common/util/render-status";
|
|||||||
import { HaCodeEditor } from "./ha-code-editor";
|
import { HaCodeEditor } from "./ha-code-editor";
|
||||||
|
|
||||||
const isEmpty = (obj: object) => {
|
const isEmpty = (obj: object) => {
|
||||||
|
if (typeof obj !== "object") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
for (const key in obj) {
|
for (const key in obj) {
|
||||||
if (obj.hasOwnProperty(key)) {
|
if (obj.hasOwnProperty(key)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import "@polymer/paper-input/paper-input";
|
import "@polymer/paper-input/paper-input";
|
||||||
import "../../../../../components/ha-service-picker";
|
import "../../../../../components/ha-service-picker";
|
||||||
import "../../../../../components/entity/ha-entity-picker";
|
import "../../../../../components/entity/ha-entity-picker";
|
||||||
import "../../../../../components/ha-yaml-editor";
|
|
||||||
|
|
||||||
import { LitElement, property, customElement, html } from "lit-element";
|
import { LitElement, property, customElement, html } from "lit-element";
|
||||||
import { ActionElement, handleChangeEvent } from "../ha-automation-action-row";
|
import { ActionElement, handleChangeEvent } from "../ha-automation-action-row";
|
||||||
|
@ -3,22 +3,44 @@ import "../../../../../components/ha-service-picker";
|
|||||||
import "../../../../../components/entity/ha-entity-picker";
|
import "../../../../../components/entity/ha-entity-picker";
|
||||||
import "../../../../../components/ha-yaml-editor";
|
import "../../../../../components/ha-yaml-editor";
|
||||||
|
|
||||||
import { LitElement, property, customElement } from "lit-element";
|
import {
|
||||||
|
LitElement,
|
||||||
|
property,
|
||||||
|
customElement,
|
||||||
|
PropertyValues,
|
||||||
|
query,
|
||||||
|
} from "lit-element";
|
||||||
import { ActionElement, handleChangeEvent } from "../ha-automation-action-row";
|
import { ActionElement, handleChangeEvent } from "../ha-automation-action-row";
|
||||||
import { HomeAssistant } from "../../../../../types";
|
import { HomeAssistant } from "../../../../../types";
|
||||||
import { html } from "lit-html";
|
import { html } from "lit-html";
|
||||||
import { EventAction } from "../../../../../data/script";
|
import { EventAction } from "../../../../../data/script";
|
||||||
|
// tslint:disable-next-line
|
||||||
|
import { HaYamlEditor } from "../../../../../components/ha-yaml-editor";
|
||||||
|
|
||||||
@customElement("ha-automation-action-event")
|
@customElement("ha-automation-action-event")
|
||||||
export class HaEventAction extends LitElement implements ActionElement {
|
export class HaEventAction extends LitElement implements ActionElement {
|
||||||
@property() public hass!: HomeAssistant;
|
@property() public hass!: HomeAssistant;
|
||||||
@property() public action!: EventAction;
|
@property() public action!: EventAction;
|
||||||
|
@query("ha-yaml-editor") private _yamlEditor?: HaYamlEditor;
|
||||||
|
private _actionData?: EventAction["event_data"];
|
||||||
|
|
||||||
public static get defaultConfig(): EventAction {
|
public static get defaultConfig(): EventAction {
|
||||||
return { event: "", event_data: {} };
|
return { event: "", event_data: {} };
|
||||||
}
|
}
|
||||||
|
|
||||||
public render() {
|
protected updated(changedProperties: PropertyValues) {
|
||||||
|
if (!changedProperties.has("action")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this._actionData && this._actionData !== this.action.event_data) {
|
||||||
|
if (this._yamlEditor) {
|
||||||
|
this._yamlEditor.setValue(this.action.event_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this._actionData = this.action.event_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected render() {
|
||||||
const { event, event_data } = this.action;
|
const { event, event_data } = this.action;
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
@ -36,11 +58,16 @@ export class HaEventAction extends LitElement implements ActionElement {
|
|||||||
)}
|
)}
|
||||||
.name=${"event_data"}
|
.name=${"event_data"}
|
||||||
.value=${event_data}
|
.value=${event_data}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._dataChanged}
|
||||||
></ha-yaml-editor>
|
></ha-yaml-editor>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _dataChanged(ev: CustomEvent): void {
|
||||||
|
this._actionData = ev.detail.value;
|
||||||
|
handleChangeEvent(this, ev);
|
||||||
|
}
|
||||||
|
|
||||||
private _valueChanged(ev: CustomEvent): void {
|
private _valueChanged(ev: CustomEvent): void {
|
||||||
handleChangeEvent(this, ev);
|
handleChangeEvent(this, ev);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,13 @@ import "../../../../../components/ha-service-picker";
|
|||||||
import "../../../../../components/entity/ha-entity-picker";
|
import "../../../../../components/entity/ha-entity-picker";
|
||||||
import "../../../../../components/ha-yaml-editor";
|
import "../../../../../components/ha-yaml-editor";
|
||||||
|
|
||||||
import { LitElement, property, customElement } from "lit-element";
|
import {
|
||||||
|
LitElement,
|
||||||
|
property,
|
||||||
|
customElement,
|
||||||
|
PropertyValues,
|
||||||
|
query,
|
||||||
|
} from "lit-element";
|
||||||
import { ActionElement, handleChangeEvent } from "../ha-automation-action-row";
|
import { ActionElement, handleChangeEvent } from "../ha-automation-action-row";
|
||||||
import { HomeAssistant } from "../../../../../types";
|
import { HomeAssistant } from "../../../../../types";
|
||||||
import { html } from "lit-html";
|
import { html } from "lit-html";
|
||||||
@ -13,11 +19,15 @@ import { computeObjectId } from "../../../../../common/entity/compute_object_id"
|
|||||||
import { PolymerChangedEvent } from "../../../../../polymer-types";
|
import { PolymerChangedEvent } from "../../../../../polymer-types";
|
||||||
import { fireEvent } from "../../../../../common/dom/fire_event";
|
import { fireEvent } from "../../../../../common/dom/fire_event";
|
||||||
import { ServiceAction } from "../../../../../data/script";
|
import { ServiceAction } from "../../../../../data/script";
|
||||||
|
// tslint:disable-next-line
|
||||||
|
import { HaYamlEditor } from "../../../../../components/ha-yaml-editor";
|
||||||
|
|
||||||
@customElement("ha-automation-action-service")
|
@customElement("ha-automation-action-service")
|
||||||
export class HaServiceAction extends LitElement implements ActionElement {
|
export class HaServiceAction extends LitElement implements ActionElement {
|
||||||
@property() public hass!: HomeAssistant;
|
@property() public hass!: HomeAssistant;
|
||||||
@property() public action!: ServiceAction;
|
@property() public action!: ServiceAction;
|
||||||
|
@query("ha-yaml-editor") private _yamlEditor?: HaYamlEditor;
|
||||||
|
private _actionData?: ServiceAction["data"];
|
||||||
|
|
||||||
public static get defaultConfig() {
|
public static get defaultConfig() {
|
||||||
return { service: "", data: {} };
|
return { service: "", data: {} };
|
||||||
@ -43,7 +53,19 @@ export class HaServiceAction extends LitElement implements ActionElement {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
public render() {
|
protected updated(changedProperties: PropertyValues) {
|
||||||
|
if (!changedProperties.has("action")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this._actionData && this._actionData !== this.action.data) {
|
||||||
|
if (this._yamlEditor) {
|
||||||
|
this._yamlEditor.setValue(this.action.data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this._actionData = this.action.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected render() {
|
||||||
const { service, data, entity_id } = this.action;
|
const { service, data, entity_id } = this.action;
|
||||||
|
|
||||||
const serviceData = this._getServiceData(service);
|
const serviceData = this._getServiceData(service);
|
||||||
@ -73,12 +95,13 @@ export class HaServiceAction extends LitElement implements ActionElement {
|
|||||||
)}
|
)}
|
||||||
.name=${"data"}
|
.name=${"data"}
|
||||||
.value=${data}
|
.value=${data}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._dataChanged}
|
||||||
></ha-yaml-editor>
|
></ha-yaml-editor>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _valueChanged(ev: CustomEvent): void {
|
private _dataChanged(ev: CustomEvent): void {
|
||||||
|
this._actionData = ev.detail.value;
|
||||||
handleChangeEvent(this, ev);
|
handleChangeEvent(this, ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user