feat: add isShadow field browser steps
This commit is contained in:
@@ -5,8 +5,9 @@ export interface TextStep {
|
|||||||
type: 'text';
|
type: 'text';
|
||||||
label: string;
|
label: string;
|
||||||
data: string;
|
data: string;
|
||||||
|
isShadow?: boolean;
|
||||||
selectorObj: SelectorObject;
|
selectorObj: SelectorObject;
|
||||||
actionId?: string;
|
actionId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ScreenshotStep {
|
interface ScreenshotStep {
|
||||||
@@ -14,20 +15,22 @@ interface ScreenshotStep {
|
|||||||
type: 'screenshot';
|
type: 'screenshot';
|
||||||
fullPage: boolean;
|
fullPage: boolean;
|
||||||
actionId?: string;
|
actionId?: string;
|
||||||
screenshotData?: string;
|
screenshotData?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ListStep {
|
export interface ListStep {
|
||||||
id: number;
|
id: number;
|
||||||
type: 'list';
|
type: 'list';
|
||||||
listSelector: string;
|
listSelector: string;
|
||||||
|
isShadow?: boolean;
|
||||||
fields: { [key: string]: TextStep };
|
fields: { [key: string]: TextStep };
|
||||||
pagination?: {
|
pagination?: {
|
||||||
type: string;
|
type: string;
|
||||||
selector: string;
|
selector: string;
|
||||||
|
isShadow?: boolean;
|
||||||
};
|
};
|
||||||
limit?: number;
|
limit?: number;
|
||||||
actionId?: string;
|
actionId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type BrowserStep = TextStep | ScreenshotStep | ListStep;
|
export type BrowserStep = TextStep | ScreenshotStep | ListStep;
|
||||||
@@ -36,14 +39,14 @@ export interface SelectorObject {
|
|||||||
selector: string;
|
selector: string;
|
||||||
tag?: string;
|
tag?: string;
|
||||||
attribute?: string;
|
attribute?: string;
|
||||||
shadow?: boolean;
|
isShadow?: boolean;
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface BrowserStepsContextType {
|
interface BrowserStepsContextType {
|
||||||
browserSteps: BrowserStep[];
|
browserSteps: BrowserStep[];
|
||||||
addTextStep: (label: string, data: string, selectorObj: SelectorObject, actionId: string) => void;
|
addTextStep: (label: string, data: string, selectorObj: SelectorObject, actionId: string) => void;
|
||||||
addListStep: (listSelector: string, fields: { [key: string]: TextStep }, listId: number, actionId: string, pagination?: { type: string; selector: string }, limit?: number) => void
|
addListStep: (listSelector: string, fields: { [key: string]: TextStep }, listId: number, actionId: string, pagination?: { type: string; selector: string, isShadow?: boolean }, limit?: number, isShadow?: boolean) => void
|
||||||
addScreenshotStep: (fullPage: boolean, actionId: string) => void;
|
addScreenshotStep: (fullPage: boolean, actionId: string) => void;
|
||||||
deleteBrowserStep: (id: number) => void;
|
deleteBrowserStep: (id: number) => void;
|
||||||
updateBrowserTextStepLabel: (id: number, newLabel: string) => void;
|
updateBrowserTextStepLabel: (id: number, newLabel: string) => void;
|
||||||
@@ -51,7 +54,7 @@ interface BrowserStepsContextType {
|
|||||||
updateListStepLimit: (listId: number, limit: number) => void;
|
updateListStepLimit: (listId: number, limit: number) => void;
|
||||||
updateListStepData: (listId: number, extractedData: any[]) => void;
|
updateListStepData: (listId: number, extractedData: any[]) => void;
|
||||||
removeListTextField: (listId: number, fieldKey: string) => void;
|
removeListTextField: (listId: number, fieldKey: string) => void;
|
||||||
deleteStepsByActionId: (actionId: string) => void;
|
deleteStepsByActionId: (actionId: string) => void;
|
||||||
updateScreenshotStepData: (id: number, screenshotData: string) => void;
|
updateScreenshotStepData: (id: number, screenshotData: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,14 +71,22 @@ export const BrowserStepsProvider: React.FC<{ children: React.ReactNode }> = ({
|
|||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
|
|
||||||
const addListStep = (listSelector: string, newFields: { [key: string]: TextStep }, listId: number, actionId: string, pagination?: { type: string; selector: string }, limit?: number) => {
|
const addListStep = (
|
||||||
|
listSelector: string,
|
||||||
|
newFields: { [key: string]: TextStep },
|
||||||
|
listId: number,
|
||||||
|
actionId: string,
|
||||||
|
pagination?: { type: string; selector: string; isShadow?: boolean },
|
||||||
|
limit?: number,
|
||||||
|
isShadow?: boolean
|
||||||
|
) => {
|
||||||
setBrowserSteps(prevSteps => {
|
setBrowserSteps(prevSteps => {
|
||||||
const existingListStepIndex = prevSteps.findIndex(step => step.type === 'list' && step.id === listId);
|
const existingListStepIndex = prevSteps.findIndex(step => step.type === 'list' && step.id === listId);
|
||||||
|
|
||||||
if (existingListStepIndex !== -1) {
|
if (existingListStepIndex !== -1) {
|
||||||
const updatedSteps = [...prevSteps];
|
const updatedSteps = [...prevSteps];
|
||||||
const existingListStep = updatedSteps[existingListStepIndex] as ListStep;
|
const existingListStep = updatedSteps[existingListStepIndex] as ListStep;
|
||||||
|
|
||||||
// Preserve existing labels for fields
|
// Preserve existing labels for fields
|
||||||
const mergedFields = Object.entries(newFields).reduce((acc, [key, field]) => {
|
const mergedFields = Object.entries(newFields).reduce((acc, [key, field]) => {
|
||||||
if (!discardedFields.has(`${listId}-${key}`)) {
|
if (!discardedFields.has(`${listId}-${key}`)) {
|
||||||
@@ -95,13 +106,14 @@ export const BrowserStepsProvider: React.FC<{ children: React.ReactNode }> = ({
|
|||||||
}
|
}
|
||||||
return acc;
|
return acc;
|
||||||
}, {} as { [key: string]: TextStep });
|
}, {} as { [key: string]: TextStep });
|
||||||
|
|
||||||
updatedSteps[existingListStepIndex] = {
|
updatedSteps[existingListStepIndex] = {
|
||||||
...existingListStep,
|
...existingListStep,
|
||||||
fields: mergedFields,
|
fields: mergedFields,
|
||||||
pagination: pagination || existingListStep.pagination,
|
pagination: pagination || existingListStep.pagination,
|
||||||
limit: limit,
|
limit: limit,
|
||||||
actionId
|
actionId,
|
||||||
|
isShadow: isShadow !== undefined ? isShadow : existingListStep.isShadow
|
||||||
};
|
};
|
||||||
return updatedSteps;
|
return updatedSteps;
|
||||||
} else {
|
} else {
|
||||||
@@ -115,7 +127,16 @@ export const BrowserStepsProvider: React.FC<{ children: React.ReactNode }> = ({
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
...prevSteps,
|
...prevSteps,
|
||||||
{ id: listId, type: 'list', listSelector, fields: fieldsWithActionId, pagination, limit, actionId }
|
{
|
||||||
|
id: listId,
|
||||||
|
type: 'list',
|
||||||
|
listSelector,
|
||||||
|
fields: fieldsWithActionId,
|
||||||
|
pagination,
|
||||||
|
limit,
|
||||||
|
actionId,
|
||||||
|
isShadow
|
||||||
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -236,7 +257,7 @@ export const BrowserStepsProvider: React.FC<{ children: React.ReactNode }> = ({
|
|||||||
updateListStepLimit,
|
updateListStepLimit,
|
||||||
updateListStepData,
|
updateListStepData,
|
||||||
removeListTextField,
|
removeListTextField,
|
||||||
deleteStepsByActionId,
|
deleteStepsByActionId,
|
||||||
updateScreenshotStepData,
|
updateScreenshotStepData,
|
||||||
}}>
|
}}>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
Reference in New Issue
Block a user