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

546 lines
22 KiB
TypeScript
Raw Normal View History

2024-10-08 17:39:36 +05:30
import React, { useState, useCallback, useEffect } from 'react';
2024-08-06 02:33:39 +05:30
import { Button, Paper, Box, TextField } 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-06-24 22:42:22 +05:30
import { SimpleBox } from "../atoms/Box";
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-07 08:38:00 +05:30
import { SidePanelHeader } from '../molecules/SidePanelHeader';
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 17:16:35 +05:30
import { emptyWorkflow } from "../../shared/constants";
2024-10-08 18:39:59 +05:30
import { getActiveWorkflow } from "../../api/workflow";
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-08-11 08:46:48 +05:30
// TODO:
2024-09-14 02:23:40 +05:30
// 1. Add description for each browser step
// 2. Handle non custom action steps
2024-09-08 07:39:09 +05:30
interface RightSidePanelProps {
onFinishCapture: () => void;
}
export const RightSidePanel: React.FC<RightSidePanelProps> = ({ onFinishCapture }) => {
2024-10-08 17:17:03 +05:30
const [workflow, setWorkflow] = useState<WorkflowFile>(emptyWorkflow);
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 [showPaginationOptions, setShowPaginationOptions] = useState(false);
2024-09-08 12:19:11 +05:30
const [showLimitOptions, setShowLimitOptions] = useState(false);
const [showCaptureList, setShowCaptureList] = useState(true);
const [showCaptureScreenshot, setShowCaptureScreenshot] = useState(true);
const [showCaptureText, setShowCaptureText] = useState(true);
2024-09-08 13:52:01 +05:30
const [captureStage, setCaptureStage] = useState<'initial' | 'pagination' | 'limit' | 'complete'>('initial');
const { lastAction, notify } = useGlobalInfoStore();
2024-09-14 07:04:20 +05:30
const { getText, startGetText, stopGetText, getScreenshot, startGetScreenshot, stopGetScreenshot, getList, startGetList, stopGetList, startPaginationMode, stopPaginationMode, paginationType, updatePaginationType, limitType, customLimit, updateLimitType, updateCustomLimit, stopLimitMode, startLimitMode } = 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();
2024-06-24 22:42:22 +05:30
2024-10-08 17:36:52 +05:30
const workflowHandler = useCallback((data: WorkflowFile) => {
setWorkflow(data);
2024-10-08 17:38:41 +05:30
//setRecordingLength(data.workflow.length);
2024-10-08 17:36:52 +05:30
}, [workflow])
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);
}
}, (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(() => {
const hasScrapeListAction = workflow.workflow.some(pair =>
pair.what.some(action => action.action === "scrapeList")
);
2024-10-08 18:07:24 +05:30
const hasScreenshotAction = workflow.workflow.some(pair =>
pair.what.some(action => action.action === "screenshot")
);
2024-10-08 18:29:34 +05:30
const hasScrapeSchemaAction = workflow.workflow.some(pair =>
pair.what.some(action => action.action === "scrapeSchema")
);
2024-10-08 18:53:17 +05:30
setShowCaptureList(!(hasScrapeListAction || hasScrapeSchemaAction || hasScreenshotAction));
setShowCaptureScreenshot(!(hasScrapeListAction || hasScrapeSchemaAction || hasScreenshotAction));
setShowCaptureText(!(hasScrapeListAction || hasScreenshotAction));
}, [workflow]);
2024-10-08 18:36:19 +05:30
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]: 'Label cannot be empty' }));
} 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 {
2024-07-26 23:25:03 +05:30
setErrors(prevErrors => ({ ...prevErrors, [id]: 'Label cannot be empty' }));
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 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 getTextSettingsObject = useCallback(() => {
2024-08-06 05:05:50 +05:30
const settings: Record<string, { selector: string; tag?: string;[key: string]: any }> = {};
browserSteps.forEach(step => {
2024-08-06 03:25:52 +05:30
if (step.type === 'text' && step.label && step.selectorObj?.selector) {
settings[step.label] = step.selectorObj;
}
});
return settings;
2024-08-06 03:25:52 +05:30
}, [browserSteps]);
2024-08-06 03:12:07 +05:30
2024-08-06 05:05:50 +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) {
2024-09-21 18:21:49 +05:30
notify('error', 'Please confirm all text fields');
return;
}
2024-08-06 03:25:52 +05:30
stopGetText();
const settings = getTextSettingsObject();
const hasTextSteps = browserSteps.some(step => step.type === 'text');
if (hasTextSteps) {
socket?.emit('action', { action: 'scrapeSchema', settings });
2024-08-06 03:25:52 +05:30
}
onFinishCapture();
}, [stopGetText, getTextSettingsObject, socket, browserSteps, confirmedTextSteps]);
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('');
2024-09-08 13:52:01 +05:30
}, [updatePaginationType, 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) {
socket?.emit('action', { action: 'scrapeList', settings });
2024-08-10 05:04:50 +05:30
} else {
2024-08-10 05:06:43 +05:30
notify('error', 'Unable to create list settings. Make sure you have defined a field for the list.');
}
2024-09-04 05:34:56 +05:30
handleStopGetList();
onFinishCapture();
2024-09-04 05:34:56 +05:30
}, [stopGetList, getListSettingsObject, socket, notify, handleStopGetList]);
2024-08-09 10:32:48 +05:30
const handleConfirmListCapture = useCallback(() => {
2024-09-08 13:52:01 +05:30
switch (captureStage) {
case 'initial':
startPaginationMode();
const hasUnconfirmedListTextFields = browserSteps.some(step => step.type === 'list' && Object.values(step.fields).some(field => !confirmedListTextFields[step.id]?.[field.id]));
if (hasUnconfirmedListTextFields) {
notify('error', 'Please confirm all field labels.');
return;
}
setShowPaginationOptions(true);
setCaptureStage('pagination');
2024-09-08 13:52:01 +05:30
break;
case 'pagination':
if (!paginationType) {
notify('error', 'Please select a pagination type.');
return;
}
const settings = getListSettingsObject();
const paginationSelector = settings.pagination?.selector;
if (['clickNext', 'clickLoadMore'].includes(paginationType) && !paginationSelector) {
notify('error', 'Please select the pagination element first.');
return;
}
stopPaginationMode();
setShowPaginationOptions(false);
startLimitMode();
setShowLimitOptions(true);
setCaptureStage('limit');
break;
case 'limit':
if (!limitType || (limitType === 'custom' && !customLimit)) {
notify('error', 'Please select a limit or enter a custom limit.');
return;
}
const limit = limitType === 'custom' ? parseInt(customLimit) : parseInt(limitType);
if (isNaN(limit) || limit <= 0) {
notify('error', 'Please enter a valid limit.');
return;
}
stopLimitMode();
setShowLimitOptions(false);
stopCaptureAndEmitGetListSettings();
setCaptureStage('complete');
break;
case 'complete':
setCaptureStage('initial');
break;
}
2024-09-08 13:52:01 +05:30
}, [captureStage, paginationType, limitType, customLimit, startPaginationMode, stopPaginationMode, startLimitMode, stopLimitMode, notify, stopCaptureAndEmitGetListSettings, getListSettingsObject]);
2024-09-08 13:52:23 +05:30
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({});
2024-09-21 16:57:07 +05:30
notify('error', 'Capture Text Discarded');
2024-09-14 08:32:56 +05:30
}, [browserSteps, stopGetText, deleteBrowserStep]);
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();
2024-09-21 16:57:07 +05:30
notify('error', 'Capture List Discarded');
2024-09-14 08:33:23 +05:30
}, [browserSteps, stopGetList, deleteBrowserStep, resetListState]);
2024-09-14 08:38:32 +05:30
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-08-05 23:24:11 +05:30
socket?.emit('action', { action: 'screenshot', settings: screenshotSettings });
2024-08-06 03:16:09 +05:30
addScreenshotStep(fullPage);
stopGetScreenshot();
};
2024-06-24 22:42:22 +05:30
return (
<Paper variant="outlined" sx={{ height: '100%', width: '100%', backgroundColor: 'white', alignItems: "center" }}>
2024-06-24 22:42:22 +05:30
<SimpleBox height={60} width='100%' background='lightGray' radius='0%'>
<Typography sx={{ padding: '10px' }}>Last action: {` ${lastAction}`}</Typography>
2024-06-24 22:42:22 +05:30
</SimpleBox>
2024-09-07 08:38:00 +05:30
<SidePanelHeader />
2024-07-25 01:56:45 +05:30
<Box display="flex" flexDirection="column" gap={2} style={{ margin: '15px' }}>
{!getText && !getScreenshot && !getList && !showCaptureList && <Button variant="contained" onClick={startGetList}>Capture List</Button>}
2024-09-08 13:52:01 +05:30
{getList && (
2024-08-08 02:19:38 +05:30
<>
<Box display="flex" justifyContent="space-between" gap={2} style={{ margin: '15px' }}>
2024-09-08 13:52:01 +05:30
<Button variant="outlined" onClick={handleConfirmListCapture}>
2024-09-08 13:52:47 +05:30
{captureStage === 'initial' ? 'Confirm Capture' :
2024-09-08 13:52:23 +05:30
captureStage === 'pagination' ? 'Confirm Pagination' :
captureStage === 'limit' ? 'Confirm Limit' : 'Finish Capture'}
2024-09-08 13:52:01 +05:30
</Button>
2024-09-14 08:35:41 +05:30
<Button variant="outlined" color="error" onClick={discardGetList}>Discard</Button>
2024-08-08 02:19:38 +05:30
</Box>
</>
2024-09-08 13:52:01 +05:30
)}
2024-08-31 01:19:34 +05:30
{showPaginationOptions && (
2024-08-31 01:19:24 +05:30
<Box display="flex" flexDirection="column" gap={2} style={{ margin: '15px' }}>
2024-08-31 01:28:13 +05:30
<Typography>How can we find the next list item on the page?</Typography>
<Button variant={paginationType === 'clickNext' ? "contained" : "outlined"} onClick={() => handlePaginationSettingSelect('clickNext')}>Click on next to navigate to the next page</Button>
<Button variant={paginationType === 'clickLoadMore' ? "contained" : "outlined"} onClick={() => handlePaginationSettingSelect('clickLoadMore')}>Click on load more to load more items</Button>
<Button variant={paginationType === 'scrollDown' ? "contained" : "outlined"} onClick={() => handlePaginationSettingSelect('scrollDown')}>Scroll down to load more items</Button>
<Button variant={paginationType === 'scrollUp' ? "contained" : "outlined"} onClick={() => handlePaginationSettingSelect('scrollUp')}>Scroll up to load more items</Button>
<Button variant={paginationType === 'none' ? "contained" : "outlined"} onClick={() => handlePaginationSettingSelect('none')}>No more items to load</Button>
2024-08-31 01:19:24 +05:30
</Box>
)}
2024-09-08 13:52:01 +05:30
{showLimitOptions && (
2024-09-08 14:09:08 +05:30
<FormControl>
<FormLabel>
<h4>What is the maximum number of rows you want to extract?</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="Custom" />
{limitType === 'custom' && (
<TextField
type="number"
value={customLimit}
onChange={(e) => updateCustomLimit(e.target.value)}
placeholder="Enter number"
sx={{
marginLeft: '10px',
'& input': {
padding: '10px',
},
}}
/>
)}
</div>
</RadioGroup>
</FormControl>
2024-09-08 12:23:34 +05:30
)}
2024-10-08 19:00:02 +05:30
{!getText && !getScreenshot && !getList && !showCaptureText && <Button variant="contained" onClick={startGetText}>Capture Text</Button>}
2024-08-06 06:04:22 +05:30
{getText &&
<>
<Box display="flex" justifyContent="space-between" gap={2} style={{ margin: '15px' }}>
<Button variant="outlined" onClick={stopCaptureAndEmitGetTextSettings} >Confirm</Button>
2024-09-14 08:35:41 +05:30
<Button variant="outlined" color="error" onClick={discardGetText} >Discard</Button>
2024-08-06 06:04:22 +05:30
</Box>
</>
}
{!getText && !getScreenshot && !getList && !showCaptureScreenshot && <Button variant="contained" onClick={startGetScreenshot}>Capture Screenshot</Button>}
{getScreenshot && (
<Box display="flex" flexDirection="column" gap={2}>
2024-08-05 23:24:11 +05:30
<Button variant="contained" onClick={() => captureScreenshot(true)}>Capture Fullpage</Button>
<Button variant="contained" onClick={() => captureScreenshot(false)}>Capture Visible Part</Button>
2024-08-06 05:05:50 +05:30
<Button variant="outlined" color="error" onClick={stopGetScreenshot}>Discard</Button>
</Box>
)}
2024-07-25 01:56:31 +05:30
</Box>
2024-08-06 05:06:04 +05:30
<Box>
{browserSteps.map(step => (
<Box key={step.id} sx={{ boxShadow: 5, padding: '10px', margin: '10px', borderRadius: '4px' }}>
{
2024-08-10 07:07:49 +05:30
step.type === 'text' && (
2024-08-06 05:06:04 +05:30
<>
<TextField
label="Label"
value={textLabels[step.id] || step.label || ''}
onChange={(e) => handleTextLabelChange(step.id, e.target.value)}
fullWidth
margin="normal"
error={!!errors[step.id]}
helperText={errors[step.id]}
2024-08-06 06:13:24 +05:30
InputProps={{
2024-08-06 06:04:22 +05:30
readOnly: confirmedTextSteps[step.id],
startAdornment: (
<InputAdornment position="start">
<EditIcon />
</InputAdornment>
)
}}
2024-08-06 05:06:04 +05:30
/>
<TextField
label="Data"
value={step.data}
fullWidth
margin="normal"
2024-08-06 06:13:24 +05:30
InputProps={{
2024-08-06 06:04:22 +05:30
readOnly: confirmedTextSteps[step.id],
startAdornment: (
<InputAdornment position="start">
<TextFieldsIcon />
</InputAdornment>
)
}}
2024-08-06 05:06:04 +05:30
/>
{!confirmedTextSteps[step.id] && (
<Box display="flex" justifyContent="space-between" gap={2}>
<Button variant="contained" onClick={() => handleTextStepConfirm(step.id)} disabled={!textLabels[step.id]?.trim()}>Confirm</Button>
<Button variant="contained" onClick={() => handleTextStepDiscard(step.id)}>Discard</Button>
</Box>
)}
</>
2024-08-10 07:07:49 +05:30
)}
2024-08-10 07:42:41 +05:30
{step.type === 'screenshot' && (
2024-08-10 07:07:49 +05:30
<Box display="flex" alignItems="center">
<DocumentScannerIcon sx={{ mr: 1 }} />
<Typography>
{`Take ${step.fullPage ? 'Fullpage' : 'Visible Part'} Screenshot`}
</Typography>
</Box>
2024-08-10 07:42:41 +05:30
)}
{step.type === 'list' && (
2024-08-10 07:07:49 +05:30
<>
<Typography>List Selected Successfully</Typography>
{Object.entries(step.fields).map(([key, field]) => (
<Box key={key}>
<TextField
label="Field Label"
value={field.label || ''}
2024-09-13 23:34:02 +05:30
onChange={(e) => handleTextLabelChange(field.id, e.target.value, step.id, key)}
2024-08-10 07:07:49 +05:30
fullWidth
margin="normal"
InputProps={{
readOnly: confirmedListTextFields[field.id]?.[key],
2024-08-10 07:07:49 +05:30
startAdornment: (
<InputAdornment position="start">
<EditIcon />
</InputAdornment>
)
}}
/>
<TextField
label="Field Data"
value={field.data || ''}
fullWidth
margin="normal"
InputProps={{
readOnly: true,
startAdornment: (
<InputAdornment position="start">
<TextFieldsIcon />
</InputAdornment>
)
}}
/>
2024-09-13 23:58:00 +05:30
{!confirmedListTextFields[step.id]?.[key] && (
<Box display="flex" justifyContent="space-between" gap={2}>
2024-09-13 23:58:09 +05:30
<Button
variant="contained"
2024-09-13 23:58:00 +05:30
onClick={() => handleListTextFieldConfirm(step.id, key)}
disabled={!field.label?.trim()}
>
Confirm
</Button>
2024-09-13 23:58:09 +05:30
<Button
variant="contained"
2024-09-13 23:58:00 +05:30
onClick={() => handleListTextFieldDiscard(step.id, key)}
>
Discard
</Button>
</Box>
)}
2024-08-06 06:13:24 +05:30
</Box>
2024-08-10 07:07:49 +05:30
))}
</>
)}
2024-07-26 23:25:03 +05:30
</Box>
2024-08-06 05:06:04 +05:30
))}
</Box>
2024-06-24 22:42:22 +05:30
</Paper>
);
2024-08-10 07:07:49 +05:30
};