Skip to content

Commit 9bf0e32

Browse files
authored
Merge pull request #75 from FlowTestAI/minor-improvements-1
Minor improvements
2 parents 345af8e + a070633 commit 9bf0e32

File tree

7 files changed

+45
-11
lines changed

7 files changed

+45
-11
lines changed

src/components/molecules/flow/graph/Graph.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,30 @@ class Graph {
7070
useCanvasStore.getState().setOutputNode(node.id, prevNodeOutputData);
7171
result = {
7272
status: 'Success',
73+
data: prevNodeOutputData,
7374
};
7475
}
7576

7677
if (node.type === 'assertNode') {
77-
const eNode = new assertNode(node.data.operator, node.data.variables, prevNodeOutputData, this.logs);
78+
const eNode = new assertNode(
79+
node.data.operator,
80+
node.data.variables,
81+
prevNodeOutputData,
82+
this.envVariables,
83+
this.logs,
84+
);
7885
if (eNode.evaluate()) {
7986
this.logs.push('Result: true');
8087
result = {
8188
status: 'Success',
89+
data: prevNodeOutputData,
8290
output: true,
8391
};
8492
} else {
8593
this.logs.push('Result: false');
8694
result = {
8795
status: 'Success',
96+
data: prevNodeOutputData,
8897
output: false,
8998
};
9099
}

src/components/molecules/flow/graph/compute/assertnode.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
11
import Operators from '../../constants/operators';
2-
import { computeNodeVariables } from './utils';
2+
import { computeNodeVariable } from './utils';
33
import Node from './node';
44

55
class assertNode extends Node {
6-
constructor(operator, variables, prevNodeOutputData, logs) {
6+
constructor(operator, variables, prevNodeOutputData, envVariables, logs) {
77
super('assertNode');
88
this.operator = operator;
99
this.variables = variables;
1010
this.prevNodeOutputData = prevNodeOutputData;
1111
this.logs = logs;
12+
this.envVariables = envVariables;
13+
}
14+
15+
getVariableValue(variable) {
16+
if (variable.type.toLowerCase() === 'variable') {
17+
const varValue = this.envVariables[variable.value];
18+
if (varValue) {
19+
return varValue;
20+
} else {
21+
throw Error(`Cannot find value of variable ${variable.value}`);
22+
}
23+
} else {
24+
return computeNodeVariable(variable, this.prevNodeOutputData);
25+
}
1226
}
1327

1428
evaluate() {
1529
console.log('Evaluating an assert node');
16-
const evalVariables = computeNodeVariables(this.variables, this.prevNodeOutputData);
17-
const var1 = evalVariables.var1;
18-
const var2 = evalVariables.var2;
30+
const var1 = this.getVariableValue(this.variables.var1);
31+
const var2 = this.getVariableValue(this.variables.var2);
1932

2033
const operator = this.operator;
2134
if (operator == undefined) {

src/components/molecules/flow/graph/compute/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const computeNodeVariable = (variable, prevNodeOutputData) => {
1+
export const computeNodeVariable = (variable, prevNodeOutputData) => {
22
if (variable.type.toLowerCase() === 'string') {
33
return variable.value;
44
}

src/components/molecules/flow/nodes/AssertNode.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ const variableElem = (id, data, varName) => {
5151
case 'Select':
5252
setAssertNodeVariable(id, varName, selectedValue, '');
5353
break;
54+
case 'Variable':
55+
setAssertNodeVariable(id, varName, selectedValue, '');
56+
break;
5457
case 'Number':
5558
setAssertNodeVariable(id, varName, selectedValue, 0);
5659
break;
@@ -98,6 +101,11 @@ const variableElem = (id, data, varName) => {
98101
// setVariableValue(updatedValue.toString());
99102
setAssertNodeVariable(id, varName, 'Select', updatedValue.toString());
100103
break;
104+
case 'Variable':
105+
// data.variables[varName].value = updatedValue.toString();
106+
// setVariableValue(updatedValue.toString());
107+
setAssertNodeVariable(id, varName, 'Variable', updatedValue.toString());
108+
break;
101109
case 'Number':
102110
// data.variables[varName].value = parseInt(updatedValue);
103111
// setVariableValue(parseInt(updatedValue));
@@ -131,6 +139,7 @@ const variableElem = (id, data, varName) => {
131139
>
132140
<option value='Select'>Select</option>
133141
<option value='String'>String</option>
142+
<option value='Variable'>Variable</option>
134143
<option value='Number'>Number</option>
135144
<option value='Boolean'>Boolean</option>
136145
</select>

src/components/molecules/flow/nodes/OutputNode.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ import { PropTypes } from 'prop-types';
33
import FlowNode from 'components/atoms/flow/FlowNode';
44

55
const OutputNode = ({ id, data }) => {
6-
console.log('output node id: ', id);
7-
console.log('output node data: ', data);
8-
96
return (
107
<FlowNode
118
title='Output'

src/components/molecules/flow/utils.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ export const initFlowData = {
100100
x: 400,
101101
y: 150,
102102
},
103-
deletable: false,
104103
width: 147,
105104
height: 107,
106105
},

src/stores/CanvasStore.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ const useCanvasStore = create((set, get) => ({
7474
return node;
7575
}),
7676
});
77+
useTabStore.getState().updateFlowTestNodes(get().nodes);
7778
},
7879
setRequestNodeUrl: (nodeId, url) => {
7980
set({
@@ -89,6 +90,7 @@ const useCanvasStore = create((set, get) => ({
8990
return node;
9091
}),
9192
});
93+
useTabStore.getState().updateFlowTestNodes(get().nodes);
9294
},
9395
requestNodeAddPreRequestVar: (nodeId, name, type) => {
9496
set({
@@ -152,6 +154,7 @@ const useCanvasStore = create((set, get) => ({
152154
return node;
153155
}),
154156
});
157+
useTabStore.getState().updateFlowTestNodes(get().nodes);
155158
},
156159
requestNodeAddPostResponseVar: (nodeId, name, type) => {
157160
set({
@@ -215,6 +218,7 @@ const useCanvasStore = create((set, get) => ({
215218
return node;
216219
}),
217220
});
221+
useTabStore.getState().updateFlowTestNodes(get().nodes);
218222
},
219223
setRequestNodeBody: (nodeId, type, data) => {
220224
set({
@@ -253,6 +257,7 @@ const useCanvasStore = create((set, get) => ({
253257
return node;
254258
}),
255259
});
260+
useTabStore.getState().updateFlowTestNodes(get().nodes);
256261
},
257262
setAssertNodeVariable: (nodeId, name, type, value) => {
258263
set({
@@ -274,6 +279,7 @@ const useCanvasStore = create((set, get) => ({
274279
return node;
275280
}),
276281
});
282+
useTabStore.getState().updateFlowTestNodes(get().nodes);
277283
},
278284
setAssertNodeOperator: (nodeId, operator) => {
279285
set({
@@ -304,6 +310,7 @@ const useCanvasStore = create((set, get) => ({
304310
return node;
305311
}),
306312
});
313+
useTabStore.getState().updateFlowTestNodes(get().nodes);
307314
},
308315
setOutputNode: (nodeId, output) => {
309316
set({

0 commit comments

Comments
 (0)