Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Validation for TESTS Edge in Functions #2463

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 34 additions & 34 deletions src/components/Universe/Graph/UI/NodeControls/index.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -40,12 +40,32 @@
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) {
Expand All @@ -56,7 +76,7 @@
}
}
} catch (error) {
console.log(error)

Check warning on line 79 in src/components/Universe/Graph/UI/NodeControls/index.tsx

View workflow job for this annotation

GitHub Actions / eslint-run

Unexpected console statement
}
}, [addNewNode, selectedNode?.ref_id, selectionGraphData.nodes.length])

Expand Down Expand Up @@ -169,7 +189,7 @@

const isRepository = selectedNode?.node_type?.toLowerCase() === 'repository'

const isShowCreateTestButton = !!(selectedNode && selectedNode?.node_type?.toLowerCase() === 'function')
const isFunction = selectedNode?.node_type?.toLowerCase() === 'function'

return (
<group ref={ref}>
Expand Down Expand Up @@ -202,17 +222,6 @@
</IconButton>
))}

{isShowCreateTestButton && (
<CreateTestButton
left={2}
onClick={() => {
createBountyModal()
}}
>
Create Test
</CreateTestButton>
)}

<PopoverWrapper
anchorEl={anchorEl}
anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}
Expand Down Expand Up @@ -242,6 +251,18 @@
<AddCircleIcon data-testid="AddCircleIcon" />
Add edge
</PopoverOption>
{isFunction && !hasTestEdge && (
<PopoverOption
data-testid="generate_test"
onClick={() => {
createBountyModal()
handleClose()
}}
>
<AddCircleIcon data-testid="AddCircleIcon" />
Generate Test
</PopoverOption>
)}
</>
) : (
<>
Expand Down Expand Up @@ -368,24 +389,3 @@
height: 12px;
}
`

const CreateTestButton = styled.div<ButtonProps>`
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);
}
`
Loading