Skip to content

Commit 2f4f2a9

Browse files
committed
Add a variable of type now() that gives current timestamp
1 parent 9bf0e32 commit 2f4f2a9

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ class assertNode extends Node {
1414

1515
getVariableValue(variable) {
1616
if (variable.type.toLowerCase() === 'variable') {
17-
const varValue = this.envVariables[variable.value];
18-
if (varValue) {
19-
return varValue;
17+
if (Object.prototype.hasOwnProperty.call(this.envVariables, variable.value)) {
18+
return this.envVariables[variable.value];
2019
} else {
2120
throw Error(`Cannot find value of variable ${variable.value}`);
2221
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,15 @@ class requestNode extends Node {
2020
...this.envVariables,
2121
...evalVariables,
2222
};
23+
console.debug('Avialable variables: ', variablesDict);
2324

2425
// step2 replace variables in url with value
2526
const finalUrl = computeVariables(this.nodeData.url, variablesDict);
27+
console.debug('Evaluated Url: ', finalUrl);
2628

2729
// step 3
2830
const options = this.formulateRequest(finalUrl, variablesDict);
2931

30-
console.debug('Avialable variables: ', variablesDict);
31-
console.debug('Evaluated Url: ', finalUrl);
32-
3332
const res = await this.runHttpRequest(options);
3433

3534
if (res.error) {

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
export const computeNodeVariable = (variable, prevNodeOutputData) => {
22
if (variable.type.toLowerCase() === 'string') {
3-
return variable.value;
3+
return variable.value.toString();
44
}
55

66
if (variable.type.toLowerCase() === 'number') {
7-
return variable.value;
7+
return Number(variable.value);
88
}
99

10-
if (variable.type.toLowerCase() === 'bool') {
10+
if (variable.type.toLowerCase() === 'boolean') {
1111
return Boolean(variable.value);
1212
}
1313

14+
if (variable.type.toLowerCase() === 'now') {
15+
return Date.now();
16+
}
17+
1418
if (variable.type.toLowerCase() === 'select') {
1519
try {
1620
if (prevNodeOutputData == undefined || Object.keys(prevNodeOutputData).length === 0) {
@@ -61,8 +65,8 @@ export const computeVariables = (str, variablesDict) => {
6165
if (foundRegex) {
6266
const match = str.match(/{{([^}]+)}}/);
6367
if (variablesDict) {
64-
const varValue = variablesDict[`${match[1]}`];
65-
if (varValue) {
68+
if (Object.prototype.hasOwnProperty.call(variablesDict, match[1])) {
69+
const varValue = variablesDict[`${match[1]}`];
6670
return computeVariables(str.replaceAll(match[0], varValue), variablesDict);
6771
} else {
6872
throw Error(`Cannot find value of variable ${match[1]}`);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ const RequestNode = ({ id, data }) => {
6868
<option value='true'>True</option>
6969
<option value='false'>False</option>
7070
</select>
71+
) : variables[id].type === 'Now' ? (
72+
<div></div>
7173
) : (
7274
<input
7375
type={getInputType(variables[id].type)}

src/components/molecules/modals/flow/AddVariableModal.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ const variableTypes = [
2020
value: 'Boolean',
2121
label: 'Boolean',
2222
},
23+
{
24+
value: 'Now',
25+
label: 'Now',
26+
},
2327
];
2428

2529
const AddVariableModal = ({ closeFn = () => null, open = false, modalType, onVariableAdd }) => {
@@ -57,7 +61,7 @@ const AddVariableModal = ({ closeFn = () => null, open = false, modalType, onVar
5761
as='h3'
5862
className='pb-4 text-lg font-semibold text-center text-gray-900 border-b border-neutral-300'
5963
>
60-
Create a new variable for request node
64+
Create a new variable
6165
</Dialog.Title>
6266
<div className='mt-6 flex w-24 min-w-[40vw] items-center justify-center rounded-md border border-neutral-500 text-sm text-neutral-500 outline-0 focus:ring-0'>
6367
<input

0 commit comments

Comments
 (0)