MCPcopy Create free account
hub / github.com/FlowiseAI/Flowise / IterationNode

Function IterationNode

packages/ui/src/views/agentflowsv2/IterationNode.jsx:51–419  ·  view source on GitHub ↗
({ data })

Source from the content-addressed store, hash-verified

49// ===========================|| ITERATION NODE ||=========================== //
50
51const IterationNode = ({ data }) => {
52 const theme = useTheme()
53 const customization = useSelector((state) => state.customization)
54 const ref = useRef(null)
55 const reactFlowWrapper = useRef(null)
56
57 const updateNodeInternals = useUpdateNodeInternals()
58 // eslint-disable-next-line
59 const [position, setPosition] = useState(0)
60 const [isHovered, setIsHovered] = useState(false)
61 const { deleteNode, duplicateNode, reactFlowInstance } = useContext(flowContext)
62 const [showInfoDialog, setShowInfoDialog] = useState(false)
63 const [infoDialogProps, setInfoDialogProps] = useState({})
64
65 const [cardDimensions, setCardDimensions] = useState({
66 width: '300px',
67 height: '250px'
68 })
69
70 // Add useEffect to update dimensions when reactFlowInstance becomes available
71 useEffect(() => {
72 if (reactFlowInstance) {
73 const node = reactFlowInstance.getNodes().find((node) => node.id === data.id)
74 if (node && node.width && node.height) {
75 setCardDimensions({
76 width: `${node.width}px`,
77 height: `${node.height}px`
78 })
79 }
80 }
81 }, [reactFlowInstance, data.id])
82
83 const defaultColor = '#666666' // fallback color if data.color is not present
84 const nodeColor = data.color || defaultColor
85
86 // Get different shades of the color based on state
87 const getStateColor = () => {
88 if (data.selected) return nodeColor
89 if (isHovered) return alpha(nodeColor, 0.8)
90 return alpha(nodeColor, 0.5)
91 }
92
93 const getOutputAnchors = () => {
94 return data.outputAnchors ?? []
95 }
96
97 const getAnchorPosition = (index) => {
98 const currentHeight = ref.current?.clientHeight || 0
99 const spacing = currentHeight / (getOutputAnchors().length + 1)
100 const position = spacing * (index + 1)
101
102 // Update node internals when we get a non-zero position
103 if (position > 0) {
104 updateNodeInternals(data.id)
105 }
106
107 return position
108 }

Callers

nothing calls this directly

Calls 10

useUpdateNodeInternalsFunction · 0.90
duplicateNodeFunction · 0.85
deleteNodeFunction · 0.85
renderIconFunction · 0.70
getMinimumHeightFunction · 0.70
getStateColorFunction · 0.70
getBackgroundColorFunction · 0.70
getStatusBackgroundColorFunction · 0.70
getOutputAnchorsFunction · 0.70
getAnchorPositionFunction · 0.70

Tested by

no test coverage detected