diff --git a/src/components/molecules/BrowserRecordingSave.tsx b/src/components/molecules/BrowserRecordingSave.tsx index e1eff20e..e837e8dd 100644 --- a/src/components/molecules/BrowserRecordingSave.tsx +++ b/src/components/molecules/BrowserRecordingSave.tsx @@ -1,7 +1,9 @@ -import React, { useState } from 'react' +import React, { useState } from 'react'; import { Grid, Button, Box, Typography } from '@mui/material'; import { SaveRecording } from "./SaveRecording"; import { useGlobalInfoStore } from '../../context/globalInfo'; +import { useActionContext } from '../../context/browserActions'; +import { useBrowserSteps } from '../../context/browserSteps'; import { stopRecording } from "../../api/recording"; import { useNavigate } from 'react-router-dom'; import { GenericModal } from "../atoms/GenericModal"; @@ -9,10 +11,27 @@ import { useTranslation } from 'react-i18next'; const BrowserRecordingSave = () => { const { t } = useTranslation(); - const [openModal, setOpenModal] = useState(false); - const { recordingName, browserId, setBrowserId, notify } = useGlobalInfoStore(); + const [openDiscardModal, setOpenDiscardModal] = useState(false); + const [openResetModal, setOpenResetModal] = useState(false); + const { recordingName, browserId, setBrowserId, notify, setCurrentWorkflowActionsState, resetInterpretationLog } = useGlobalInfoStore(); const navigate = useNavigate(); + const { + stopGetText, + stopGetList, + stopGetScreenshot, + stopPaginationMode, + stopLimitMode, + setCaptureStage, + updatePaginationType, + updateLimitType, + updateCustomLimit, + setShowLimitOptions, + setShowPaginationOptions, + } = useActionContext(); + + const { browserSteps, deleteBrowserStep } = useBrowserSteps(); + const goToMainMenu = async () => { if (browserId) { await stopRecording(browserId); @@ -22,6 +41,41 @@ const BrowserRecordingSave = () => { navigate('/'); }; + const performReset = () => { + stopGetText(); + stopGetList(); + stopGetScreenshot(); + stopPaginationMode(); + stopLimitMode(); + + setShowLimitOptions(false); + setShowPaginationOptions(false); + setCaptureStage('initial'); + + updatePaginationType(''); + updateLimitType(''); + updateCustomLimit(''); + + setCurrentWorkflowActionsState({ + hasScrapeListAction: false, + hasScreenshotAction: false, + hasScrapeSchemaAction: false + }); + + resetInterpretationLog(); + + // Clear all browser steps + browserSteps.forEach(step => { + deleteBrowserStep(step.id); + }); + + // Close the reset confirmation modal + setOpenResetModal(false); + + // Notify user + notify('info', t('browser_recording.notifications.environment_reset')); + }; + return ( @@ -38,28 +92,76 @@ const BrowserRecordingSave = () => { display: 'flex', justifyContent: 'space-between', }}> - - setOpenModal(false)} modalStyle={modalStyle}> + + {/* Reset Button */} + + + + + {/* Discard Confirmation Modal */} + setOpenDiscardModal(false)} modalStyle={modalStyle}> {t('browser_recording.modal.confirm_discard')} - + + + + + {/* Reset Confirmation Modal */} + setOpenResetModal(false)} modalStyle={modalStyle}> + + {t('browser_recording.modal.confirm_reset')} + + {t('browser_recording.modal.reset_warning')} + + + + - ); -} +}; export default BrowserRecordingSave;