Skip to content

Commit aa6a8d0

Browse files
committed
cleanup code
1 parent 33df65f commit aa6a8d0

3 files changed

Lines changed: 17 additions & 103 deletions

File tree

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,44 @@
1-
import useCollectionStore from 'stores/CollectionStore';
21
import GraphLogger, { LogLevel } from './GraphLogger';
32
import Graph from './Graph';
43
import { useTabStore } from 'stores/TabStore';
54
import { cloneDeep } from 'lodash';
65
import { uploadGraphRunLogs } from 'service/collection';
76
import { toast } from 'react-toastify';
87

8+
const postResult = async (tab, status, time, logs) => {
9+
const response = await uploadGraphRunLogs(tab.name, status, time, logs);
10+
useTabStore.getState().updateFlowTestLogs(tab.id, status, logs, response);
11+
useTabStore.getState().updateFlowTestRunStatus(tab.id, false);
12+
if (status == 'Success') {
13+
toast.success(`FlowTest Run Success!`);
14+
} else if (status == 'Failed') {
15+
toast.error(`FlowTest Run Failed!`);
16+
}
17+
};
18+
919
export const graphRun = async (tab, nodes, edges, timeout, collectionPath, selectedEnv) => {
1020
useTabStore.getState().updateFlowTestRunStatus(tab.id, true);
1121

12-
//runnableEdges(true);
1322
const startTime = Date.now();
1423
const logger = new GraphLogger();
1524
try {
1625
let envVariables = {};
1726

18-
//const activeCollection = useCollectionStore.getState().collections.find((c) => c.id === collectionId);
19-
//const activeEnv = activeCollection?.environments.find((e) => e.name === useTabStore.getState().selectedEnv);
2027
if (selectedEnv) {
2128
envVariables = cloneDeep(selectedEnv.variables);
2229
}
2330

2431
// ============= flow =====================
25-
const g = new Graph(
26-
nodes, //cloneDeep(reactFlowInstance.getNodes()),
27-
edges, //cloneDeep(reactFlowInstance.getEdges()),
28-
startTime,
29-
envVariables,
30-
logger,
31-
//'main',
32-
collectionPath,
33-
timeout,
34-
tab,
35-
);
32+
const g = new Graph(nodes, edges, startTime, envVariables, logger, collectionPath, timeout, tab);
3633
const result = await g.run();
3734
const time = Date.now() - startTime;
3835
logger.add(LogLevel.INFO, `Total time: ${time} ms`);
39-
//useTabStore.getState().updateFlowTestRunStatus(tab.id, false);
40-
const logs = logger.get();
41-
console.log(logs);
42-
const response = await uploadGraphRunLogs(tab.name, result.status, time, logs);
43-
useTabStore.getState().updateFlowTestLogs(tab.id, result.status, logs, response);
44-
useTabStore.getState().updateFlowTestRunStatus(tab.id, false);
45-
if (result.status == 'Success') {
46-
toast.success(`FlowTest Run Success!`);
47-
} else if (result.status == 'Failed') {
48-
toast.error(`FlowTest Run Failed!`);
49-
}
50-
//await onGraphComplete(result.status, time, logger.get());
36+
37+
await postResult(tab, result.status, time, logger.get());
5138
} catch (error) {
5239
const time = Date.now() - startTime;
40+
logger.add(LogLevel.ERROR, 'Internal error running graph');
5341
logger.add(LogLevel.INFO, `Total time: ${time} ms`);
54-
useTabStore.getState().updateFlowTestRunStatus(tab.id, false);
55-
//await onGraphComplete('Failed', time, logger.get());
56-
//toast.error(`Internal error running graph`);
57-
//runnableEdges(false);
42+
await postResult(tab, 'Failed', time, logger.get());
5843
}
5944
};

src/components/molecules/flow/index.js

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -113,28 +113,6 @@ const Flow = ({ tab, collectionId }) => {
113113
[],
114114
);
115115

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-
// }, [reactFlowInstance, tab.running]);
127-
128-
// const runnableEdges = (runnable) => {
129-
// const updatedEdges = reactFlowInstance.getEdges().map((edge) => {
130-
// return {
131-
// ...edge,
132-
// animated: runnable,
133-
// };
134-
// });
135-
// setEdges(updatedEdges);
136-
// };
137-
138116
const onDragOver = useCallback((event) => {
139117
event.preventDefault();
140118
event.dataTransfer.dropEffect = 'move';
@@ -207,18 +185,6 @@ const Flow = ({ tab, collectionId }) => {
207185
return true;
208186
};
209187

210-
// const onGraphComplete = async (status, time, logs) => {
211-
// const response = await uploadGraphRunLogs(tab.name, status, time, logs);
212-
// //console.log(response);
213-
// setLogs(tab.id, status, logs, response);
214-
// if (status == 'Success') {
215-
// toast.success(`FlowTest Run Success!`);
216-
// } else if (status == 'Failed') {
217-
// toast.error(`FlowTest Run Failed!`);
218-
// }
219-
// runnableEdges(false);
220-
// };
221-
222188
reactFlowInstance?.setViewport(viewport);
223189

224190
//const cmdAndSPressed = useKeyPress(['Meta+s', 'Strg+s', 'Ctrl+s']);
@@ -276,43 +242,6 @@ const Flow = ({ tab, collectionId }) => {
276242

277243
graphRun(tab, nodes, edges, timeout, activeCollection?.pathname, activeEnv);
278244
}}
279-
// onClickHandle={async () => {
280-
// runnableEdges(true);
281-
// const startTime = Date.now();
282-
// const logger = new GraphLogger();
283-
// try {
284-
// let envVariables = {};
285-
286-
// const activeCollection = useCollectionStore.getState().collections.find((c) => c.id === collectionId);
287-
// const activeEnv = activeCollection?.environments.find(
288-
// (e) => e.name === useTabStore.getState().selectedEnv,
289-
// );
290-
// if (activeEnv) {
291-
// envVariables = cloneDeep(activeEnv.variables);
292-
// }
293-
294-
// // ============= flow =====================
295-
// const g = new Graph(
296-
// cloneDeep(reactFlowInstance.getNodes()),
297-
// cloneDeep(reactFlowInstance.getEdges()),
298-
// startTime,
299-
// envVariables,
300-
// logger,
301-
// 'main',
302-
// activeCollection.pathname,
303-
// );
304-
// const result = await g.run();
305-
// const time = Date.now() - startTime;
306-
// logger.add(LogLevel.INFO, `Total time: ${time} ms`);
307-
// await onGraphComplete(result.status, time, logger.get());
308-
// } catch (error) {
309-
// const time = Date.now() - startTime;
310-
// logger.add(LogLevel.INFO, `Total time: ${time} ms`);
311-
// await onGraphComplete('Failed', time, logger.get());
312-
// toast.error(`Internal error running graph`);
313-
// runnableEdges(false);
314-
// }
315-
// }}
316245
fullWidth={false}
317246
>
318247
Run

src/components/molecules/sideSheets/FlowLogs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ const FlowLogs = ({ logsData }) => {
9494
<div>{renderFlowScan(logsData.run.scan)}</div>
9595
<div className='mt-4 flex flex-col rounded-md border-2 border-slate-300 bg-background-light text-cyan-900 shadow-sm'>
9696
<h2 className='border-b-2 border-slate-300 px-4 py-2 text-2xl font-medium'>
97-
<div className='flex flex-row'>
97+
<div className='flex flex-row items-center gap-2'>
9898
Logs
9999
{logsData.run.status === 'Success' ? (
100100
<CheckCircleIcon className='h-5 w-5' />

0 commit comments

Comments
 (0)