feat: support arrays in flows

This commit is contained in:
Ali BARIN
2024-07-29 11:33:36 +00:00
parent 02a872a376
commit 920a711c00
2 changed files with 33 additions and 7 deletions

View File

@@ -11,6 +11,7 @@ export default function computeParameters(parameters, executionSteps) {
const computedValue = parts
.map((part) => {
const isVariable = part.match(variableRegExp);
if (isVariable) {
const stepIdAndKeyPath = part.replace(/{{step.|}}/g, '');
const [stepId, ...keyPaths] = stepIdAndKeyPath.split('.');
@@ -20,17 +21,32 @@ export default function computeParameters(parameters, executionSteps) {
});
const data = executionStep?.dataOut;
const dataValue = get(data, keyPath);
// Covers both arrays and objects
if (typeof dataValue === 'object') {
return JSON.stringify(dataValue);
}
return dataValue;
}
return part;
})
.join('');
}).join('');
return {
...result,
[key]: computedValue,
};
// challenge the input to see if it is stringifies object or array
try {
const parsedValue = JSON.parse(computedValue);
return {
...result,
[key]: parsedValue,
};
} catch (error) {
return {
...result,
[key]: computedValue,
};
}
}
if (Array.isArray(value)) {