stable editor

This commit is contained in:
ari committed 2022-05-05 13:48:51 -04:00
1 parent b29596fe78
commit a56c7ff964
18 files changed
+830 -431

No files matched your search

@@ -15,6 +15,8 @@ import { NodeEditor } from "components/NodeEditor";
import { ButtonIcon } from "components/Icons/ButtonIcons"; import { ButtonIcon } from "components/Icons/ButtonIcons";
import { Button } from "components/Inputs/Button"; import { Button } from "components/Inputs/Button";
import { useAutomatioEditorState } from "./state"; import { useAutomatioEditorState } from "./state";
import { DAGAutomationFlow } from "components/DAGFlow";
import * as dgconst from 'components/DAGSvgs/constants';
interface TriggerEditorModalState { interface TriggerEditorModalState {
trigger: AutomationTrigger; trigger: AutomationTrigger;
@@ -101,38 +103,23 @@ export const AutomationEditor: FC<Props> = ({
Save <CheckMarkIcon color="#bf4" /> Save <CheckMarkIcon color="#bf4" />
</Button> </Button>
</div> </div>
<SequenceNodes <DAGAutomationFlow
zoomLevel={zoomLevel * 200 / 100 + 50}
startPoint={[2, 0.5]}
dims={dims}
sequence={state.data.sequence} sequence={state.data.sequence}
onChange={updateSequence} trigger={state.data.trigger}
additionalElements={() => chain([ onSequenceUpdate={updateSequence}
computeExtraField([1, 0.5], [2, 0.5]), triggersOpts={{
computeTriggerPos(
[0.5, 0.5], }}
state.data.trigger, dims={{
[1.5, 0.5], nodeHeight: dgconst.NODE_HEIGHT,
updateTrigger, nodeWidth: dgconst.NODE_WIDTH,
() => { distanceFactor: dgconst.DISTANCE_FACTOR,
setModalState({ circleSize: dgconst.CIRCLE_SIZE,
trigger: { padding: {
$smType: "trigger", x: dgconst.PADDING,
platform: "device", y: dgconst.PADDING,
device_id: "", },
domain: "", }}
type: "",
subtype: ""
},
onSave: (t) => updateTrigger([...state.data.trigger, t])
});
},
(trigger, onSave) => setModalState({
trigger,
onSave,
})
),
])}
/> />
</div> </div>
</div> </div>
+3 -1
View File
@@ -44,7 +44,9 @@ export const DAGNode: FC<{ data: DAGNodeProps }> = ({
{label} {label}
</span> </span>
</div> </div>
<div className={classes.rightEdge} onClick={onEditClick}> <div className={classes.rightEdge} onClick={() => {
console.log('editing me', label, onEditClick, onEditClick())
}}>
<button className={classes.buttonEdit}> <button className={classes.buttonEdit}>
<PencilIcon size={1.1} color={Color(theme.primary).set('rgb.g', 200).hex()} /> <PencilIcon size={1.1} color={Color(theme.primary).set('rgb.g', 200).hex()} />
</button> </button>
+233 -283
View File
@@ -2,15 +2,14 @@
import React from "react"; import React from "react";
import { ComponentMeta, ComponentStory } from '@storybook/react'; import { ComponentMeta, ComponentStory } from '@storybook/react';
import { DAGFlow } from '.'; import { DAGAutomationFlow } from '.';
import { useState } from 'react'; import { useState } from 'react';
import * as dgconst from "components/DAGSvgs/constants"; import * as dgconst from "components/DAGSvgs/constants";
import { makeAumationStateEditor } from '../../utils/AutomationState';
export default { export default {
title: 'DAGFlow/Viewer', title: 'DAGAutomationFlow/Viewer',
component: DAGFlow, component: DAGAutomationFlow,
parameters: { actions: { argTypesRegex: '^on.*' } }, parameters: { actions: { argTypesRegex: '^on.*' } },
args: { args: {
dims: { dims: {
@@ -24,26 +23,23 @@ export default {
}, },
} }
} }
} as ComponentMeta<typeof DAGFlow> } as ComponentMeta<typeof DAGAutomationFlow>
const Template: ComponentStory<typeof DAGFlow> = args => { const Template: ComponentStory<typeof DAGAutomationFlow> = args => {
const [state, setState] = useState(args.automation) const [state, setState] = useState({
const triggerEditor = makeAumationStateEditor(state, setState).triggers; trigger: args.trigger,
sequence: args.sequence,
})
console.log(state)
return <div className="page"> return <div className="page">
<DAGFlow <DAGAutomationFlow
{...args} {...args}
automation={state} {...state}
opts={{ onTriggerUpdate={trigger => {
triggers: { console.log({ trigger })
onAdd: () => triggerEditor.add({ setState({ ...state, trigger })
platform: 'event',
$smType: 'trigger',
event_type: 'test',
}),
onDelete: triggerEditor.delete,
onEdit: () => { },
}
}} }}
onSequenceUpdate={sequence => setState({ ...state, sequence })}
/> />
</div> </div>
} }
@@ -51,290 +47,244 @@ const Template: ComponentStory<typeof DAGFlow> = args => {
export const Simple = Template.bind({}) export const Simple = Template.bind({})
Simple.args = { Simple.args = {
...Simple.args, ...Simple.args,
automation: { trigger: [
tags: { {
"Room": "Bathroom", "$smType": undefined,
"For": "Toliet", "platform": "numeric_state",
"Type": "Smell", "entity_id": "test",
"Use": "Flushing"
}, },
metadata: { {
id: "random", "$smType": undefined,
alias: "Random", "platform": "homeassistant",
description: "Example Metadata", "event": "start",
trigger_variables: { }
'wowo': '!' ],
}, sequence: [
mode: 'single', {
}, $smType: "condition",
trigger: [ condition: 'and',
{ condition_data: {
"$smType": undefined, conditions: [
"platform": "numeric_state", {
"entity_id": "test", $smType: 'condition',
}, condition: 'numeric_state',
{ condition_data: {
"$smType": undefined, entity_id: 'sensor.temperature_kitchen',
"platform": "homeassistant", below: '15',
"event": "start",
}
],
sequence: [
{
$smType: "condition",
condition: 'and',
condition_data: {
conditions: [
{
$smType: 'condition',
condition: 'numeric_state',
condition_data: {
entity_id: 'sensor.temperature_kitchen',
below: '15',
}
},
{
$smType: "condition",
condition: 'template',
condition_data: {
value_template: 'states(switch.kitchen_light) == "on"'
}
} }
]
}
},
{
$smType: "action",
action: "service",
action_data: {
alias: "Start Music In Kitchen",
service: 'media_player.play_media',
target: {
entity_id: "media_player.kitchen_dot"
}, },
data: { {
media_content_id: "Good Morning", $smType: "condition",
media_content_type: "SPOTIFY", condition: 'template',
condition_data: {
value_template: 'states(switch.kitchen_light) == "on"'
}
} }
]
}
},
{
$smType: "action",
action: "service",
action_data: {
alias: "Start Music In Kitchen",
service: 'media_player.play_media',
target: {
entity_id: "media_player.kitchen_dot"
},
data: {
media_content_id: "Good Morning",
media_content_type: "SPOTIFY",
} }
} }
] }
} ]
} }
export const Complex = Template.bind({}) export const Complex = Template.bind({})
Complex.args = { Complex.args = {
...Complex.args, ...Complex.args,
automation: { trigger: [
tags: { {
"Room": "Bathroom", "$smType": undefined,
"For": "Toliet", "platform": "numeric_state",
"Type": "Smell", "entity_id": "test",
"Use": "Flushing"
}, },
metadata: { {
id: "random", "$smType": undefined,
alias: "Random", "platform": "homeassistant",
description: "Example Metadata", "event": "start",
trigger_variables: { }
'wowo': '!' ],
}, sequence: [
mode: 'single', {
}, "$smType": "condition",
trigger: [ "condition": "and",
{ "condition_data": {
"$smType": undefined, "conditions": [
"platform": "numeric_state", {
"entity_id": "test", "$smType": "condition",
}, "condition": "numeric_state",
{ "condition_data": {
"$smType": undefined, "entity_id": "sensor.temperature_kitchen",
"platform": "homeassistant", "below": "15"
"event": "start",
}
],
sequence: [
{
"$smType": "condition",
"condition": "and",
"condition_data": {
"conditions": [
{
"$smType": "condition",
"condition": "numeric_state",
"condition_data": {
"entity_id": "sensor.temperature_kitchen",
"below": "15"
}
},
{
"$smType": "condition",
"condition": "template",
"condition_data": {
"value_template": "states(switch.kitchen_light) == \"on\""
}
} }
]
}
},
{
"$smType": "action",
"action": "service",
"action_data": {
"alias": "Start Music In Kitchen",
"service": "media_player.play_media",
"target": {
"entity_id": "media_player.kitchen_dot"
}, },
"data": { {
"media_content_id": "Good Morning", "$smType": "condition",
"media_content_type": "SPOTIFY" "condition": "template",
"condition_data": {
"value_template": "states(switch.kitchen_light) == \"on\""
}
} }
} ]
}, }
{ },
"$smType": "action", {
"action": "choose", "$smType": "action",
"action_data": { "action": "service",
"choose": [ "action_data": {
{ "alias": "Start Music In Kitchen",
"conditions": [ "service": "media_player.play_media",
{ "target": {
"$smType": "condition", "entity_id": "media_player.kitchen_dot"
"condition": "state", },
"condition_data": { "data": {
"entity_id": "lights.bathroom", "media_content_id": "Good Morning",
"state": "off", "media_content_type": "SPOTIFY"
}
}
],
"sequence": [
{
"$smType": "action",
"action": "service",
"action_data": {
"service": "light.turn_on",
"target": {
"entity_id": "lights.bathroom"
},
"data": {}
}
},
{
"$smType": "action",
"action": "service",
"action_data": {
"alias": "Turn off bedroom",
"service": "light.turn_off",
"target": {
"entity_id": "lights.bedroom"
},
"data": {}
}
}
]
},
{
"conditions": [
{
"$smType": "condition",
"condition": "state",
"condition_data": {
"entity_id": "lights.bedroom",
"state": "off",
}
}
],
"sequence": [
{
"$smType": "action",
"action": "service",
"action_data": {
"alias": "Turn on bedroom",
"service": "light.turn_on",
"target": {
"entity_id": "lights.bedroom"
},
"data": {}
}
},
{
"$smType": "action",
"action": "choose",
"action_data": {
"choose": [
{
"conditions": [],
"sequence": [
{
"$smType": "action",
"action": "choose",
"action_data": {
"choose": [],
"default": [],
}
}
]
}
],
"default": [
{
"$smType": "action",
"action": "choose",
"action_data": {
"choose": [],
"default": [],
}
}
],
}
}
]
}
],
"default": [
{
"$smType": "action",
"action": "service",
"action_data": {
"service": "light.turn_off",
"target": {
"entity_id": "lights.bathroom"
},
"data": {}
}
}
]
}
},
{
"$smType": "condition",
"condition": "and",
"condition_data": {
"conditions": []
} }
} }
] },
} {
"$smType": "action",
"action": "choose",
"action_data": {
"choose": [
{
"conditions": [
{
"$smType": "condition",
"condition": "state",
"condition_data": {
"entity_id": "lights.bathroom",
"state": "off",
}
}
],
"sequence": [
{
"$smType": "action",
"action": "service",
"action_data": {
"service": "light.turn_on",
"target": {
"entity_id": "lights.bathroom"
},
"data": {}
}
},
{
"$smType": "action",
"action": "service",
"action_data": {
"alias": "Turn off bedroom",
"service": "light.turn_off",
"target": {
"entity_id": "lights.bedroom"
},
"data": {}
}
}
]
},
{
"conditions": [
{
"$smType": "condition",
"condition": "state",
"condition_data": {
"entity_id": "lights.bedroom",
"state": "off",
}
}
],
"sequence": [
{
"$smType": "action",
"action": "service",
"action_data": {
"alias": "Turn on bedroom",
"service": "light.turn_on",
"target": {
"entity_id": "lights.bedroom"
},
"data": {}
}
},
{
"$smType": "action",
"action": "choose",
"action_data": {
"choose": [
{
"conditions": [],
"sequence": [
{
"$smType": "action",
"action": "choose",
"action_data": {
"choose": [],
"default": [],
}
}
]
}
],
"default": [
{
"$smType": "action",
"action": "choose",
"action_data": {
"choose": [],
"default": [],
}
}
],
}
}
]
}
],
"default": [
{
"$smType": "action",
"action": "service",
"action_data": {
"service": "light.turn_off",
"target": {
"entity_id": "lights.bathroom"
},
"data": {}
}
}
]
}
},
{
"$smType": "condition",
"condition": "and",
"condition_data": {
"conditions": []
}
}
]
} }
export const EmptyStart = Template.bind({}) export const EmptyStart = Template.bind({})
EmptyStart.args = { EmptyStart.args = {
...EmptyStart.args, ...EmptyStart.args,
automation: { trigger: [
tags: {}, ],
metadata: { sequence: []
id: "random",
alias: "Random",
description: "Example Metadata",
trigger_variables: {
'wowo': '!'
},
mode: 'single',
},
trigger: [
],
sequence: []
}
} }
+84 -16
View File
@@ -1,12 +1,17 @@
import { FC } from "react"; import { FC, useState } from "react";
import ReactFlow, { MiniMap, Controls } from 'react-flow-renderer'; import ReactFlow, { MiniMap, Controls } from 'react-flow-renderer';
import { AutomationData } from "types/automations"; import { AutomationSequenceNode } from "types/automations";
import { AutomationTrigger } from 'types/automations/triggers';
import { triggerToFlow } from "./triggerConvertor"; import { triggerToFlow } from "./triggerConvertor";
import { DAGNode } from "./DAGNode"; import { DAGNode } from "./DAGNode";
import { DAGFlowDims, TriggerMakerOptions, FlowData } from './types'; import { DAGAutomationFlowDims, TriggerMakerOptions, FlowData, ModalState } from './types';
import { DAGCircle } from './DAGCircle'; import { DAGCircle } from './DAGCircle';
import { sequenceToFlow } from "./sequenceConvertor"; import { sequenceToFlow } from "./sequenceConvertor";
import { makeSequenceUpdater } from "./updater";
import { NodeEditor } from "components/NodeEditor";
import { MultiNodeEditor } from "components/MultiNodeEditors";
import { Modal } from "components/Modal";
const nodeTypes = { const nodeTypes = {
'dagnode': DAGNode, 'dagnode': DAGNode,
@@ -14,26 +19,89 @@ const nodeTypes = {
} }
interface Props { interface Props {
automation: AutomationData; sequence: AutomationSequenceNode[];
dims: DAGFlowDims; trigger: AutomationTrigger[];
opts: { dims: DAGAutomationFlowDims;
triggers: TriggerMakerOptions; onTriggerUpdate: (t: AutomationTrigger[]) => void;
} onSequenceUpdate: (s: AutomationSequenceNode[]) => void;
} }
export const DAGFlow: FC<Props> = ({ export const DAGAutomationFlow: FC<Props> = ({
automation, sequence,
opts, trigger,
onTriggerUpdate,
onSequenceUpdate,
dims, dims,
}) => { }) => {
// state
const [modalState, setModalState] = useState<ModalState | null>(null);
// modal
let modalBody = <></>
if (modalState) {
if (modalState.single) {
modalBody = <NodeEditor
node={modalState.node}
onClose={() => setModalState(null)}
onSave={n => { modalState.update(n as any); setModalState(null); }}
allowedTypes={modalState.allowedTypes}
saveBtnCreateText={modalState.saveBtnCreateText}
/>
} else {
modalBody = <MultiNodeEditor
sequence={modalState.node}
onClose={() => setModalState(null)}
onSave={(n) => {
modalState.update(n as any);
setModalState(null);
}}
allowedTypes={['condition']}
/>
}
}
// convert automation to flow data
const condPoint = makeConditionPoint(dims); const condPoint = makeConditionPoint(dims);
const flowData: FlowData = { const flowData: FlowData = {
nodes: [condPoint], nodes: [condPoint],
edges: [], edges: [],
} }
triggerToFlow(flowData, automation.trigger, condPoint.id, dims, opts.triggers); triggerToFlow(flowData, trigger, condPoint.id, dims, {
sequenceToFlow(flowData, automation.sequence, condPoint.id, dims); onAdd: () => onTriggerUpdate([
return ( ...trigger, {
platform: 'event',
$smType: 'trigger',
event_type: 'test',
}
]),
onDelete: i => onTriggerUpdate([
...trigger.slice(0, i),
...trigger.slice(i + 1)
]),
onEdit: i => setModalState({
single: true,
node: trigger[i],
update: t => onTriggerUpdate([
...trigger.slice(0, i),
t,
...trigger.slice(i + 1)
]),
allowedTypes: ['trigger'],
})
});
sequenceToFlow(
flowData,
sequence,
condPoint.id,
dims,
makeSequenceUpdater(sequence, onSequenceUpdate, setModalState),
);
// render
return <>
<Modal open={!!modalState}>
{modalBody}
</Modal>
<ReactFlow <ReactFlow
nodeTypes={nodeTypes} nodeTypes={nodeTypes}
snapToGrid snapToGrid
@@ -45,7 +113,7 @@ export const DAGFlow: FC<Props> = ({
<MiniMap /> <MiniMap />
<Controls /> <Controls />
</ReactFlow> </ReactFlow>
); </>;
} }
@@ -54,7 +122,7 @@ const makeConditionPoint = ({
nodeWidth, nodeWidth,
nodeHeight, nodeHeight,
circleSize, circleSize,
}: DAGFlowDims) => ({ }: DAGAutomationFlowDims) => ({
id: `c`, id: `c`,
type: 'dagcircle', type: 'dagcircle',
position: { x: padding.x + nodeWidth * 2, y: padding.y + nodeHeight * 0.25 }, position: { x: padding.x + nodeWidth * 2, y: padding.y + nodeHeight * 0.25 },
@@ -1,20 +1,23 @@
import { AutomationSequenceNode } from 'types/automations'; import { AutomationSequenceNode } from 'types/automations';
import { DAGFlowDims, FlowData } from './types'; import { DAGAutomationFlowDims, FlowData } from './types';
import { getDescriptionFromAutomationNode } from 'utils/formatting'; import { getDescriptionFromAutomationNode } from 'utils/formatting';
import { XYPosition } from 'react-flow-renderer'; import { XYPosition } from 'react-flow-renderer';
import { ChooseAction } from 'types/automations/actions'; import { ChooseAction } from 'types/automations/actions';
import { DAGCircleProps, makeFlowCircle } from './DAGCircle'; import { makeFlowCircle } from './DAGCircle';
import { createOnRemoveForChooseNode, SequenceUpdater } from './updater';
export const sequenceToFlow = ( export const sequenceToFlow = (
flowData: FlowData, flowData: FlowData,
sequence: AutomationSequenceNode[], sequence: AutomationSequenceNode[],
fromPoint: string, fromPoint: string,
dims: DAGFlowDims, dims: DAGAutomationFlowDims,
updater: SequenceUpdater,
prefix: string = "", prefix: string = "",
) => { ) => {
let lastPointId = fromPoint; let lastPointId = fromPoint;
let lasPos: XYPosition | null = null; let lasPos: XYPosition | null = null;
// sequence
for (let i = 0; i < sequence.length; i++) { for (let i = 0; i < sequence.length; i++) {
const node = sequence[i]; const node = sequence[i];
const nodeId = `${prefix}n-${i}`; const nodeId = `${prefix}n-${i}`;
@@ -30,27 +33,35 @@ export const sequenceToFlow = (
y: dims.padding.y y: dims.padding.y
}; };
} }
// draw node
if (node.$smType === 'action') { if (node.$smType === 'action') {
if (node.action === 'choose') { if (node.action === 'choose') {
position = addChooseNode(flowData, node, position, nodeId, dims) position = addChooseNode(flowData, node, position, nodeId, dims, updater, i)
} else { } else {
addSingleNode(flowData, node, position, nodeId, dims); addSingleNode(flowData, node, position, nodeId, dims, {
onEditClick: updater.makeOnModalOpenForNode(i, node),
onXClick: () => updater.removeNode(i)
});
} }
} else { } else {
addSingleNode(flowData, node, position, nodeId, dims); addSingleNode(flowData, node, position, nodeId, dims, {
onEditClick: updater.makeOnModalOpenForNode(i, node),
onXClick: () => updater.removeNode(i)
});
} }
addEdge(flowData, lastPointId, nodeId, false) addEdge(flowData, lastPointId, nodeId, false)
lastPointId = nodeId; lastPointId = nodeId;
lasPos = position; lasPos = position;
} }
// add button
const addCircle = makeFlowCircle( const addCircle = makeFlowCircle(
`${prefix}-+`, `${prefix}-+`,
{ {
x: (lasPos === null ? dims.padding.x + dims.nodeWidth * dims.distanceFactor * (sequence.length + 1) : lasPos.x) + dims.nodeWidth * dims.distanceFactor, x: (lasPos === null ? dims.padding.x + dims.nodeWidth * dims.distanceFactor * (sequence.length + 1) : lasPos.x) + dims.nodeWidth * dims.distanceFactor,
y: dims.padding.y + dims.circleSize / 2 y: dims.padding.y + dims.circleSize / 2
}, },
{ onAdd: () => { }, size: dims.circleSize, disableSource: true, } { onAdd: updater.addNode, size: dims.circleSize, disableSource: true, }
) )
flowData.nodes.push(addCircle) flowData.nodes.push(addCircle)
addEdge(flowData, lastPointId, addCircle.id, false) addEdge(flowData, lastPointId, addCircle.id, false)
@@ -79,8 +90,11 @@ const addSingleNode = (
{ {
nodeHeight, nodeHeight,
nodeWidth, nodeWidth,
}: DAGFlowDims, }: DAGAutomationFlowDims,
extra: Record<string, any> = {}, opts: {
onEditClick: () => void;
onXClick: () => void;
}
) => flowData.nodes.push({ ) => flowData.nodes.push({
id: nodeId, id: nodeId,
type: 'dagnode', type: 'dagnode',
@@ -89,12 +103,10 @@ const addSingleNode = (
height: nodeHeight, height: nodeHeight,
width: nodeWidth, width: nodeWidth,
color: node.$smType === 'action' ? 'green' : 'blue', color: node.$smType === 'action' ? 'green' : 'blue',
// onEdit: () => opts.onEdit(i),
// onXClick: () => opts.onDelete(i, flowId),
hasInput: true, hasInput: true,
...opts,
}, },
position, position,
...extra
}); });
@@ -104,28 +116,45 @@ const addChooseNode = (
node: ChooseAction, node: ChooseAction,
position: XYPosition, position: XYPosition,
nodeId: string, nodeId: string,
dims: DAGFlowDims, dims: DAGAutomationFlowDims,
updater: SequenceUpdater,
i: number,
) => { ) => {
addSingleNode(flowData, node, position, nodeId, dims); addSingleNode(flowData, node, position, nodeId, dims, {
onEditClick: updater.makeOnModalOpenForNode(i, node),
onXClick: () => updater.removeNode(i),
});
let lastPos: XYPosition = position; let lastPos: XYPosition = position;
// conditions // conditions
node.action_data.choose.forEach(({ sequence, conditions }, j) => { node.action_data.choose.forEach(({ sequence, conditions }, j) => {
const sequenceId = `${nodeId}.${j}`; const sequenceId = `${nodeId}.${j}`;
// edit/delete circle
const circle = makeFlowCircle(`${sequenceId}>cond`, { const circle = makeFlowCircle(`${sequenceId}>cond`, {
x: position.x + dims.nodeWidth * dims.distanceFactor, x: position.x + dims.nodeWidth * dims.distanceFactor,
y: lastPos.y + dims.nodeHeight * dims.distanceFactor, y: lastPos.y + dims.nodeHeight * dims.distanceFactor,
}, { size: dims.circleSize * dims.distanceFactor, onEdit: () => { }, onRemove: () => { } }) }, {
size: dims.circleSize * dims.distanceFactor,
onEdit: updater.makeOnEditConditionsForChooseNode(i, j),
onRemove: createOnRemoveForChooseNode(
node,
d => updater.updateNode(i, d),
j,
),
})
flowData.nodes.push(circle) flowData.nodes.push(circle)
addEdge(flowData, nodeId, circle.id, true) addEdge(flowData, nodeId, circle.id, true)
// actual sub sequence
const lastPoint = sequenceToFlow(flowData, sequence, circle.id, { const lastPoint = sequenceToFlow(flowData, sequence, circle.id, {
...dims, ...dims,
padding: { padding: {
x: position.x - dims.nodeWidth, x: position.x - dims.nodeWidth,
y: circle.position.y, y: circle.position.y,
}, },
}, `${sequenceId}.`); }, updater.makeChildUpdaterForChooseAction(i, j), `${sequenceId}.`);
if (lastPoint.position) { if (lastPoint.position) {
lastPos = xyApply(lastPos, lastPoint.position, Math.max) lastPos = xyApply(lastPos, lastPoint.position, Math.max)
} else {
lastPos = xyApply(lastPos, { x: lastPos.x, y: lastPos.y + dims.nodeHeight * dims.distanceFactor }, Math.max)
} }
}) })
const totalChildren = node.action_data.choose.length; const totalChildren = node.action_data.choose.length;
@@ -138,7 +167,19 @@ const addChooseNode = (
}, },
{ {
size: dims.circleSize * dims.distanceFactor, size: dims.circleSize * dims.distanceFactor,
onAdd: () => { }, onAdd: () => updater.updateNode(i, {
...node,
action_data: {
...node.action_data,
choose: [
...node.action_data.choose,
{
sequence: [],
conditions: [],
}
]
}
}),
disableSource: true, disableSource: true,
} }
); );
@@ -158,7 +199,7 @@ const addChooseNode = (
x: position.x - dims.nodeWidth, x: position.x - dims.nodeWidth,
y: elseCircle.position.y, y: elseCircle.position.y,
}, },
}, `${nodeId}.${totalChildren}.`) }, updater.makeChildUpdaterForChooseAction(i, null), `${nodeId}.${totalChildren}.`)
if (lastPoint.position) { if (lastPoint.position) {
lastPos = xyApply(lastPos, lastPoint.position, Math.max) lastPos = xyApply(lastPos, lastPoint.position, Math.max)
} else { } else {
@@ -1,8 +1,7 @@
import { AutomationTrigger } from 'types/automations/triggers'; import { AutomationTrigger } from 'types/automations/triggers';
import { DAGFlowDims, FlowData, TriggerMakerOptions } from './types'; import { DAGAutomationFlowDims, FlowData, TriggerMakerOptions } from './types';
import { makeFlowCircle } from './DAGCircle'; import { makeFlowCircle } from './DAGCircle';
export const triggerToFlow = ( export const triggerToFlow = (
flowData: FlowData, flowData: FlowData,
trigger: AutomationTrigger[], trigger: AutomationTrigger[],
@@ -13,7 +12,7 @@ export const triggerToFlow = (
nodeWidth, nodeWidth,
circleSize, circleSize,
padding, padding,
}: DAGFlowDims, }: DAGAutomationFlowDims,
opts: TriggerMakerOptions, opts: TriggerMakerOptions,
) => { ) => {
// convert all triggers to dag nodes // convert all triggers to dag nodes
@@ -27,7 +26,7 @@ export const triggerToFlow = (
height: nodeHeight, height: nodeHeight,
width: nodeWidth, width: nodeWidth,
color: 'red', color: 'red',
onEdit: () => opts.onEdit(i), onEditClick: () => opts.onEdit(i),
onXClick: () => opts.onDelete(i), onXClick: () => opts.onDelete(i),
}, },
position: { x: padding.x, y: padding.y + nodeHeight * distanceFactor * i } position: { x: padding.x, y: padding.y + nodeHeight * distanceFactor * i }
+23 -5
View File
@@ -1,21 +1,22 @@
import { Edge, Node, XYPosition } from 'react-flow-renderer'; import { Edge, Node, XYPosition } from 'react-flow-renderer';
import { AutomationSequenceNode } from 'types/automations';
import { DAGCircleProps } from './DAGCircle'; import { DAGCircleProps } from './DAGCircle';
import { DAGNodeProps } from './DAGNode'; import { DAGNodeProps } from './DAGNode';
import { AutomationTrigger } from 'types/automations/triggers';
import { MultiNodeEditorProps } from 'components/MultiNodeEditors';
export type DAGFlowDims = { export type DAGAutomationFlowDims = {
padding: XYPosition; padding: XYPosition;
nodeHeight: number; nodeHeight: number;
nodeWidth: number; nodeWidth: number;
// addHeight: number;
// addWidth: number;
circleSize: number; circleSize: number;
distanceFactor: number; distanceFactor: number;
} }
export type DAGFlowNode = Node<DAGNodeProps | DAGCircleProps | any>; export type DAGAutomationFlowNode = Node<DAGNodeProps | DAGCircleProps | any>;
export type FlowData = { export type FlowData = {
nodes: DAGFlowNode[], nodes: DAGAutomationFlowNode[],
edges: Edge[], edges: Edge[],
} }
@@ -24,3 +25,20 @@ export type TriggerMakerOptions = {
onEdit: (i: number) => void, onEdit: (i: number) => void,
onDelete: (i: number) => void, onDelete: (i: number) => void,
} }
export type UpdateModalState<T extends AutomationSequenceNode | AutomationTrigger = any> = (
s: ModalState<T>
) => void;
export type ModalState<T extends AutomationSequenceNode | AutomationTrigger = any> = {
single: true,
node: T
update: (n: T) => void;
saveBtnCreateText?: boolean;
allowedTypes: MultiNodeEditorProps['allowedTypes'],
} | {
single: false,
node: AutomationSequenceNode[]
update: (n: AutomationSequenceNode[]) => void;
allowedTypes: ['condition']
}
@@ -0,0 +1,85 @@
import { AutomationSequenceNode } from "types/automations"
import { ChooseAction } from "types/automations/actions";
import { ModalState } from "./types";
import { makeSequenceUpdater } from "./updater"
const mockSequenceUpdater = (defaultState: AutomationSequenceNode[] = []) => {
let state: AutomationSequenceNode[] = [...defaultState]
const modalStates: ModalState[] = [];
const updater = makeSequenceUpdater(
state,
s => {
state = s
console.log(state, s)
},
ms => modalStates.push(ms)
);
return {
get state() {
return state
},
modalStates,
updater
};
}
test("sequence updater updates nodes", () => {
const mock = mockSequenceUpdater([
{
"$smType": "action",
"action": "choose",
"action_data": {
"choose": [
{
"conditions": [],
"sequence": [],
}
],
"default": [],
}
}
]);
expect(mock.state.length).toBe(1)
expect((mock.state[0] as ChooseAction).action_data.alias).toBe(undefined)
mock.updater.updateNode(0, {
...mock.state[0],
action_data: {
...(mock.state[0] as ChooseAction).action_data,
alias: "Hello"
}
} as any)
expect((mock.state[0] as ChooseAction).action_data.alias).toBe("Hello")
})
test('update conditions for node', () => {
const mock = mockSequenceUpdater([
{
"$smType": "action",
"action": "choose",
"action_data": {
"choose": [
{
"conditions": [],
"sequence": [],
}
],
"default": [],
}
}
]);
mock.updater.makeOnEditConditionsForChooseNode(0, 0)();
expect(mock.modalStates.length).toBe(1)
expect((mock.modalStates[0].node as AutomationSequenceNode[]).length).toBe(0)
mock.modalStates[0].update([
{
"$smType": "condition",
"condition": "and",
"condition_data": {
"conditions": [],
}
}
] as any)
expect((mock.state[0] as ChooseAction).action_data.choose[0].conditions.length).toBe(1)
expect((mock.state[0] as ChooseAction).action_data.choose[0].conditions[0].condition).toBe("and")
})
+146
View File
@@ -0,0 +1,146 @@
import { AutomationSequenceNode } from "types/automations";
import { ChooseAction } from "types/automations/actions";
import { AutomationCondition } from "types/automations/conditions";
import { UpdateModalState } from "./types";
export type SequenceUpdater = ReturnType<typeof makeSequenceUpdater>;
export const makeSequenceUpdater = (
sequence: AutomationSequenceNode[],
onChange: (s: AutomationSequenceNode[]) => void,
openModal: UpdateModalState,
) => ({
sequence,
onChange,
removeNode(i: number) {
return onChange([
...sequence.slice(0, i),
...sequence.slice(i + 1),
])
},
addNode() {
return openModal({
single: true,
saveBtnCreateText: true,
node: {
$smType: 'action',
action: 'choose',
action_data: {
choose: [],
default: [],
}
},
update: n => onChange([
...sequence,
n,
]),
allowedTypes: ['action', 'condition']
})
},
updateNode(i: number, node: AutomationSequenceNode) {
return onChange([
...sequence.slice(0, i),
node,
...sequence.slice(i + 1),
])
},
updateChooseActionData(i: number, data: ChooseAction['action_data']) {
const node = sequence[i] as ChooseAction;
return this.updateNode(i, {
...node,
action_data: data,
})
},
makeChildUpdaterForChooseAction(i: number, j: number | null) {
const node = sequence[i];
if ((node.$smType === 'action') && (node.action === 'choose')) {
if (j !== null) {
return makeSequenceUpdater(
node.action_data.choose[j].sequence,
seq => this.updateNode(i, {
...node,
action_data: {
...node.action_data,
choose: [
...node.action_data.choose.slice(0, j),
{
...node.action_data.choose[j],
sequence: seq,
},
...node.action_data.choose.slice(j + 1),
]
}
}),
openModal,
)
} else {
return makeSequenceUpdater(
node.action_data.default,
seq => this.updateNode(i, {
...node,
action_data: {
...node.action_data,
default: seq
}
}),
openModal,
)
}
}
throw new Error(`Cannot create sub-updater for ${node}`)
},
makeOnModalOpenForNode(
i: number,
node: AutomationSequenceNode,
) {
return () => openModal({
single: true,
node,
allowedTypes: ['action', 'condition'],
update: n => this.updateNode(i, n),
})
},
makeOnEditConditionsForChooseNode(
i: number,
j: number,
) {
return () => {
const node = sequence[i] as ChooseAction;
return openModal({
single: false,
node: node.action_data.choose[j].conditions,
allowedTypes: ['condition'],
update: conditions => this.updateNode(i, {
...node,
action_data: {
...node.action_data,
choose: [
...node.action_data.choose.slice(0, j),
{
sequence: node.action_data.choose[j].sequence,
conditions: conditions as AutomationCondition[],
},
...node.action_data.choose.slice(j + 1),
]
}
}),
})
}
}
});
export const createOnRemoveForChooseNode = (
action: ChooseAction,
update: (data: ChooseAction) => void,
j: number
) => () => update({
...action,
action_data: {
...action.action_data,
choose: [
...action.action_data.choose.slice(0, j),
...action.action_data.choose.slice(j + 1),
]
}
})
+2 -2
View File
@@ -27,8 +27,8 @@ const commonInputStyle = (theme: AppTheme) => ({
export const useButtonStyles = createAppUseStyles<{}>(theme => ({ export const useButtonStyles = createAppUseStyles<{}>(theme => ({
input: { input: {
...commonInputStyle(theme).input, ...commonInputStyle(theme).input,
paddingTop: '1em', paddingTop: '0.5em',
paddingBottom: '1em', paddingBottom: '0.5em',
cursor: 'pointer', cursor: 'pointer',
}, },
})); }));
@@ -50,14 +50,7 @@ export const InAModal: ComponentStory<typeof MultiNodeEditor> = props => {
{...props} {...props}
sequence={state} sequence={state}
onClose={() => setOpen(!open)} onClose={() => setOpen(!open)}
onAdd={(n, slide) => { setState([...state, n]); slide(state.length) }} onSave={setState}
onRemove={(n, slide) => {
setState([
...state.slice(0, n),
...state.slice(n + 1)
]);
slide(state.length - 2)
}}
/> />
</Modal> </Modal>
</div> </div>
@@ -36,43 +36,84 @@ const makeDefault = (nodeType: keyof AutomationNodeMapping): AutomationNode => {
} }
} }
export interface Props { export interface MultiNodeEditorProps {
sequence: AutomationNode[]; sequence: AutomationNode[];
allowedTypes?: Array<keyof AutomationNodeMapping>; allowedTypes?: Array<keyof AutomationNodeMapping>;
onAdd?: (n: AutomationNode, slide: (i: number) => void) => void;
onClose?: () => void; onClose?: () => void;
onSave?: (i: number, n: AutomationNode) => void; onSave?: (n: AutomationNode[]) => void;
onRemove?: (i: number, slide: (i: number) => void) => void;
} }
export const MultiNodeEditor: FC<Props> = ({ export const MultiNodeEditor: FC<MultiNodeEditorProps> = ({
sequence, sequence: initialState,
allowedTypes = ['action', 'condition'], allowedTypes = ['action', 'condition'],
onClose, onClose = () => { },
onAdd = () => { },
onSave = () => { }, onSave = () => { },
onRemove = () => { },
}) => { }) => {
const [slide, setSlide] = useState(0); // state
const [{ slide, state, isNodeModified, isModified, isReady }, setState] = useState({
slide: 0,
state: initialState,
isModified: false,
isNodeModified: false,
isReady: true,
})
// alias
const areYouSureItsModified = () => isNodeModified ?
window.confirm("You've made changes, by pressing this you will lose them!") :
true
const areYouSureItsNotReady = () => !isReady ?
window.confirm("The node is not ready, are you sure you want to move?") :
true
const onAdd = () => setState({
slide: state.length,
state: [...state, makeDefault(allowedTypes[0])],
isNodeModified: false,
isReady,
isModified: true,
});
const onRemove = () => setState({
slide: slide > 0 ? slide - 1 : 0,
state: [...state.slice(0, slide), ...state.slice(slide + 1)],
isNodeModified: false,
isReady,
isModified: true,
});
const onNodeSave = (n: AutomationNode) => setState({
slide,
state: [...state.slice(0, slide), n, ...state.slice(slide + 1)],
isNodeModified: false,
isReady,
isModified: true,
});
const onSaveAll = () => isNodeModified ?
window.alert("Please save the node data first!") :
onSave(state)
const onNextOrAdd = () => {
if (!areYouSureItsModified()) {
return
}
if (!areYouSureItsNotReady()) {
return
}
if (slide >= state.length - 1) {
onAdd()
} else {
setState({ slide: slide + 1, state, isNodeModified, isReady, isModified, })
}
}
const onBack = () => areYouSureItsModified() &&
areYouSureItsNotReady() &&
setState({ slide: slide - 1, state, isNodeModified, isReady, isModified, })
// components // components
const nextOrAddBtn = <Button const nextOrAddBtn = <Button
onClick={() => { onClick={onNextOrAdd}
if (slide >= sequence.length - 1) {
onAdd(makeDefault(allowedTypes[0]), setSlide)
} else {
setSlide(slide + 1)
}
}}
> >
{(slide < sequence.length - 1) ? ">>" : "+"} {(slide < state.length - 1) ? ">>" : "+"}
</Button>; </Button>;
// branch // branch
if (sequence.length === 0) { if (state.length === 0) {
return <div style={{ return <div className='column center' style={{
display: 'flex', minWidth: '20vw',
flexDirection: 'column',
flex: 1,
justifyContent: 'center',
}}> }}>
<div style={{ <div style={{
flex: 1, flex: 1,
@@ -82,20 +123,22 @@ export const MultiNodeEditor: FC<Props> = ({
}}> }}>
{nextOrAddBtn} {nextOrAddBtn}
</div> </div>
<Button onClick={onClose}>Close</Button> <div className='column center' style={{ marginTop: '1em' }}>
<Button onClick={() => areYouSureItsModified() && onClose()}>Close</Button>
</div>
</div> </div>
} }
return <> return <>
<div style={{ <div style={{
display: 'flex', display: 'flex',
flexDirection: 'row', flexDirection: 'row',
justifyContent: 'center', justifyContent: 'space-evenly',
alignItems: 'center', alignItems: 'center',
minWidth: '20vw',
}}> }}>
<Button onClick={() => setSlide(slide - 1)} disabled={slide === 0}>{"<<"}</Button> <Button onClick={onBack} disabled={slide === 0}>{"<<"}</Button>
<span>{slide + 1}/{sequence.length}</span>
<Button <Button
onClick={() => onRemove(slide, setSlide)} onClick={onRemove}
> >
Delete Delete
</Button> </Button>
@@ -103,10 +146,22 @@ export const MultiNodeEditor: FC<Props> = ({
</div> </div>
<NodeEditor <NodeEditor
key={slide} key={slide}
node={sequence[slide]} node={state[slide]}
allowedTypes={allowedTypes} allowedTypes={allowedTypes}
onClose={onClose} onClose={onClose}
onSave={n => onSave(slide, n)} onSave={onNodeSave}
/> onFlags={
(ir, inm) => ((inm !== isNodeModified) || (ir !== isReady)) &&
setState({ slide, state, isNodeModified: inm, isReady: ir, isModified })
}
>
<Button onClick={onSaveAll} style={{
borderColor: isModified ? "var(--change)" : undefined,
color: isModified ? "var(--change)" : undefined,
}}>Save All</Button>
</NodeEditor>
<div className='column center'>
<span>{slide + 1}/{state.length}</span>
</div>
</> </>
} }
@@ -1,22 +1,32 @@
import { useState } from 'react'; import { useEffect, useState } from 'react';
import { AutomationNode, AutomationNodeTypes } from 'types/automations'; import { AutomationNode, AutomationNodeTypes } from 'types/automations';
import { AutomationNodeSubtype } from 'types/automations'; import { AutomationNodeSubtype } from 'types/automations';
import { getOptionManager } from './getOptionManager'; import { getOptionManager } from './getOptionManager';
export const useEditorNodeState = (node: AutomationNode) => { export const useEditorNodeState = (node: AutomationNode) => {
const [state, setState] = useState(node); const [{ node: state, isModified }, setAllState] = useState({
node,
isModified: false,
});
useEffect(() => {
setAllState({ node, isModified: false })
}, [node])
const setState = (node: AutomationNode) => setAllState(({ node, isModified: true }))
const nodeType: AutomationNodeTypes = state.$smType ?? 'trigger'; const nodeType: AutomationNodeTypes = state.$smType ?? 'trigger';
const subType: AutomationNodeSubtype = const subType: AutomationNodeSubtype =
state.$smType === 'action' ? state.action : state.$smType === 'action' ? state.action :
state.$smType === 'condition' ? state.condition : state.$smType === 'condition' ? state.condition :
state.platform; state.platform;
const subTypes = getSubTypeList(nodeType) const subTypes = getSubTypeList(nodeType)
const optionManager = getOptionManager(nodeType, subType as any); const optionManager = getOptionManager(nodeType, subType as any);
return { return {
nodeType, nodeType,
subType, subType,
subTypes, subTypes,
get isModified() {
return isModified
},
get data() { get data() {
return state return state
}, },
@@ -101,7 +111,7 @@ const getSubTypeList = <T extends AutomationNodeTypes>(nodeType: T): AutomationN
'time', 'time',
'trigger', 'trigger',
'zone', 'zone',
]as any ] as any
case 'trigger': case 'trigger':
return [ return [
'event', 'event',
@@ -116,7 +126,7 @@ const getSubTypeList = <T extends AutomationNodeTypes>(nodeType: T): AutomationN
'webhook', 'webhook',
'zone', 'zone',
'device', 'device',
]as any ] as any
default: default:
return []; return [];
} }
+29 -17
View File
@@ -1,16 +1,27 @@
.node-editor--root { .node-editor--root {
display : flex; display: flex;
flex-direction : column; flex-direction: column;
justify-content: center; justify-content: center;
align-items : center; align-items: center;
height : 100%; height: 100%;
padding: 1em;
margin-top: 0.5em;
}
.node-editor--root.modded {
border: 1px solid var(--change);
border-radius: 5px;
}
.node-editor--root.modded * {
border-color: var(--change);
} }
.node-editor--body-title { .node-editor--body-title {
display : flex; display: flex;
flex-direction : row; flex-direction: row;
justify-content: space-between; justify-content: space-between;
margin-bottom : 6px; margin-bottom: 6px;
} }
.node-editor--body-title>* { .node-editor--body-title>* {
@@ -18,21 +29,22 @@
} }
.node-editor--body { .node-editor--body {
overflow : overlay; overflow: overlay;
padding-left : 1%; padding-left: 1%;
padding-right: 1%; padding-right: 1%;
min-width : 100%; min-width: 100%;
min-height: fit-content; min-height: fit-content;
} }
.node-editor--footer { .node-editor--footer {
bottom : 0; bottom: 0;
left : 0; left: 0;
display : flex; display: flex;
flex-direction : row; flex-direction: row;
justify-content: space-between; justify-content: space-between;
align-items : center; align-items: center;
width : 100%; width: 100%;
min-height : 50px; min-height: 50px;
min-width: 25vw;
} }
+16 -3
View File
@@ -11,6 +11,7 @@ export interface Props {
allowedTypes?: Array<keyof AutomationNodeMapping>; allowedTypes?: Array<keyof AutomationNodeMapping>;
onClose?: () => void; onClose?: () => void;
onSave?: (n: AutomationNode) => void; onSave?: (n: AutomationNode) => void;
onFlags?: (isReady: boolean, isModified: boolean) => void;
saveBtnCreateText?: boolean; saveBtnCreateText?: boolean;
} }
@@ -19,11 +20,22 @@ export const NodeEditor: FC<Props> = ({
allowedTypes = ["action", "condition", "trigger"], allowedTypes = ["action", "condition", "trigger"],
onClose = () => { }, onClose = () => { },
onSave = () => { }, onSave = () => { },
onFlags = () => { },
saveBtnCreateText = false, saveBtnCreateText = false,
children
}) => { }) => {
// state
const state = useEditorNodeState(node); const state = useEditorNodeState(node);
return <div className="node-editor--root"> // state
const isModified = state.isModified;
const isReady = state.isReady();
// events
onFlags(isReady, isModified);
// render
return <div className={["node-editor--root", isModified ? "modded" : ""].join(" ")}>
<div className="node-editor--body"> <div className="node-editor--body">
<div className="node-editor--body-title"> <div className="node-editor--body-title">
{allowedTypes.length > 1 ? <InputList {allowedTypes.length > 1 ? <InputList
@@ -44,8 +56,9 @@ export const NodeEditor: FC<Props> = ({
<div className="node-editor--footer"> <div className="node-editor--footer">
<Button onClick={onClose}>Close</Button> <Button onClick={onClose}>Close</Button>
<Button onClick={() => { <Button onClick={() => {
state.isReady() && onSave(state.data) isReady && onSave(state.data)
}} disabled={!state.isReady()}>{saveBtnCreateText ? "Create" : "Save"}</Button> }} disabled={!isReady}>{saveBtnCreateText ? "Create" : "Save"}</Button>
{children}
</div> </div>
</div> </div>
} }
@@ -14,7 +14,7 @@ export const makeUpdater = (
removeNode(i: number) { removeNode(i: number) {
return onChange([ return onChange([
...sequence.slice(0, i), ...sequence.slice(0, i),
...sequence.slice(i+1), ...sequence.slice(i + 1),
]) ])
}, },
addNode() { addNode() {
@@ -40,7 +40,7 @@ export const makeUpdater = (
return onChange([ return onChange([
...sequence.slice(0, i), ...sequence.slice(0, i),
node, node,
...sequence.slice(i+1), ...sequence.slice(i + 1),
]) ])
}, },
updateChooseActionData(i: number, data: ChooseAction['action_data']) { updateChooseActionData(i: number, data: ChooseAction['action_data']) {
@@ -50,7 +50,7 @@ export const makeUpdater = (
action_data: data, action_data: data,
}) })
}, },
makeChildUpdaterForChooseAction(i: number, j:number | null) { makeChildUpdaterForChooseAction(i: number, j: number | null) {
const node = sequence[i]; const node = sequence[i];
if ((node.$smType === 'action') && (node.action === 'choose')) { if ((node.$smType === 'action') && (node.action === 'choose')) {
if (j !== null) { if (j !== null) {
@@ -66,7 +66,7 @@ export const makeUpdater = (
...node.action_data.choose[j], ...node.action_data.choose[j],
sequence: seq, sequence: seq,
}, },
...node.action_data.choose.slice(j+1), ...node.action_data.choose.slice(j + 1),
] ]
} }
}), }),
+16
View File
@@ -4,6 +4,7 @@
--primary-accent: #bbbbbb; --primary-accent: #bbbbbb;
--secondary-accent: #929191; --secondary-accent: #929191;
--error: #c55; --error: #c55;
--change: #0f9;
touch-action: pan-x pan-y; touch-action: pan-x pan-y;
height: 100%; height: 100%;
} }
@@ -46,3 +47,18 @@ body,
* { * {
transition: all 200ms ease-out; transition: all 200ms ease-out;
} }
.column {
display: flex;
flex-direction: column;
}
.center {
justify-content: center;
align-items: center;
}
.row {
display: flex;
flex-direction: row;
}
+6 -2
View File
@@ -1,4 +1,4 @@
import { AutomationData } from "types/automations"; import { AutomationData, AutomationSequenceNode } from "types/automations";
import { AutomationTrigger } from '../types/automations/triggers'; import { AutomationTrigger } from '../types/automations/triggers';
export type AumationStateEditor = ReturnType<typeof makeAumationStateEditor>; export type AumationStateEditor = ReturnType<typeof makeAumationStateEditor>;
@@ -32,5 +32,9 @@ export const makeAumationStateEditor = (
trigger: automation.trigger trigger: automation.trigger
.concat([t]) .concat([t])
}), }),
} },
updateSequence: (s: AutomationSequenceNode[]) => onUpdate({
...automation,
sequence: s,
})
}) })