import { h, Component } from 'preact'; import CallService from './call_service'; function getType(action) { if ('service' in action) { return 'Call Service'; } return null; } const TYPES = { 'Call Service': CallService, Delay: null, 'Templated Delay': null, Condition: null, 'Fire Event': null, }; const OPTIONS = Object.keys(TYPES).sort(); export default class Action extends Component { constructor() { super(); this.typeChanged = this.typeChanged.bind(this); this.onDelete = this.onDelete.bind(this); } typeChanged(ev) { const newType = ev.target.selectedItem.innerHTML; const oldType = getType(this.props.action); if (oldType !== newType) { this.props.onChange(this.props.index, { platform: newType, }); } } onDelete() { // eslint-disable-next-line if (confirm('Sure you want to delete?')) { this.props.onChange(this.props.index, null); } } render({ index, action, onChange }) { const type = getType(action); const Comp = TYPES[type]; const selected = OPTIONS.indexOf(type); let content; if (Comp) { content = (
{JSON.stringify(action, null, 2)}