@@ -28,6 +28,7 @@ import { BUTTON_INTENT_TYPES, BUTTON_TYPES } from 'constants/Common';
2828import GraphLogger , { LogLevel } from './graph/GraphLogger' ;
2929import Mousetrap from 'mousetrap' ;
3030import { uploadGraphRunLogs } from 'service/collection' ;
31+ import { graphRun } from './graph/GraphRun' ;
3132
3233const StartNode = ( ) => (
3334 < FlowNode title = 'Start' handleLeft = { false } handleRight = { true } handleRightData = { { type : 'source' } } > </ FlowNode >
@@ -112,6 +113,18 @@ const Flow = ({ tab, collectionId }) => {
112113 [ ] ,
113114 ) ;
114115
116+ useMemo ( ( ) => {
117+ if ( reactFlowInstance ) {
118+ const updatedEdges = reactFlowInstance . getEdges ( ) . map ( ( edge ) => {
119+ return {
120+ ...edge ,
121+ animated : tab . running ,
122+ } ;
123+ } ) ;
124+ setEdges ( updatedEdges ) ;
125+ }
126+ } , [ tab . running ] ) ;
127+
115128 const runnableEdges = ( runnable ) => {
116129 const updatedEdges = reactFlowInstance . getEdges ( ) . map ( ( edge ) => {
117130 return {
@@ -251,43 +264,51 @@ const Flow = ({ tab, collectionId }) => {
251264 classes = { 'absolute bottom-4 right-20 z-[2000] text-xl' }
252265 btnType = { BUTTON_TYPES . primary }
253266 isDisabled = { false }
254- onClickHandle = { async ( ) => {
255- runnableEdges ( true ) ;
256- const startTime = Date . now ( ) ;
257- const logger = new GraphLogger ( ) ;
258- try {
259- let envVariables = { } ;
260-
261- const activeCollection = useCollectionStore . getState ( ) . collections . find ( ( c ) => c . id === collectionId ) ;
262- const activeEnv = activeCollection ?. environments . find (
263- ( e ) => e . name === useTabStore . getState ( ) . selectedEnv ,
264- ) ;
265- if ( activeEnv ) {
266- envVariables = cloneDeep ( activeEnv . variables ) ;
267- }
268-
269- // ============= flow =====================
270- const g = new Graph (
271- cloneDeep ( reactFlowInstance . getNodes ( ) ) ,
272- cloneDeep ( reactFlowInstance . getEdges ( ) ) ,
273- startTime ,
274- envVariables ,
275- logger ,
276- 'main' ,
277- activeCollection . pathname ,
278- ) ;
279- const result = await g . run ( ) ;
280- const time = Date . now ( ) - startTime ;
281- logger . add ( LogLevel . INFO , `Total time: ${ time } ms` ) ;
282- await onGraphComplete ( result . status , time , logger . get ( ) ) ;
283- } catch ( error ) {
284- const time = Date . now ( ) - startTime ;
285- logger . add ( LogLevel . INFO , `Total time: ${ time } ms` ) ;
286- await onGraphComplete ( 'Failed' , time , logger . get ( ) ) ;
287- toast . error ( `Internal error running graph` ) ;
288- runnableEdges ( false ) ;
289- }
267+ onClickHandle = { ( ) => {
268+ const activeCollection = useCollectionStore . getState ( ) . collections . find ( ( c ) => c . id === collectionId ) ;
269+ const activeEnv = activeCollection ?. environments . find ( ( e ) => e . name === useTabStore . getState ( ) . selectedEnv ) ;
270+ const nodes = cloneDeep ( reactFlowInstance . getNodes ( ) ) ;
271+ const edges = cloneDeep ( reactFlowInstance . getEdges ( ) ) ;
272+
273+ graphRun ( tab , nodes , edges , activeCollection ?. pathname , activeEnv ) ;
290274 } }
275+ // onClickHandle={async () => {
276+ // runnableEdges(true);
277+ // const startTime = Date.now();
278+ // const logger = new GraphLogger();
279+ // try {
280+ // let envVariables = {};
281+
282+ // const activeCollection = useCollectionStore.getState().collections.find((c) => c.id === collectionId);
283+ // const activeEnv = activeCollection?.environments.find(
284+ // (e) => e.name === useTabStore.getState().selectedEnv,
285+ // );
286+ // if (activeEnv) {
287+ // envVariables = cloneDeep(activeEnv.variables);
288+ // }
289+
290+ // // ============= flow =====================
291+ // const g = new Graph(
292+ // cloneDeep(reactFlowInstance.getNodes()),
293+ // cloneDeep(reactFlowInstance.getEdges()),
294+ // startTime,
295+ // envVariables,
296+ // logger,
297+ // 'main',
298+ // activeCollection.pathname,
299+ // );
300+ // const result = await g.run();
301+ // const time = Date.now() - startTime;
302+ // logger.add(LogLevel.INFO, `Total time: ${time} ms`);
303+ // await onGraphComplete(result.status, time, logger.get());
304+ // } catch (error) {
305+ // const time = Date.now() - startTime;
306+ // logger.add(LogLevel.INFO, `Total time: ${time} ms`);
307+ // await onGraphComplete('Failed', time, logger.get());
308+ // toast.error(`Internal error running graph`);
309+ // runnableEdges(false);
310+ // }
311+ // }}
291312 fullWidth = { false }
292313 >
293314 Run
0 commit comments