From b31da3b1956c0ca71f08d06fbd89abc45c843d9d Mon Sep 17 00:00:00 2001 From: StyleZhang Date: Tue, 19 Mar 2024 17:59:09 +0800 Subject: [PATCH] initial node position --- web/app/components/workflow/utils.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/web/app/components/workflow/utils.ts b/web/app/components/workflow/utils.ts index 12ee876009..da1ce569f8 100644 --- a/web/app/components/workflow/utils.ts +++ b/web/app/components/workflow/utils.ts @@ -9,9 +9,23 @@ import type { Node, } from './types' import { BlockEnum } from './types' +import { + NODE_WIDTH_X_OFFSET, + START_INITIAL_POSITION, +} from './constants' import type { QuestionClassifierNodeType } from './nodes/question-classifier/types' export const initialNodes = (nodes: Node[], edges: Edge[]) => { + const firstNode = nodes[0] + + if (!firstNode?.position) { + nodes.forEach((node, index) => { + node.position = { + x: START_INITIAL_POSITION.x + index * NODE_WIDTH_X_OFFSET, + y: START_INITIAL_POSITION.y, + } + }) + } return nodes.map((node) => { node.type = 'custom'