feat: add action id param for steps
This commit is contained in:
@@ -6,12 +6,14 @@ export interface TextStep {
|
||||
label: string;
|
||||
data: string;
|
||||
selectorObj: SelectorObject;
|
||||
actionId?: string; // Add actionId to track which action created this step
|
||||
}
|
||||
|
||||
interface ScreenshotStep {
|
||||
id: number;
|
||||
type: 'screenshot';
|
||||
fullPage: boolean;
|
||||
actionId?: string; // Add actionId to track which action created this step
|
||||
}
|
||||
|
||||
export interface ListStep {
|
||||
@@ -24,6 +26,7 @@ export interface ListStep {
|
||||
selector: string;
|
||||
};
|
||||
limit?: number;
|
||||
actionId?: string; // Add actionId to track which action created this step
|
||||
}
|
||||
|
||||
export type BrowserStep = TextStep | ScreenshotStep | ListStep;
|
||||
@@ -38,15 +41,16 @@ export interface SelectorObject {
|
||||
|
||||
interface BrowserStepsContextType {
|
||||
browserSteps: BrowserStep[];
|
||||
addTextStep: (label: string, data: string, selectorObj: SelectorObject) => void;
|
||||
addListStep: (listSelector: string, fields: { [key: string]: TextStep }, listId: number, pagination?: { type: string; selector: string }, limit?: number) => void
|
||||
addScreenshotStep: (fullPage: boolean) => 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
|
||||
addScreenshotStep: (fullPage: boolean, actionId: string) => void;
|
||||
deleteBrowserStep: (id: number) => void;
|
||||
updateBrowserTextStepLabel: (id: number, newLabel: string) => void;
|
||||
updateListTextFieldLabel: (listId: number, fieldKey: string, newLabel: string) => void;
|
||||
updateListStepLimit: (listId: number, limit: number) => void;
|
||||
updateListStepData: (listId: number, extractedData: any[]) => void;
|
||||
removeListTextField: (listId: number, fieldKey: string) => void;
|
||||
deleteStepsByActionId: (actionId: string) => void; // New function to delete steps by actionId
|
||||
}
|
||||
|
||||
const BrowserStepsContext = createContext<BrowserStepsContextType | undefined>(undefined);
|
||||
@@ -55,14 +59,14 @@ export const BrowserStepsProvider: React.FC<{ children: React.ReactNode }> = ({
|
||||
const [browserSteps, setBrowserSteps] = useState<BrowserStep[]>([]);
|
||||
const [discardedFields, setDiscardedFields] = useState<Set<string>>(new Set());
|
||||
|
||||
const addTextStep = (label: string, data: string, selectorObj: SelectorObject) => {
|
||||
const addTextStep = (label: string, data: string, selectorObj: SelectorObject, actionId: string) => {
|
||||
setBrowserSteps(prevSteps => [
|
||||
...prevSteps,
|
||||
{ id: Date.now(), type: 'text', label, data, selectorObj }
|
||||
{ id: Date.now(), type: 'text', label, data, selectorObj, actionId }
|
||||
]);
|
||||
};
|
||||
|
||||
const addListStep = (listSelector: string, newFields: { [key: string]: TextStep }, listId: number, pagination?: { type: string; selector: string }, limit?: number) => {
|
||||
const addListStep = (listSelector: string, newFields: { [key: string]: TextStep }, listId: number, actionId: string, pagination?: { type: string; selector: string }, limit?: number) => {
|
||||
setBrowserSteps(prevSteps => {
|
||||
const existingListStepIndex = prevSteps.findIndex(step => step.type === 'list' && step.id === listId);
|
||||
|
||||
@@ -77,10 +81,14 @@ export const BrowserStepsProvider: React.FC<{ children: React.ReactNode }> = ({
|
||||
if (existingListStep.fields[key]) {
|
||||
acc[key] = {
|
||||
...field,
|
||||
label: existingListStep.fields[key].label
|
||||
label: existingListStep.fields[key].label,
|
||||
actionId
|
||||
};
|
||||
} else {
|
||||
acc[key] = field;
|
||||
acc[key] = {
|
||||
...field,
|
||||
actionId
|
||||
};
|
||||
}
|
||||
}
|
||||
return acc;
|
||||
@@ -90,22 +98,31 @@ export const BrowserStepsProvider: React.FC<{ children: React.ReactNode }> = ({
|
||||
...existingListStep,
|
||||
fields: mergedFields,
|
||||
pagination: pagination || existingListStep.pagination,
|
||||
limit: limit
|
||||
limit: limit,
|
||||
actionId
|
||||
};
|
||||
return updatedSteps;
|
||||
} else {
|
||||
const fieldsWithActionId = Object.entries(newFields).reduce((acc, [key, field]) => {
|
||||
acc[key] = {
|
||||
...field,
|
||||
actionId
|
||||
};
|
||||
return acc;
|
||||
}, {} as { [key: string]: TextStep });
|
||||
|
||||
return [
|
||||
...prevSteps,
|
||||
{ id: listId, type: 'list', listSelector, fields: newFields, pagination, limit }
|
||||
{ id: listId, type: 'list', listSelector, fields: fieldsWithActionId, pagination, limit, actionId }
|
||||
];
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const addScreenshotStep = (fullPage: boolean) => {
|
||||
const addScreenshotStep = (fullPage: boolean, actionId: string) => {
|
||||
setBrowserSteps(prevSteps => [
|
||||
...prevSteps,
|
||||
{ id: Date.now(), type: 'screenshot', fullPage }
|
||||
{ id: Date.now(), type: 'screenshot', fullPage, actionId }
|
||||
]);
|
||||
};
|
||||
|
||||
@@ -113,6 +130,10 @@ export const BrowserStepsProvider: React.FC<{ children: React.ReactNode }> = ({
|
||||
setBrowserSteps(prevSteps => prevSteps.filter(step => step.id !== id));
|
||||
};
|
||||
|
||||
const deleteStepsByActionId = (actionId: string) => {
|
||||
setBrowserSteps(prevSteps => prevSteps.filter(step => step.actionId !== actionId));
|
||||
};
|
||||
|
||||
const updateBrowserTextStepLabel = (id: number, newLabel: string) => {
|
||||
setBrowserSteps(prevSteps =>
|
||||
prevSteps.map(step =>
|
||||
@@ -199,6 +220,7 @@ export const BrowserStepsProvider: React.FC<{ children: React.ReactNode }> = ({
|
||||
updateListStepLimit,
|
||||
updateListStepData,
|
||||
removeListTextField,
|
||||
deleteStepsByActionId, // Export the new function
|
||||
}}>
|
||||
{children}
|
||||
</BrowserStepsContext.Provider>
|
||||
@@ -211,4 +233,4 @@ export const useBrowserSteps = () => {
|
||||
throw new Error('useBrowserSteps must be used within a BrowserStepsProvider');
|
||||
}
|
||||
return context;
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user