Merge pull request #1996 from automatisch/support-arrays-in-flows
feat: support arrays in flows
This commit is contained in:
@@ -11,6 +11,7 @@ export default function computeParameters(parameters, executionSteps) {
|
|||||||
const computedValue = parts
|
const computedValue = parts
|
||||||
.map((part) => {
|
.map((part) => {
|
||||||
const isVariable = part.match(variableRegExp);
|
const isVariable = part.match(variableRegExp);
|
||||||
|
|
||||||
if (isVariable) {
|
if (isVariable) {
|
||||||
const stepIdAndKeyPath = part.replace(/{{step.|}}/g, '');
|
const stepIdAndKeyPath = part.replace(/{{step.|}}/g, '');
|
||||||
const [stepId, ...keyPaths] = stepIdAndKeyPath.split('.');
|
const [stepId, ...keyPaths] = stepIdAndKeyPath.split('.');
|
||||||
@@ -20,17 +21,32 @@ export default function computeParameters(parameters, executionSteps) {
|
|||||||
});
|
});
|
||||||
const data = executionStep?.dataOut;
|
const data = executionStep?.dataOut;
|
||||||
const dataValue = get(data, keyPath);
|
const dataValue = get(data, keyPath);
|
||||||
|
|
||||||
|
// Covers both arrays and objects
|
||||||
|
if (typeof dataValue === 'object') {
|
||||||
|
return JSON.stringify(dataValue);
|
||||||
|
}
|
||||||
|
|
||||||
return dataValue;
|
return dataValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return part;
|
return part;
|
||||||
})
|
}).join('');
|
||||||
.join('');
|
|
||||||
|
|
||||||
return {
|
// challenge the input to see if it is stringifies object or array
|
||||||
...result,
|
try {
|
||||||
[key]: computedValue,
|
const parsedValue = JSON.parse(computedValue);
|
||||||
};
|
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
[key]: parsedValue,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
[key]: computedValue,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Array.isArray(value)) {
|
if (Array.isArray(value)) {
|
||||||
|
@@ -19,7 +19,13 @@ const process = ({ data, parentKey, index, parentLabel = '' }) => {
|
|||||||
const value = joinBy('.', parentKey, index?.toString(), name);
|
const value = joinBy('.', parentKey, index?.toString(), name);
|
||||||
|
|
||||||
if (Array.isArray(sampleValue)) {
|
if (Array.isArray(sampleValue)) {
|
||||||
return sampleValue.flatMap((item, index) =>
|
const arrayItself = {
|
||||||
|
label,
|
||||||
|
value,
|
||||||
|
sampleValue: JSON.stringify(sampleValue),
|
||||||
|
};
|
||||||
|
|
||||||
|
const arrayItems = sampleValue.flatMap((item, index) =>
|
||||||
process({
|
process({
|
||||||
data: item,
|
data: item,
|
||||||
parentKey: value,
|
parentKey: value,
|
||||||
@@ -27,6 +33,9 @@ const process = ({ data, parentKey, index, parentLabel = '' }) => {
|
|||||||
parentLabel: label,
|
parentLabel: label,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// TODO: remove spreading
|
||||||
|
return [arrayItself, ...arrayItems];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof sampleValue === 'object' && sampleValue !== null) {
|
if (typeof sampleValue === 'object' && sampleValue !== null) {
|
||||||
@@ -36,6 +45,7 @@ const process = ({ data, parentKey, index, parentLabel = '' }) => {
|
|||||||
parentLabel: label,
|
parentLabel: label,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
label,
|
label,
|
||||||
|
Reference in New Issue
Block a user