From 55250c80767c0d6d5e898860de9ab9063ac2d10e Mon Sep 17 00:00:00 2001 From: Ahmad Kholid Date: Tue, 6 Feb 2024 12:20:58 +0800 Subject: [PATCH] feat: support number and string variable value in loop data block (#1631) --- .../blocksHandler/handlerLoopData.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/workflowEngine/blocksHandler/handlerLoopData.js b/src/workflowEngine/blocksHandler/handlerLoopData.js index 073aa6e61..746c8df33 100644 --- a/src/workflowEngine/blocksHandler/handlerLoopData.js +++ b/src/workflowEngine/blocksHandler/handlerLoopData.js @@ -29,14 +29,29 @@ async function loopData({ data, id }, { refData }) { 'data-columns': () => refData.table, 'google-sheets': () => refData.googleSheets[data.referenceKey], variable: () => { - const variableVal = objectPath.get( + let variableVal = objectPath.get( refData.variables, data.variableName ); if (Array.isArray(variableVal)) return variableVal; - return parseJSON(variableVal, variableVal); + variableVal = parseJSON(variableVal, variableVal); + + switch (typeof variableVal) { + case 'string': + variableVal = variableVal.split(''); + break; + case 'number': + variableVal = Array.from( + { length: variableVal }, + (_, index) => index + 1 + ); + break; + default: + } + + return variableVal; }, elements: async () => { const findBy = isXPath(data.elementSelector)