commitRow.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import * as React from 'react';
  2. import styled from '@emotion/styled';
  3. import {openInviteMembersModal} from 'app/actionCreators/modal';
  4. import UserAvatar from 'app/components/avatar/userAvatar';
  5. import CommitLink from 'app/components/commitLink';
  6. import Hovercard from 'app/components/hovercard';
  7. import Link from 'app/components/links/link';
  8. import {PanelItem} from 'app/components/panels';
  9. import TextOverflow from 'app/components/textOverflow';
  10. import TimeSince from 'app/components/timeSince';
  11. import {IconWarning} from 'app/icons';
  12. import {t, tct} from 'app/locale';
  13. import space from 'app/styles/space';
  14. import {Commit, User} from 'app/types';
  15. type Props = {
  16. commit: Commit;
  17. customAvatar?: React.ReactNode;
  18. };
  19. class CommitRow extends React.Component<Props> {
  20. renderMessage(message: Commit['message']): string {
  21. if (!message) {
  22. return t('No message provided');
  23. }
  24. const firstLine = message.split(/\n/)[0];
  25. return firstLine;
  26. }
  27. renderHovercardBody(author: User) {
  28. return (
  29. <EmailWarning>
  30. {tct(
  31. 'The email [actorEmail] is not a member of your organization. [inviteUser:Invite] them or link additional emails in [accountSettings:account settings].',
  32. {
  33. actorEmail: <strong>{author.email}</strong>,
  34. accountSettings: <StyledLink to="/settings/account/emails/" />,
  35. inviteUser: (
  36. <StyledLink
  37. to=""
  38. onClick={() =>
  39. openInviteMembersModal({
  40. initialData: [
  41. {
  42. emails: new Set([author.email]),
  43. },
  44. ],
  45. source: 'suspect_commit',
  46. })
  47. }
  48. />
  49. ),
  50. }
  51. )}
  52. </EmailWarning>
  53. );
  54. }
  55. render() {
  56. const {commit, customAvatar, ...props} = this.props;
  57. const {id, dateCreated, message, author, repository} = commit;
  58. const nonMemberEmail = author && author.id === undefined;
  59. return (
  60. <PanelItem key={id} {...props}>
  61. {customAvatar ? (
  62. customAvatar
  63. ) : nonMemberEmail ? (
  64. <AvatarWrapper>
  65. <Hovercard body={this.renderHovercardBody(author!)}>
  66. <UserAvatar size={36} user={author} />
  67. <EmailWarningIcon>
  68. <IconWarning size="xs" />
  69. </EmailWarningIcon>
  70. </Hovercard>
  71. </AvatarWrapper>
  72. ) : (
  73. <AvatarWrapper>
  74. <UserAvatar size={36} user={author} />
  75. </AvatarWrapper>
  76. )}
  77. <CommitMessage>
  78. <Message>{this.renderMessage(message)}</Message>
  79. <Meta>
  80. {tct('[author] committed [timeago]', {
  81. author: <strong>{(author && author.name) || t('Unknown author')}</strong>,
  82. timeago: <TimeSince date={dateCreated} />,
  83. })}
  84. </Meta>
  85. </CommitMessage>
  86. <div>
  87. <CommitLink commitId={id} repository={repository} />
  88. </div>
  89. </PanelItem>
  90. );
  91. }
  92. }
  93. const AvatarWrapper = styled('div')`
  94. position: relative;
  95. align-self: flex-start;
  96. margin-right: ${space(2)};
  97. `;
  98. const EmailWarning = styled('div')`
  99. font-size: ${p => p.theme.fontSizeSmall};
  100. line-height: 1.4;
  101. margin: -4px;
  102. `;
  103. const StyledLink = styled(Link)`
  104. color: ${p => p.theme.textColor};
  105. border-bottom: 1px dotted ${p => p.theme.textColor};
  106. &:hover {
  107. color: ${p => p.theme.textColor};
  108. }
  109. `;
  110. const EmailWarningIcon = styled('span')`
  111. position: absolute;
  112. bottom: -6px;
  113. right: -7px;
  114. line-height: 12px;
  115. border-radius: 50%;
  116. border: 1px solid ${p => p.theme.background};
  117. background: ${p => p.theme.yellow200};
  118. padding: 1px 2px 3px 2px;
  119. `;
  120. const CommitMessage = styled('div')`
  121. flex: 1;
  122. flex-direction: column;
  123. min-width: 0;
  124. margin-right: ${space(2)};
  125. `;
  126. const Message = styled(TextOverflow)`
  127. font-size: 15px;
  128. line-height: 1.1;
  129. font-weight: bold;
  130. `;
  131. const Meta = styled(TextOverflow)`
  132. font-size: 13px;
  133. line-height: 1.5;
  134. margin: 0;
  135. color: ${p => p.theme.subText};
  136. `;
  137. export default styled(CommitRow)`
  138. align-items: center;
  139. `;