/
Revision.jsx
73 lines (64 loc) · 2.21 KB
/
Revision.jsx
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
import PropTypes from 'prop-types';
import { parseAuthor } from '../helpers/revisionHelper';
export function Initials(props) {
const str = props.author || '';
const words = str.split(' ');
const firstLetters = words.map(
word => word.replace(/[^A-Z]/gi, '')[0]
).filter(firstLetter => typeof firstLetter !== 'undefined');
let initials = '';
if (firstLetters.length === 1) {
initials = firstLetters[0];
} else if (firstLetters.length > 1) {
initials = firstLetters[0] + firstLetters[firstLetters.length - 1];
}
return (
<span title={props.title}>
<span className="user-push-icon">
<i className="fa fa-user-o" aria-hidden="true" />
</span>
<div className="icon-superscript user-push-initials">{initials}</div>
</span>
);
}
export class Revision extends React.PureComponent {
constructor(props) {
super(props);
const { revision, linkifyBugsFilter } = this.props;
this.escapedComment = _.escape(revision.comments.split('\n')[0]);
this.escapedCommentHTML = { __html: linkifyBugsFilter(this.escapedComment) };
this.tags = this.escapedComment.search('Backed out') >= 0 || this.escapedComment.search('Back out') >= 0 ?
'backout' : '';
}
render() {
const { revision, repo } = this.props;
const { name, email } = parseAuthor(revision.author);
const commitRevision = revision.revision;
return (<li className="clearfix">
<span className="revision" data-tags={this.tags}>
<span className="revision-holder">
<a
title={`Open revision ${commitRevision} on ${repo.url}`}
href={repo.getRevisionHref(commitRevision)}
data-ignore-job-clear-on-click
>{commitRevision.substring(0, 12)}
</a>
</span>
<Initials
title={`${name}: ${email}`}
author={name}
/>
<span title={this.escapedComment}>
<span className="revision-comment">
<em dangerouslySetInnerHTML={this.escapedCommentHTML} />
</span>
</span>
</span>
</li>);
}
}
Revision.propTypes = {
linkifyBugsFilter: PropTypes.func.isRequired,
revision: PropTypes.object.isRequired,
repo: PropTypes.object.isRequired,
};