({ data })
| 49 | // ===========================|| ITERATION NODE ||=========================== // |
| 50 | |
| 51 | const 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 | } |
nothing calls this directly
no test coverage detected