-
Notifications
You must be signed in to change notification settings - Fork 51
/
index.js
256 lines (243 loc) · 9.09 KB
/
index.js
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/*
* Copyright 2016, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import {FormattedMessage} from 'react-intl'
import Icon from '../../../components/Icon'
import Link from '../../../components/Link'
import DateAndTimeDisplay from '../DateAndTimeDisplay'
import {Well} from 'react-bootstrap'
import {profileUrl} from '../../api'
export const MINOR = 'Minor'
export const MAJOR = 'Major'
export const CRITICAL = 'Critical'
const statusToWellClass = {
approved: 'well-approved',
rejected: 'well-rejected',
translated: 'well-translated',
fuzzy: 'well-fuzzy',
// FIXME class does not exist, create it
untranslated: 'well-untranslated'
}
class ActivityFeedItem extends Component {
static propTypes = {
criteria: PropTypes.string,
commentText: PropTypes.string,
content: PropTypes.string,
lastModifiedTime: PropTypes.instanceOf(Date).isRequired,
// TODO damason define type for status
priority: PropTypes.oneOf([
MINOR,
MAJOR,
CRITICAL
]),
status: PropTypes.oneOf(['translated', 'fuzzy', 'approved', 'rejected',
'untranslated']),
textStatus: PropTypes.oneOf(['u-textWarning', 'u-textDanger', 'u-textHighlight']),
type: PropTypes.oneOf(['comment', 'revision']).isRequired,
user: PropTypes.shape({
name: PropTypes.string.isRequired,
username: PropTypes.string.isRequired,
imageUrl: PropTypes.string.isRequired,
}).isRequired
}
getMessage = () => {
const {user, type, status} = this.props
// Uses href because editor app is separate from frontend app
const comment = (
<span className="comment">
<Well bsSize="small">
<Icon name="comment" className="s0"/>
{this.props.commentText}
</Well>
</span>
)
const criteria = (
<span className="criteria-text">
{this.props.criteria}
</span>
)
const name = (
<Link useHref link={profileUrl(user.username)}>{user.name}</Link>
)
const priority = (
<span className="criteria-text">
<Icon name="warning" className="s0"/>
<span className={this.props.textStatus}>
{this.props.priority}
</span>
</span>
)
if (type === 'comment') {
return (
<FormattedMessage id="ActivityFeedItem.comment"
description="Title for a comment in the activity feed."
defaultMessage="{name} has commented on a translation"
values={{
name
}}
/>
)
}
// else it is a revision
switch (status) {
case 'approved':
// Nested formatted messages are needed to highlight part of the message
const approvedTranslation = (
<span className="u-textHighlight">
<FormattedMessage id="ActivityFeedItem.approved.approvedTranslation"
description={
'Highlighted section inserted into ActivityFeedItem.approved'}
defaultMessage="approved a translation"/>
</span>
)
return (
<FormattedMessage id="ActivityFeedItem.approved"
description={
'Title for an item in the activity feed showing a reviewer ' +
'approved the translation. The inserted section is from ' +
'ActivityFeedItem.approved.approvedTranslation'}
defaultMessage="{name} has {approvedTranslation}"
values={{
name,
approvedTranslation
}}/>
)
case 'rejected':
// Nested formatted messages are needed to highlight part of the message
const rejectedTranslation = (
<span className="u-textWarning">
<FormattedMessage id="ActivityFeedItem.rejected.rejectedTranslation"
description={
'Highlighted section inserted into ActivityFeedItem.rejected'}
defaultMessage="rejected a translation"/>
</span>
)
return (
<FormattedMessage id="ActivityFeedItem.rejected"
description={
'Title for an item in the activity feed showing a reviewer ' +
'rejected the translation. The inserted section is from ' +
'ActivityFeedItem.rejected.rejectedTranslation'}
defaultMessage="{name} has {rejectedTranslation} for the reason: {criteria} - {priority} priority. {comment}"
values={{
comment,
criteria,
name,
priority,
rejectedTranslation
}}/>
)
case 'translated':
// Nested formatted messages are needed to highlight part of the message
const translatedRevision = (
<span className="u-textSuccess">
<FormattedMessage
id="ActivityFeedItem.translated.translatedRevision"
description={
'Highlighted section inserted into ActivityFeedItem.translated'}
defaultMessage="created a translation revision"/>
</span>
)
return (
<FormattedMessage id="ActivityFeedItem.translated"
description={
'Title for an item in the activity feed showing a ' +
'translator added a translation. The inserted section is from ' +
'ActivityFeedItem.translated.translatedRevision'}
defaultMessage="{name} has {translatedRevision}"
values={{
name,
translatedRevision
}}/>
)
case 'fuzzy':
// Nested formatted messages are needed to highlight part of the message
const fuzzyRevision = (
<span className="u-textUnsure">
<FormattedMessage id="ActivityFeedItem.fuzzy.fuzzyRevision"
description={
'Highlighted section inserted into ActivityFeedItem.fuzzy'}
defaultMessage="created a fuzzy revision"/>
</span>
)
return (
<FormattedMessage id="ActivityFeedItem.fuzzy"
description={
'Title for an item in the activity feed showing a ' +
'translator saved a fuzzy translation (a translation that ' +
'still needs to be edited). The inserted section is from ' +
'ActivityFeedItem.fuzzy.fuzzyRevision'}
defaultMessage="{name} has {fuzzyRevision}"
values={{
name,
fuzzyRevision
}}/>
)
case 'untranslated':
// Nested formatted messages are needed to highlight part of the message
const deletedTranslation = (
<span className="u-textPrimary">
<FormattedMessage id="ActivityFeedItem.deleted.deletedTranslation"
description={
'Highlighted section inserted into ActivityFeedItem.deleted'}
defaultMessage="deleted a translation"/>
</span>
)
return (
<FormattedMessage id="ActivityFeedItem.deleted"
description={
'Title for an item in the activity feed showing a ' +
'translator has deleted the translation. The inserted ' +
'section is from ActivityFeedItem.deleted.deletedTranslation'}
defaultMessage="{name} has {deletedTranslation}"
values={{
name,
deletedTranslation
}}/>
)
default:
console.error('Unknown status type', status)
}
}
render() {
const {content, lastModifiedTime, status, type, user} = this.props
const isComment = type === 'comment'
return (
<div className="revision-box">
<p>
<Icon name={isComment ? 'comment' : 'refresh'} className="s0"/>
<Link useHref link={profileUrl(user.username)}>
{/* TODO use component for avatar image */}
<img className="u-round activity-avatar" src={user.imageUrl}/>
</Link>
{this.getMessage()}
</p>
<Well className={isComment ? '' : statusToWellClass[status]}>
{content}</Well>
<DateAndTimeDisplay dateTime={lastModifiedTime}
className="u-block small u-sMT-1-2 u-sPB-1-4
u-textMuted u-textSecondary"/>
</div>
)
}
}
export default ActivityFeedItem