MCPcopy Create free account
hub / github.com/code-with-antonio/nodebase / Editor

Function Editor

src/features/editor/components/editor.tsx:38–96  ·  view source on GitHub ↗
({ workflowId }: { workflowId: string })

Source from the content-addressed store, hash-verified

36};
37
38export const Editor = ({ workflowId }: { workflowId: string }) => {
39 const {
40 data: workflow
41 } = useSuspenseWorkflow(workflowId);
42
43 const setEditor = useSetAtom(editorAtom);
44
45 const [nodes, setNodes] = useState<Node[]>(workflow.nodes);
46 const [edges, setEdges] = useState<Edge[]>(workflow.edges);
47
48 const onNodesChange = useCallback(
49 (changes: NodeChange[]) => setNodes((nodesSnapshot) => applyNodeChanges(changes, nodesSnapshot)),
50 [],
51 );
52 const onEdgesChange = useCallback(
53 (changes: EdgeChange[]) => setEdges((edgesSnapshot) => applyEdgeChanges(changes, edgesSnapshot)),
54 [],
55 );
56 const onConnect = useCallback(
57 (params: Connection) => setEdges((edgesSnapshot) => addEdge(params, edgesSnapshot)),
58 [],
59 );
60
61 const hasManualTrigger = useMemo(() => {
62 return nodes.some((node) => node.type === NodeType.MANUAL_TRIGGER);
63 }, [nodes]);
64
65 return (
66 <div className='size-full'>
67 <ReactFlow
68 nodes={nodes}
69 edges={edges}
70 onNodesChange={onNodesChange}
71 onEdgesChange={onEdgesChange}
72 onConnect={onConnect}
73 nodeTypes={nodeComponents}
74 onInit={setEditor}
75 fitView
76 snapGrid={[10, 10]}
77 snapToGrid
78 panOnScroll
79 panOnDrag={false}
80 selectionOnDrag
81 >
82 <Background />
83 <Controls />
84 <MiniMap />
85 <Panel position="top-right">
86 <AddNodeButton />
87 </Panel>
88 {hasManualTrigger && (
89 <Panel position="bottom-center">
90 <ExecuteWorkflowButton workflowId={workflowId} />
91 </Panel>
92 )}
93 </ReactFlow>
94 </div>
95 );

Callers

nothing calls this directly

Calls 1

useSuspenseWorkflowFunction · 0.90

Tested by

no test coverage detected