1- import React , { useCallback , useMemo , useState , useEffect } from 'react' ;
1+ import React , { useCallback , useMemo , useState } from 'react' ;
22import { PropTypes } from 'prop-types' ;
33import ReactFlow , { useNodesState , useEdgesState , addEdge , Controls , Background , ControlButton } from 'reactflow' ;
44import 'reactflow/dist/style.css' ;
@@ -8,9 +8,6 @@ import { toast } from 'react-toastify';
88// css
99import './index.css' ;
1010
11- // notification
12- import { useSnackbar } from 'notistack' ;
13-
1411// ReactFlow Canvas
1512import CustomEdge from './edges/ButtonEdge' ;
1613
@@ -20,18 +17,10 @@ import RequestNode from './nodes/RequestNode';
2017import OutputNode from './nodes/OutputNode' ;
2118import EvaluateNode from './nodes/EvaluateNode' ;
2219import DelayNode from './nodes/DelayNode' ;
23-
24- // file system
2520import AuthNode from './nodes/AuthNode' ;
26- import { useTabStore } from 'stores/TabStore' ;
2721import FlowNode from 'components/atoms/flow/FlowNode' ;
28- import { Popover } from '@headlessui/react' ;
29- import { generateFlowData } from './flowtestai' ;
30- import { GENAI_MODELS } from 'constants/Common' ;
3122import useCanvasStore from 'stores/CanvasStore' ;
3223
33- import { shallow } from 'zustand/shallow' ;
34-
3524const StartNode = ( ) => (
3625 < FlowNode title = 'Start' handleLeft = { false } handleRight = { true } handleRightData = { { type : 'source' } } > </ FlowNode >
3726) ;
@@ -107,16 +96,14 @@ const selector = (state) => ({
10796 onConnect : state . onConnect ,
10897 setNodes : state . setNodes ,
10998 setEdges : state . setEdges ,
99+ setLogs : state . setLogs ,
110100} ) ;
111101
112102const Flow = ( { collectionId } ) => {
113- const { nodes, edges, onNodesChange, onEdgesChange, onConnect, setNodes, setEdges } = useCanvasStore ( selector ) ;
103+ const { nodes, edges, onNodesChange, onEdgesChange, onConnect, setNodes, setEdges, setLogs } =
104+ useCanvasStore ( selector ) ;
114105 //console.log(nodes);
115106
116- // notification
117- // eslint-disable-next-line no-unused-vars
118- const { enqueueSnackbar, closeSnackbar } = useSnackbar ( ) ;
119-
120107 const [ reactFlowInstance , setReactFlowInstance ] = useState ( null ) ;
121108
122109 const nodeTypes = useMemo (
@@ -212,20 +199,13 @@ const Flow = ({ collectionId }) => {
212199 return canConnect ;
213200 } ;
214201
215- // graph
216- // eslint-disable-next-line no-unused-vars
217- const [ graphRun , setGraphRun ] = useState ( false ) ;
218- // eslint-disable-next-line no-unused-vars
219- const [ graphRunLogs , setGraphRunLogs ] = useState ( undefined ) ;
220-
221202 const onGraphComplete = ( result , logs ) => {
222203 console . debug ( 'Graph complete callback: ' , result ) ;
223- setGraphRun ( true ) ;
224- setGraphRunLogs ( logs ) ;
204+ setLogs ( logs ) ;
225205 if ( result [ 0 ] == 'Success' ) {
226- enqueueSnackbar ( 'FlowTest Run Success!' , { variant : 'success' } ) ;
206+ toast . success ( 'FlowTest Run Success! View Logs' ) ;
227207 } else if ( result [ 0 ] == 'Failed' ) {
228- enqueueSnackbar ( 'FlowTest Run Failed!' , { variant : 'error' } ) ;
208+ toast . error ( 'FlowTest Run Failed! View Logs' ) ;
229209 }
230210 runnableEdges ( false ) ;
231211 } ;
@@ -245,7 +225,7 @@ const Flow = ({ collectionId }) => {
245225 onDragOver = { onDragOver }
246226 //onNodeDragStop={() => setCanvasDirty()}
247227 isValidConnection = { isValidConnection }
248- // fitView
228+ fitView
249229 >
250230 < Controls >
251231 < ControlButton
@@ -265,26 +245,6 @@ const Flow = ({ collectionId }) => {
265245 </ ControlButton >
266246 </ Controls >
267247 < Background variant = 'dots' gap = { 12 } size = { 1 } />
268- < div className = 'absolute right-4 z-[2000] max-w-sm px-4 ' >
269- < button
270- type = 'button'
271- onClick = { ( ) => {
272- generateFlowData ( 'Add a pet then get all pets with status available' , GENAI_MODELS . openai , collectionId )
273- . then ( ( flowData ) => {
274- const result = init ( flowData ) ;
275- console . log ( result ) ;
276- setNodes ( result . nodes ) ;
277- setEdges ( result . edges ) ;
278- } )
279- . catch ( ( error ) => {
280- console . log ( error ) ;
281- toast . error ( `Error while generating flow data` ) ;
282- } ) ;
283- } }
284- >
285- FlowTestAI
286- </ button >
287- </ div >
288248 < AddNodes collectionId = { collectionId } />
289249 </ ReactFlow >
290250 </ div >
0 commit comments