From 8e4b48f2cb362fef6e03849e8e2b274f515e1e7e Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 31 Jul 2024 04:47:00 +0530 Subject: [PATCH] feat: emit key-value pair for scrapeSchema --- src/components/organisms/RightSidePanel.tsx | 117 +++++++------------- 1 file changed, 40 insertions(+), 77 deletions(-) diff --git a/src/components/organisms/RightSidePanel.tsx b/src/components/organisms/RightSidePanel.tsx index 3cdfe8e6..e0a6167d 100644 --- a/src/components/organisms/RightSidePanel.tsx +++ b/src/components/organisms/RightSidePanel.tsx @@ -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 { Dropdown as MuiDropdown } from '../atoms/DropdownMui'; import styled from "styled-components"; @@ -10,17 +10,12 @@ import { useGlobalInfoStore } from "../../context/globalInfo"; import { PairForEdit } from "../../pages/RecordingPage"; import { useActionContext } from '../../context/browserActions'; import { useBrowserSteps } from '../../context/browserSteps'; +import { useSocketStore } from '../../context/socket'; interface RightSidePanelProps { pairForEdit: PairForEdit; } -interface BrowserStep { - id: number; - label: string; - description: string; -} - export const RightSidePanel = ({ pairForEdit }: RightSidePanelProps) => { const [content, setContent] = useState('action'); const [action, setAction] = useState(''); @@ -29,10 +24,10 @@ export const RightSidePanel = ({ pairForEdit }: RightSidePanelProps) => { const [errors, setErrors] = useState<{ [id: number]: string }>({}); const [confirmedSteps, setConfirmedSteps] = useState<{ [id: number]: boolean }>({}); - const { lastAction } = useGlobalInfoStore(); const { getText, getScreenshot, startGetText, stopGetText, startGetScreenshot, stopGetScreenshot } = useActionContext(); const { browserSteps, updateBrowserStepLabel, deleteBrowserStep } = useBrowserSteps(); + const { socket } = useSocketStore(); const handleChange = (event: React.SyntheticEvent, newValue: string) => { setContent(newValue); @@ -44,7 +39,6 @@ export const RightSidePanel = ({ pairForEdit }: RightSidePanelProps) => { setIsSettingsDisplayed(true); }; - const handleLabelChange = (id: number, label: string) => { setLabels(prevLabels => ({ ...prevLabels, [id]: label })); 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 = {}; + 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 ( - + - - Last action: - {` ${lastAction}`} - + Last action: {` ${lastAction}`} - {content === 'action' ? ( - + {content === 'action' && ( + <> Type of action: - + click on coordinates enqueueLinks scrape @@ -111,44 +110,20 @@ export const RightSidePanel = ({ pairForEdit }: RightSidePanelProps) => { - {isSettingsDisplayed && - - } - - ) : null} + {isSettingsDisplayed && } + + )} - {!getText && !getScreenshot && ( - - )} - {getText && ( - - )} - - {!getText && !getScreenshot && ( - - )} - {getScreenshot && ( - - )} + {!getText && !getScreenshot && } + {getText && } + {!getText && !getScreenshot && } + {getScreenshot && } {browserSteps.map(step => ( - + { margin="normal" error={!!errors[step.id]} helperText={errors[step.id]} - InputProps={{ - readOnly: confirmedSteps[step.id] - }} + InputProps={{ readOnly: confirmedSteps[step.id] }} /> {!confirmedSteps[step.id] && ( - - + + )} @@ -201,4 +164,4 @@ const ActionTypeWrapper = styled.div` export const ActionDescription = styled.p` margin-left: 15px; -`; \ No newline at end of file +`;