Browse Source

fix: loop elements

Ahmad Kholid 3 years ago
parent
commit
9b24dc26e6

+ 1 - 0
src/background/workflow-engine/blocks-handler/handler-loop-data.js

@@ -37,6 +37,7 @@ async function loopData({ data, id, outputs }) {
         },
         elements: async () => {
           const elements = await this._sendMessageToTab({
+            blockId: id,
             isBlock: false,
             max: data.maxLoop,
             type: 'loop-elements',

+ 2 - 2
src/background/workflow-engine/engine.js

@@ -198,7 +198,7 @@ class WorkflowEngine {
       const endedTimestamp = Date.now();
       this.executeQueue();
 
-      if (!this.workflow.isTesting && this.saveLog) {
+      if (!this.workflow.isTesting) {
         const { name, id } = this.workflow;
 
         await this.logger.add({
@@ -207,7 +207,7 @@ class WorkflowEngine {
           message,
           id: this.id,
           workflowId: id,
-          history: this.history,
+          history: this.saveLog ? this.history : [],
           endedAt: endedTimestamp,
           parentLog: this.parentWorkflow,
           startedAt: this.startedTimestamp,

+ 8 - 3
src/content/index.js

@@ -1,5 +1,5 @@
 import browser from 'webextension-polyfill';
-import { finder } from '@medv/finder';
+import { nanoid } from 'nanoid';
 import { toCamelCase } from '@/utils/helper';
 import elementSelector from './element-selector';
 import executedBlock from './executed-block';
@@ -52,12 +52,17 @@ import blocksHandler from './blocks-handler';
           break;
         case 'loop-elements': {
           const selectors = [];
+          const attrId = nanoid(5);
           const elements = document.body.querySelectorAll(data.selector);
 
-          elements.forEach((el) => {
+          elements.forEach((el, index) => {
             if (data.max > 0 && selectors.length - 1 > data.max) return;
 
-            selectors.push(finder(el));
+            const attrName = 'automa-loop';
+            const attrValue = `${attrId}--${index}`;
+
+            el.setAttribute(attrName, attrValue);
+            selectors.push(`[${attrName}="${attrValue}"]`);
           });
 
           resolve(selectors);