@@ -9,14 +9,23 @@ import produce from 'immer';
99import React , { memo , useContext , useState } from 'react' ;
1010import { shallow } from 'zustand/shallow' ;
1111import { useStore } from '../../hooks/useStore' ;
12- import { uuid } from '../../utils' ;
12+ import { ConfigContext } from '../../models/context' ;
13+ import { uuid , uuid4 } from '../../utils' ;
1314import NodeSelectPopover from '../NodesPopover' ;
1415import './index.less' ;
15- import { ConfigContext } from '../../models/context' ;
1616
1717export default memo ( ( edge : any ) => {
18- const { id, selected, sourceX, sourceY, targetX, targetY, source, target, sourceHandleId } =
19- edge ;
18+ const {
19+ id,
20+ selected,
21+ sourceX,
22+ sourceY,
23+ targetX,
24+ targetY,
25+ source,
26+ target,
27+ sourceHandleId,
28+ } = edge ;
2029
2130 const reactflow = useReactFlow ( ) ;
2231 const [ isHovered , setIsHovered ] = useState ( false ) ;
@@ -27,7 +36,7 @@ export default memo((edge: any) => {
2736 targetY,
2837 } ) ;
2938
30- const { globalConfig } = useContext ( ConfigContext ) ;
39+ const { globalConfig, settingMap } = useContext ( ConfigContext ) ;
3140 const hideEdgeAddBtn = globalConfig ?. edge ?. hideEdgeAddBtn ?? false ;
3241
3342 const {
@@ -49,7 +58,7 @@ export default memo((edge: any) => {
4958 onEdgesChange : state . onEdgesChange ,
5059 } ) ,
5160 shallow
52- ) ;
61+ ) ;
5362
5463 const handleAddNode = ( data : any ) => {
5564 const { screenToFlowPosition } = reactflow ;
@@ -59,11 +68,16 @@ export default memo((edge: any) => {
5968 } ) ;
6069
6170 const targetId = uuid ( ) ;
71+ const title = settingMap [ data ?. _nodeType ] ?. title || data ?. _nodeType ;
72+
6273 const newNodes = produce ( nodes , ( draft : any ) => {
6374 draft . push ( {
6475 id : targetId ,
6576 type : 'custom' ,
66- data,
77+ data : {
78+ ...data ,
79+ title : `${ title } _${ uuid4 ( ) } ` ,
80+ } ,
6781 position : { x, y } ,
6882 } ) ;
6983 } ) ;
@@ -75,7 +89,7 @@ export default memo((edge: any) => {
7589 id : uuid ( ) ,
7690 source,
7791 target : targetId ,
78- ...sourceHandleId && { sourceHandle : sourceHandleId }
92+ ...( sourceHandleId && { sourceHandle : sourceHandleId } ) ,
7993 } ,
8094 {
8195 id : uuid ( ) ,
@@ -127,13 +141,16 @@ export default memo((edge: any) => {
127141 >
128142 < CloseOutlined style = { { color : '#fff' , fontSize : 10 } } />
129143 </ div >
130- {
131- ! hideEdgeAddBtn && < NodeSelectPopover placement = "right" addNode = { handleAddNode } >
144+ { ! hideEdgeAddBtn && (
145+ < NodeSelectPopover
146+ placement = "right"
147+ addNode = { handleAddNode }
148+ >
132149 < div className = "line-icon-box" >
133150 < PlusOutlined style = { { color : '#fff' , fontSize : 10 } } />
134151 </ div >
135152 </ NodeSelectPopover >
136- }
153+ ) }
137154 </ div >
138155 </ div >
139156 </ EdgeLabelRenderer >
0 commit comments