diff --git a/webapp/src/components/DAGFlow/index.stories.tsx b/webapp/src/components/DAGFlow/index.stories.tsx index 93893ff..1e0d00c 100644 --- a/webapp/src/components/DAGFlow/index.stories.tsx +++ b/webapp/src/components/DAGFlow/index.stories.tsx @@ -307,6 +307,13 @@ Complex.args = { } ] } + }, + { + "$smType": "condition", + "condition": "and", + "condition_data": { + "conditions": [] + } } ] } diff --git a/webapp/src/components/DAGFlow/sequenceConvertor.ts b/webapp/src/components/DAGFlow/sequenceConvertor.ts index 67b9873..a53f19a 100644 --- a/webapp/src/components/DAGFlow/sequenceConvertor.ts +++ b/webapp/src/components/DAGFlow/sequenceConvertor.ts @@ -13,13 +13,19 @@ export const sequenceToFlow = ( prefix: string = "", ) => { let lastPointId = fromPoint; + let lasPos: XYPosition | null = null; for (let i = 0; i < sequence.length; i++) { const node = sequence[i]; const nodeId = `${prefix}n-${i}`; - const position = computeNodePos(i, dims); + let position: XYPosition; + if (lasPos) { + position = { x: lasPos.x + dims.nodeWidth * dims.distanceFactor, y: dims.padding.y } + } else { + position = computeNodePos(i, dims); + } if (node.$smType === 'action') { if (node.action === 'choose') { - addChooseNode(flowData, node, i, nodeId, lastPointId, dims) + position = addChooseNode(flowData, node, position, nodeId, lastPointId, dims) } else { addSingleNode(flowData, node, position, nodeId, dims); } @@ -33,7 +39,12 @@ export const sequenceToFlow = ( target: nodeId, }); lastPointId = nodeId; + lasPos = position; } + return { + position: lasPos, + pointId: lastPointId, + }; } const computeNodePos = (i: number, { padding, distanceFactor, nodeWidth }: DAGFlowDims): XYPosition => ({ @@ -71,28 +82,33 @@ const addSingleNode = ( const addChooseNode = ( flowData: FlowData, node: ChooseAction, - i: number, + position: XYPosition, nodeId: string, lastPointId: string, dims: DAGFlowDims, ) => { - const { x, y } = computeNodePos(i, dims); - addSingleNode(flowData, node, { x, y }, nodeId, dims); + addSingleNode(flowData, node, position, nodeId, dims); + let lastPos: XYPosition = position; node.action_data.choose.forEach(({ sequence, conditions }, j) => { - sequenceToFlow(flowData, sequence, nodeId, { + const { y } = lastPos; + const lastPoint = sequenceToFlow(flowData, sequence, nodeId, { ...dims, padding: { - x: x - dims.nodeWidth, - y: y + dims.nodeHeight * (j + 0.25) * dims.distanceFactor, + x: position.x - dims.nodeWidth, + y: y + dims.nodeHeight * dims.distanceFactor, }, - }, `${nodeId}.${j}.`) + }, `${nodeId}.${j}.`); + if (lastPoint.position) { + lastPos = lastPoint.position; + } }) const totalChildren = node.action_data.choose.length; sequenceToFlow(flowData, node.action_data.default, nodeId, { ...dims, padding: { - x: x - dims.nodeWidth, - y: y + dims.nodeHeight * (totalChildren + 0.25) * dims.distanceFactor, + x: position.x - dims.nodeWidth, + y: lastPos.y + dims.nodeHeight * (totalChildren + 0.25) * dims.distanceFactor, }, }, `${nodeId}.${totalChildren}.`) + return lastPos } \ No newline at end of file