# FlowForge Frontend Integration Guide This guide provides instructions for integrating the new components we've created into the existing WorkflowEditor.js file. ## Step 1: Import New Components Add these imports at the top of your `WorkflowEditor.js` file: ```javascript import Modal from '../components/common/Modal'; import WorkflowEditorTabs from '../components/workflow/WorkflowEditorTabs'; import WorkflowEditorActions from '../components/workflow/WorkflowEditorActions'; import NodeTester from '../components/workflow/NodeTester'; import ExecutionResults from '../components/execution/ExecutionResults'; ``` ## Step 2: Add New State Variables Add these state variables inside your WorkflowEditor component: ```javascript const [showNodeTester, setShowNodeTester] = useState(false); const [showExecutionResults, setShowExecutionResults] = useState(false); const [latestExecutionId, setLatestExecutionId] = useState(null); const [currentVersion, setCurrentVersion] = useState(1); const [showTabs, setShowTabs] = useState(true); ``` ## Step 3: Add New Methods Add these methods inside your WorkflowEditor component: ```javascript // Duplicate a node const handleDuplicateNode = (node) => { const newNode = { ...node, id: `${node.id}-copy-${Date.now()}`, position: { x: node.position.x + 50, y: node.position.y + 50 } }; setNodes((nds) => nds.concat(newNode)); }; // Delete a node const handleDeleteNode = (node) => { setNodes((nds) => nds.filter((n) => n.id !== node.id)); setEdges((eds) => eds.filter((e) => e.source !== node.id && e.target !== node.id)); setSelectedNode(null); }; // Handle workflow execution const handleExecuteWorkflow = (executionId) => { setLatestExecutionId(executionId); }; // Handle version restoration const handleRestoreVersion = async (version) => { try { setIsLoading(true); const response = await api.get(`/api/workflows/${id}/versions/${version}`); const workflowData = response.data.workflow; // Update workflow data setWorkflow({ ...workflow, name: workflowData.name, description: workflowData.description }); // Convert backend nodes/connections to React Flow format const flowNodes = workflowData.nodes.map(node => ({ id: node.id, type: 'customNode', position: { x: node.position_x, y: node.position_y }, data: { label: node.name, nodeType: node.type, config: node.config || {} } })); const flowEdges = workflowData.connections.map(conn => ({ id: conn.id, source: conn.source_node_id, target: conn.target_node_id, sourceHandle: conn.source_handle, targetHandle: conn.target_handle })); setNodes(flowNodes); setEdges(flowEdges); setCurrentVersion(version); toast.success(`Restored workflow to version ${version}`); } catch (error) { console.error('Error restoring version:', error); toast.error('Failed to restore workflow version'); } finally { setIsLoading(false); } }; ``` ## Step 4: Update the Return Statement Replace the existing buttons in the workflow header with the WorkflowEditorActions component: ```jsx