diff --git a/Data/WebUI/src/components/FlowEditor.jsx b/Data/WebUI/src/components/FlowEditor.jsx index b341d84..4c72a61 100644 --- a/Data/WebUI/src/components/FlowEditor.jsx +++ b/Data/WebUI/src/components/FlowEditor.jsx @@ -1,52 +1,68 @@ import React, { useState, useEffect, useCallback } from "react"; import ReactFlow, { - addEdge, - Controls, - Background, + addEdge, + Controls, + Background, } from "reactflow"; import "reactflow/dist/style.css"; -import "./FlowEditor.css"; +import "./FlowEditor.css"; const fetchNodes = async () => { - const response = await fetch("/api/workflow"); - return response.json(); + const response = await fetch("/api/workflow"); + return response.json(); }; const saveWorkflow = async (workflow) => { - await fetch("/api/workflow", { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify(workflow), - }); + await fetch("/api/workflow", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(workflow), + }); }; export default function FlowEditor() { - const [elements, setElements] = useState([]); + const [elements, setElements] = useState([]); - useEffect(() => { - fetchNodes().then((data) => setElements([...data.nodes, ...data.edges])); - }, []); + useEffect(() => { + fetchNodes().then((data) => { + // Data should contain nodes and edges arrays + const newElements = [...data.nodes, ...data.edges]; + setElements(newElements); + }); + }, []); - const onConnect = useCallback( - (params) => { - const newEdge = { id: `e${params.source}-${params.target}`, ...params }; - setElements((els) => [...els, newEdge]); - saveWorkflow({ nodes: elements.filter(e => e.type), edges: [...elements.filter(e => !e.type), newEdge] }); - }, - [elements] - ); + const onConnect = useCallback( + (params) => { + const newEdge = { id: `e${params.source}-${params.target}`, ...params }; + setElements((els) => [...els, newEdge]); - return ( -