Skip to content

Commit 8f16ad9

Browse files
nipunharkid15r
andauthored
entity leader component added (#1143)
* entity leader component added * code quality * removed code smells * improved code logic * unknown keyword added * unstagged changes retry * updated test case * code formatting updated * Update code --------- Co-authored-by: Arkadii Yakovets <[email protected]> Co-authored-by: Arkadii Yakovets <[email protected]>
1 parent 9c39955 commit 8f16ad9

File tree

4 files changed

+53
-6
lines changed

4 files changed

+53
-6
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ describe('CommitteeDetailsPage Component', () => {
4747
expect(screen.getByText('Test Committee')).toBeInTheDocument()
4848
})
4949
expect(screen.getByText('This is a test committee summary.')).toBeInTheDocument()
50-
expect(screen.getByText('Leader 1, Leader 2')).toBeInTheDocument()
50+
expect(screen.getByText('Leader 1')).toBeInTheDocument()
51+
expect(screen.getByText('Leader 2')).toBeInTheDocument()
5152
expect(screen.getByText('https://owasp.org/test-committee')).toBeInTheDocument()
5253
})
5354

frontend/src/components/CardDetailsPage.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import RepositoriesCard from 'components/RepositoriesCard'
1212
import SecondaryCard from 'components/SecondaryCard'
1313
import ToggleableList from 'components/ToggleableList'
1414
import TopContributors from 'components/ToggleContributors'
15+
import LeadersList from './LeadersList'
1516

1617
const DetailsCard = ({
1718
title,
@@ -56,12 +57,18 @@ const DetailsCard = ({
5657
title={`${capitalize(type)} Details`}
5758
className={`${type !== 'chapter' ? 'md:col-span-5' : 'md:col-span-3'} gap-2`}
5859
>
59-
{details &&
60-
details.map((detail, index) => (
61-
<div key={index} className="pb-1">
62-
<strong>{detail.label}:</strong> {detail.value ? detail.value : 'Unknown'}
60+
{details?.map((detail) =>
61+
detail?.label === 'Leaders' ? (
62+
<div key={detail.label} className="pb-1">
63+
<strong>{detail.label}:</strong>{' '}
64+
<LeadersList leaders={detail?.value != null ? String(detail.value) : 'Unknown'} />
6365
</div>
64-
))}
66+
) : (
67+
<div key={detail.label} className="pb-1">
68+
<strong>{detail.label}:</strong> {detail?.value || 'Unknown'}
69+
</div>
70+
)
71+
)}
6572
{socialLinks && (type === 'chapter' || type === 'committee') && (
6673
<SocialLinks urls={socialLinks || []} />
6774
)}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { Link } from 'react-router-dom'
2+
import { LeadersListProps } from 'types/leaders'
3+
4+
/**
5+
* Component that renders a list of project leaders as clickable links.
6+
* Takes a comma-separated string of leader names and renders each as a link
7+
* to their user profile page.
8+
*
9+
* @param {LeadersListProps} props - Component props
10+
* @param {string} props.leaders - Comma-separated string of leader names
11+
* @returns {JSX.Element} A list of leader links
12+
*/
13+
14+
const LeadersList = ({ leaders }: LeadersListProps) => {
15+
if (!leaders || leaders.trim() === '') return <>Unknown</>
16+
17+
const leadersArray = leaders.split(',').map((leader) => leader.trim())
18+
19+
return (
20+
<>
21+
{leadersArray.map((leader, index) => (
22+
<span key={`${leader}-${index}`}>
23+
<Link
24+
to={`/community/users?q=${encodeURIComponent(leader)}`}
25+
aria-label={`View profile of ${leader}`}
26+
>
27+
{leader}
28+
</Link>
29+
{index < leadersArray.length - 1 && ', '}
30+
</span>
31+
))}
32+
</>
33+
)
34+
}
35+
36+
export default LeadersList

frontend/src/types/leaders.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface LeadersListProps {
2+
leaders: string
3+
}

0 commit comments

Comments
 (0)