From b452ed648c7c994b520e80f14eafd5ab6b2bf1f5 Mon Sep 17 00:00:00 2001 From: Ali BARIN Date: Fri, 16 Aug 2024 13:22:31 +0000 Subject: [PATCH] feat(PowerInput): support whole objects as variables --- .../web/src/components/PowerInput/data.js | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/packages/web/src/components/PowerInput/data.js b/packages/web/src/components/PowerInput/data.js index df9ea7df..ea0f9470 100644 --- a/packages/web/src/components/PowerInput/data.js +++ b/packages/web/src/components/PowerInput/data.js @@ -25,25 +25,40 @@ const process = ({ data, parentKey, index, parentLabel = '' }) => { sampleValue: JSON.stringify(sampleValue), }; - const arrayItems = sampleValue.flatMap((item, index) => - process({ + const arrayItems = sampleValue.flatMap((item, index) => { + const itemItself = { + label: `${label}.${index}`, + value: `${value}.${index}`, + sampleValue: JSON.stringify(item), + }; + + const itemEntries = process({ data: item, parentKey: value, index, parentLabel: label, - }), - ); + }); - // TODO: remove spreading - return [arrayItself, ...arrayItems]; + return [itemItself].concat(itemEntries); + }); + + return [arrayItself].concat(arrayItems); } if (typeof sampleValue === 'object' && sampleValue !== null) { - return process({ + const objectItself = { + label, + value, + sampleValue: JSON.stringify(sampleValue), + }; + + const objectEntries = process({ data: sampleValue, parentKey: value, parentLabel: label, }); + + return [objectItself].concat(objectEntries); } return [