diff --git a/src/components/Universe/Graph/UI/NodeControls/index.tsx b/src/components/Universe/Graph/UI/NodeControls/index.tsx index 7b3fc5cb2..8a90fe088 100644 --- a/src/components/Universe/Graph/UI/NodeControls/index.tsx +++ b/src/components/Universe/Graph/UI/NodeControls/index.tsx @@ -24,6 +24,7 @@ import { useUserStore } from '~/stores/useUserStore' import { NodeExtended } from '~/types' import { colors } from '~/utils/colors' import { buttonColors } from './constants' +import { analyzeGitHubRepository } from '~/network/fetchSourcesData' const reuseableVector3 = new Vector3() @@ -38,7 +39,7 @@ export const NodeControls = memo(() => { const { open: createBountyModal } = useModal('createBounty') const [isAdmin] = useUserStore((s) => [s.isAdmin]) - const [addNewNode] = useDataStore((s) => [s.addNewNode]) + const { addNewNode, setGraph } = useDataStore((s) => s) const selectedNode = useSelectedNode() @@ -163,6 +164,20 @@ export const NodeControls = memo(() => { setAnchorEl(null) } + const handleAnalyzeTestCoverage = async (githubName: string) => { + try { + const res = await analyzeGitHubRepository(githubName) + + if (res) { + setSelectedNode(null) + + setGraph({ nodes: res.functions }) + } + } catch (error) { + console.error('Error during test coverage analysis:', error) + } + } + const open = Boolean(anchorEl) const id = open ? 'simple-popover' : undefined @@ -248,13 +263,17 @@ export const NodeControls = memo(() => { { + if (selectedNode?.name) { + handleAnalyzeTestCoverage(selectedNode.name) + } + handleClose() }} > - Generate Tests + Analyze Test Coverage => { + const url = `/github/analyze?github_repository=${github_repository}&analysis=["coverage"]` + + const res = await api.get(url) + + return res +} + export const getNodes = async (): Promise => { const url = `/prediction/graph/search?node_type=['Episode']&include_properties=true&includeContent=true&sort_by=date` diff --git a/src/stores/useDataStore/index.ts b/src/stores/useDataStore/index.ts index 45f78bf88..4445c801b 100644 --- a/src/stores/useDataStore/index.ts +++ b/src/stores/useDataStore/index.ts @@ -86,6 +86,7 @@ export type DataStore = { abortFetchData: () => void resetGraph: () => void resetData: () => void + setGraph: (graph: { nodes: NodeExtended[] }) => void } const defaultData: Omit< @@ -117,6 +118,7 @@ const defaultData: Omit< | 'abortFetchData' | 'resetGraph' | 'resetData' + | 'setGraph' > = { categoryFilter: null, dataInitial: null, @@ -318,6 +320,26 @@ export const useDataStore = create()( }) }, + setGraph: (data: { nodes: NodeExtended[] }) => { + const uniqueNodes = deduplicateByRefId(data.nodes) + + const nodeTypes = [...new Set(uniqueNodes.map((node) => node.node_type))] + const sidebarFilters = ['all', ...nodeTypes.map((type) => type.toLowerCase())] + + const sidebarFilterCounts = sidebarFilters.map((filter) => ({ + name: filter, + count: uniqueNodes.filter((node) => filter === 'all' || node.node_type?.toLowerCase() === filter).length, + })) + + set({ + dataInitial: { nodes: uniqueNodes, links: [] }, + dataNew: { nodes: uniqueNodes, links: [] }, + nodeTypes, + sidebarFilters, + sidebarFilterCounts, + }) + }, + nextPage: () => { const { filters, fetchData, setAbortRequests } = get() const { setBudget } = useUserStore.getState()