Skip to content

Commit 249d0b9

Browse files
committed
feat: update TopContributors to use Next.js links for member and project navigation
1 parent 317b881 commit 249d0b9

File tree

4 files changed

+30
-15
lines changed

4 files changed

+30
-15
lines changed

frontend/__tests__/unit/pages/ProjectDetails.test.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,8 @@ describe('ProjectDetailsPage', () => {
128128
expect(screen.getByText('Contributor 1')).toBeInTheDocument()
129129
})
130130

131-
screen.getByText('Contributor 1').closest('button')?.click()
132-
133-
expect(mockRouter.push).toHaveBeenCalledWith('/members/contributor1')
131+
const contributorLink = screen.getByText('Contributor 1').closest('a')
132+
expect(contributorLink).toHaveAttribute('href', '/members/contributor1')
134133
})
135134

136135
test('Recent issues are rendered correctly', async () => {

frontend/__tests__/unit/pages/RepositoryDetails.test.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,8 @@ describe('RepositoryDetailsPage', () => {
130130
expect(screen.getByText('Contributor 1')).toBeInTheDocument()
131131
})
132132

133-
screen.getByText('Contributor 1').closest('button')?.click()
134-
135-
expect(mockRouter.push).toHaveBeenCalledWith('/members/contributor1')
133+
const contributorLink = screen.getByText('Contributor 1').closest('a')
134+
expect(contributorLink).toHaveAttribute('href', '/members/contributor1')
136135
})
137136

138137
test('Recent issues are rendered correctly', async () => {

frontend/src/components/TopContributors.tsx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import { faChevronDown, faChevronUp } from '@fortawesome/free-solid-svg-icons'
33
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
44
import { Button } from '@heroui/button'
55
import Image from 'next/image'
6-
import { useRouter } from 'next/navigation'
6+
import Link from 'next/link'
77
import { useState } from 'react'
88
import { TopContributorsTypeGraphql } from 'types/contributor'
99
import { capitalize } from 'utils/capitalize'
10+
import { getMemberUrl, getProjectUrl } from 'utils/urlFormatter'
1011
import SecondaryCard from './SecondaryCard'
1112

1213
const TopContributors = ({
@@ -22,7 +23,6 @@ const TopContributors = ({
2223
type: string
2324
icon?: IconProp
2425
}) => {
25-
const router = useRouter()
2626
const [showAllContributors, setShowAllContributors] = useState(false)
2727

2828
const toggleContributors = () => setShowAllContributors(!showAllContributors)
@@ -34,14 +34,15 @@ const TopContributors = ({
3434
if (contributors.length === 0) {
3535
return
3636
}
37+
const isContributor = type === 'contributor'
38+
3739
return (
3840
<SecondaryCard icon={icon} title={label}>
3941
<div className="grid gap-4 sm:grid-cols-1 md:grid-cols-3">
4042
{displayContributors.map((item, index) => (
4143
<button
4244
key={index}
43-
onClick={() => router.push(`/members/${item.login}`)}
44-
className="overflow-hidden rounded-lg bg-gray-200 p-4 dark:bg-gray-700"
45+
className="cursor-default overflow-hidden rounded-lg bg-gray-200 p-4 dark:bg-gray-700"
4546
>
4647
<div className="flex w-full flex-col justify-between">
4748
<div className="flex w-full items-center gap-2">
@@ -52,17 +53,23 @@ const TopContributors = ({
5253
alt={item?.name || ''}
5354
className="rounded-full"
5455
/>
55-
<h3 className="overflow-hidden text-ellipsis whitespace-nowrap font-semibold text-blue-400">
56+
<Link
57+
className="cursor-pointer overflow-hidden text-ellipsis whitespace-nowrap font-semibold text-blue-400 hover:underline"
58+
href={getMemberUrl(item?.login)}
59+
>
5660
{capitalize(item.name) || capitalize(item.login)}
57-
</h3>
61+
</Link>
5862
</div>
5963
<div className="ml-0.5 w-full">
6064
<div className="mt-2 flex flex-shrink-0 items-center text-sm text-gray-600 dark:text-gray-400">
61-
<span className="overflow-hidden text-ellipsis whitespace-nowrap">
62-
{type === 'contributor'
65+
<Link
66+
className={`overflow-hidden text-ellipsis whitespace-nowrap text-gray-600 dark:text-gray-400 ${!isContributor ? 'cursor-pointer hover:underline' : 'cursor-default'}`}
67+
href={!isContributor ? getProjectUrl(item?.projectUrl) : ''}
68+
>
69+
{isContributor
6370
? `${item.contributionsCount ?? 0} contributions`
6471
: item.projectName}
65-
</span>
72+
</Link>
6673
</div>
6774
</div>
6875
</div>

frontend/src/utils/urlFormatter.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import _ from 'lodash'
2+
3+
export const getProjectUrl = (url: string): string => {
4+
const projectName = _.last(_.split(url, 'www-project-')) || ''
5+
return `/projects/${projectName}`
6+
}
7+
8+
export const getMemberUrl = (loginName = ''): string => {
9+
return `/members/${loginName}`
10+
}

0 commit comments

Comments
 (0)