// External Dependencies import React, { useMemo } from 'react'; /** * Custom hook to manage flow edges * Calculates and maintains edge connections between nodes * * @param {Array} nodes - Current nodes in the flow * @param {Array} value - Original YAML node data * @param {Object} sNodes - Node signal data * @returns {Array} Calculated edges for the flow */ const useFlowEdges = (nodes, value, sNodes) => { return useMemo(() => { return nodes.reduce((accum, node) => { // Skip nodes without inputs if (!node.data.input) return accum; // Process each input connection Object.keys(node.data.input).forEach((input) => { // Find corresponding workflow node const workflowNode = value.find((n) => n.id === node.id); if (!workflowNode && !node.type) return; // Get actual node definition const actualNode = (sNodes || {})[workflowNode?.node || node?.type]; if (!actualNode) return; // Determine input type from node definition or workflow configuration const actualInput = actualNode?.inputs?.find((i) => i.id === input)?.type?.[0]?.name || workflowNode?.inputs?.find((i) => i.id === input)?.type?.[0]?.name; if (!actualInput) return; // Create edge definition accum.push({ id: `${node.data.input[input]}-${node.id || node.temp}-${input}`, source: node.data.input[input].split('-')[0], target: node.id || node.temp, className: `edge-${actualInput || 'none'}`, sourceHandle: `output-${node.data.input[input]}`, targetHandle: `input-${node.id || node.temp}-${input}`, }); }); return accum; }, []); }, [nodes, value, sNodes]); }; /** * Custom hook to manage flow edges */ export default useFlowEdges;