Fix editing delay action (#4309)

This commit is contained in:
Bram Kragten 2019-12-02 20:08:38 +01:00 committed by Paulus Schoutsen
parent 808cde033f
commit 73b3262491
2 changed files with 18 additions and 3 deletions

View File

@ -1,14 +1,12 @@
import { h } from "preact"; import { h } from "preact";
import "@polymer/paper-input/paper-input"; import "@polymer/paper-input/paper-input";
import { onChangeEvent } from "../../../../common/preact/event";
import { AutomationComponent } from "../automation-component"; import { AutomationComponent } from "../automation-component";
export default class DelayAction extends AutomationComponent<any> { export default class DelayAction extends AutomationComponent<any> {
private onChange: (obj: any) => void;
constructor() { constructor() {
super(); super();
this.onChange = onChangeEvent.bind(this, "action"); this.onChange = this.onChange.bind(this);
} }
public render({ action, localize }) { public render({ action, localize }) {
@ -26,6 +24,20 @@ export default class DelayAction extends AutomationComponent<any> {
</div> </div>
); );
} }
private onChange(ev) {
if (
!this.initialized ||
ev.target.value === this.props.action[ev.target.name]
) {
return;
}
this.props.onChange(this.props.index, {
...this.props.action,
[ev.target.name]: ev.target.value,
});
}
} }
(DelayAction as any).defaultConfig = { (DelayAction as any).defaultConfig = {

View File

@ -18,6 +18,9 @@ export default class WaitAction extends AutomationComponent<any> {
// Gets fired on mount. If empty, onChangeEvent removes attribute. // Gets fired on mount. If empty, onChangeEvent removes attribute.
// Without the attribute this action is no longer matched to this component. // Without the attribute this action is no longer matched to this component.
public onTemplateChange(ev) { public onTemplateChange(ev) {
if (!this.initialized) {
return;
}
this.props.onChange(this.props.index, { this.props.onChange(this.props.index, {
...this.props.action, ...this.props.action,
[ev.target.getAttribute("name")]: ev.target.value, [ev.target.getAttribute("name")]: ev.target.value,