From f8d3eb18241a2289b2c06f7d16fcf0b2641d34cf Mon Sep 17 00:00:00 2001 From: ogabrielluiz Date: Thu, 13 Jun 2024 00:41:07 -0300 Subject: [PATCH] refactor: Improve ParameterComponent logic and handle output preview Refactor the ParameterComponent in index.tsx to improve the logic for displaying the output preview. Also, handle the case where there are outputs available for the selected output name. This change enhances the functionality and user experience of the component. --- .../components/parameterComponent/index.tsx | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx index c4e8684fb..0f2bfbf6b 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx @@ -85,10 +85,18 @@ export default function ParameterComponent({ const [openOutputModal, setOpenOutputModal] = useState(false); const flowPool = useFlowStore((state) => state.flowPool); - const displayOutputPreview = + const isValid = !!flowPool[data.id] && flowPool[data.id][flowPool[data.id].length - 1]?.valid; + const flowPoolNode = (flowPool[data.id] ?? [])[ + (flowPool[data.id]?.length ?? 1) - 1 + ]; + let hasOutputs; + if (flowPoolNode?.data?.logs && outputName) { + hasOutputs = flowPoolNode?.data?.logs[outputName] ?? null; + } + const displayOutputPreview = isValid && hasOutputs; const unknownOutput = !!( flowPool[data.id] && flowPool[data.id][flowPool[data.id].length - 1]?.data?.logs[0]?.type === @@ -115,7 +123,7 @@ export default function ParameterComponent({ handleUpdateValues, debouncedHandleUpdateValues, setNode, - setIsLoading, + setIsLoading ); const { handleNodeClass: handleNodeClassHook } = useHandleNodeClass( @@ -123,7 +131,7 @@ export default function ParameterComponent({ name, takeSnapshot, setNode, - updateNodeInternals, + updateNodeInternals ); const { handleRefreshButtonPress: handleRefreshButtonPressHook } = @@ -132,13 +140,13 @@ export default function ParameterComponent({ let disabled = edges.some( (edge) => - edge.targetHandle === scapedJSONStringfy(proxy ? { ...id, proxy } : id), + edge.targetHandle === scapedJSONStringfy(proxy ? { ...id, proxy } : id) ) ?? false; let disabledOutput = edges.some( (edge) => - edge.sourceHandle === scapedJSONStringfy(proxy ? { ...id, proxy } : id), + edge.sourceHandle === scapedJSONStringfy(proxy ? { ...id, proxy } : id) ) ?? false; const handleRefreshButtonPress = async (name, data) => { @@ -149,7 +157,7 @@ export default function ParameterComponent({ const handleOnNewValue = async ( newValue: string | string[] | boolean | Object[], - skipSnapshot: boolean | undefined = false, + skipSnapshot: boolean | undefined = false ): Promise => { handleOnNewValueHook(newValue, skipSnapshot); }; @@ -262,14 +270,14 @@ export default function ParameterComponent({ className={classNames( left ? "my-12 -ml-0.5 " : " my-12 -mr-0.5 ", "h-3 w-3 rounded-full border-2 bg-background", - !showNode ? "mt-0" : "", + !showNode ? "mt-0" : "" )} style={{ borderColor: color ?? nodeColors.unknown, }} onClick={() => { setFilterEdge( - groupByFamily(myData, tooltipTitle!, left, nodes!), + groupByFamily(myData, tooltipTitle!, left, nodes!) ); }} > @@ -348,7 +356,7 @@ export default function ParameterComponent({ "h-5 w-5 rounded-md", displayOutputPreview && !unknownOutput ? " hover:text-medium-indigo" - : " cursor-not-allowed text-muted-foreground", + : " cursor-not-allowed text-muted-foreground" )} name={"ScanEye"} /> @@ -405,12 +413,12 @@ export default function ParameterComponent({ } className={classNames( left ? "-ml-0.5" : "-mr-0.5", - "h-3 w-3 rounded-full border-2 bg-background", + "h-3 w-3 rounded-full border-2 bg-background" )} style={{ borderColor: color ?? nodeColors.unknown }} onClick={() => { setFilterEdge( - groupByFamily(myData, tooltipTitle!, left, nodes!), + groupByFamily(myData, tooltipTitle!, left, nodes!) ); }} />