From 91704c3da2902dbc1516cb87b350a44c5928dbe6 Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Thu, 25 Nov 2021 15:24:55 -0500 Subject: [PATCH] all current work --- .../SequenceNodes/index.stories.tsx | 3 +- .../src/components/SequenceNodes/location.tsx | 97 ++++++++++++++----- 2 files changed, 74 insertions(+), 26 deletions(-) diff --git a/webapp/src/components/SequenceNodes/index.stories.tsx b/webapp/src/components/SequenceNodes/index.stories.tsx index ece1b2a..9891faa 100644 --- a/webapp/src/components/SequenceNodes/index.stories.tsx +++ b/webapp/src/components/SequenceNodes/index.stories.tsx @@ -163,7 +163,8 @@ Multinode.args = { } ] } - ] + ], + default: [], } }, { diff --git a/webapp/src/components/SequenceNodes/location.tsx b/webapp/src/components/SequenceNodes/location.tsx index a71450a..5728503 100644 --- a/webapp/src/components/SequenceNodes/location.tsx +++ b/webapp/src/components/SequenceNodes/location.tsx @@ -5,6 +5,7 @@ import { BaseSequenceNodeSettings, SequenceNodeSettings } from './types'; import { AddButton } from '../DAGSvgs/AddButton'; import { makeUpdater, Updater } from "./updater"; import { ChooseAction } from "types/automations/actions"; +import { AutomationSequenceNode } from '../../types/automations/index'; export function* computeNodesEdges( @@ -40,21 +41,24 @@ export function* computeNodesEdges( onXClick={() => rootUpdater.removeNode(i)} /> if ((node.$smType === 'action') && (node.action === 'choose')) { - const it = computeChooseNodesEdges( + const it = (new computeChooseNodesEdges( node, nodeLoc, lastStartPoint, nextNodeLoc, j => rootUpdater.makeChildUpdaterForChooseAction(i, j), { ...st, keyPrefix: `${keyPrefix}.${i}` } - ); + )).iter(); let next = it.next(); while (!next.done) { yield next.value next = it.next(); }; nextNodeLoc = next.value.nextNodeLoc - lastStartPoint = next.value.lastStartPoint + lastStartPoint = [ + next.value.lastStartPoint[0], + lastStartPoint[1], + ] } if (i === sequence.length - 1) { yield Updater, - st: BaseSequenceNodeSettings, -) { - for (let j = 0; j < node.action_data.choose.length; j++) { - const subStartLoc: Point = [ - nodeLoc[0] + st.nodeWidth * st.distanceFactor, - nodeLoc[1] + st.nodeHeight * (j + 1) - ]; - const updater = makeChildUpder(j); - const it = computeNodesEdges({ +class computeChooseNodesEdges { + constructor( + private node: ChooseAction, + private nodeLoc: Point, + private lastStartPoint: Point, + private nextNodeLoc: Point, + private makeChildUpder: (j: number | null) => Updater, + private st: BaseSequenceNodeSettings, + ) { } + + private *genNodesEdges( + seq: AutomationSequenceNode[], + subStartLoc: Point, + updater: Updater, + keyPrefix: string + ) { + const { + st, nodeLoc, + } = this; + let it = computeNodesEdges({ ...st, onChange: updater.onChange, - sequence: node.action_data.choose[j].sequence, + sequence: seq, startPoint: subStartLoc, - keyPrefix: `.${j}` + keyPrefix: keyPrefix }); let next = it.next(); while (!next.done) { @@ -104,18 +113,18 @@ export function* computeChooseNodesEdges( next = it.next() } yield if (next.value) { - nextNodeLoc[0] = next.value[0] + st.nodeWidth * st.distanceFactor - lastStartPoint = [Math.max(next.value[0], lastStartPoint[0]), lastStartPoint[1]] + this.nextNodeLoc[0] = next.value[0] + st.nodeWidth * st.distanceFactor + this.lastStartPoint = [Math.max(next.value[0], this.lastStartPoint[0]), Math.max(this.lastStartPoint[1], next.value[1])] } else { yield } } - return { lastStartPoint, nextNodeLoc } + + *iter() { + const { st, node, makeChildUpder, nodeLoc } = this; + for (let j = 0; j < node.action_data.choose.length; j++) { + const it = this.genNodesEdges( + node.action_data.choose[j].sequence, + [ + nodeLoc[0] + st.nodeWidth * st.distanceFactor, + Math.max(nodeLoc[1] + st.nodeHeight * (j + 1), this.lastStartPoint[1]) + ], + makeChildUpder(j), + `${st.keyPrefix}.${j}`, + ); + let next = it.next(); + while (!next.done) { + yield next.value + next = it.next(); + } + } + const it = this.genNodesEdges( + node.action_data.default, + [ + nodeLoc[0] + st.nodeWidth * st.distanceFactor, + nodeLoc[1] + st.nodeHeight * (node.action_data.choose.length + 1) + ], + makeChildUpder(null), + `${st.keyPrefix}.default`, + ); + let next = it.next(); + while (!next.done) { + yield next.value + next = it.next(); + } + return { + lastStartPoint: this.lastStartPoint, + nextNodeLoc: this.nextNodeLoc + } + } } +