-
Notifications
You must be signed in to change notification settings - Fork 0
/
DiffLineCommentBox.tsx
175 lines (168 loc) · 5.38 KB
/
DiffLineCommentBox.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import React, {useState} from 'react'
import {ActionList, ActionMenu, Avatar, Box, IconButton, Label, Link, Text} from '@primer/react'
import {KebabHorizontalIcon} from '@primer/octicons-react'
import {Ago} from '../../../react-shared/Ago'
import {SafeHTMLBox, SafeHTMLString} from '../../../react-shared/SafeHTML'
import '@github/clipboard-copy-element'
const actionListItemStyles = {
p: 2,
m: 0,
borderRadius: 0,
'&:focus:not([data-focus-visible-added])': {
color: 'inherit',
bg: 'inherit'
},
'&:hover:not([aria-disabled])': {
color: 'fg.onEmphasis',
bg: 'accent.emphasis'
}
}
const actionListLinkItemStyles = {
...actionListItemStyles,
':first-child': {
mx: -2
}
}
export interface DiffLineCommentBoxProps {
viewer: {
isSiteAdmin: boolean
diffView: string
}
comment: {
id: string
author: {
login: string
avatarUrl: string
url: string
}
repository: {
owner: {
login: string
}
}
isMinimized: boolean
path: string
bodyHTML: string
currentDiffResourcePath: string
publishedAt: string
viewerRelationship: string
viewerDidAuthor: boolean
stafftoolsUrl: string
}
}
export default function DiffLineCommentBox({viewer, comment}: DiffLineCommentBoxProps) {
const commentPublishedData = new Date(comment.publishedAt)
const [isCommentActionsOpen, toggleCommentActions] = useState(false)
const closeCommentActions = () => toggleCommentActions(false)
return (
<Box
as="tr"
sx={{
borderColor: 'border.default',
borderWidth: 1,
borderStyle: 'solid',
borderLeft: 0,
borderRight: 0
}}
>
<Box as="td" colSpan={viewer.diffView === 'split' ? 2 : 3}>
<Box
sx={{
borderColor: 'border.default',
borderWidth: [0, 0, 1],
borderRadius: 2,
borderStyle: 'solid',
margin: 2,
p: 3,
maxWidth: ['100%', '100%', '714px'],
display: 'block'
}}
>
<Box>
<Box sx={{display: 'flex', justifyContent: 'space-between'}}>
<Box>
<Avatar alt="Avatar image for comment author" size={24} src={comment.author.avatarUrl} sx={{mr: 2}} />
<Text as="strong" sx={{fontWeight: 'bold', mr: 1}}>
<Link
href={comment.author.url}
sx={{
color: 'fg.default',
'&:hover': {
color: 'accent.fg'
}
}}
>
{comment.author.login}
</Link>
</Text>
<Link
href={comment.currentDiffResourcePath}
sx={{
color: 'fg.muted',
fontWeight: '400',
'&:hover': {
color: 'accent.fg'
}
}}
>
<Ago timestamp={commentPublishedData} />
</Link>
</Box>
<Box>
<Label sx={{mr: 1, textTransform: 'capitalize'}}>{comment.viewerRelationship.toLowerCase()}</Label>
{comment.viewerDidAuthor && <Label>Author</Label>}
<ActionMenu
open={isCommentActionsOpen}
onOpenChange={() => toggleCommentActions(!isCommentActionsOpen)}
>
<ActionMenu.Anchor>
<IconButton
aria-label="Open comment options"
icon={KebabHorizontalIcon}
sx={{ml: 1}}
variant="invisible"
/>
</ActionMenu.Anchor>
<ActionMenu.Overlay align="end" aria-label="Comment options menu" sx={{borderRadius: 2}}>
<ActionList
sx={{
p: 0
}}
>
<clipboard-copy
aria-label="Copy comment link"
value={`${window.location.origin}${comment.currentDiffResourcePath}`}
onClick={closeCommentActions}
>
<ActionList.Item sx={actionListItemStyles}>Copy link</ActionList.Item>
</clipboard-copy>
{viewer.isSiteAdmin && (
<>
<ActionList.Divider sx={{m: 0}} />
<ActionList.LinkItem
aria-label="View in Stafftools link"
href={comment.stafftoolsUrl}
sx={actionListLinkItemStyles}
>
View in Stafftools
</ActionList.LinkItem>
</>
)}
</ActionList>
</ActionMenu.Overlay>
</ActionMenu>
</Box>
</Box>
<Box sx={{ml: 5, mt: 2}}>
<SafeHTMLBox
as="div"
data-testid={`Comment body html for comment ${comment.id}`}
html={comment.bodyHTML as SafeHTMLString}
/>
</Box>
</Box>
</Box>
</Box>
</Box>
)
}