import React from 'react'; import PropTypes from 'prop-types'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faUser } from '@fortawesome/free-regular-svg-icons'; import { Row, UncontrolledTooltip } from 'reactstrap'; import { parseAuthor } from '../helpers/revision'; import BugLinkify from './BugLinkify'; import Clipboard from './Clipboard'; export function AuthorInitials(props) { const str = props.author || ''; const words = str.split(' '); const firstLetters = words .map((word) => word.replace(/\P{General_Category=Letter}/gu, '')[0]) .filter((firstLetter) => typeof firstLetter !== 'undefined'); let initials = ''; if (firstLetters.length === 1) { // eslint-disable-next-line prefer-destructuring initials = firstLetters[0]; } else if (firstLetters.length > 1) { initials = firstLetters[0] + firstLetters[firstLetters.length - 1]; } return ( {initials} ); } AuthorInitials.propTypes = { author: PropTypes.string.isRequired, title: PropTypes.string.isRequired, }; export class Revision extends React.PureComponent { constructor(props) { super(props); this.state = { clipboardVisible: false, }; } showClipboard = (show) => { this.setState({ clipboardVisible: show }); }; isBackout = (comment) => { return comment.search('Backed out') >= 0 || comment.search('Back out') >= 0; }; render() { const { revision: { comments, author, revision }, repo, bugSummaryMap, commitShaClass, commentFont, } = this.props; const comment = comments.split('\n')[0]; const bugMatches = comment.match(/-- ([0-9]+)|bug.([0-9]+)/gi); const { clipboardVisible } = this.state; const { name, email } = parseAuthor(author); const commitRevision = revision; const commentColor = this.isBackout(comment) ? 'text-danger' : 'text-secondary'; return ( this.showClipboard(true)} onMouseLeave={() => this.showClipboard(false)} className="pr-1 text-nowrap" > {commitRevision.substring(0, 12)} {comment} {bugSummaryMap && !!bugMatches && bugMatches.map((bug) => { const bugId = bug.split(' ')[1]; return (
Bug {bugId} - {bugSummaryMap[bugId]}
); })}
Commit:
{comment}
); } } Revision.propTypes = { revision: PropTypes.shape({ comments: PropTypes.string.isRequired, author: PropTypes.string.isRequired, revision: PropTypes.string.isRequired, }).isRequired, repo: PropTypes.shape({ url: PropTypes.string, revisionHrefPrefix: PropTypes.string, }).isRequired, commitShaClass: PropTypes.string, commentFont: PropTypes.string, }; Revision.defaultProps = { commitShaClass: 'commit-sha', commentFont: '', };