From 005f2eb2ced7e67d824477f5eb76a2ab4005158f Mon Sep 17 00:00:00 2001 From: aliraza556 Date: Fri, 22 Nov 2024 10:02:19 +0500 Subject: [PATCH] fix(function): add check for TESTS edge --- .../Universe/Graph/UI/NodeControls/index.tsx | 68 +++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/src/components/Universe/Graph/UI/NodeControls/index.tsx b/src/components/Universe/Graph/UI/NodeControls/index.tsx index d66fa1972..ab082d51d 100644 --- a/src/components/Universe/Graph/UI/NodeControls/index.tsx +++ b/src/components/Universe/Graph/UI/NodeControls/index.tsx @@ -1,7 +1,7 @@ import Popover from '@mui/material/Popover' import { Html } from '@react-three/drei' import { useFrame } from '@react-three/fiber' -import React, { memo, useCallback, useMemo, useRef } from 'react' +import React, { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react' import { MdClose, MdViewInAr } from 'react-icons/md' import styled from 'styled-components' import { Group, Vector3 } from 'three' @@ -40,12 +40,32 @@ export const NodeControls = memo(() => { const [isAdmin] = useUserStore((s) => [s.isAdmin]) const [addNewNode] = useDataStore((s) => [s.addNewNode]) + const [hasTestEdge, setHasTestEdge] = useState(false) + const selectedNode = useSelectedNode() const { showSelectionGraph, selectionGraphData, setSelectedNode, setShowSelectionGraph } = useGraphStore((s) => s) const allGraphData = useGraphData() + useEffect(() => { + const checkForTestEdges = async () => { + if (selectedNode?.ref_id && selectedNode?.node_type?.toLowerCase() === 'function') { + try { + const edges = await fetchNodeEdges(selectedNode.ref_id, 0) + const hasTests = edges?.edges?.some((edge) => edge.edge_type === 'TESTS') + + setHasTestEdge(!!hasTests) + } catch (error) { + console.error('Error checking for test edges:', error) + setHasTestEdge(false) + } + } + } + + checkForTestEdges() + }, [selectedNode]) + const getChildren = useCallback(async () => { try { if (selectedNode?.ref_id) { @@ -169,7 +189,7 @@ export const NodeControls = memo(() => { const isRepository = selectedNode?.node_type?.toLowerCase() === 'repository' - const isShowCreateTestButton = !!(selectedNode && selectedNode?.node_type?.toLowerCase() === 'function') + const isFunction = selectedNode?.node_type?.toLowerCase() === 'function' return ( @@ -202,17 +222,6 @@ export const NodeControls = memo(() => { ))} - {isShowCreateTestButton && ( - { - createBountyModal() - }} - > - Create Test - - )} - { Add edge + {isFunction && !hasTestEdge && ( + { + createBountyModal() + handleClose() + }} + > + + Generate Test + + )} ) : ( <> @@ -368,24 +389,3 @@ const IconWrapper = styled.div` height: 12px; } ` - -const CreateTestButton = styled.div` - position: fixed; - top: 40px; - left: ${(p: ButtonProps) => -53 + p.left}px; - width: 100px; - padding: 6px; - border-radius: 4px; - display: flex; - justify-content: center; - align-items: center; - background: ${colors.createTestButton}; - color: ${colors.black}; - font-size: 14px; - font-family: Barlow; - font-weight: 600; - cursor: pointer; - &:hover { - transform: scale(1.05); - } -`