1
0
mirror of https://github.com/home-assistant/frontend.git synced 2025-12-20 10:48:44 +00:00
Files
frontend/js/automation-editor/trigger/index.js
Paulus Schoutsen 0707528bd7 Entity dropdown improvement (#674)
* Ignore hass changes while dropdown is open

* Upgrade vaadin-combo-box

* Fix styling on dev-service panel

* Fix styling for ha-entity-dropdown

* Fix height vaadin-combo-box dropdown

* Rename ha-entity-dropdown to ha-entity-picker

* More entity improvement (#675)

* Update script and automation editor to use entity picker

* Add entity and service picker to service dev panel

* Lint
2017-11-25 16:00:43 -08:00

54 lines
1.2 KiB
JavaScript

import { h, Component } from 'preact';
import TriggerRow from './trigger_row.js';
import StateTrigger from './state.js';
export default class Trigger extends Component {
constructor() {
super();
this.addTrigger = this.addTrigger.bind(this);
this.triggerChanged = this.triggerChanged.bind(this);
}
addTrigger() {
const trigger = this.props.trigger.concat({
platform: 'state',
...StateTrigger.defaultConfig,
});
this.props.onChange(trigger);
}
triggerChanged(index, newValue) {
const trigger = this.props.trigger.concat();
if (newValue === null) {
trigger.splice(index, 1);
} else {
trigger[index] = newValue;
}
this.props.onChange(trigger);
}
render({ trigger, hass }) {
return (
<div class="triggers">
{trigger.map((trg, idx) => (
<TriggerRow
index={idx}
trigger={trg}
onChange={this.triggerChanged}
hass={hass}
/>))}
<paper-card>
<div class='card-actions add-card'>
<paper-button onTap={this.addTrigger}>Add trigger</paper-button>
</div>
</paper-card>
</div>
);
}
}