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

166 lines
5.2 KiB
TypeScript
Raw Normal View History

2024-07-26 18:09:13 +05:30
import React, { useState } from 'react';
2024-07-26 09:29:14 +05:30
import { Button, MenuItem, Paper, Box, TextField } from "@mui/material";
2024-06-24 22:42:22 +05:30
import { Dropdown as MuiDropdown } from '../atoms/DropdownMui';
import styled from "styled-components";
import { ActionSettings } from "../molecules/ActionSettings";
import { SelectChangeEvent } from "@mui/material/Select/Select";
import { SimpleBox } from "../atoms/Box";
import Typography from "@mui/material/Typography";
import { useGlobalInfoStore } from "../../context/globalInfo";
import { PairForEdit } from "../../pages/RecordingPage";
2024-07-24 20:25:22 +05:30
import { useActionContext } from '../../context/browserActions';
2024-06-24 22:42:22 +05:30
interface RightSidePanelProps {
pairForEdit: PairForEdit;
}
2024-07-26 09:29:14 +05:30
interface BrowserStep {
id: number;
label: string;
description: string;
}
2024-06-24 22:42:22 +05:30
2024-07-26 09:29:14 +05:30
export const RightSidePanel = ({ pairForEdit }: RightSidePanelProps) => {
2024-06-24 22:42:22 +05:30
const [content, setContent] = useState<string>('action');
2024-07-26 09:29:14 +05:30
const [action, setAction] = useState<string>('');
const [isSettingsDisplayed, setIsSettingsDisplayed] = useState<boolean>(false);
const [browserSteps, setBrowserSteps] = useState<BrowserStep[]>([]);
const [stepLabel, setStepLabel] = useState<string>('');
2024-07-26 18:09:13 +05:30
const [stepDescription, setStepDescription] = useState<string>('');
2024-06-24 22:42:22 +05:30
const { lastAction } = useGlobalInfoStore();
2024-07-24 21:37:26 +05:30
const { getText, getScreenshot, startGetText, stopGetText, startGetScreenshot, stopGetScreenshot } = useActionContext();
2024-06-24 22:42:22 +05:30
const handleChange = (event: React.SyntheticEvent, newValue: string) => {
setContent(newValue);
};
const handleActionSelect = (event: SelectChangeEvent) => {
const { value } = event.target;
setAction(value);
setIsSettingsDisplayed(true);
};
2024-07-26 18:09:13 +05:30
const confirmStep = () => {
setBrowserSteps([
...browserSteps,
{ id: Date.now(), label: stepLabel, description: stepDescription }
]);
2024-07-26 09:29:14 +05:30
setStepLabel('');
2024-07-26 18:09:13 +05:30
setStepDescription('');
2024-07-26 09:29:14 +05:30
};
2024-07-26 18:09:13 +05:30
const discardStep = () => {
setStepLabel('');
setStepDescription('');
2024-07-26 09:29:14 +05:30
};
2024-07-24 21:37:26 +05:30
2024-06-24 22:42:22 +05:30
return (
<Paper
variant="outlined"
sx={{
height: '100%',
width: '100%',
backgroundColor: 'white',
alignItems: "center",
}}>
<SimpleBox height={60} width='100%' background='lightGray' radius='0%'>
<Typography sx={{ padding: '10px' }}>
Last action:
{` ${lastAction}`}
</Typography>
</SimpleBox>
{content === 'action' ? (
2024-07-24 21:25:13 +05:30
<React.Fragment>
<ActionDescription>Type of action:</ActionDescription>
<ActionTypeWrapper>
<MuiDropdown
id="action"
label="Action"
value={action}
handleSelect={handleActionSelect}>
<MenuItem value="mouse.click">click on coordinates</MenuItem>
<MenuItem value="enqueueLinks">enqueueLinks</MenuItem>
<MenuItem value="scrape">scrape</MenuItem>
<MenuItem value="scrapeSchema">scrapeSchema</MenuItem>
<MenuItem value="screenshot">screenshot</MenuItem>
<MenuItem value="script">script</MenuItem>
<MenuItem value="scroll">scroll</MenuItem>
</MuiDropdown>
</ActionTypeWrapper>
2024-06-24 22:42:22 +05:30
2024-07-24 21:25:13 +05:30
{isSettingsDisplayed &&
<ActionSettings action={action} />
}
</React.Fragment>
2024-07-26 09:29:14 +05:30
) : null}
2024-07-24 20:25:22 +05:30
2024-07-25 01:56:45 +05:30
<Box display="flex" flexDirection="column" gap={2} style={{ margin: '15px' }}>
2024-07-25 01:56:31 +05:30
{!getText && !getScreenshot && (
<Button variant="contained" onClick={startGetText}>
Capture Text
</Button>
)}
{getText && (
<Button variant="contained" onClick={stopGetText}>
Stop Capture Text
</Button>
)}
2024-07-25 00:58:08 +05:30
2024-07-25 01:56:31 +05:30
{!getText && !getScreenshot && (
<Button variant="contained" onClick={startGetScreenshot}>
Capture Screenshot
</Button>
)}
{getScreenshot && (
<Button variant="contained" onClick={stopGetScreenshot}>
Stop Capture Screenshot
</Button>
)}
</Box>
2024-07-26 09:29:14 +05:30
<Box display="flex" flexDirection="column" gap={2} style={{ margin: '15px' }}>
<TextField
2024-07-26 18:09:13 +05:30
label="Label"
2024-07-26 09:29:14 +05:30
value={stepLabel}
onChange={(e) => setStepLabel(e.target.value)}
/>
2024-07-26 18:09:13 +05:30
<TextField
label="Description"
value={stepDescription}
onChange={(e) => setStepDescription(e.target.value)}
/>
<Box display="flex" justifyContent="space-between" gap={2}>
<Button variant="contained" onClick={confirmStep}>
Confirm
</Button>
<Button variant="contained" onClick={discardStep}>
Discard
</Button>
</Box>
2024-07-26 09:29:14 +05:30
</Box>
<Box display="flex" flexDirection="column" gap={2} style={{ margin: '15px' }}>
{browserSteps.map(step => (
<Box key={step.id} sx={{ border: '1px solid black', padding: '10px' }}>
2024-07-26 18:09:13 +05:30
<Typography variant="h6">{step.label}</Typography>
2024-07-26 09:29:14 +05:30
<Typography>{step.description}</Typography>
</Box>
))}
</Box>
2024-06-24 22:42:22 +05:30
</Paper>
);
};
const ActionTypeWrapper = styled.div`
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
margin-top: 20px;
`;
export const ActionDescription = styled.p`
margin-left: 15px;
2024-07-26 09:29:14 +05:30
`;