feat: discard steps based on action id

This commit is contained in:
Rohit
2025-05-20 17:58:07 +05:30
parent 9da3f7f291
commit 515ad5b7c9

View File

@@ -52,7 +52,7 @@ export const RightSidePanel: React.FC<RightSidePanelProps> = ({ onFinishCapture
const [isCaptureListConfirmed, setIsCaptureListConfirmed] = useState(false); const [isCaptureListConfirmed, setIsCaptureListConfirmed] = useState(false);
const { panelHeight } = useBrowserDimensionsStore(); const { panelHeight } = useBrowserDimensionsStore();
const { lastAction, notify, currentWorkflowActionsState, setCurrentWorkflowActionsState, resetInterpretationLog } = useGlobalInfoStore(); const { lastAction, notify, currentWorkflowActionsState, setCurrentWorkflowActionsState, resetInterpretationLog, currentListActionId, setCurrentListActionId, currentTextActionId, setCurrentTextActionId, currentScreenshotActionId, setCurrentScreenshotActionId } = useGlobalInfoStore();
const { const {
getText, startGetText, stopGetText, getText, startGetText, stopGetText,
getList, startGetList, stopGetList, getList, startGetList, stopGetList,
@@ -69,7 +69,7 @@ export const RightSidePanel: React.FC<RightSidePanelProps> = ({ onFinishCapture
startAction, finishAction startAction, finishAction
} = useActionContext(); } = useActionContext();
const { browserSteps, updateBrowserTextStepLabel, deleteBrowserStep, addScreenshotStep, updateListTextFieldLabel, removeListTextField, updateListStepLimit } = useBrowserSteps(); const { browserSteps, updateBrowserTextStepLabel, deleteBrowserStep, addScreenshotStep, updateListTextFieldLabel, removeListTextField, updateListStepLimit, deleteStepsByActionId } = useBrowserSteps();
const { id, socket } = useSocketStore(); const { id, socket } = useSocketStore();
const { t } = useTranslation(); const { t } = useTranslation();
@@ -139,15 +139,21 @@ export const RightSidePanel: React.FC<RightSidePanelProps> = ({ onFinishCapture
const handleStartGetText = () => { const handleStartGetText = () => {
setIsCaptureTextConfirmed(false); setIsCaptureTextConfirmed(false);
const newActionId = `text-${Date.now()}`;
setCurrentTextActionId(newActionId);
startGetText(); startGetText();
} }
const handleStartGetList = () => { const handleStartGetList = () => {
setIsCaptureListConfirmed(false); setIsCaptureListConfirmed(false);
const newActionId = `list-${Date.now()}`;
setCurrentListActionId(newActionId);
startGetList(); startGetList();
} }
const handleStartGetScreenshot = () => { const handleStartGetScreenshot = () => {
const newActionId = `screenshot-${Date.now()}`;
setCurrentScreenshotActionId(newActionId);
startGetScreenshot(); startGetScreenshot();
}; };
@@ -277,6 +283,7 @@ export const RightSidePanel: React.FC<RightSidePanelProps> = ({ onFinishCapture
socket?.emit('action', { action: 'scrapeSchema', settings }); socket?.emit('action', { action: 'scrapeSchema', settings });
} }
setIsCaptureTextConfirmed(true); setIsCaptureTextConfirmed(true);
setCurrentTextActionId('');
resetInterpretationLog(); resetInterpretationLog();
finishAction('text'); finishAction('text');
onFinishCapture(); onFinishCapture();
@@ -337,6 +344,7 @@ export const RightSidePanel: React.FC<RightSidePanelProps> = ({ onFinishCapture
notify('error', t('right_panel.errors.unable_create_settings')); notify('error', t('right_panel.errors.unable_create_settings'));
} }
handleStopGetList(); handleStopGetList();
setCurrentListActionId('');
resetInterpretationLog(); resetInterpretationLog();
finishAction('list'); finishAction('list');
onFinishCapture(); onFinishCapture();
@@ -434,35 +442,73 @@ export const RightSidePanel: React.FC<RightSidePanelProps> = ({ onFinishCapture
const discardGetText = useCallback(() => { const discardGetText = useCallback(() => {
stopGetText(); stopGetText();
browserSteps.forEach(step => {
if (step.type === 'text') { if (currentTextActionId) {
deleteBrowserStep(step.id); const stepsToDelete = browserSteps
} .filter(step => step.type === 'text' && step.actionId === currentTextActionId)
}); .map(step => step.id);
setTextLabels({});
setErrors({}); deleteStepsByActionId(currentTextActionId);
setConfirmedTextSteps({});
setTextLabels(prevLabels => {
const newLabels = { ...prevLabels };
stepsToDelete.forEach(id => {
delete newLabels[id];
});
return newLabels;
});
setErrors(prevErrors => {
const newErrors = { ...prevErrors };
stepsToDelete.forEach(id => {
delete newErrors[id];
});
return newErrors;
});
setConfirmedTextSteps(prev => {
const newConfirmed = { ...prev };
stepsToDelete.forEach(id => {
delete newConfirmed[id];
});
return newConfirmed;
});
}
setCurrentTextActionId('');
setIsCaptureTextConfirmed(false); setIsCaptureTextConfirmed(false);
notify('error', t('right_panel.errors.capture_text_discarded')); notify('error', t('right_panel.errors.capture_text_discarded'));
}, [browserSteps, stopGetText, deleteBrowserStep, notify, t]); }, [currentTextActionId, browserSteps, stopGetText, deleteStepsByActionId, notify, t]);
const discardGetList = useCallback(() => { const discardGetList = useCallback(() => {
stopGetList(); stopGetList();
browserSteps.forEach(step => {
if (step.type === 'list') { if (currentListActionId) {
deleteBrowserStep(step.id); const listStepsToDelete = browserSteps
} .filter(step => step.type === 'list' && step.actionId === currentListActionId)
}); .map(step => step.id);
deleteStepsByActionId(currentListActionId);
setConfirmedListTextFields(prev => {
const newConfirmed = { ...prev };
listStepsToDelete.forEach(id => {
delete newConfirmed[id];
});
return newConfirmed;
});
}
resetListState(); resetListState();
stopPaginationMode(); stopPaginationMode();
stopLimitMode(); stopLimitMode();
setShowPaginationOptions(false); setShowPaginationOptions(false);
setShowLimitOptions(false); setShowLimitOptions(false);
setCaptureStage('initial'); setCaptureStage('initial');
setConfirmedListTextFields({}); setCurrentListActionId('');
setIsCaptureListConfirmed(false); setIsCaptureListConfirmed(false);
notify('error', t('right_panel.errors.capture_list_discarded')); notify('error', t('right_panel.errors.capture_list_discarded'));
}, [browserSteps, stopGetList, deleteBrowserStep, resetListState, setShowPaginationOptions, setShowLimitOptions, setCaptureStage, notify, t]); }, [currentListActionId, browserSteps, stopGetList, deleteStepsByActionId, resetListState, setShowPaginationOptions, setShowLimitOptions, setCaptureStage, notify, t]);
const captureScreenshot = (fullPage: boolean) => { const captureScreenshot = (fullPage: boolean) => {
const screenshotSettings: ScreenshotSettings = { const screenshotSettings: ScreenshotSettings = {
@@ -474,7 +520,7 @@ export const RightSidePanel: React.FC<RightSidePanelProps> = ({ onFinishCapture
scale: 'device', scale: 'device',
}; };
socket?.emit('action', { action: 'screenshot', settings: screenshotSettings }); socket?.emit('action', { action: 'screenshot', settings: screenshotSettings });
addScreenshotStep(fullPage); addScreenshotStep(fullPage, currentScreenshotActionId);
stopGetScreenshot(); stopGetScreenshot();
resetInterpretationLog(); resetInterpretationLog();
finishAction('screenshot'); finishAction('screenshot');