feat: emit key-value pair for scrapeSchema
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState, useEffect, useCallback } from 'react';
|
||||||
import { Button, MenuItem, Paper, Box, TextField } from "@mui/material";
|
import { Button, MenuItem, Paper, Box, TextField } from "@mui/material";
|
||||||
import { Dropdown as MuiDropdown } from '../atoms/DropdownMui';
|
import { Dropdown as MuiDropdown } from '../atoms/DropdownMui';
|
||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
@@ -10,17 +10,12 @@ import { useGlobalInfoStore } from "../../context/globalInfo";
|
|||||||
import { PairForEdit } from "../../pages/RecordingPage";
|
import { PairForEdit } from "../../pages/RecordingPage";
|
||||||
import { useActionContext } from '../../context/browserActions';
|
import { useActionContext } from '../../context/browserActions';
|
||||||
import { useBrowserSteps } from '../../context/browserSteps';
|
import { useBrowserSteps } from '../../context/browserSteps';
|
||||||
|
import { useSocketStore } from '../../context/socket';
|
||||||
|
|
||||||
interface RightSidePanelProps {
|
interface RightSidePanelProps {
|
||||||
pairForEdit: PairForEdit;
|
pairForEdit: PairForEdit;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface BrowserStep {
|
|
||||||
id: number;
|
|
||||||
label: string;
|
|
||||||
description: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const RightSidePanel = ({ pairForEdit }: RightSidePanelProps) => {
|
export const RightSidePanel = ({ pairForEdit }: RightSidePanelProps) => {
|
||||||
const [content, setContent] = useState<string>('action');
|
const [content, setContent] = useState<string>('action');
|
||||||
const [action, setAction] = useState<string>('');
|
const [action, setAction] = useState<string>('');
|
||||||
@@ -29,10 +24,10 @@ export const RightSidePanel = ({ pairForEdit }: RightSidePanelProps) => {
|
|||||||
const [errors, setErrors] = useState<{ [id: number]: string }>({});
|
const [errors, setErrors] = useState<{ [id: number]: string }>({});
|
||||||
const [confirmedSteps, setConfirmedSteps] = useState<{ [id: number]: boolean }>({});
|
const [confirmedSteps, setConfirmedSteps] = useState<{ [id: number]: boolean }>({});
|
||||||
|
|
||||||
|
|
||||||
const { lastAction } = useGlobalInfoStore();
|
const { lastAction } = useGlobalInfoStore();
|
||||||
const { getText, getScreenshot, startGetText, stopGetText, startGetScreenshot, stopGetScreenshot } = useActionContext();
|
const { getText, getScreenshot, startGetText, stopGetText, startGetScreenshot, stopGetScreenshot } = useActionContext();
|
||||||
const { browserSteps, updateBrowserStepLabel, deleteBrowserStep } = useBrowserSteps();
|
const { browserSteps, updateBrowserStepLabel, deleteBrowserStep } = useBrowserSteps();
|
||||||
|
const { socket } = useSocketStore();
|
||||||
|
|
||||||
const handleChange = (event: React.SyntheticEvent, newValue: string) => {
|
const handleChange = (event: React.SyntheticEvent, newValue: string) => {
|
||||||
setContent(newValue);
|
setContent(newValue);
|
||||||
@@ -44,7 +39,6 @@ export const RightSidePanel = ({ pairForEdit }: RightSidePanelProps) => {
|
|||||||
setIsSettingsDisplayed(true);
|
setIsSettingsDisplayed(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const handleLabelChange = (id: number, label: string) => {
|
const handleLabelChange = (id: number, label: string) => {
|
||||||
setLabels(prevLabels => ({ ...prevLabels, [id]: label }));
|
setLabels(prevLabels => ({ ...prevLabels, [id]: label }));
|
||||||
if (!label.trim()) {
|
if (!label.trim()) {
|
||||||
@@ -76,31 +70,36 @@ export const RightSidePanel = ({ pairForEdit }: RightSidePanelProps) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Create settings object when stopping text capture
|
||||||
|
const createSettingsObject = useCallback(() => {
|
||||||
|
const settings: Record<string, string> = {};
|
||||||
|
browserSteps.forEach(step => {
|
||||||
|
if (step.label && step.value) {
|
||||||
|
settings[step.label] = step.value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
console.log(`settings from getText:`, settings);
|
||||||
|
return settings;
|
||||||
|
}, [browserSteps]);
|
||||||
|
|
||||||
|
// Stop text capture and emit settings object
|
||||||
|
const stopCaptureAndEmitSettings = useCallback(() => {
|
||||||
|
stopGetText();
|
||||||
|
const settings = createSettingsObject();
|
||||||
|
socket?.emit('action', { action: 'settings', settings });
|
||||||
|
}, [stopGetText, createSettingsObject, socket]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Paper
|
<Paper variant="outlined" sx={{ height: '100%', width: '100%', backgroundColor: 'white', alignItems: "center" }}>
|
||||||
variant="outlined"
|
|
||||||
sx={{
|
|
||||||
height: '100%',
|
|
||||||
width: '100%',
|
|
||||||
backgroundColor: 'white',
|
|
||||||
alignItems: "center",
|
|
||||||
}}>
|
|
||||||
<SimpleBox height={60} width='100%' background='lightGray' radius='0%'>
|
<SimpleBox height={60} width='100%' background='lightGray' radius='0%'>
|
||||||
<Typography sx={{ padding: '10px' }}>
|
<Typography sx={{ padding: '10px' }}>Last action: {` ${lastAction}`}</Typography>
|
||||||
Last action:
|
|
||||||
{` ${lastAction}`}
|
|
||||||
</Typography>
|
|
||||||
</SimpleBox>
|
</SimpleBox>
|
||||||
|
|
||||||
{content === 'action' ? (
|
{content === 'action' && (
|
||||||
<React.Fragment>
|
<>
|
||||||
<ActionDescription>Type of action:</ActionDescription>
|
<ActionDescription>Type of action:</ActionDescription>
|
||||||
<ActionTypeWrapper>
|
<ActionTypeWrapper>
|
||||||
<MuiDropdown
|
<MuiDropdown id="action" label="Action" value={action} handleSelect={handleActionSelect}>
|
||||||
id="action"
|
|
||||||
label="Action"
|
|
||||||
value={action}
|
|
||||||
handleSelect={handleActionSelect}>
|
|
||||||
<MenuItem value="mouse.click">click on coordinates</MenuItem>
|
<MenuItem value="mouse.click">click on coordinates</MenuItem>
|
||||||
<MenuItem value="enqueueLinks">enqueueLinks</MenuItem>
|
<MenuItem value="enqueueLinks">enqueueLinks</MenuItem>
|
||||||
<MenuItem value="scrape">scrape</MenuItem>
|
<MenuItem value="scrape">scrape</MenuItem>
|
||||||
@@ -111,44 +110,20 @@ export const RightSidePanel = ({ pairForEdit }: RightSidePanelProps) => {
|
|||||||
</MuiDropdown>
|
</MuiDropdown>
|
||||||
</ActionTypeWrapper>
|
</ActionTypeWrapper>
|
||||||
|
|
||||||
{isSettingsDisplayed &&
|
{isSettingsDisplayed && <ActionSettings action={action} />}
|
||||||
<ActionSettings action={action} />
|
</>
|
||||||
}
|
)}
|
||||||
</React.Fragment>
|
|
||||||
) : null}
|
|
||||||
|
|
||||||
<Box display="flex" flexDirection="column" gap={2} style={{ margin: '15px' }}>
|
<Box display="flex" flexDirection="column" gap={2} style={{ margin: '15px' }}>
|
||||||
{!getText && !getScreenshot && (
|
{!getText && !getScreenshot && <Button variant="contained" onClick={startGetText}>Capture Text</Button>}
|
||||||
<Button variant="contained" onClick={startGetText}>
|
{getText && <Button variant="contained" onClick={stopCaptureAndEmitSettings}>Stop Capture Text</Button>}
|
||||||
Capture Text
|
{!getText && !getScreenshot && <Button variant="contained" onClick={startGetScreenshot}>Capture Screenshot</Button>}
|
||||||
</Button>
|
{getScreenshot && <Button variant="contained" onClick={stopGetScreenshot}>Stop Capture Screenshot</Button>}
|
||||||
)}
|
|
||||||
{getText && (
|
|
||||||
<Button variant="contained" onClick={stopGetText}>
|
|
||||||
Stop Capture Text
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{!getText && !getScreenshot && (
|
|
||||||
<Button variant="contained" onClick={startGetScreenshot}>
|
|
||||||
Capture Screenshot
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
{getScreenshot && (
|
|
||||||
<Button variant="contained" onClick={stopGetScreenshot}>
|
|
||||||
Stop Capture Screenshot
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<Box>
|
<Box>
|
||||||
{browserSteps.map(step => (
|
{browserSteps.map(step => (
|
||||||
<Box key={step.id} sx={{
|
<Box key={step.id} sx={{ boxShadow: 5, padding: '10px', margin: '10px', borderRadius: '4px' }}>
|
||||||
boxShadow: 5,
|
|
||||||
padding: '10px',
|
|
||||||
margin: '10px',
|
|
||||||
borderRadius: '4px',
|
|
||||||
}}>
|
|
||||||
<TextField
|
<TextField
|
||||||
label="Label"
|
label="Label"
|
||||||
value={labels[step.id] || step.label || ''}
|
value={labels[step.id] || step.label || ''}
|
||||||
@@ -157,31 +132,19 @@ export const RightSidePanel = ({ pairForEdit }: RightSidePanelProps) => {
|
|||||||
margin="normal"
|
margin="normal"
|
||||||
error={!!errors[step.id]}
|
error={!!errors[step.id]}
|
||||||
helperText={errors[step.id]}
|
helperText={errors[step.id]}
|
||||||
InputProps={{
|
InputProps={{ readOnly: confirmedSteps[step.id] }}
|
||||||
readOnly: confirmedSteps[step.id]
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
<TextField
|
<TextField
|
||||||
label="Data"
|
label="Data"
|
||||||
value={step.value}
|
value={step.value}
|
||||||
fullWidth
|
fullWidth
|
||||||
margin="normal"
|
margin="normal"
|
||||||
InputProps={{
|
InputProps={{ readOnly: confirmedSteps[step.id] }}
|
||||||
readOnly: confirmedSteps[step.id]
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
{!confirmedSteps[step.id] && (
|
{!confirmedSteps[step.id] && (
|
||||||
<Box display="flex" justifyContent="space-between" gap={2}>
|
<Box display="flex" justifyContent="space-between" gap={2}>
|
||||||
<Button
|
<Button variant="contained" onClick={() => handleConfirm(step.id)} disabled={!labels[step.id]?.trim()}>Confirm</Button>
|
||||||
variant="contained"
|
<Button variant="contained" onClick={() => handleDiscard(step.id)}>Discard</Button>
|
||||||
onClick={() => handleConfirm(step.id)}
|
|
||||||
disabled={!labels[step.id]?.trim()}
|
|
||||||
>
|
|
||||||
Confirm
|
|
||||||
</Button>
|
|
||||||
<Button variant="contained" onClick={() => handleDiscard(step.id)}>
|
|
||||||
Discard
|
|
||||||
</Button>
|
|
||||||
</Box>
|
</Box>
|
||||||
)}
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
Reference in New Issue
Block a user