Skip to content

Commit 5b18bc5

Browse files
authored
refactor(UI):The timeline and tab components of the MR Page (#1176)
* refactor(UI):The timeline and tab components of the MR Page * fix(UI):Module import configuration
1 parent a0a6de1 commit 5b18bc5

File tree

7 files changed

+249
-136
lines changed

7 files changed

+249
-136
lines changed

moon/apps/web/components/DiffView/FileDiff.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export default function FileDiff({ diffs }: { diffs: string }) {
9898
}
9999

100100
return (
101-
<div className='flex font-sans'>
101+
<div className='flex font-sans mt-3'>
102102
<div
103103
className='rounded-lg w-[300px] h-[85vh] p-2 overflow-y-auto sticky top-5'
104104
>

moon/apps/web/components/MrView/MRComment.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const Comment = ({ conv, id, whoamI }: CommentProps) => {
7676
</Dropdown>
7777
}
7878
>
79-
<div className='prose'>
79+
<div className='prose copyable-text'>
8080
<RichTextRenderer content={conv.comment} extensions={extensions} />
8181
</div>
8282
</Card>
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import React from 'react'
2+
import '@primer/primitives/dist/css/functional/themes/light.css'
3+
import { BaseStyles, ThemeProvider, Timeline } from '@primer/react'
4+
import { FeedPullRequestClosedIcon, CommentIcon, FeedMergedIcon, IssueReopenedIcon } from '@primer/octicons-react'
5+
import MRComment from '@/components/MrView/MRComment';
6+
import { formatDistance, fromUnixTime } from 'date-fns';
7+
import { MRDetail } from '@/pages/[org]/mr/[id]';
8+
9+
interface TimelineItemProps {
10+
badge?: React.ReactNode
11+
children?: React.ReactNode
12+
isOver?: boolean
13+
}
14+
15+
interface ConvItem {
16+
id: number
17+
badge?: React.ReactNode
18+
children?: React.ReactNode
19+
isOver: boolean;
20+
}
21+
22+
interface TimelineWrapperProps {
23+
convItems?: ConvItem[];
24+
}
25+
26+
27+
const TimelineItem = ({ badge, children, isOver }: TimelineItemProps) => {
28+
return (
29+
<>
30+
<Timeline.Item>
31+
<Timeline.Badge>{badge}</Timeline.Badge>
32+
<Timeline.Body>{children}</Timeline.Body>
33+
</Timeline.Item>
34+
{isOver && <Timeline.Break />}
35+
</>
36+
)
37+
}
38+
39+
const TimelineWrapper: React.FC<TimelineWrapperProps> = ({ convItems = [] }) => {
40+
return (
41+
<ThemeProvider>
42+
<BaseStyles>
43+
<Timeline clipSidebar>
44+
{convItems?.map((item) => (
45+
<TimelineItem key={item.id} badge={item.badge} isOver={item.isOver}>
46+
{item.children}
47+
</TimelineItem>
48+
))}
49+
</Timeline>
50+
</BaseStyles>
51+
</ThemeProvider>
52+
);
53+
};
54+
55+
const TimelineItems: React.FC<{ mrDetail?: MRDetail, id: string }> = ({ mrDetail, id }) => {
56+
if (!mrDetail) {
57+
return null;
58+
}
59+
60+
const convItems: ConvItem[] = mrDetail?.conversations.map((conv) => {
61+
let icon;
62+
let children;
63+
let isOver = false;
64+
65+
switch (conv.conv_type) {
66+
case 'Comment':
67+
icon = <CommentIcon />;
68+
children = <MRComment conv={conv} id={id} whoamI="mr" />;
69+
break;
70+
case 'Merged':
71+
icon = <FeedMergedIcon size={24} className="text-purple-500" />;
72+
children =
73+
'Merged via the queue into main ' +
74+
formatDistance(fromUnixTime(conv.created_at), new Date(), { addSuffix: true });
75+
isOver = true;
76+
break;
77+
case 'Closed':
78+
icon = <FeedPullRequestClosedIcon size={24} className="text-red-500" />;
79+
children = conv.comment;
80+
isOver = true;
81+
break;
82+
case 'Reopen':
83+
icon = <IssueReopenedIcon />;
84+
children = conv.comment;
85+
break;
86+
}
87+
88+
return { badge: icon, children, isOver, id: conv.id };
89+
});
90+
91+
return <TimelineWrapper convItems={convItems} />;
92+
};
93+
94+
export default TimelineItems;

moon/apps/web/package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"@ant-design/icons": "catalog:",
2222
"@emoji-mart/data": "catalog:",
2323
"@emotion/styled": "catalog:",
24-
"@git-diff-view/react": "0.0.26",
24+
"@git-diff-view/react": "catalog:",
2525
"@gitmono/config": "workspace:*",
2626
"@gitmono/editor": "workspace:*",
2727
"@gitmono/regex": "workspace:*",
@@ -35,8 +35,9 @@
3535
"@next/bundle-analyzer": "catalog:",
3636
"@octokit/auth-app": "catalog:",
3737
"@octokit/core": "catalog:",
38-
"@primer/primitives": "^10.7.0",
39-
"@primer/react": "^37.27.0",
38+
"@primer/octicons-react": "catalog:",
39+
"@primer/primitives": "catalog:",
40+
"@primer/react": "catalog:",
4041
"@radix-ui/react-accordion": "catalog:",
4142
"@radix-ui/react-dialog": "catalog:",
4243
"@radix-ui/react-hover-card": "catalog:",
@@ -68,7 +69,7 @@
6869
"deepmerge": "catalog:",
6970
"fast-deep-equal": "catalog:",
7071
"framer-motion": "catalog:",
71-
"fuse.js": "^7.1.0",
72+
"fuse.js": "catalog:",
7273
"github-markdown-css": "catalog:",
7374
"gray-matter": "catalog:",
7475
"jotai": "catalog:",
@@ -125,7 +126,7 @@
125126
"react-wrap-balancer": "catalog:",
126127
"remeda": "catalog:",
127128
"slugify": "catalog:",
128-
"styled-components": "^6.1.19",
129+
"styled-components": "catalog:",
129130
"tippy.js": "catalog:",
130131
"use-debounce": "catalog:",
131132
"use-sound": "catalog:",

0 commit comments

Comments
 (0)