From 0818069df0b676e109c99acc4ca4971312b59f64 Mon Sep 17 00:00:00 2001 From: MahtabBukhari Date: Fri, 6 Dec 2024 23:23:05 +0500 Subject: [PATCH 1/7] fix(generate-analyze): replace generate tests with analyze test coverage in repository node --- .../Universe/Graph/UI/NodeControls/index.tsx | 23 +++++++++++++++++-- src/network/fetchSourcesData/index.ts | 12 ++++++++++ src/stores/useDataStore/index.ts | 22 ++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) 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 response = await api.get(url) + + return response +} + 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 866291d1c..9d23ee3fb 100644 --- a/src/stores/useDataStore/index.ts +++ b/src/stores/useDataStore/index.ts @@ -88,6 +88,7 @@ export type DataStore = { abortFetchData: () => void resetGraph: () => void resetData: () => void + setGraph: (graph: { nodes: NodeExtended[] }) => void } const defaultData: Omit< @@ -119,6 +120,7 @@ const defaultData: Omit< | 'abortFetchData' | 'resetGraph' | 'resetData' + | 'setGraph' > = { categoryFilter: null, dataInitial: null, @@ -320,6 +322,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() From 83ddcec55bd483e8cca79ff2c3589ffa083b359c Mon Sep 17 00:00:00 2001 From: MahtabBukhari Date: Fri, 6 Dec 2024 23:43:48 +0500 Subject: [PATCH 2/7] fix(generate-analyze): replace generate tests with analyze test coverage in repository --- src/network/fetchSourcesData/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/network/fetchSourcesData/index.ts b/src/network/fetchSourcesData/index.ts index c0d8f6a7b..b61746ccb 100644 --- a/src/network/fetchSourcesData/index.ts +++ b/src/network/fetchSourcesData/index.ts @@ -187,9 +187,9 @@ type GithubRepositoryResponse = { export const analyzeGitHubRepository = async (github_repository: string): Promise => { const url = `/github/analyze?github_repository=${github_repository}&analysis=["coverage"]` - const response = await api.get(url) + const res = await api.get(url) - return response + return res } export const getNodes = async (): Promise => { From a518dbfc500fcf3cbf457699bc332f190bc06601 Mon Sep 17 00:00:00 2001 From: MahtabBukhari Date: Thu, 6 Feb 2025 01:07:37 +0500 Subject: [PATCH 3/7] fix(reset-data-and-addnewnode): calling resetdata and addnewnode --- src/components/Universe/Graph/UI/NodeControls/index.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/Universe/Graph/UI/NodeControls/index.tsx b/src/components/Universe/Graph/UI/NodeControls/index.tsx index 8a90fe088..dd382fa4a 100644 --- a/src/components/Universe/Graph/UI/NodeControls/index.tsx +++ b/src/components/Universe/Graph/UI/NodeControls/index.tsx @@ -39,7 +39,7 @@ export const NodeControls = memo(() => { const { open: createBountyModal } = useModal('createBounty') const [isAdmin] = useUserStore((s) => [s.isAdmin]) - const { addNewNode, setGraph } = useDataStore((s) => s) + const { addNewNode, setGraph, resetData } = useDataStore((s) => s) const selectedNode = useSelectedNode() @@ -169,8 +169,9 @@ export const NodeControls = memo(() => { const res = await analyzeGitHubRepository(githubName) if (res) { + resetData() setSelectedNode(null) - + addNewNode({ nodes: res.functions, edges: [] }) setGraph({ nodes: res.functions }) } } catch (error) { From 2ca4501d1070c6449c3d39cef51ea28dfbc6de89 Mon Sep 17 00:00:00 2001 From: MahtabBukhari Date: Thu, 6 Feb 2025 01:30:27 +0500 Subject: [PATCH 4/7] fix(reset-data): calling reset data --- src/components/Universe/Graph/UI/NodeControls/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Universe/Graph/UI/NodeControls/index.tsx b/src/components/Universe/Graph/UI/NodeControls/index.tsx index dd382fa4a..3bafaa870 100644 --- a/src/components/Universe/Graph/UI/NodeControls/index.tsx +++ b/src/components/Universe/Graph/UI/NodeControls/index.tsx @@ -175,7 +175,7 @@ export const NodeControls = memo(() => { setGraph({ nodes: res.functions }) } } catch (error) { - console.error('Error during test coverage analysis:', error) + console.error('error during test coverage analysis:', error) } } From 4f6eb499b46e3e944cb9044330fd6a48f58baad1 Mon Sep 17 00:00:00 2001 From: MahtabBukhari Date: Thu, 6 Feb 2025 01:34:43 +0500 Subject: [PATCH 5/7] fix(reset-data): push again --- src/components/Universe/Graph/UI/NodeControls/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Universe/Graph/UI/NodeControls/index.tsx b/src/components/Universe/Graph/UI/NodeControls/index.tsx index 3bafaa870..4889bacfa 100644 --- a/src/components/Universe/Graph/UI/NodeControls/index.tsx +++ b/src/components/Universe/Graph/UI/NodeControls/index.tsx @@ -171,7 +171,7 @@ export const NodeControls = memo(() => { if (res) { resetData() setSelectedNode(null) - addNewNode({ nodes: res.functions, edges: [] }) + setGraph({ nodes: res.functions }) } } catch (error) { From 63001c1738008c2be9503ce437d3edb9bbbe3667 Mon Sep 17 00:00:00 2001 From: MahtabBukhari Date: Thu, 6 Feb 2025 01:38:55 +0500 Subject: [PATCH 6/7] fix(reset-data): push again --- src/components/Universe/Graph/UI/NodeControls/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Universe/Graph/UI/NodeControls/index.tsx b/src/components/Universe/Graph/UI/NodeControls/index.tsx index 4889bacfa..3bafaa870 100644 --- a/src/components/Universe/Graph/UI/NodeControls/index.tsx +++ b/src/components/Universe/Graph/UI/NodeControls/index.tsx @@ -171,7 +171,7 @@ export const NodeControls = memo(() => { if (res) { resetData() setSelectedNode(null) - + addNewNode({ nodes: res.functions, edges: [] }) setGraph({ nodes: res.functions }) } } catch (error) { From 4c6ba5b1ece14bb86e90e657603acb07b92d4f67 Mon Sep 17 00:00:00 2001 From: MahtabBukhari Date: Thu, 6 Feb 2025 07:12:35 +0500 Subject: [PATCH 7/7] fix(reset-data): update changes --- .../Universe/Graph/UI/NodeControls/index.tsx | 13 +++-------- src/network/analyzeGithubRepo/index.ts | 14 ++++++++++++ src/network/fetchSourcesData/index.ts | 12 ---------- src/stores/useDataStore/index.ts | 22 ------------------- 4 files changed, 17 insertions(+), 44 deletions(-) create mode 100644 src/network/analyzeGithubRepo/index.ts diff --git a/src/components/Universe/Graph/UI/NodeControls/index.tsx b/src/components/Universe/Graph/UI/NodeControls/index.tsx index 6ed727df3..de115e54c 100644 --- a/src/components/Universe/Graph/UI/NodeControls/index.tsx +++ b/src/components/Universe/Graph/UI/NodeControls/index.tsx @@ -24,7 +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' +import { analyzeGitHubRepository } from '~/network/analyzeGithubRepo' const reuseableVector3 = new Vector3() @@ -39,7 +39,7 @@ export const NodeControls = memo(() => { const { open: createBountyModal } = useModal('createBounty') const [isAdmin] = useUserStore((s) => [s.isAdmin]) - const { addNewNode, setGraph, resetData } = useDataStore((s) => s) + const { addNewNode } = useDataStore((s) => s) const selectedNode = useSelectedNode() @@ -168,14 +168,7 @@ export const NodeControls = memo(() => { const handleAnalyzeTestCoverage = async (githubName: string) => { try { - const res = await analyzeGitHubRepository(githubName) - - if (res) { - resetData() - setSelectedNode(null) - addNewNode({ nodes: res.functions, edges: [] }) - setGraph({ nodes: res.functions }) - } + await analyzeGitHubRepository(githubName) } catch (error) { console.error('error during test coverage analysis:', error) } diff --git a/src/network/analyzeGithubRepo/index.ts b/src/network/analyzeGithubRepo/index.ts new file mode 100644 index 000000000..44ef0b1b7 --- /dev/null +++ b/src/network/analyzeGithubRepo/index.ts @@ -0,0 +1,14 @@ +import { api } from '~/network/api' +import { NodeExtended } from '~/types' + +type GithubRepositoryResponse = { + functions: NodeExtended[] +} + +export const analyzeGitHubRepository = async (githubRepository: string): Promise => { + const url = `/github/analyze?github_repository=${githubRepository}&analysis=["coverage"]` + + const res = await api.get(url) + + return res +} diff --git a/src/network/fetchSourcesData/index.ts b/src/network/fetchSourcesData/index.ts index 6e58037d4..aa9853bfc 100644 --- a/src/network/fetchSourcesData/index.ts +++ b/src/network/fetchSourcesData/index.ts @@ -181,18 +181,6 @@ export interface UpdateSchemaParams { } } -type GithubRepositoryResponse = { - functions: NodeExtended[] -} - -export const analyzeGitHubRepository = async (github_repository: string): Promise => { - 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 280acdf7c..7f32970a2 100644 --- a/src/stores/useDataStore/index.ts +++ b/src/stores/useDataStore/index.ts @@ -91,7 +91,6 @@ export type DataStore = { abortFetchData: () => void resetGraph: () => void resetData: () => void - setGraph: (graph: { nodes: NodeExtended[] }) => void } const defaultData: Omit< @@ -123,7 +122,6 @@ const defaultData: Omit< | 'abortFetchData' | 'resetGraph' | 'resetData' - | 'setGraph' > = { categoryFilter: null, dataInitial: null, @@ -357,26 +355,6 @@ 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()