From 5c7920c783029cd56b84b09c7a28714e4be825ba Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sat, 19 Oct 2024 12:30:44 +0530 Subject: [PATCH] feat: show interpretation buttons based on pairs in the workflow --- src/components/organisms/RightSidePanel.tsx | 35 +++++++++++++++------ 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/components/organisms/RightSidePanel.tsx b/src/components/organisms/RightSidePanel.tsx index 55b57f94..4aaba0ab 100644 --- a/src/components/organisms/RightSidePanel.tsx +++ b/src/components/organisms/RightSidePanel.tsx @@ -54,6 +54,12 @@ export const RightSidePanel: React.FC = ({ onFinishCapture const [showCaptureScreenshot, setShowCaptureScreenshot] = useState(true); const [showCaptureText, setShowCaptureText] = useState(true); const [hoverStates, setHoverStates] = useState<{ [id: string]: boolean }>({}); + const [actionsState, setActionsState] = useState({ + hasScrapeListAction: false, + hasScreenshotAction: false, + hasScrapeSchemaAction: false, + }); + const { lastAction, notify } = useGlobalInfoStore(); const { getText, startGetText, stopGetText, getScreenshot, startGetScreenshot, stopGetScreenshot, getList, startGetList, stopGetList, startPaginationMode, stopPaginationMode, paginationType, updatePaginationType, limitType, customLimit, updateLimitType, updateCustomLimit, stopLimitMode, startLimitMode, captureStage, setCaptureStage } = useActionContext(); @@ -87,7 +93,6 @@ export const RightSidePanel: React.FC = ({ onFinishCapture useEffect(() => { const hasPairs = workflow.workflow.length > 0; - if (!hasPairs) { setShowCaptureList(true); setShowCaptureScreenshot(true); @@ -96,19 +101,25 @@ export const RightSidePanel: React.FC = ({ onFinishCapture } const hasScrapeListAction = workflow.workflow.some(pair => - pair.what.some(action => action.action === "scrapeList") + pair.what.some(action => action.action === 'scrapeList') ); - const hasScreenshotAction = workflow.workflow.some(pair => - pair.what.some(action => action.action === "screenshot") + pair.what.some(action => action.action === 'screenshot') ); - const hasScrapeSchemaAction = workflow.workflow.some(pair => - pair.what.some(action => action.action === "scrapeSchema") + pair.what.some(action => action.action === 'scrapeSchema') ); - setShowCaptureList(!(hasScrapeListAction || hasScrapeSchemaAction || hasScreenshotAction)); - setShowCaptureScreenshot(!(hasScrapeListAction || hasScrapeSchemaAction || hasScreenshotAction)); + setActionsState({ + hasScrapeListAction, + hasScreenshotAction, + hasScrapeSchemaAction, + }); + + const shouldHideActions = hasScrapeListAction || hasScrapeSchemaAction || hasScreenshotAction; + + setShowCaptureList(!shouldHideActions); + setShowCaptureScreenshot(!shouldHideActions); setShowCaptureText(!(hasScrapeListAction || hasScreenshotAction)); }, [workflow]); @@ -368,12 +379,18 @@ export const RightSidePanel: React.FC = ({ onFinishCapture stopGetScreenshot(); }; + const { hasScrapeListAction, hasScreenshotAction, hasScrapeSchemaAction } = actionsState; + return ( Last action: {` ${lastAction}`} - + { + hasScrapeListAction || hasScrapeSchemaAction || hasScreenshotAction ? ( + + ) : "" + } {!getText && !getScreenshot && !getList && showCaptureList && }