Files
parcer/src/components/molecules/BrowserRecordingSave.tsx

192 lines
5.8 KiB
TypeScript
Raw Normal View History

import React, { useState } from 'react';
2024-10-24 15:41:50 +05:30
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";
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";
import { useTranslation } from 'react-i18next';
import { emptyWorkflow } from '../../shared/constants';
import { useSocketStore } from '../../context/socket';
const BrowserRecordingSave = () => {
const { t } = useTranslation();
const [openDiscardModal, setOpenDiscardModal] = useState<boolean>(false);
const [openResetModal, setOpenResetModal] = useState<boolean>(false);
2025-01-03 19:37:06 +05:30
const { recordingName, browserId, initialUrl, setRecordingUrl, setBrowserId, notify, setCurrentWorkflowActionsState, resetInterpretationLog } = useGlobalInfoStore();
2024-10-24 15:35:31 +05:30
const navigate = useNavigate();
const { socket } = useSocketStore();
const {
stopGetText,
stopGetList,
stopGetScreenshot,
stopPaginationMode,
stopLimitMode,
setCaptureStage,
updatePaginationType,
updateLimitType,
updateCustomLimit,
setShowLimitOptions,
setShowPaginationOptions,
setWorkflow,
} = useActionContext();
const { browserSteps, deleteBrowserStep } = useBrowserSteps();
2024-10-24 15:35:31 +05:30
const goToMainMenu = async () => {
if (browserId) {
await stopRecording(browserId);
notify('warning', t('browser_recording.notifications.terminated'));
2024-10-24 15:35:31 +05:30
setBrowserId(null);
}
navigate('/');
};
const performReset = () => {
stopGetText();
stopGetList();
stopGetScreenshot();
stopPaginationMode();
stopLimitMode();
setShowLimitOptions(false);
setShowPaginationOptions(false);
setCaptureStage('initial');
updatePaginationType('');
updateLimitType('');
updateCustomLimit('');
setCurrentWorkflowActionsState({
hasScrapeListAction: false,
hasScreenshotAction: false,
hasScrapeSchemaAction: false
});
setWorkflow(emptyWorkflow);
resetInterpretationLog();
// Clear all browser steps
browserSteps.forEach(step => {
deleteBrowserStep(step.id);
});
2025-01-03 19:37:06 +05:30
if (socket) {
socket?.emit('new-recording');
socket.emit('input:url', initialUrl);
// Update the URL in the navbar to match
setRecordingUrl(initialUrl);
}
// 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',
width: 'calc(100% - 20px)',
2024-10-24 15:35:31 +05:30
overflow: 'hidden',
display: 'flex',
justifyContent: 'space-between',
}}>
<Button
onClick={() => setOpenDiscardModal(true)}
variant="outlined"
style={{ marginLeft: "25px" }}
size="small"
color="error"
>
{t('right_panel.buttons.discard')}
2024-10-24 15:35:31 +05:30
</Button>
{/* 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}>
<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">
{t('right_panel.buttons.discard')}
2024-10-24 15:35:31 +05:30
</Button>
<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"
>
{t('right_panel.buttons.cancel')}
2024-10-24 15:35:31 +05:30
</Button>
</Box>
</Box>
</GenericModal>
</div>
</Grid>
</Grid>
);
};
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',
};