Skip to content

Commit f1b1d8f

Browse files
committed
output and delay node use canvas store to push updates
1 parent 09678a5 commit f1b1d8f

File tree

5 files changed

+51
-18
lines changed

5 files changed

+51
-18
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// assumption is that apis are giving json as output
22

3+
import useCanvasStore from 'stores/CanvasStore';
34
import useCollectionStore from 'stores/CollectionStore';
45
import { useTabStore } from 'stores/TabStore';
56
import { computeAuthNode } from './compute/authnode';
@@ -69,7 +70,7 @@ class Graph {
6970

7071
if (node.type === 'outputNode') {
7172
this.logs.push(`Output: ${JSON.stringify(prevNodeOutputData)}`);
72-
node.data.setOutput(prevNodeOutputData);
73+
useCanvasStore.getState().setOutputNode(node.id, prevNodeOutputData);
7374
result = ['Success', node, prevNodeOutput];
7475
}
7576

@@ -94,7 +95,7 @@ class Graph {
9495
}
9596

9697
if (node.type === 'authNode') {
97-
this.auth = computeAuthNode(node.data.auth, this.env);
98+
this.auth = node.data.type ? computeAuthNode(node.data, this.env) : undefined;
9899
result = ['Success', node, prevNodeOutput];
99100
}
100101

@@ -134,7 +135,7 @@ class Graph {
134135
// reset every output node for a fresh run
135136
this.nodes.forEach((node) => {
136137
if (node.type === 'outputNode') {
137-
node.data.setOutput(undefined);
138+
useCanvasStore.getState().unSetOutputNode(node.id);
138139
}
139140
});
140141
this.graphRunNodeOutput = {};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const formulateRequest = (node, finalUrl, variablesDict, auth, logs) => {
3838
data: requestData,
3939
};
4040

41-
if (auth.type === 'basic-auth') {
41+
if (auth && auth.type === 'basic-auth') {
4242
options.auth = {};
4343
options.auth.username = auth.username;
4444
options.auth.password = auth.password;

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
import * as React from 'react';
22
import { PropTypes } from 'prop-types';
33
import FlowNode from 'components/atoms/flow/FlowNode';
4+
import useCanvasStore from 'stores/CanvasStore';
45

5-
/**
6-
* I have commented the code which is not required but do check it once
7-
*/
8-
const DelayNode = ({ data }) => {
9-
const [value, setValue] = React.useState(data.delay ? data.delay : 0);
10-
data.delay = value;
6+
const DelayNode = ({ id, data }) => {
7+
const setDelayNodeValue = useCanvasStore((state) => state.setDelayNodeValue);
118

129
/**
1310
* ToDo: Implement Debouncing for this function
1411
*/
1512
const handleDelayInMsInputChange = (event) => {
1613
event.preventDefault();
17-
const delayInMs = event.target.value;
18-
setValue(delayInMs);
14+
setDelayNodeValue(id, event.target.value);
1915
};
2016

2117
return (

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ import * as React from 'react';
22
import { PropTypes } from 'prop-types';
33
import FlowNode from 'components/atoms/flow/FlowNode';
44

5-
const OutputNode = ({ data }) => {
6-
const [output, setOutput] = React.useState(undefined);
7-
8-
data.setOutput = setOutput;
9-
5+
const OutputNode = ({ id, data }) => {
106
return (
117
<FlowNode
128
title='Output'
@@ -18,7 +14,7 @@ const OutputNode = ({ data }) => {
1814
<div>
1915
<textarea
2016
name='output-text'
21-
value={output ? JSON.stringify(output, undefined, 4) : 'Run flow to see data'}
17+
value={data.output ? JSON.stringify(data.output, undefined, 4) : 'Run flow to see data'}
2218
placeholder='Run flow to see data'
2319
className='nodrag nowheel min-h-80 w-full min-w-60 rounded-lg border border-gray-300 bg-gray-50 p-2.5 text-xs text-gray-900 outline-blue-300 focus:border-blue-100 focus:ring-blue-100'
2420
/>

src/stores/CanvasStore.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,46 @@ const useCanvasStore = create((set, get) => ({
217217
};
218218
}
219219

220+
return node;
221+
}),
222+
});
223+
},
224+
setDelayNodeValue: (nodeId, value) => {
225+
set({
226+
nodes: get().nodes.map((node) => {
227+
if (node.id === nodeId) {
228+
// it's important to create a new object here, to inform React Flow about the cahnges
229+
node.data = {
230+
delay: value,
231+
};
232+
}
233+
234+
return node;
235+
}),
236+
});
237+
},
238+
setOutputNode: (nodeId, output) => {
239+
set({
240+
nodes: get().nodes.map((node) => {
241+
if (node.id === nodeId) {
242+
// it's important to create a new object here, to inform React Flow about the cahnges
243+
node.data = {
244+
output,
245+
};
246+
}
247+
248+
return node;
249+
}),
250+
});
251+
},
252+
unSetOutputNode: (nodeId) => {
253+
set({
254+
nodes: get().nodes.map((node) => {
255+
if (node.id === nodeId) {
256+
// it's important to create a new object here, to inform React Flow about the cahnges
257+
node.data = {};
258+
}
259+
220260
return node;
221261
}),
222262
});

0 commit comments

Comments
 (0)