feat: add bottom up get selectors logic
This commit is contained in:
@@ -142,31 +142,23 @@ export default class Interpreter extends EventEmitter {
|
|||||||
// return selectors;
|
// return selectors;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
private getSelectors(workflow: Workflow, actionId: number): string[] {
|
private getSelectors(workflow: Workflow): string[] {
|
||||||
const selectors: string[] = [];
|
const selectorsSet = new Set<string>();
|
||||||
|
|
||||||
// Validate actionId
|
if (workflow.length === 0) {
|
||||||
if (actionId <= 0) {
|
return [];
|
||||||
console.log("No previous selectors to collect.");
|
|
||||||
return selectors; // Empty array as there are no previous steps
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate from the start up to (but not including) actionId
|
for (let index = workflow.length - 1; index >= 0; index--) {
|
||||||
for (let index = 0; index < actionId; index++) {
|
|
||||||
const currentSelectors = workflow[index]?.where?.selectors;
|
const currentSelectors = workflow[index]?.where?.selectors;
|
||||||
console.log(`Selectors at step ${index}:`, currentSelectors);
|
|
||||||
|
|
||||||
if (currentSelectors && currentSelectors.length > 0) {
|
if (currentSelectors && currentSelectors.length > 0) {
|
||||||
currentSelectors.forEach((selector) => {
|
currentSelectors.forEach((selector) => selectorsSet.add(selector));
|
||||||
if (!selectors.includes(selector)) {
|
return Array.from(selectorsSet);
|
||||||
selectors.push(selector); // Avoid duplicates
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Collected Selectors:", selectors);
|
return [];
|
||||||
return selectors;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -216,9 +208,8 @@ export default class Interpreter extends EventEmitter {
|
|||||||
// return [];
|
// return [];
|
||||||
// }),
|
// }),
|
||||||
// ).then((x) => x.flat());
|
// ).then((x) => x.flat());
|
||||||
const action = workflowCopy[workflowCopy.length - 1];
|
|
||||||
|
|
||||||
console.log("Next action:", action)
|
const action = workflowCopy[workflowCopy.length - 1];
|
||||||
|
|
||||||
let url: any = page.url();
|
let url: any = page.url();
|
||||||
|
|
||||||
@@ -709,10 +700,10 @@ export default class Interpreter extends EventEmitter {
|
|||||||
usedActions.push(action.id ?? 'undefined');
|
usedActions.push(action.id ?? 'undefined');
|
||||||
|
|
||||||
workflowCopy.splice(actionId, 1);
|
workflowCopy.splice(actionId, 1);
|
||||||
console.log(`Action with ID ${action.id} removed from the workflow copy.`);
|
console.log(`Action with ID ${actionId} removed from the workflow copy.`);
|
||||||
|
|
||||||
// const newSelectors = this.getPreviousSelectors(workflow, actionId);
|
// const newSelectors = this.getPreviousSelectors(workflow, actionId);
|
||||||
const newSelectors = this.getSelectors(workflowCopy, actionId);
|
const newSelectors = this.getSelectors(workflowCopy);
|
||||||
newSelectors.forEach(selector => {
|
newSelectors.forEach(selector => {
|
||||||
if (!selectors.includes(selector)) {
|
if (!selectors.includes(selector)) {
|
||||||
selectors.push(selector);
|
selectors.push(selector);
|
||||||
|
|||||||
Reference in New Issue
Block a user