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