Merge pull request #1996 from automatisch/support-arrays-in-flows

feat: support arrays in flows
This commit is contained in:
Ömer Faruk Aydın
2024-07-30 13:26:56 +02:00
committed by GitHub
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,18 +21,33 @@ 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('');
// 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)) {
return {

View File

@@ -19,7 +19,13 @@ const process = ({ data, parentKey, index, parentLabel = '' }) => {
const value = joinBy('.', parentKey, index?.toString(), name);
if (Array.isArray(sampleValue)) {
return sampleValue.flatMap((item, index) =>
const arrayItself = {
label,
value,
sampleValue: JSON.stringify(sampleValue),
};
const arrayItems = sampleValue.flatMap((item, index) =>
process({
data: item,
parentKey: value,
@@ -27,6 +33,9 @@ const process = ({ data, parentKey, index, parentLabel = '' }) => {
parentLabel: label,
}),
);
// TODO: remove spreading
return [arrayItself, ...arrayItems];
}
if (typeof sampleValue === 'object' && sampleValue !== null) {
@@ -36,6 +45,7 @@ const process = ({ data, parentKey, index, parentLabel = '' }) => {
parentLabel: label,
});
}
return [
{
label,