From bf5af517ec3a2feb5400e2ba56ce205eaa9c92cf Mon Sep 17 00:00:00 2001 From: abhi1992002 Date: Mon, 19 Jan 2026 11:59:13 +0530 Subject: [PATCH] refactor(frontend): enhance NodeOutput component with accordion UI and cleanup logic ### Summary This commit refactors the `NodeOutput` component to improve its user interface and streamline the handling of source names. ### Key Changes 1. **Accordion Integration**: Replaced the previous expandable section with an accordion layout for better organization of node output data. 2. **Source Name Cleanup**: Introduced utility functions to clean up source names, ensuring consistency in how tool source names are displayed. 3. **Code Simplification**: Removed unnecessary state management for expansion, simplifying the component's logic. ### Benefits - **Improved User Experience**: The accordion layout enhances readability and interaction with node output data. - **Cleaner Code**: The refactor reduces complexity and improves maintainability of the `NodeOutput` component. ### Testing - Verified that the accordion functionality works as intended and that source names are displayed correctly without regressions in the node output display. --- .../components/NodeOutput/NodeOutput.tsx | 223 +++++++++--------- .../components/NodeOutput/useNodeOutput.tsx | 12 +- .../app/(platform)/build/components/helper.ts | 10 +- 3 files changed, 120 insertions(+), 125 deletions(-) diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/components/NodeOutput/NodeOutput.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/components/NodeOutput/NodeOutput.tsx index 7189ab9ca7..552c1a6a70 100644 --- a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/components/NodeOutput/NodeOutput.tsx +++ b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/components/NodeOutput/NodeOutput.tsx @@ -1,22 +1,21 @@ import { Button } from "@/components/atoms/Button/Button"; import { Text } from "@/components/atoms/Text/Text"; +import { + Accordion, + AccordionContent, + AccordionItem, + AccordionTrigger, +} from "@/components/molecules/Accordion/Accordion"; import { beautifyString, cn } from "@/lib/utils"; -import { CaretDownIcon, CopyIcon, CheckIcon } from "@phosphor-icons/react"; +import { CopyIcon, CheckIcon } from "@phosphor-icons/react"; import { NodeDataViewer } from "./components/NodeDataViewer/NodeDataViewer"; import { ContentRenderer } from "./components/ContentRenderer"; import { useNodeOutput } from "./useNodeOutput"; import { ViewMoreData } from "./components/ViewMoreData"; export const NodeDataRenderer = ({ nodeId }: { nodeId: string }) => { - const { - outputData, - isExpanded, - setIsExpanded, - copiedKey, - handleCopy, - executionResultId, - inputData, - } = useNodeOutput(nodeId); + const { outputData, copiedKey, handleCopy, executionResultId, inputData } = + useNodeOutput(nodeId); if (Object.keys(outputData).length === 0) { return null; @@ -25,122 +24,114 @@ export const NodeDataRenderer = ({ nodeId }: { nodeId: string }) => { return (
-
- - Node Output - - -
+ + + + + Node Output + + + +
+
+ Input - {isExpanded && ( - <> -
-
- Input + - - -
- - +
+ + +
-
- {Object.entries(outputData) - .slice(0, 2) - .map(([key, value]) => ( -
-
- - Pin: - - - {beautifyString(key)} - -
-
- - Data: - -
- {value.map((item, index) => ( -
- + {Object.entries(outputData) + .slice(0, 2) + .map(([key, value]) => ( +
+
+ + Pin: + + + {beautifyString(key)} + +
+
+ + Data: + +
+ {value.map((item, index) => ( +
+ +
+ ))} + +
+ +
- ))} - -
- -
-
- ))} -
+ ))} +
- {Object.keys(outputData).length > 2 && ( - - )} - - )} + {Object.keys(outputData).length > 2 && ( + + )} + + +
); }; diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/components/NodeOutput/useNodeOutput.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/components/NodeOutput/useNodeOutput.tsx index ba8559a66c..cfc599c6e4 100644 --- a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/components/NodeOutput/useNodeOutput.tsx +++ b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/components/NodeOutput/useNodeOutput.tsx @@ -4,7 +4,6 @@ import { useShallow } from "zustand/react/shallow"; import { useState } from "react"; export const useNodeOutput = (nodeId: string) => { - const [isExpanded, setIsExpanded] = useState(true); const [copiedKey, setCopiedKey] = useState(null); const { toast } = useToast(); @@ -37,13 +36,10 @@ export const useNodeOutput = (nodeId: string) => { } }; return { - outputData: outputData, - inputData: inputData, - isExpanded: isExpanded, - setIsExpanded: setIsExpanded, - copiedKey: copiedKey, - setCopiedKey: setCopiedKey, - handleCopy: handleCopy, + outputData, + inputData, + copiedKey, + handleCopy, executionResultId: nodeExecutionResult?.node_exec_id, }; }; diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/helper.ts b/autogpt_platform/frontend/src/app/(platform)/build/components/helper.ts index 7b3c5b1d01..e7a85bfa68 100644 --- a/autogpt_platform/frontend/src/app/(platform)/build/components/helper.ts +++ b/autogpt_platform/frontend/src/app/(platform)/build/components/helper.ts @@ -61,12 +61,20 @@ export const convertNodesPlusBlockInfoIntoCustomNodes = ( return customNode; }; + +const isToolSourceName = (sourceName: string): boolean => + sourceName.startsWith("tools_^_"); + + +const cleanupSourceName = (sourceName: string): string => + isToolSourceName(sourceName) ? "tools" : sourceName; + export const linkToCustomEdge = (link: Link): CustomEdge => ({ id: link.id ?? "", type: "custom" as const, source: link.source_id, target: link.sink_id, - sourceHandle: link.source_name, + sourceHandle: cleanupSourceName(link.source_name), targetHandle: link.sink_name, data: { isStatic: link.is_static,