Skip to content

feat: change pagination selector used for scrape list #318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions server/src/workflow-management/classes/Generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export class WorkflowGenerator {
*/
private getList: boolean = false;

private paginationMode: boolean = false;

private listSelector: string = '';

/**
Expand Down Expand Up @@ -120,6 +122,9 @@ export class WorkflowGenerator {
this.socket.on('listSelector', (data: { selector: string }) => {
this.listSelector = data.selector;
})
this.socket.on('setPaginationMode', (data: { paginationMode: boolean }) => {
this.paginationMode = data.paginationMode;
})
}

/**
Expand Down Expand Up @@ -703,6 +708,25 @@ export class WorkflowGenerator {
? await getNonUniqueSelectors(page, coordinates, this.listSelector)
: await getSelectors(page, coordinates);

if (this.paginationMode) {
if (selectorBasedOnCustomAction.hrefSelector) {
// Look for pagination-specific parameters that would make the selector unreliable
const isOverlySpecific = (
selectorBasedOnCustomAction.hrefSelector.includes('page=') ||
selectorBasedOnCustomAction.hrefSelector.includes('offset=') ||
selectorBasedOnCustomAction.hrefSelector.includes('start=') ||
/p=\d+/.test(selectorBasedOnCustomAction.hrefSelector)
);

// If the href selector is too specific for pagination, try the other selector
if (isOverlySpecific) {
selectorBasedOnCustomAction.hrefSelector = null;
selectorBasedOnCustomAction.accessibilitySelector = null;
selectorBasedOnCustomAction.generalSelector = null;
}
}
}

Comment on lines +711 to +729
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Validate fallback logic for overly specific pagination selectors.
By nullifying all selectors when isOverlySpecific is true, you might lose valuable fallback selectors that aren't pagination-related. Consider a more selective approach—e.g., nullifying only the hrefSelector and leaving other viable selectors intact if they do not contain pagination parameters.

-            selectorBasedOnCustomAction.hrefSelector = null;
-            selectorBasedOnCustomAction.accessibilitySelector = null;
-            selectorBasedOnCustomAction.generalSelector = null;
+            selectorBasedOnCustomAction.hrefSelector = null;
+            // Instead, leave other selectors intact to allow for fallback usage:
+            // e.g. if (isOverlySpecificHref) { preserve accessibilitySelector; preserve generalSelector; }

Committable suggestion skipped: line range outside the PR's diff.

const bestSelector = getBestSelectorForAction(
{
type: action,
Expand All @@ -715,6 +739,7 @@ export class WorkflowGenerator {
hasOnlyText: elementInfo?.hasOnlyText || false,
} as Action,
);

return bestSelector;
}

Expand Down
1 change: 1 addition & 0 deletions src/components/organisms/BrowserWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ export const BrowserWindow = () => {
notify(`info`, t('browser_window.attribute_modal.notifications.pagination_select_success'));
addListStep(listSelector!, fields, currentListId || 0, { type: paginationType, selector: highlighterData.selector });
}
socket?.emit('setPaginationMode', { paginationMode: false });
return;
}

Expand Down
1 change: 1 addition & 0 deletions src/context/browserActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const ActionProvider = ({ children }: { children: ReactNode }) => {
setPaginationMode(true);
setCaptureStage('pagination');
socket?.emit('setGetList', { getList: false });
socket?.emit('setPaginationMode', { paginationMode: true });
};

const stopPaginationMode = () => setPaginationMode(false);
Expand Down