Files
parcer/src/components/recorder/RightSidePanel.tsx

866 lines
33 KiB
TypeScript
Raw Normal View History

import React, { useState, useCallback, useEffect, useMemo } from 'react';
2024-10-10 07:17:43 +05:30
import { Button, Paper, Box, TextField, IconButton } from "@mui/material";
2024-08-06 06:04:22 +05:30
import EditIcon from '@mui/icons-material/Edit';
import TextFieldsIcon from '@mui/icons-material/TextFields';
2024-08-06 06:13:13 +05:30
import DocumentScannerIcon from '@mui/icons-material/DocumentScanner';
2024-10-08 18:39:59 +05:30
import { WorkflowFile } from "maxun-core";
2024-06-24 22:42:22 +05:30
import Typography from "@mui/material/Typography";
import { useGlobalInfoStore } from "../../context/globalInfo";
2024-09-08 13:52:01 +05:30
import { PaginationType, useActionContext, LimitType } from '../../context/browserActions';
2024-09-04 05:38:48 +05:30
import { useBrowserSteps } from '../../context/browserSteps';
import { useSocketStore } from '../../context/socket';
import { ScreenshotSettings } from '../../shared/types';
2024-08-06 06:04:22 +05:30
import InputAdornment from '@mui/material/InputAdornment';
2024-09-08 12:19:11 +05:30
import FormControlLabel from '@mui/material/FormControlLabel';
import FormControl from '@mui/material/FormControl';
import FormLabel from '@mui/material/FormLabel';
import Radio from '@mui/material/Radio';
import RadioGroup from '@mui/material/RadioGroup';
2024-10-08 18:39:59 +05:30
import { getActiveWorkflow } from "../../api/workflow";
2025-01-09 20:15:27 +05:30
import ActionDescriptionBox from '../action/ActionDescriptionBox';
2024-11-10 11:29:06 +05:30
import { useThemeMode } from '../../context/theme-provider';
import { useTranslation } from 'react-i18next';
import { useBrowserDimensionsStore } from '../../context/browserDimensions';
2024-10-08 17:16:35 +05:30
2024-10-08 17:35:29 +05:30
const fetchWorkflow = (id: string, callback: (response: WorkflowFile) => void) => {
getActiveWorkflow(id).then(
(response) => {
if (response) {
callback(response);
} else {
throw new Error("No workflow found");
}
}
).catch((error) => { console.log(error.message) })
};
2024-08-06 06:04:22 +05:30
2024-09-08 07:39:09 +05:30
interface RightSidePanelProps {
onFinishCapture: () => void;
}
2024-10-19 18:44:52 +05:30
export const RightSidePanel: React.FC<RightSidePanelProps> = ({ onFinishCapture }) => {
2024-09-14 02:00:37 +05:30
const [textLabels, setTextLabels] = useState<{ [id: string]: string }>({});
const [errors, setErrors] = useState<{ [id: string]: string }>({});
const [confirmedTextSteps, setConfirmedTextSteps] = useState<{ [id: string]: boolean }>({});
const [confirmedListTextFields, setConfirmedListTextFields] = useState<{ [listId: string]: { [fieldKey: string]: boolean } }>({});
const [showCaptureList, setShowCaptureList] = useState(true);
const [showCaptureScreenshot, setShowCaptureScreenshot] = useState(true);
const [showCaptureText, setShowCaptureText] = useState(true);
2024-10-10 07:07:29 +05:30
const [hoverStates, setHoverStates] = useState<{ [id: string]: boolean }>({});
const [browserStepIdList, setBrowserStepIdList] = useState<number[]>([]);
const [isCaptureTextConfirmed, setIsCaptureTextConfirmed] = useState(false);
const [isCaptureListConfirmed, setIsCaptureListConfirmed] = useState(false);
const { panelHeight } = useBrowserDimensionsStore();
const { lastAction, notify, currentWorkflowActionsState, setCurrentWorkflowActionsState, resetInterpretationLog } = useGlobalInfoStore();
const {
getText, startGetText, stopGetText,
getList, startGetList, stopGetList,
getScreenshot, startGetScreenshot, stopGetScreenshot,
startPaginationMode, stopPaginationMode,
paginationType, updatePaginationType,
limitType, customLimit, updateLimitType, updateCustomLimit,
stopLimitMode, startLimitMode,
captureStage, setCaptureStage,
showPaginationOptions, setShowPaginationOptions,
showLimitOptions, setShowLimitOptions,
workflow, setWorkflow,
activeAction, setActiveAction,
startAction, finishAction
} = useActionContext();
2024-09-13 23:40:42 +05:30
const { browserSteps, updateBrowserTextStepLabel, deleteBrowserStep, addScreenshotStep, updateListTextFieldLabel, removeListTextField } = useBrowserSteps();
2024-10-08 17:41:50 +05:30
const { id, socket } = useSocketStore();
const { t } = useTranslation();
2024-06-24 22:42:22 +05:30
const isAnyActionActive = activeAction !== 'none';
2024-10-08 17:36:52 +05:30
const workflowHandler = useCallback((data: WorkflowFile) => {
setWorkflow(data);
}, [setWorkflow]);
2024-10-08 17:36:52 +05:30
useEffect(() => {
2024-10-08 18:05:57 +05:30
if (socket) {
socket.on("workflow", workflowHandler);
}
// fetch the workflow every time the id changes
if (id) {
fetchWorkflow(id, workflowHandler);
}
// fetch workflow in 15min intervals
let interval = setInterval(() => {
if (id) {
fetchWorkflow(id, workflowHandler);
}
2024-10-11 18:32:38 +05:30
}, (1000 * 60 * 15));
2024-10-08 18:05:57 +05:30
return () => {
socket?.off("workflow", workflowHandler);
clearInterval(interval);
2024-10-08 18:07:24 +05:30
};
}, [id, socket, workflowHandler]);
2024-10-08 18:07:24 +05:30
useEffect(() => {
2024-10-08 19:12:40 +05:30
const hasPairs = workflow.workflow.length > 0;
if (!hasPairs) {
2024-10-08 19:12:55 +05:30
setShowCaptureList(true);
setShowCaptureScreenshot(true);
setShowCaptureText(true);
return;
2024-10-08 19:12:40 +05:30
}
2024-10-08 19:16:27 +05:30
const hasScrapeListAction = workflow.workflow.some(pair =>
pair.what.some(action => action.action === 'scrapeList')
);
const hasScreenshotAction = workflow.workflow.some(pair =>
pair.what.some(action => action.action === 'screenshot')
);
const hasScrapeSchemaAction = workflow.workflow.some(pair =>
pair.what.some(action => action.action === 'scrapeSchema')
);
2024-10-08 18:53:17 +05:30
setCurrentWorkflowActionsState({
hasScrapeListAction,
hasScreenshotAction,
hasScrapeSchemaAction,
});
setShowCaptureList(true);
setShowCaptureScreenshot(true);
setShowCaptureText(true);
}, [workflow, setCurrentWorkflowActionsState]);
2024-10-08 18:36:19 +05:30
2024-10-10 07:07:29 +05:30
const handleMouseEnter = (id: number) => {
setHoverStates(prev => ({ ...prev, [id]: true }));
};
const handleMouseLeave = (id: number) => {
setHoverStates(prev => ({ ...prev, [id]: false }));
};
const handleStartGetText = () => {
setIsCaptureTextConfirmed(false);
startGetText();
}
const handleStartGetList = () => {
setIsCaptureListConfirmed(false);
startGetList();
}
const handleStartGetScreenshot = () => {
startGetScreenshot();
};
2024-09-13 23:32:42 +05:30
const handleTextLabelChange = (id: number, label: string, listId?: number, fieldKey?: string) => {
if (listId !== undefined && fieldKey !== undefined) {
// Prevent editing if the field is confirmed
2024-09-14 08:17:00 +05:30
if (confirmedListTextFields[listId]?.[fieldKey]) {
return;
}
2024-09-13 23:32:42 +05:30
updateListTextFieldLabel(listId, fieldKey, label);
} else {
setTextLabels(prevLabels => ({ ...prevLabels, [id]: label }));
}
2024-08-06 05:05:50 +05:30
if (!label.trim()) {
setErrors(prevErrors => ({ ...prevErrors, [id]: t('right_panel.errors.label_required') }));
2024-08-06 05:05:50 +05:30
} else {
setErrors(prevErrors => ({ ...prevErrors, [id]: '' }));
}
2024-07-26 23:25:03 +05:30
};
2024-07-26 23:07:54 +05:30
const handleTextStepConfirm = (id: number) => {
const label = textLabels[id]?.trim();
2024-07-26 23:24:41 +05:30
if (label) {
2024-08-06 03:12:07 +05:30
updateBrowserTextStepLabel(id, label);
setConfirmedTextSteps(prev => ({ ...prev, [id]: true }));
2024-07-26 23:24:41 +05:30
} else {
setErrors(prevErrors => ({ ...prevErrors, [id]: t('right_panel.errors.label_required') }));
2024-07-26 23:07:54 +05:30
}
2024-07-26 23:25:03 +05:30
};
2024-07-26 23:07:54 +05:30
const handleTextStepDiscard = (id: number) => {
2024-07-26 23:07:54 +05:30
deleteBrowserStep(id);
setTextLabels(prevLabels => {
2024-07-26 23:25:03 +05:30
const { [id]: _, ...rest } = prevLabels;
return rest;
2024-07-26 23:24:41 +05:30
});
setErrors(prevErrors => {
2024-07-26 23:25:03 +05:30
const { [id]: _, ...rest } = prevErrors;
return rest;
2024-07-26 23:24:41 +05:30
});
2024-07-26 23:25:03 +05:30
};
2024-07-26 23:07:54 +05:30
const handleTextStepDelete = (id: number) => {
deleteBrowserStep(id);
setTextLabels(prevLabels => {
const { [id]: _, ...rest } = prevLabels;
return rest;
});
setConfirmedTextSteps(prev => {
const { [id]: _, ...rest } = prev;
return rest;
});
setErrors(prevErrors => {
const { [id]: _, ...rest } = prevErrors;
return rest;
});
};
const handleListTextFieldConfirm = (listId: number, fieldKey: string) => {
setConfirmedListTextFields(prev => ({
...prev,
[listId]: {
...(prev[listId] || {}),
[fieldKey]: true
}
}));
};
2024-09-13 23:40:11 +05:30
const handleListTextFieldDiscard = (listId: number, fieldKey: string) => {
removeListTextField(listId, fieldKey);
2024-09-14 02:00:37 +05:30
setConfirmedListTextFields(prev => {
const updatedListFields = { ...(prev[listId] || {}) };
delete updatedListFields[fieldKey];
return {
...prev,
[listId]: updatedListFields
};
});
setErrors(prev => {
const { [fieldKey]: _, ...rest } = prev;
return rest;
});
2024-09-13 23:55:22 +05:30
};
const handleListTextFieldDelete = (listId: number, fieldKey: string) => {
removeListTextField(listId, fieldKey);
setConfirmedListTextFields(prev => {
const updatedListFields = { ...(prev[listId] || {}) };
delete updatedListFields[fieldKey];
return {
...prev,
[listId]: updatedListFields
};
});
setErrors(prev => {
const { [fieldKey]: _, ...rest } = prev;
return rest;
});
};
const getTextSettingsObject = useCallback(() => {
2024-08-06 05:05:50 +05:30
const settings: Record<string, { selector: string; tag?: string;[key: string]: any }> = {};
browserSteps.forEach(step => {
if (browserStepIdList.includes(step.id)) {
2025-01-09 17:16:14 +05:30
return;
}
2025-01-09 17:16:14 +05:30
2024-08-06 03:25:52 +05:30
if (step.type === 'text' && step.label && step.selectorObj?.selector) {
settings[step.label] = step.selectorObj;
}
setBrowserStepIdList(prevList => [...prevList, step.id]);
});
return settings;
}, [browserSteps, browserStepIdList]);
2024-08-06 03:12:07 +05:30
2024-08-06 03:25:52 +05:30
const stopCaptureAndEmitGetTextSettings = useCallback(() => {
const hasUnconfirmedTextSteps = browserSteps.some(step => step.type === 'text' && !confirmedTextSteps[step.id]);
if (hasUnconfirmedTextSteps) {
notify('error', t('right_panel.errors.confirm_text_fields'));
return;
}
2024-08-06 03:25:52 +05:30
stopGetText();
const settings = getTextSettingsObject();
const hasTextSteps = browserSteps.some(step => step.type === 'text');
2024-10-10 18:34:04 +05:30
if (hasTextSteps) {
socket?.emit('action', { action: 'scrapeSchema', settings });
}
setIsCaptureTextConfirmed(true);
resetInterpretationLog();
finishAction('text');
2024-10-10 18:34:04 +05:30
onFinishCapture();
}, [stopGetText, getTextSettingsObject, socket, browserSteps, confirmedTextSteps, resetInterpretationLog, finishAction, notify, onFinishCapture, t]);
2024-08-09 10:32:48 +05:30
const getListSettingsObject = useCallback(() => {
2024-08-31 03:32:43 +05:30
let settings: {
listSelector?: string;
2024-09-21 17:40:06 +05:30
fields?: Record<string, { selector: string; tag?: string;[key: string]: any }>;
2024-09-08 12:19:11 +05:30
pagination?: { type: string; selector?: string };
limit?: number;
2024-08-31 03:31:20 +05:30
} = {};
2024-09-21 17:40:06 +05:30
2024-08-10 04:46:09 +05:30
browserSteps.forEach(step => {
2024-08-10 05:06:43 +05:30
if (step.type === 'list' && step.listSelector && Object.keys(step.fields).length > 0) {
2024-09-21 17:40:06 +05:30
const fields: Record<string, { selector: string; tag?: string;[key: string]: any }> = {};
2024-09-21 15:56:26 +05:30
Object.entries(step.fields).forEach(([id, field]) => {
2024-08-10 05:06:43 +05:30
if (field.selectorObj?.selector) {
2024-09-21 15:56:26 +05:30
fields[field.label] = {
2024-08-10 05:06:43 +05:30
selector: field.selectorObj.selector,
tag: field.selectorObj.tag,
2024-09-08 12:19:11 +05:30
attribute: field.selectorObj.attribute,
2024-08-10 05:06:43 +05:30
};
}
});
2024-09-21 17:40:06 +05:30
settings = {
2024-08-10 05:06:43 +05:30
listSelector: step.listSelector,
2024-08-31 03:33:34 +05:30
fields: fields,
pagination: { type: paginationType, selector: step.pagination?.selector },
2024-09-08 14:01:17 +05:30
limit: parseInt(limitType === 'custom' ? customLimit : limitType),
2024-08-10 21:25:17 +05:30
};
2024-08-10 05:06:43 +05:30
}
2024-08-10 04:46:09 +05:30
});
2024-09-21 17:40:06 +05:30
2024-08-10 04:46:09 +05:30
return settings;
2024-09-08 14:01:17 +05:30
}, [browserSteps, paginationType, limitType, customLimit]);
2024-09-21 17:40:06 +05:30
const resetListState = useCallback(() => {
2024-09-04 05:34:56 +05:30
setShowPaginationOptions(false);
2024-09-08 13:53:22 +05:30
updatePaginationType('');
2024-09-08 14:02:56 +05:30
setShowLimitOptions(false);
2024-09-08 13:53:22 +05:30
updateLimitType('');
updateCustomLimit('');
}, [setShowPaginationOptions, updatePaginationType, setShowLimitOptions, updateLimitType, updateCustomLimit]);
2024-09-08 13:52:23 +05:30
2024-09-04 05:35:16 +05:30
const handleStopGetList = useCallback(() => {
2024-09-04 05:34:56 +05:30
stopGetList();
resetListState();
2024-09-04 05:35:16 +05:30
}, [stopGetList, resetListState]);
2024-08-10 05:04:50 +05:30
const stopCaptureAndEmitGetListSettings = useCallback(() => {
2024-08-10 05:06:43 +05:30
const settings = getListSettingsObject();
if (settings) {
2024-10-10 18:34:04 +05:30
socket?.emit('action', { action: 'scrapeList', settings });
2024-08-10 05:04:50 +05:30
} else {
notify('error', t('right_panel.errors.unable_create_settings'));
2024-08-10 05:06:43 +05:30
}
2024-09-04 05:34:56 +05:30
handleStopGetList();
resetInterpretationLog();
finishAction('list');
2024-10-10 18:34:04 +05:30
onFinishCapture();
}, [getListSettingsObject, socket, notify, handleStopGetList, resetInterpretationLog, finishAction, onFinishCapture, t]);
2024-08-09 10:32:48 +05:30
const hasUnconfirmedListTextFields = browserSteps.some(step =>
step.type === 'list' &&
Object.entries(step.fields).some(([fieldKey]) =>
!confirmedListTextFields[step.id]?.[fieldKey]
)
);
2024-10-10 19:29:21 +05:30
const handleConfirmListCapture = useCallback(() => {
switch (captureStage) {
case 'initial':
startPaginationMode();
2024-10-10 19:29:21 +05:30
setShowPaginationOptions(true);
setCaptureStage('pagination');
break;
case 'pagination':
if (!paginationType) {
notify('error', t('right_panel.errors.select_pagination'));
2024-10-10 19:29:21 +05:30
return;
}
const settings = getListSettingsObject();
const paginationSelector = settings.pagination?.selector;
if (['clickNext', 'clickLoadMore'].includes(paginationType) && !paginationSelector) {
notify('error', t('right_panel.errors.select_pagination_element'));
2024-10-10 19:29:21 +05:30
return;
}
stopPaginationMode();
setShowPaginationOptions(false);
startLimitMode();
setShowLimitOptions(true);
setCaptureStage('limit');
break;
case 'limit':
if (!limitType || (limitType === 'custom' && !customLimit)) {
notify('error', t('right_panel.errors.select_limit'));
2024-10-10 19:29:21 +05:30
return;
}
const limit = limitType === 'custom' ? parseInt(customLimit) : parseInt(limitType);
if (isNaN(limit) || limit <= 0) {
notify('error', t('right_panel.errors.invalid_limit'));
2024-10-10 19:29:21 +05:30
return;
}
stopLimitMode();
setShowLimitOptions(false);
setIsCaptureListConfirmed(true);
2024-10-10 19:29:21 +05:30
stopCaptureAndEmitGetListSettings();
setCaptureStage('complete');
break;
case 'complete':
setCaptureStage('initial');
break;
}
}, [captureStage, paginationType, limitType, customLimit, startPaginationMode, setShowPaginationOptions, setCaptureStage, getListSettingsObject, notify, stopPaginationMode, startLimitMode, setShowLimitOptions, stopLimitMode, setIsCaptureListConfirmed, stopCaptureAndEmitGetListSettings, t]);
2024-09-08 13:52:23 +05:30
const handleBackCaptureList = useCallback(() => {
switch (captureStage) {
case 'limit':
stopLimitMode();
setShowLimitOptions(false);
startPaginationMode();
setShowPaginationOptions(true);
setCaptureStage('pagination');
break;
case 'pagination':
stopPaginationMode();
setShowPaginationOptions(false);
setCaptureStage('initial');
break;
}
}, [captureStage, stopLimitMode, setShowLimitOptions, startPaginationMode, setShowPaginationOptions, setCaptureStage, stopPaginationMode]);
const handlePaginationSettingSelect = (option: PaginationType) => {
updatePaginationType(option);
};
2024-09-14 08:34:31 +05:30
const discardGetText = useCallback(() => {
2024-09-14 08:32:56 +05:30
stopGetText();
browserSteps.forEach(step => {
if (step.type === 'text') {
deleteBrowserStep(step.id);
}
});
setTextLabels({});
setErrors({});
setConfirmedTextSteps({});
setIsCaptureTextConfirmed(false);
notify('error', t('right_panel.errors.capture_text_discarded'));
}, [browserSteps, stopGetText, deleteBrowserStep, notify, t]);
2024-09-14 08:38:32 +05:30
2024-09-14 08:34:31 +05:30
const discardGetList = useCallback(() => {
2024-09-14 08:33:23 +05:30
stopGetList();
browserSteps.forEach(step => {
if (step.type === 'list') {
deleteBrowserStep(step.id);
}
});
resetListState();
stopPaginationMode();
stopLimitMode();
2024-10-17 00:32:16 +05:30
setShowPaginationOptions(false);
setShowLimitOptions(false);
setCaptureStage('initial');
setConfirmedListTextFields({});
setIsCaptureListConfirmed(false);
notify('error', t('right_panel.errors.capture_list_discarded'));
}, [browserSteps, stopGetList, deleteBrowserStep, resetListState, setShowPaginationOptions, setShowLimitOptions, setCaptureStage, notify, t]);
2024-09-14 08:32:56 +05:30
const captureScreenshot = (fullPage: boolean) => {
const screenshotSettings: ScreenshotSettings = {
fullPage,
2024-08-05 23:24:11 +05:30
type: 'png',
timeout: 30000,
animations: 'allow',
caret: 'hide',
scale: 'device',
};
2024-10-10 18:34:04 +05:30
socket?.emit('action', { action: 'screenshot', settings: screenshotSettings });
2024-08-06 03:16:09 +05:30
addScreenshotStep(fullPage);
stopGetScreenshot();
resetInterpretationLog();
finishAction('screenshot');
onFinishCapture();
};
const isConfirmCaptureDisabled = useMemo(() => {
if (captureStage !== 'initial') return false;
2025-01-09 17:16:14 +05:30
const hasValidListSelector = browserSteps.some(step =>
step.type === 'list' &&
step.listSelector &&
Object.keys(step.fields).length > 0
);
2025-01-09 17:16:14 +05:30
return !hasValidListSelector || hasUnconfirmedListTextFields;
}, [captureStage, browserSteps, hasUnconfirmedListTextFields]);
2024-11-10 11:29:06 +05:30
const theme = useThemeMode();
const isDarkMode = theme.darkMode;
2025-03-14 23:47:46 +05:30
2024-06-24 22:42:22 +05:30
return (
<Paper sx={{ height: panelHeight, width: 'auto', alignItems: "center", background: 'inherit' }} id="browser-actions" elevation={0}>
2025-01-09 17:16:14 +05:30
<ActionDescriptionBox isDarkMode={isDarkMode} />
2024-10-23 22:26:30 +05:30
<Box display="flex" flexDirection="column" gap={2} style={{ margin: '13px' }}>
{!isAnyActionActive && (
<>
{showCaptureList && (
<Button
variant="contained"
onClick={handleStartGetList}
>
{t('right_panel.buttons.capture_list')}
</Button>
)}
{showCaptureText && (
<Button
variant="contained"
onClick={handleStartGetText}
>
{t('right_panel.buttons.capture_text')}
</Button>
)}
{showCaptureScreenshot && (
<Button
variant="contained"
onClick={handleStartGetScreenshot}
>
{t('right_panel.buttons.capture_screenshot')}
</Button>
)}
</>
)}
2025-01-09 17:16:14 +05:30
2024-09-08 13:52:01 +05:30
{getList && (
<Box>
2024-10-10 20:16:07 +05:30
<Box display="flex" justifyContent="space-between" gap={2} style={{ margin: '15px' }}>
{(captureStage === 'pagination' || captureStage === 'limit') && (
<Button
variant="outlined"
onClick={handleBackCaptureList}
2025-01-09 17:16:14 +05:30
sx={{
color: '#ff00c3 !important',
borderColor: '#ff00c3 !important',
2025-01-08 20:53:02 +05:30
backgroundColor: 'whitesmoke !important',
2025-01-09 17:16:14 +05:30
}}
>
{t('right_panel.buttons.back')}
</Button>
)}
2024-10-10 20:16:07 +05:30
<Button
variant="outlined"
onClick={handleConfirmListCapture}
disabled={captureStage === 'initial' ? isConfirmCaptureDisabled : hasUnconfirmedListTextFields}
2025-01-09 17:16:14 +05:30
sx={{
color: '#ff00c3 !important',
borderColor: '#ff00c3 !important',
2025-01-08 20:53:02 +05:30
backgroundColor: 'whitesmoke !important',
2025-01-09 17:16:14 +05:30
}}
2024-10-10 20:16:07 +05:30
>
{captureStage === 'initial' ? t('right_panel.buttons.confirm_capture') :
2025-01-09 17:16:14 +05:30
captureStage === 'pagination' ? t('right_panel.buttons.confirm_pagination') :
captureStage === 'limit' ? t('right_panel.buttons.confirm_limit') :
t('right_panel.buttons.finish_capture')}
2024-10-10 20:16:07 +05:30
</Button>
2025-01-09 17:16:14 +05:30
<Button
variant="outlined"
color="error"
onClick={discardGetList}
sx={{
color: 'red !important',
borderColor: 'red !important',
2025-01-08 20:53:02 +05:30
backgroundColor: 'whitesmoke !important',
}}
>
{t('right_panel.buttons.discard')}
2024-10-10 20:16:07 +05:30
</Button>
</Box>
{showPaginationOptions && (
<Box display="flex" flexDirection="column" gap={2} style={{ margin: '13px' }}>
<Typography>{t('right_panel.pagination.title')}</Typography>
<Button
variant={paginationType === 'clickNext' ? "contained" : "outlined"}
onClick={() => handlePaginationSettingSelect('clickNext')}
sx={{
color: paginationType === 'clickNext' ? 'whitesmoke !important' : '#ff00c3 !important',
borderColor: '#ff00c3 !important',
backgroundColor: paginationType === 'clickNext' ? '#ff00c3 !important' : 'whitesmoke !important',
}}>
{t('right_panel.pagination.click_next')}
</Button>
<Button
variant={paginationType === 'clickLoadMore' ? "contained" : "outlined"}
onClick={() => handlePaginationSettingSelect('clickLoadMore')}
sx={{
color: paginationType === 'clickLoadMore' ? 'whitesmoke !important' : '#ff00c3 !important',
borderColor: '#ff00c3 !important',
backgroundColor: paginationType === 'clickLoadMore' ? '#ff00c3 !important' : 'whitesmoke !important',
}}>
{t('right_panel.pagination.click_load_more')}
</Button>
<Button
variant={paginationType === 'scrollDown' ? "contained" : "outlined"}
onClick={() => handlePaginationSettingSelect('scrollDown')}
sx={{
color: paginationType === 'scrollDown' ? 'whitesmoke !important' : '#ff00c3 !important',
borderColor: '#ff00c3 !important',
backgroundColor: paginationType === 'scrollDown' ? '#ff00c3 !important' : 'whitesmoke !important',
}}>
{t('right_panel.pagination.scroll_down')}
</Button>
<Button
variant={paginationType === 'scrollUp' ? "contained" : "outlined"}
onClick={() => handlePaginationSettingSelect('scrollUp')}
sx={{
color: paginationType === 'scrollUp' ? 'whitesmoke !important' : '#ff00c3 !important',
borderColor: '#ff00c3 !important',
backgroundColor: paginationType === 'scrollUp' ? '#ff00c3 !important' : 'whitesmoke !important',
}}>
{t('right_panel.pagination.scroll_up')}
</Button>
<Button
variant={paginationType === 'none' ? "contained" : "outlined"}
onClick={() => handlePaginationSettingSelect('none')}
sx={{
color: paginationType === 'none' ? 'whitesmoke !important' : '#ff00c3 !important',
borderColor: '#ff00c3 !important',
backgroundColor: paginationType === 'none' ? '#ff00c3 !important' : 'whitesmoke !important',
}}>
{t('right_panel.pagination.none')}</Button>
</Box>
)}
{showLimitOptions && (
<FormControl>
<FormLabel>
<h4>{t('right_panel.limit.title')}</h4>
</FormLabel>
<RadioGroup
value={limitType}
onChange={(e) => updateLimitType(e.target.value as LimitType)}
sx={{
display: 'flex',
flexDirection: 'column',
width: '500px'
}}
>
<FormControlLabel value="10" control={<Radio />} label="10" />
<FormControlLabel value="100" control={<Radio />} label="100" />
<div style={{ display: 'flex', alignItems: 'center' }}>
<FormControlLabel value="custom" control={<Radio />} label={t('right_panel.limit.custom')} />
{limitType === 'custom' && (
<TextField
type="number"
value={customLimit}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
const value = parseInt(e.target.value);
if (e.target.value === '' || value >= 1) {
updateCustomLimit(e.target.value);
}
}}
inputProps={{
min: 1,
onKeyPress: (e: React.KeyboardEvent<HTMLInputElement>) => {
const value = (e.target as HTMLInputElement).value + e.key;
if (parseInt(value) < 1) {
e.preventDefault();
}
}
}}
placeholder={t('right_panel.limit.enter_number')}
sx={{
marginLeft: '10px',
'& input': {
padding: '10px',
},
width: '150px',
background: isDarkMode ? "#1E2124" : 'white',
color: isDarkMode ? "white" : 'black',
}}
/>
)}
</div>
</RadioGroup>
</FormControl>
)}
2024-08-31 01:19:24 +05:30
</Box>
)}
{getText && (
<Box>
2024-08-06 06:04:22 +05:30
<Box display="flex" justifyContent="space-between" gap={2} style={{ margin: '15px' }}>
2025-01-09 17:16:14 +05:30
<Button
variant="outlined"
onClick={stopCaptureAndEmitGetTextSettings}
sx={{
2025-01-08 20:53:02 +05:30
color: '#ff00c3 !important',
borderColor: '#ff00c3 !important',
backgroundColor: 'whitesmoke !important',
}}
>
2025-01-09 17:16:14 +05:30
{t('right_panel.buttons.confirm')}
2025-01-08 20:53:02 +05:30
</Button>
2025-01-09 17:16:14 +05:30
<Button
variant="outlined"
color="error"
onClick={discardGetText}
sx={{
2025-01-08 20:53:02 +05:30
color: '#ff00c3 !important',
borderColor: '#ff00c3 !important',
backgroundColor: 'whitesmoke !important',
}}
>
2025-01-09 17:16:14 +05:30
{t('right_panel.buttons.discard')}
2025-01-08 20:53:02 +05:30
</Button>
2024-08-06 06:04:22 +05:30
</Box>
</Box>
)}
{getScreenshot && (
<Box display="flex" flexDirection="column" gap={2}>
<Button variant="contained" onClick={() => captureScreenshot(true)}>
{t('right_panel.screenshot.capture_fullpage')}
</Button>
<Button variant="contained" onClick={() => captureScreenshot(false)}>
{t('right_panel.screenshot.capture_visible')}
</Button>
2025-01-09 17:16:14 +05:30
<Button
variant="outlined"
color="error"
onClick={() => {
stopGetScreenshot();
setActiveAction('none');
}}
2025-01-09 17:16:14 +05:30
sx={{
2025-01-08 20:53:02 +05:30
color: '#ff00c3 !important',
borderColor: '#ff00c3 !important',
backgroundColor: 'whitesmoke !important',
}}
>
2025-01-09 17:16:14 +05:30
{t('right_panel.buttons.discard')}
2025-01-08 20:53:02 +05:30
</Button>
</Box>
)}
2024-07-25 01:56:31 +05:30
</Box>
2024-10-10 16:27:38 +05:30
<Box>
{browserSteps.map(step => (
2024-11-24 00:49:39 +05:30
<Box key={step.id} onMouseEnter={() => handleMouseEnter(step.id)} onMouseLeave={() => handleMouseLeave(step.id)} sx={{ padding: '10px', margin: '11px', borderRadius: '5px', position: 'relative', background: isDarkMode ? "#1E2124" : 'white', color: isDarkMode ? "white" : 'black' }}>
2024-10-10 16:27:38 +05:30
{
step.type === 'text' && (
<>
<TextField
label={t('right_panel.fields.label')}
2024-10-10 16:27:38 +05:30
value={textLabels[step.id] || step.label || ''}
onChange={(e) => handleTextLabelChange(step.id, e.target.value)}
fullWidth
2024-10-23 22:26:30 +05:30
size="small"
2024-10-10 16:27:38 +05:30
margin="normal"
error={!!errors[step.id]}
helperText={errors[step.id]}
InputProps={{
readOnly: confirmedTextSteps[step.id],
startAdornment: (
<InputAdornment position="start">
<EditIcon />
</InputAdornment>
)
}}
2024-11-10 14:30:33 +05:30
sx={{ background: isDarkMode ? "#1E2124" : 'white', color: isDarkMode ? "white" : 'black' }}
2024-10-10 16:27:38 +05:30
/>
<TextField
label={t('right_panel.fields.data')}
2024-10-10 16:27:38 +05:30
value={step.data}
fullWidth
margin="normal"
InputProps={{
readOnly: confirmedTextSteps[step.id],
startAdornment: (
<InputAdornment position="start">
<TextFieldsIcon />
</InputAdornment>
)
}}
/>
{!confirmedTextSteps[step.id] ? (
2024-10-10 16:27:38 +05:30
<Box display="flex" justifyContent="space-between" gap={2}>
<Button variant="contained" onClick={() => handleTextStepConfirm(step.id)} disabled={!textLabels[step.id]?.trim()}>{t('right_panel.buttons.confirm')}</Button>
<Button variant="contained" color="error" onClick={() => handleTextStepDiscard(step.id)}>{t('right_panel.buttons.discard')}</Button>
2024-10-10 16:27:38 +05:30
</Box>
) : !isCaptureTextConfirmed && (
<Box display="flex" justifyContent="flex-end" gap={2}>
<Button
variant="contained"
color="error"
onClick={() => handleTextStepDelete(step.id)}
>
{t('right_panel.buttons.delete')}
</Button>
2024-10-10 16:27:38 +05:30
</Box>
)}
</>
)}
{step.type === 'screenshot' && (
<Box display="flex" alignItems="center">
<DocumentScannerIcon sx={{ mr: 1 }} />
<Typography>
2025-01-09 17:16:14 +05:30
{step.fullPage ?
t('right_panel.screenshot.display_fullpage') :
t('right_panel.screenshot.display_visible')}
2024-10-10 16:27:38 +05:30
</Typography>
</Box>
)}
{step.type === 'list' && (
Object.entries(step.fields).length === 0 ? (
<Typography>{t('right_panel.messages.list_empty')}</Typography>
) : (
<>
<Typography>{t('right_panel.messages.list_selected')}</Typography>
{Object.entries(step.fields).map(([key, field]) => (
<Box key={key}>
<TextField
label={t('right_panel.fields.field_label')}
value={field.label || ''}
onChange={(e) => handleTextLabelChange(field.id, e.target.value, step.id, key)}
fullWidth
margin="normal"
InputProps={{
readOnly: confirmedListTextFields[field.id]?.[key],
startAdornment: (
<InputAdornment position="start">
<EditIcon />
</InputAdornment>
)
}}
/>
<TextField
label={t('right_panel.fields.field_data')}
value={field.data || ''}
fullWidth
margin="normal"
InputProps={{
readOnly: true,
startAdornment: (
<InputAdornment position="start">
<TextFieldsIcon />
</InputAdornment>
)
}}
/>
{!confirmedListTextFields[step.id]?.[key] && (
<Box display="flex" justifyContent="space-between" gap={2}>
<Button
variant="contained"
onClick={() => handleListTextFieldConfirm(step.id, key)}
disabled={!field.label?.trim()}
>
{t('right_panel.buttons.confirm')}
</Button>
<Button
variant="contained"
color="error"
onClick={() => handleListTextFieldDiscard(step.id, key)}
>
{t('right_panel.buttons.discard')}
</Button>
</Box>
)}
</Box>
))}
</>
)
2024-10-10 16:27:38 +05:30
)}
2024-10-10 16:21:39 +05:30
</Box>
))}
2024-10-10 16:27:38 +05:30
</Box>
2024-06-24 22:42:22 +05:30
</Paper>
);
2024-08-10 07:07:49 +05:30
};