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

124 lines
3.8 KiB
TypeScript
Raw Normal View History

import React from 'react';
2024-10-19 06:07:56 +05:30
import styled from 'styled-components';
import { Typography, FormControlLabel, Checkbox, Box } from '@mui/material';
import { useActionContext } from '../../context/browserActions';
2024-11-03 21:18:17 +05:30
import MaxunLogo from "../../assets/maxunlogo.png";
2024-10-19 06:07:56 +05:30
const CustomBoxContainer = styled.div`
position: relative;
2024-10-20 15:55:27 +05:30
min-width: 250px;
width: auto;
2024-10-19 09:00:01 +05:30
min-height: 100px;
height: auto;
// border: 2px solid #ff00c3;
2024-10-23 19:01:19 +05:30
border-radius: 5px;
2024-10-19 06:07:56 +05:30
background-color: white;
2024-10-23 22:06:56 +05:30
margin: 80px 13px 25px 13px;
2024-10-19 06:07:56 +05:30
`;
const Triangle = styled.div`
position: absolute;
2024-10-23 20:22:42 +05:30
top: -15px;
2024-10-19 06:07:56 +05:30
left: 50%;
transform: translateX(-50%);
width: 0;
height: 0;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
border-bottom: 20px solid white;
`;
const Logo = styled.img`
position: absolute;
2024-10-23 20:26:11 +05:30
top: -80px;
left: 50%;
transform: translateX(-50%);
2024-10-23 20:26:11 +05:30
width: 70px;
height: auto;
2024-10-23 20:23:58 +05:30
border-radius: 5px;
2024-10-19 06:07:56 +05:30
`;
const Content = styled.div`
padding: 20px;
2024-10-19 08:14:32 +05:30
text-align: left;
2024-10-19 06:07:56 +05:30
`;
2024-10-19 06:45:10 +05:30
const ActionDescriptionBox = () => {
const { getText, getScreenshot, getList, captureStage } = useActionContext() as {
getText: boolean;
getScreenshot: boolean;
getList: boolean;
captureStage: 'initial' | 'pagination' | 'limit' | 'complete';
};
const messages = [
{ stage: 'initial' as const, text: 'Select the list you want to extract along with the texts inside it' },
{ stage: 'pagination' as const, text: 'Select how the robot can capture the rest of the list' },
{ stage: 'limit' as const, text: 'Choose the number of items to extract' },
{ stage: 'complete' as const, text: 'Capture is complete' },
];
2024-10-19 06:45:10 +05:30
const stages = messages.map(({ stage }) => stage); // Create a list of stages
const currentStageIndex = stages.indexOf(captureStage); // Get the index of the current stage
2024-10-19 06:45:10 +05:30
const renderActionDescription = () => {
if (getText) {
2024-10-19 06:48:13 +05:30
return (
<>
2024-10-19 08:55:17 +05:30
<Typography variant="subtitle2" gutterBottom>Capture Text</Typography>
<Typography variant="body2" gutterBottom>Hover over the texts you want to extract and click to select them</Typography>
2024-10-19 06:48:13 +05:30
</>
);
2024-10-19 06:45:10 +05:30
} else if (getScreenshot) {
2024-10-19 06:51:53 +05:30
return (
<>
2024-10-19 08:55:17 +05:30
<Typography variant="subtitle2" gutterBottom>Capture Screenshot</Typography>
<Typography variant="body2" gutterBottom>Capture a partial or full page screenshot of the current page.</Typography>
2024-10-19 06:51:53 +05:30
</>
);
2024-10-19 06:45:10 +05:30
} else if (getList) {
2024-10-19 06:50:27 +05:30
return (
<>
2024-10-19 08:55:17 +05:30
<Typography variant="subtitle2" gutterBottom>Capture List</Typography>
<Typography variant="body2" gutterBottom>
2024-10-19 08:07:00 +05:30
Hover over the list you want to extract. Once selected, you can hover over all texts inside the list you selected. Click to select them.
</Typography>
<Box>
{messages.map(({ stage, text }, index) => (
<FormControlLabel
key={stage}
control={
<Checkbox
checked={index < currentStageIndex} // Check the box if we are past this stage
disabled
/>
}
label={<Typography variant="body2" gutterBottom>{text}</Typography>}
/>
))}
</Box>
2024-10-19 06:50:27 +05:30
</>
);
2024-10-19 06:45:10 +05:30
} else {
return (
2024-10-19 06:58:31 +05:30
<>
2024-10-19 08:55:17 +05:30
<Typography variant="subtitle2" gutterBottom>What data do you want to extract?</Typography>
<Typography variant="body2" gutterBottom>A robot is designed to perform one action at a time. You can choose any of the options below.</Typography>
2024-10-19 06:58:31 +05:30
</>
);
2024-10-19 06:45:10 +05:30
}
};
2024-10-19 06:45:10 +05:30
2024-10-19 06:52:41 +05:30
return (
<CustomBoxContainer>
2024-11-03 21:18:17 +05:30
<Logo src={MaxunLogo} alt="Maxun Logo" />
2024-10-19 06:52:41 +05:30
<Triangle />
<Content>
{renderActionDescription()}
</Content>
</CustomBoxContainer>
);
2024-10-19 06:07:56 +05:30
};
export default ActionDescriptionBox;