From 8584690c3268dc691b94d83721d8757719a7e12e Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sat, 7 Sep 2024 22:19:58 +0530 Subject: [PATCH] fix: handle attribute selection in getList --- src/components/organisms/BrowserWindow.tsx | 39 ++++++++++++---------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/src/components/organisms/BrowserWindow.tsx b/src/components/organisms/BrowserWindow.tsx index 08c2d674..5abd81d3 100644 --- a/src/components/organisms/BrowserWindow.tsx +++ b/src/components/organisms/BrowserWindow.tsx @@ -203,27 +203,32 @@ export const BrowserWindow = () => { setCurrentListId(Date.now()); setFields({}); } else if (getList === true && listSelector && currentListId) { + const attribute = options[0].value; + const data = attribute === 'href' ? highlighterData.elementInfo?.url || '' : + attribute === 'src' ? highlighterData.elementInfo?.imageUrl || '' : + highlighterData.elementInfo?.innerText || ''; // Add fields to the list if (options.length === 1) { const attribute = options[0].value; - const data = attribute === 'href' ? highlighterData.elementInfo?.url || '' : - attribute === 'src' ? highlighterData.elementInfo?.imageUrl || '' : - highlighterData.elementInfo?.innerText || ''; const newField: TextStep = { - id: Date.now(), - type: 'text', - label: `Label ${Object.keys(fields).length + 1}`, - data: data, - selectorObj: { - selector: highlighterData.selector, - tag: highlighterData.elementInfo?.tagName, - attribute - } - }; + const newField: TextStep = { + id: Date.now(), + type: 'text', + label: `Label ${Object.keys(fields).length + 1}`, + data: data, + selectorObj: { + selector: highlighterData.selector, + tag: highlighterData.elementInfo?.tagName, + attribute + } + }; - setFields(prevFields => ({ - ...prevFields, - [newField.label]: newField - })); + setFields(prevFields => { + const updatedFields = { + ...prevFields, + [newField.label]: newField + }; + return updatedFields; + }); if (listSelector) { addListStep(listSelector, { ...fields, [newField.label]: newField }, currentListId, { type: '', selector: paginationSelector });