2025-01-03 00:16:08 +05:30
|
|
|
import React, { useState } from 'react';
|
2024-10-24 15:41:50 +05:30
|
|
|
import { Grid, Button, Box, Typography } from '@mui/material';
|
2024-10-20 03:30:22 +05:30
|
|
|
import { SaveRecording } from "./SaveRecording";
|
|
|
|
|
import { useGlobalInfoStore } from '../../context/globalInfo';
|
2025-01-03 00:16:08 +05:30
|
|
|
import { useActionContext } from '../../context/browserActions';
|
|
|
|
|
import { useBrowserSteps } from '../../context/browserSteps';
|
2024-10-20 03:30:22 +05:30
|
|
|
import { stopRecording } from "../../api/recording";
|
2024-10-24 15:41:50 +05:30
|
|
|
import { useNavigate } from 'react-router-dom';
|
2024-10-24 15:34:49 +05:30
|
|
|
import { GenericModal } from "../atoms/GenericModal";
|
2024-12-21 00:17:48 +05:30
|
|
|
import { useTranslation } from 'react-i18next';
|
2024-10-20 03:30:22 +05:30
|
|
|
|
|
|
|
|
const BrowserRecordingSave = () => {
|
2024-12-21 00:17:48 +05:30
|
|
|
const { t } = useTranslation();
|
2025-01-03 00:16:08 +05:30
|
|
|
const [openDiscardModal, setOpenDiscardModal] = useState<boolean>(false);
|
|
|
|
|
const [openResetModal, setOpenResetModal] = useState<boolean>(false);
|
|
|
|
|
const { recordingName, browserId, setBrowserId, notify, setCurrentWorkflowActionsState, resetInterpretationLog } = useGlobalInfoStore();
|
2024-10-24 15:35:31 +05:30
|
|
|
const navigate = useNavigate();
|
2024-10-20 03:30:22 +05:30
|
|
|
|
2025-01-03 00:16:08 +05:30
|
|
|
const {
|
|
|
|
|
stopGetText,
|
|
|
|
|
stopGetList,
|
|
|
|
|
stopGetScreenshot,
|
|
|
|
|
stopPaginationMode,
|
|
|
|
|
stopLimitMode,
|
|
|
|
|
setCaptureStage,
|
|
|
|
|
updatePaginationType,
|
|
|
|
|
updateLimitType,
|
|
|
|
|
updateCustomLimit,
|
|
|
|
|
setShowLimitOptions,
|
|
|
|
|
setShowPaginationOptions,
|
|
|
|
|
} = useActionContext();
|
|
|
|
|
|
|
|
|
|
const { browserSteps, deleteBrowserStep } = useBrowserSteps();
|
|
|
|
|
|
2024-10-24 15:35:31 +05:30
|
|
|
const goToMainMenu = async () => {
|
|
|
|
|
if (browserId) {
|
|
|
|
|
await stopRecording(browserId);
|
2024-12-21 00:17:48 +05:30
|
|
|
notify('warning', t('browser_recording.notifications.terminated'));
|
2024-10-24 15:35:31 +05:30
|
|
|
setBrowserId(null);
|
|
|
|
|
}
|
|
|
|
|
navigate('/');
|
|
|
|
|
};
|
2024-10-20 03:30:22 +05:30
|
|
|
|
2025-01-03 00:16:08 +05:30
|
|
|
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'));
|
|
|
|
|
};
|
|
|
|
|
|
2024-10-24 15:35:31 +05:30
|
|
|
return (
|
|
|
|
|
<Grid container>
|
|
|
|
|
<Grid item xs={12} md={3} lg={3}>
|
|
|
|
|
<div style={{
|
2024-10-25 21:26:04 +05:30
|
|
|
marginTop: '12px',
|
2024-10-24 15:35:31 +05:30
|
|
|
color: 'white',
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
background: '#ff00c3',
|
|
|
|
|
border: 'none',
|
|
|
|
|
borderRadius: '5px',
|
|
|
|
|
padding: '7.5px',
|
2024-12-21 00:17:48 +05:30
|
|
|
width: 'calc(100% - 20px)',
|
2024-10-24 15:35:31 +05:30
|
|
|
overflow: 'hidden',
|
|
|
|
|
display: 'flex',
|
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
|
}}>
|
2025-01-03 00:16:08 +05:30
|
|
|
<Button
|
|
|
|
|
onClick={() => setOpenDiscardModal(true)}
|
|
|
|
|
variant="outlined"
|
|
|
|
|
style={{ marginLeft: "25px" }}
|
|
|
|
|
size="small"
|
|
|
|
|
color="error"
|
|
|
|
|
>
|
2024-12-21 00:17:48 +05:30
|
|
|
{t('right_panel.buttons.discard')}
|
2024-10-24 15:35:31 +05:30
|
|
|
</Button>
|
2025-01-03 00:16:08 +05:30
|
|
|
|
|
|
|
|
{/* Reset Button */}
|
|
|
|
|
<Button
|
|
|
|
|
onClick={() => setOpenResetModal(true)}
|
|
|
|
|
variant="outlined"
|
|
|
|
|
size="small"
|
|
|
|
|
style={{
|
|
|
|
|
backgroundColor: 'white',
|
|
|
|
|
marginLeft: '10px',
|
|
|
|
|
marginRight: '10px'
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{t('right_panel.buttons.reset')}
|
|
|
|
|
</Button>
|
|
|
|
|
|
|
|
|
|
<SaveRecording fileName={recordingName} />
|
|
|
|
|
|
|
|
|
|
{/* Discard Confirmation Modal */}
|
|
|
|
|
<GenericModal isOpen={openDiscardModal} onClose={() => setOpenDiscardModal(false)} modalStyle={modalStyle}>
|
2024-10-24 15:35:31 +05:30
|
|
|
<Box p={2}>
|
2024-12-21 00:17:48 +05:30
|
|
|
<Typography variant="h6">{t('browser_recording.modal.confirm_discard')}</Typography>
|
2024-10-24 15:35:31 +05:30
|
|
|
<Box display="flex" justifyContent="space-between" mt={2}>
|
|
|
|
|
<Button onClick={goToMainMenu} variant="contained" color="error">
|
2024-12-21 00:17:48 +05:30
|
|
|
{t('right_panel.buttons.discard')}
|
2024-10-24 15:35:31 +05:30
|
|
|
</Button>
|
2025-01-03 00:16:08 +05:30
|
|
|
<Button onClick={() => setOpenDiscardModal(false)} variant="outlined">
|
|
|
|
|
{t('right_panel.buttons.cancel')}
|
|
|
|
|
</Button>
|
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
</GenericModal>
|
|
|
|
|
|
|
|
|
|
{/* Reset Confirmation Modal */}
|
|
|
|
|
<GenericModal isOpen={openResetModal} onClose={() => setOpenResetModal(false)} modalStyle={modalStyle}>
|
|
|
|
|
<Box p={2}>
|
|
|
|
|
<Typography variant="h6">{t('browser_recording.modal.confirm_reset')}</Typography>
|
|
|
|
|
<Typography variant="body2" sx={{ mt: 1, mb: 2 }}>
|
|
|
|
|
{t('browser_recording.modal.reset_warning')}
|
|
|
|
|
</Typography>
|
|
|
|
|
<Box display="flex" justifyContent="space-between" mt={2}>
|
|
|
|
|
<Button
|
|
|
|
|
onClick={performReset}
|
|
|
|
|
variant="contained"
|
|
|
|
|
color="primary"
|
|
|
|
|
>
|
|
|
|
|
{t('right_panel.buttons.confirm_reset')}
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
onClick={() => setOpenResetModal(false)}
|
|
|
|
|
variant="outlined"
|
|
|
|
|
>
|
2024-12-21 00:17:48 +05:30
|
|
|
{t('right_panel.buttons.cancel')}
|
2024-10-24 15:35:31 +05:30
|
|
|
</Button>
|
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
</GenericModal>
|
|
|
|
|
</div>
|
|
|
|
|
</Grid>
|
|
|
|
|
</Grid>
|
|
|
|
|
);
|
2025-01-03 00:16:08 +05:30
|
|
|
};
|
2024-10-20 03:30:22 +05:30
|
|
|
|
2024-12-21 00:17:48 +05:30
|
|
|
export default BrowserRecordingSave;
|
2024-10-24 15:34:49 +05:30
|
|
|
|
|
|
|
|
const modalStyle = {
|
|
|
|
|
top: '25%',
|
|
|
|
|
left: '50%',
|
|
|
|
|
transform: 'translate(-50%, -50%)',
|
|
|
|
|
width: '30%',
|
|
|
|
|
backgroundColor: 'background.paper',
|
|
|
|
|
p: 4,
|
|
|
|
|
height: 'fit-content',
|
|
|
|
|
display: 'block',
|
|
|
|
|
padding: '20px',
|
|
|
|
|
};
|