import * as React from "react"; import { FunctionComponent, useCallback, useEffect, useRef, useState, } from "react"; import ReactFlow, { Background, Controls, MarkerType, MiniMap, addEdge, useEdgesState, useNodesState, updateEdge, BackgroundVariant, } from "reactflow"; import PipelineStepComponent from "./pipeline-step.component"; export interface IMyComponentProps { initialNodes: any; initialEdges: any; onNodesDataChanged: Function, onEdgesDataChanged: Function } const edgeOptions = { animated: true, style: { stroke: "#B0B0B0", }, markerEnd: { type: MarkerType.ArrowClosed, color: "#B0B0B0", strokeWidth: 2, }, }; const connectionLineStyle = { stroke: "#B0B0B0" }; export const PipelineFlowComponent: FunctionComponent = ( props: IMyComponentProps ) => { // const timerHandle = useRef(null); // const [stateCounter, setStateCounter] = useState(42); const [nodes, setNodes, onNodesChange] = useNodesState(props.initialNodes?.length ? props.initialNodes : []); const [edges, setEdges, onEdgesChange] = useEdgesState(props.initialEdges?.length? props.initialEdges: []); const edgeUpdateSuccessful = useRef(true); React.useEffect(() => { props.onNodesDataChanged(nodes); }, [nodes]); React.useEffect(() => { props.onEdgesDataChanged(edges) }, [edges]) const onConnect = useCallback( (params) => setEdges((eds) => addEdge(params, eds)), [setEdges] ); /** * @function onEdgeUpdateEnd * @description this function is triggger when edge is connected to other node. */ const onEdgeUpdateEnd = useCallback((_a, edge) => { if (!edgeUpdateSuccessful.current) { setEdges((eds) => eds.filter((e) => e.id !== edge.id)); } edgeUpdateSuccessful.current = true; }, []); /** * @function onEdgeUpdateStart * @description this function is trigger when we will start updating of Edge */ const onEdgeUpdateStart = useCallback(() => { edgeUpdateSuccessful.current = false; }, []); /** * @function onEdgeUpdate * @description this function is trigger when Edge will updated. */ const onEdgeUpdate = useCallback((oldEdge, newConnection) => { edgeUpdateSuccessful.current = true; setEdges((els) => updateEdge(oldEdge, newConnection, els)); }, []); /** * @function onNodeClick * @description to update node Data */ const onNodeClick = (_event, node) => { //setIsShowNodeEditModal(true); // setNodeData(clone(node)); }; const onPaneClick = () => { // setIsShowNodeEditModal(false); }; const nodeTypes = React.useMemo( () => ({ normal: PipelineStepComponent, }), ["NormalOperationPipelineNode"] ); return (
{/* */} {/* */}
); };