diff --git a/webapp/src/components/NodeEditor/OptionManager/ActionChoose.tsx b/webapp/src/components/NodeEditor/OptionManager/ActionChoose.tsx index 8985c2a..35fce88 100644 --- a/webapp/src/components/NodeEditor/OptionManager/ActionChoose.tsx +++ b/webapp/src/components/NodeEditor/OptionManager/ActionChoose.tsx @@ -29,11 +29,13 @@ export const ActionChooseState: OptionManager = { label="Choose Sequence" value={state.action_data.choose} onChange={choose => update({ choose })} + resizable /> update({ default: d })} + resizable /> } diff --git a/webapp/src/components/NodeEditor/OptionManager/ActionService.tsx b/webapp/src/components/NodeEditor/OptionManager/ActionService.tsx index 17aeb12..7d43b87 100644 --- a/webapp/src/components/NodeEditor/OptionManager/ActionService.tsx +++ b/webapp/src/components/NodeEditor/OptionManager/ActionService.tsx @@ -1,4 +1,5 @@ import InputText from "components/Inputs/InputText"; +import InputYaml from 'components/Inputs/InputYaml'; import { ServiceAction } from "types/automations/actions"; import { OptionManager, updateActionData } from './OptionManager'; @@ -35,7 +36,7 @@ export const ActionCallServiceState: OptionManager = { value={service} onChange={service => update({ service })} /> - update({ target })} diff --git a/webapp/src/components/SequenceNodes/index.stories.tsx b/webapp/src/components/SequenceNodes/index.stories.tsx index 3be58ae..de59ba9 100644 --- a/webapp/src/components/SequenceNodes/index.stories.tsx +++ b/webapp/src/components/SequenceNodes/index.stories.tsx @@ -10,7 +10,7 @@ export default { component: SequenceNodes, parameters: { actions: { argTypesRegex: '^on.*' } }, args: { - zoomLevel: 1, + zoomLevel: 1.5, startPoint: [0.5, 0.5], dims: { nodeHeight: NODE_HEIGHT, diff --git a/webapp/src/components/SequenceNodes/index.tsx b/webapp/src/components/SequenceNodes/index.tsx index 32d4af1..b4e4ac6 100644 --- a/webapp/src/components/SequenceNodes/index.tsx +++ b/webapp/src/components/SequenceNodes/index.tsx @@ -1,23 +1,47 @@ import { DAGBoard } from "components/DAGSvgs/DAGBoard"; -import { FC } from "react"; +import { FC, useState } from "react"; +import { AutomationSequenceNode } from 'types/automations'; import { useTheme } from "styles/theme"; import { SequenceNodeProps } from './types'; import Color from 'chroma-js'; import { computeNodesEdgesPos } from './positions'; +import { Modal } from 'components/Modal'; +import { NodeEditor } from 'components/NodeEditor'; + +interface ModalState { + node: AutomationSequenceNode; + update: (n: AutomationSequenceNode) => void; + onlyConditions: boolean; +} export const SequenceNodes: FC = (props) => { const theme = useTheme(); - return + const [modalState, setModalState] = useState(null); + console.log({ modalState }); + return <> + setModalState({ + node, update, onlyConditions, + }) + )} + settings={{ + ...props.dims, + edgeNextColor: theme.secondaryAccent, + edgeChildColor: Color(theme.secondaryAccent).set('rgb.b', 200).hex(), + }} + /> + + {modalState && setModalState(null)} + onSave={n => { modalState.update(n as any); setModalState(null) }} + allowedTypes={modalState.onlyConditions ? ['condition'] : ['action', 'condition']} + />} + + } diff --git a/webapp/src/components/SequenceNodes/positions.ts b/webapp/src/components/SequenceNodes/positions.ts index 67ad960..f17520d 100644 --- a/webapp/src/components/SequenceNodes/positions.ts +++ b/webapp/src/components/SequenceNodes/positions.ts @@ -2,7 +2,14 @@ import { DAGElement } from "components/DAGSvgs/DAGBoard"; import { AutomationSequenceNode } from "types/automations"; import { Point } from "types/graphs"; import { makeUpdater, Updater } from './updater'; -import { ChooseAction } from '../../types/automations/actions'; +import { ChooseAction } from 'types/automations/actions'; +import { AutomationCondition } from "types/automations/conditions"; + +export type UpdateNode = ( + node: AutomationSequenceNode, + updateNode: (n: AutomationSequenceNode) => void, + onlyConditions: boolean, +) => void; const offsetPoint = ( [x, y]: Point, @@ -37,7 +44,8 @@ function* dealWithNested( innerStartLoc: Point, updater: Updater, sequence: AutomationSequenceNode[], - onEdit?: () => void, + openModal: UpdateNode, + onEdit: () => void, ): Generator { const np = offsetPoint(innerStartLoc, [0.5, 0]); yield { @@ -63,6 +71,7 @@ function* dealWithNested( np, sequence, updater.onChange, + openModal, )) { yield childNode } @@ -72,19 +81,39 @@ function* dealWithChoose( node: ChooseAction, nodeLoc: Point, makeUpdater: (j: number | null) => Updater, - onAdd: () => void, + updateData: (data: ChooseAction['action_data']) => void, + openModal: UpdateNode, offset: ReturnType, ): Generator { offset.resetY() // conditions for (let j = 0; j < node.action_data.choose.length; j++) { const innerStartLoc = offsetPoint(nodeLoc, [1, j + 1 + offset.y]); + const updater = makeUpdater(j); for (let elm of dealWithNested( nodeLoc, innerStartLoc , - makeUpdater(j), + updater, node.action_data.choose[j].sequence, - () => {}, + openModal, + () => openModal( + node.action_data.choose[j].conditions[0] ?? { + '$smType': 'condition', 'condition': 'and', 'condition_data': { + 'conditions': [] + }}, + (n) => updateData({ + ...node.action_data, + choose: [ + ...node.action_data.choose.slice(0, j), + { + sequence: node.action_data.choose[j].sequence, + conditions: [n] as AutomationCondition[], + }, + ...node.action_data.choose.slice(j+1), + ] + }), + true, + ), )) { yield elm if (elm.type === 'node') { @@ -105,6 +134,8 @@ function* dealWithChoose( innerStartLoc, makeUpdater(null), node.action_data.default, + openModal, + () => {} )) { yield elm if (elm.type === 'node') { @@ -119,7 +150,16 @@ function* dealWithChoose( yield { type: 'circle', loc: newCondLoc, - onClick: ['add', onAdd], + onClick: ['add', () => updateData({ + ...node.action_data, + choose: [ + ...node.action_data.choose, + { + conditions: [], + sequence: [], + } + ] + })], } } @@ -128,6 +168,7 @@ export function* computeNodesEdgesPos( startPoint: Point, sequence: AutomationSequenceNode[], onChange: (s: AutomationSequenceNode[]) => void, + openModal: UpdateNode, ): Generator { const rootUpdater = makeUpdater(sequence, onChange); const offset = makeOffsetMaintainer(startPoint) @@ -140,6 +181,7 @@ export function* computeNodesEdgesPos( type: 'node', loc: nodeLoc, node, + onOpen: () => openModal(node, n => rootUpdater.updateNode(i, n), false), onRemove: () => rootUpdater.removeNode(i), onAdd: i === sequence.length - 1 ? rootUpdater.addNode : undefined, } @@ -159,19 +201,8 @@ export function* computeNodesEdgesPos( node, nodeLoc, j => rootUpdater.makeChildUpdaterForChooseAction(i, j), - () => rootUpdater.updateNode(i, { - ...node, - action_data: { - ...node.action_data, - choose: [ - ...node.action_data.choose, - { - conditions: [], - sequence: [], - } - ] - } - }), + actionData => rootUpdater.updateChooseActionData(i, actionData), + openModal, offset, ) } diff --git a/webapp/src/components/SequenceNodes/updater.ts b/webapp/src/components/SequenceNodes/updater.ts index 35b88da..38a3edf 100644 --- a/webapp/src/components/SequenceNodes/updater.ts +++ b/webapp/src/components/SequenceNodes/updater.ts @@ -1,4 +1,5 @@ import { AutomationSequenceNode } from "types/automations"; +import { ChooseAction } from "types/automations/actions"; export type Updater = ReturnType; @@ -34,6 +35,13 @@ export const makeUpdater = ( ...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')) {