From 43afd35f57c707a6312d2d2dfc2f31d2997dd676 Mon Sep 17 00:00:00 2001 From: Aralhi Date: Wed, 31 Jan 2024 01:08:01 +0800 Subject: [PATCH] fix: add node id to node.data --- web/components/flow/node-handler.tsx | 14 ++++++++++++-- web/pages/flow/canvas/index.tsx | 20 +++++++++++--------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/web/components/flow/node-handler.tsx b/web/components/flow/node-handler.tsx index 89a1ca220..5d0d09025 100644 --- a/web/components/flow/node-handler.tsx +++ b/web/components/flow/node-handler.tsx @@ -5,6 +5,7 @@ import RequiredIcon from './required-icon'; import { InfoCircleOutlined } from '@ant-design/icons'; import { IFlowNode, IFlowNodeInput, IFlowNodeOutput, IFlowNodeParameter } from '@/types/flow'; import { useTranslation } from 'react-i18next'; +import classNames from 'classnames'; interface NodeHandlerProps { node: IFlowNode; @@ -44,7 +45,12 @@ const NodeHandler: React.FC = ({ node, data, type, label, inde } return ( -
+
= ({ node, data, type, label, inde id={`${node.id}|${label}|${index}`} isValidConnection={(connection) => isValidConnection(connection)} /> - + {data.label}: {data.description && ( diff --git a/web/pages/flow/canvas/index.tsx b/web/pages/flow/canvas/index.tsx index d968c99c7..491e1334f 100644 --- a/web/pages/flow/canvas/index.tsx +++ b/web/pages/flow/canvas/index.tsx @@ -4,7 +4,7 @@ import AddNodes from '@/components/flow/add-nodes'; import ButtonEdge from '@/components/flow/button-edge'; import CanvasNode from '@/components/flow/canvas-node'; import { IFlowData } from '@/types/flow'; -import { getUniqueNodeId, mapHumpToUnderline } from '@/utils/flow'; +import { getUniqueNodeId, mapHumpToUnderline, mapUnderlineToHump } from '@/utils/flow'; import { SaveOutlined } from '@ant-design/icons'; import { Divider, Input, Modal, message } from 'antd'; import { useSearchParams } from 'next/navigation'; @@ -37,7 +37,7 @@ const Canvas: React.FC = () => { setLoading(true); const [_, data] = await apiInterceptors(getFlowById(id)); if (data) { - const flowData = mapHumpToUnderline(data.flow_data); + const flowData = mapUnderlineToHump(data.flow_data); setName(data.name); setNodes(flowData.nodes.map((node) => ({ ...node, type: 'customNode' }))); setEdges(flowData.edges.map((edge) => ({ ...edge, type: 'buttonedge' }))); @@ -91,6 +91,7 @@ const Canvas: React.FC = () => { y: event.clientY - reactFlowBounds.top, }); const nodeId = getUniqueNodeId(nodeData, reactFlow.getNodes()); + nodeData.id = nodeId; const newNode = { id: nodeId, position, @@ -154,15 +155,15 @@ const Canvas: React.FC = () => { } return ( -
+ <> -
-
- +
+
+
- -
+ +
= () => { onDragOver={onDragOver} minZoom={0.1} fitView + deleteKeyCode={['Backspace', 'Delete']} > @@ -200,7 +202,7 @@ const Canvas: React.FC = () => { {contextHolder} -
+ ); };