-
Notifications
You must be signed in to change notification settings - Fork 22
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
[feat] Add configured repos table to the Codecov AI tab #3303
Open
rohitvinnakota-codecov
wants to merge
20
commits into
main
Choose a base branch
from
rvinnakota/ai-conf-repos
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
b3dbf55
initial commit
rohitvinnakota-codecov d8a8da0
Updates from editor
rohitvinnakota-codecov 5138d9e
tests for hooks
rohitvinnakota-codecov 169f4a3
use proper response
rohitvinnakota-codecov a454ca6
More tests
rohitvinnakota-codecov 1c76f93
Merge branch 'main' of https://github.com/codecov/gazebo into rvinnak…
rohitvinnakota-codecov 2fe4f86
Migrate
rohitvinnakota-codecov 0b90123
Update tests
rohitvinnakota-codecov c759d86
Add query client
rohitvinnakota-codecov 780bce6
add query client
rohitvinnakota-codecov e2db32b
Convert to test
rohitvinnakota-codecov 82d6b80
Update
rohitvinnakota-codecov ed0d589
Merge branch 'main' into rvinnakota/ai-conf-repos
rohitvinnakota-codecov 4403632
cleanup
rohitvinnakota-codecov 0ef0f78
Merge branch 'rvinnakota/ai-conf-repos' of https://github.com/codecov…
rohitvinnakota-codecov 3b3f724
update tests
rohitvinnakota-codecov 3c7ca5e
Merge branch 'main' into rvinnakota/ai-conf-repos
rohitvinnakota-codecov 9ff2921
Update tests
rohitvinnakota-codecov db84403
Merge branch 'rvinnakota/ai-conf-repos' of https://github.com/codecov…
rohitvinnakota-codecov 3c06152
Updates from editor
rohitvinnakota-codecov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
src/pages/CodecovAIPage/ConfiguredRepositories/ConfiguredRepositories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
import { | ||
createColumnHelper, | ||
flexRender, | ||
getCoreRowModel, | ||
useReactTable, | ||
} from '@tanstack/react-table' | ||
import React, { useMemo, useState } from 'react' | ||
import { useParams } from 'react-router-dom' | ||
|
||
import { useCodecovAIInstalledRepos } from 'services/codecovAI/useCodecovAIInstalledRepos' | ||
import A from 'ui/A' | ||
import { Card } from 'ui/Card' | ||
import Icon from 'ui/Icon' | ||
import Spinner from 'ui/Spinner' | ||
|
||
import InstallCodecovAI from '../InstallCodecovAI/InstallCodecovAI' | ||
|
||
interface URLParams { | ||
owner: string | ||
provider: string | ||
} | ||
|
||
const Loader = () => ( | ||
<div className="mb-4 flex justify-center pt-4"> | ||
<Spinner /> | ||
</div> | ||
) | ||
|
||
const columnHelper = createColumnHelper<{ name: string }>() | ||
|
||
function ConfiguredRepositories() { | ||
const { owner, provider } = useParams<URLParams>() | ||
const { data, isLoading } = useCodecovAIInstalledRepos({ | ||
owner, | ||
provider, | ||
}) | ||
|
||
const [isSortedAscending, setIsSortedAscending] = useState(true) | ||
|
||
const sortRepos = () => { | ||
setIsSortedAscending(!isSortedAscending) | ||
} | ||
|
||
const tableData = useMemo(() => { | ||
if (!data?.aiEnabledRepos) return [] | ||
const sortedRepos = [...data.aiEnabledRepos].sort((a, b) => | ||
isSortedAscending ? a.localeCompare(b) : b.localeCompare(a) | ||
) | ||
return sortedRepos.map((name) => ({ name })) | ||
}, [data?.aiEnabledRepos, isSortedAscending]) | ||
|
||
const columns = useMemo( | ||
() => [ | ||
columnHelper.accessor('name', { | ||
header: 'Repo Name', | ||
cell: (info) => { | ||
const repoName = info.getValue() | ||
const link = `/${provider}/${owner}/${repoName}` | ||
return ( | ||
<A href={link} to={undefined} hook={undefined} isExternal={false}> | ||
{repoName} | ||
</A> | ||
) | ||
}, | ||
}), | ||
], | ||
[provider, owner] | ||
) | ||
|
||
const table = useReactTable({ | ||
data: tableData, | ||
columns, | ||
getCoreRowModel: getCoreRowModel(), | ||
}) | ||
|
||
// This should technically never happen, but render a fallback just in case | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure how much value this comment is giving tbh :P |
||
if (tableData.length === 0) { | ||
return <InstallCodecovAI /> | ||
} | ||
|
||
return ( | ||
<div className="flex flex-col"> | ||
<Card className="mb-0 border-b-0"> | ||
<Card.Header className="border-b-0"> | ||
<Card.Title size="base"> | ||
{tableData.length} configured repositories | ||
</Card.Title> | ||
<p> | ||
To install more repos, please manage your Codecov AI app on GitHub. | ||
<br /> | ||
To uninstall the app, please go to your GitHub Apps settings. | ||
</p> | ||
</Card.Header> | ||
</Card> | ||
<div className="tableui border border-t-0"> | ||
<table> | ||
<thead> | ||
{table.getHeaderGroups().map((headerGroup) => ( | ||
<tr key={headerGroup.id}> | ||
{headerGroup.headers.map((header) => ( | ||
<th | ||
key={header.id} | ||
scope="col" | ||
onClick={sortRepos} | ||
className="cursor-pointer" | ||
> | ||
<div className="flex gap-1"> | ||
{flexRender( | ||
header.column.columnDef.header, | ||
header.getContext() | ||
)} | ||
<span | ||
className="text-ds-blue-darker group-hover/columnheader:opacity-100" | ||
data-sort-direction={isSortedAscending ? 'asc' : 'desc'} | ||
> | ||
<Icon name="arrowUp" size="sm" /> | ||
</span> | ||
</div> | ||
</th> | ||
))} | ||
</tr> | ||
))} | ||
</thead> | ||
<tbody> | ||
{isLoading ? ( | ||
<tr> | ||
<td colSpan={1}> | ||
<Loader /> | ||
</td> | ||
</tr> | ||
) : ( | ||
table.getRowModel().rows.map((row) => ( | ||
<tr key={row.id}> | ||
{row.getVisibleCells().map((cell) => ( | ||
<td key={cell.id}> | ||
{flexRender( | ||
cell.column.columnDef.cell, | ||
cell.getContext() | ||
)} | ||
</td> | ||
))} | ||
</tr> | ||
)) | ||
)} | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default ConfiguredRepositories |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
repo-2 right?