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

Replace "Generate Tests" with "Analyze Test Coverage" in Repository Node #2510

24 changes: 22 additions & 2 deletions src/components/Universe/Graph/UI/NodeControls/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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, resetData } = useDataStore((s) => s)

const selectedNode = useSelectedNode()

Expand Down Expand Up @@ -163,6 +164,21 @@ export const NodeControls = memo(() => {
setAnchorEl(null)
}

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 })
}
} catch (error) {
console.error('error during test coverage analysis:', error)
}
}

const open = Boolean(anchorEl)

const id = open ? 'simple-popover' : undefined
Expand Down Expand Up @@ -248,13 +264,17 @@ export const NodeControls = memo(() => {
<PopoverOption
data-testid="generate_tests"
onClick={() => {
if (selectedNode?.name) {
handleAnalyzeTestCoverage(selectedNode.name)
}

handleClose()
}}
>
<IconWrapper>
<AddCircleIcon data-testid="AddCircleIcon" />
</IconWrapper>
Generate Tests
Analyze Test Coverage
</PopoverOption>
<PopoverOption
data-testid="add_comments"
Expand Down
12 changes: 12 additions & 0 deletions src/network/fetchSourcesData/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,18 @@ export interface UpdateSchemaParams {
}
}

type GithubRepositoryResponse = {
functions: NodeExtended[]
}

export const analyzeGitHubRepository = async (github_repository: string): Promise<GithubRepositoryResponse> => {
const url = `/github/analyze?github_repository=${github_repository}&analysis=["coverage"]`

const res = await api.get<GithubRepositoryResponse>(url)

return res
}

export const getNodes = async (): Promise<FetchDataResponse> => {
const url = `/prediction/graph/search?node_type=['Episode']&include_properties=true&includeContent=true&sort_by=date`

Expand Down
22 changes: 22 additions & 0 deletions src/stores/useDataStore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
abortFetchData: () => void
resetGraph: () => void
resetData: () => void
setGraph: (graph: { nodes: NodeExtended[] }) => void
}

const defaultData: Omit<
Expand Down Expand Up @@ -117,6 +118,7 @@
| 'abortFetchData'
| 'resetGraph'
| 'resetData'
| 'setGraph'
> = {
categoryFilter: null,
dataInitial: null,
Expand Down Expand Up @@ -318,6 +320,26 @@
})
},

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()
Expand All @@ -336,20 +358,20 @@
setTrendingTopics: (trendingTopics) => set({ trendingTopics }),
setStats: (stats) => set({ stats }),
setIsFetching: (isFetching) => set({ isFetching }),

Check failure on line 361 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / craco-build-run

Cannot find name 'deduplicateByRefId'.

Check failure on line 361 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / eslint-run

Cannot find name 'deduplicateByRefId'.
setCategoryFilter: (categoryFilter) => set({ categoryFilter }),
setQueuedSources: (queuedSources) => set({ queuedSources }),

Check failure on line 363 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / craco-build-run

Parameter 'node' implicitly has an 'any' type.

Check failure on line 363 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / eslint-run

Parameter 'node' implicitly has an 'any' type.
setSidebarFilter: (sidebarFilter: string) => set({ sidebarFilter }),

Check failure on line 364 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / craco-build-run

'type' is of type 'unknown'.

Check failure on line 364 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / eslint-run

'type' is of type 'unknown'.
setSelectedTimestamp: (selectedTimestamp) => set({ selectedTimestamp }),
setSources: (sources) => set({ sources }),
setHideNodeDetails: (hideNodeDetails) => set({ hideNodeDetails }),
setSeedQuestions: (questions) => set({ seedQuestions: questions }),

Check failure on line 368 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / craco-build-run

Parameter 'node' implicitly has an 'any' type.

Check failure on line 368 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / eslint-run

Parameter 'node' implicitly has an 'any' type.
updateNode: (updatedNode) => {
console.info(updatedNode)
},
addNewNode: (data) => {
const { dataInitial: existingData, filters } = get()

Check failure on line 374 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / craco-build-run

Type 'unknown[]' is not assignable to type 'string[]'.

Check failure on line 374 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / eslint-run

Type 'unknown[]' is not assignable to type 'string[]'.
if (!data?.nodes) {
return
}
Expand Down Expand Up @@ -392,7 +414,7 @@
const sidebarFilters = ['all', ...nodeTypes.map((type) => type.toLowerCase())]

// Step 7: Calculate sidebar filter counts
const sidebarFilterCounts = sidebarFilters.map((filter) => ({

Check warning on line 417 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addSource.cy.ts)

Unexpected console statement

Check warning on line 417 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/createGeneratedEdges/createGeneratedEdges.cy.ts)

Unexpected console statement

Check warning on line 417 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/sourcesTable/sourcesTable.cy.ts)

Unexpected console statement

Check warning on line 417 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/admin/topics.cy.ts)

Unexpected console statement

Check warning on line 417 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/curationTable/curation.cy.ts)

Unexpected console statement

Check warning on line 417 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/checkEnv.cy.ts)

Unexpected console statement

Check warning on line 417 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/admin/signin.cy.ts)

Unexpected console statement

Check warning on line 417 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addYoutube.cy.ts)

Unexpected console statement

Check warning on line 417 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addTweet.cy.ts)

Unexpected console statement

Check warning on line 417 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addWebpage.cy.ts)

Unexpected console statement

Check warning on line 417 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/trendingTopics/trendingTopics.cy.ts)

Unexpected console statement

Check warning on line 417 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/seeLatest/latest.cy.ts)

Unexpected console statement

Check warning on line 417 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addNode/addNodeType.cy.ts)

Unexpected console statement
name: filter,
count: updatedNodes.filter((node) => filter === 'all' || node.node_type?.toLowerCase() === filter).length,
}))
Expand Down
Loading