|
1 | 1 | import { FC, useMemo } from 'react' |
| 2 | +import { Link } from 'react-router-dom' |
2 | 3 |
|
3 | | -import { Avatar, AvatarFallback, CommitCopyActions, NodeGroup, StackedList } from '@/components' |
| 4 | +import { Avatar, AvatarFallback, CommitCopyActions, NodeGroup, StackedList, StyledLink } from '@/components' |
4 | 5 | import { formatDate, getInitials } from '@/utils/utils' |
5 | 6 | import { TypesCommit } from '@/views' |
6 | 7 |
|
7 | 8 | type CommitsGroupedByDate = Record<string, TypesCommit[]> |
8 | 9 |
|
9 | 10 | interface CommitProps { |
10 | 11 | data?: TypesCommit[] |
| 12 | + useRepoBranchesStore: () => { spaceId: string; repoId: string } |
11 | 13 | } |
12 | 14 |
|
13 | | -export const CommitsList: FC<CommitProps> = ({ data }) => { |
| 15 | +export const CommitsList: FC<CommitProps> = ({ data, useRepoBranchesStore }) => { |
| 16 | + const { spaceId, repoId } = useRepoBranchesStore() |
14 | 17 | const entries = useMemo(() => { |
15 | 18 | const commitsGroupedByDate = !data |
16 | 19 | ? {} |
@@ -46,7 +49,27 @@ export const CommitsList: FC<CommitProps> = ({ data }) => { |
46 | 49 | <StackedList.Field |
47 | 50 | title={ |
48 | 51 | <div className="flex flex-col gap-y-1.5"> |
49 | | - <span className="truncate text-16 font-medium leading-snug">{commit.title}</span> |
| 52 | + <span className="truncate text-16 font-medium leading-snug"> |
| 53 | + {(() => { |
| 54 | + const match = commit?.title?.match(/\s*\(#(\d+)\)$/) |
| 55 | + if (!match) return commit?.title |
| 56 | + |
| 57 | + const [fullMatch, prNumber] = match |
| 58 | + const titleWithoutPR = commit?.title?.slice(0, -fullMatch.length) |
| 59 | + |
| 60 | + if (!prNumber) return commit?.title |
| 61 | + |
| 62 | + return ( |
| 63 | + <> |
| 64 | + {titleWithoutPR} ( |
| 65 | + <StyledLink to={`/${spaceId}/repos/${repoId}/pulls/${prNumber}`}> |
| 66 | + #{prNumber} |
| 67 | + </StyledLink> |
| 68 | + ) |
| 69 | + </> |
| 70 | + ) |
| 71 | + })()} |
| 72 | + </span> |
50 | 73 | <div className="flex items-center gap-x-1.5"> |
51 | 74 | {authorName && ( |
52 | 75 | <Avatar className="size-[18px]"> |
|
0 commit comments