activityFeedItem.tsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. import {Component, createRef} from 'react';
  2. import styled from '@emotion/styled';
  3. import ActivityAvatar from 'sentry/components/activity/item/avatar';
  4. import CommitLink from 'sentry/components/commitLink';
  5. import Duration from 'sentry/components/duration';
  6. import IssueLink from 'sentry/components/issueLink';
  7. import ExternalLink from 'sentry/components/links/externalLink';
  8. import Link from 'sentry/components/links/link';
  9. import PullRequestLink from 'sentry/components/pullRequestLink';
  10. import TimeSince from 'sentry/components/timeSince';
  11. import Version from 'sentry/components/version';
  12. import VersionHoverCard from 'sentry/components/versionHoverCard';
  13. import {t, tct, tn} from 'sentry/locale';
  14. import MemberListStore from 'sentry/stores/memberListStore';
  15. import TeamStore from 'sentry/stores/teamStore';
  16. import space from 'sentry/styles/space';
  17. import {Activity, GroupActivity, Organization} from 'sentry/types';
  18. import marked from 'sentry/utils/marked';
  19. const defaultProps = {
  20. defaultClipped: false,
  21. clipHeight: 68,
  22. };
  23. type DefaultProps = typeof defaultProps;
  24. type Props = {
  25. item: Activity;
  26. organization: Organization;
  27. className?: string;
  28. } & DefaultProps;
  29. type State = {
  30. clipped: Props['defaultClipped'];
  31. };
  32. class ActivityItem extends Component<Props, State> {
  33. static defaultProps = defaultProps;
  34. state: State = {
  35. clipped: this.props.defaultClipped,
  36. };
  37. componentDidMount() {
  38. if (this.activityBubbleRef.current) {
  39. const bubbleHeight = this.activityBubbleRef.current.offsetHeight;
  40. if (bubbleHeight > this.props.clipHeight) {
  41. // okay if this causes re-render; cannot determine until
  42. // rendered first anyways
  43. // eslint-disable-next-line react/no-did-mount-set-state
  44. this.setState({clipped: true});
  45. }
  46. }
  47. }
  48. renderVersionLink(version: string, item: GroupActivity) {
  49. const {organization} = this.props;
  50. const {project} = item;
  51. return version ? (
  52. <VersionHoverCard
  53. organization={organization}
  54. projectSlug={project.slug}
  55. releaseVersion={version}
  56. >
  57. <Version version={version} projectId={project.id} />
  58. </VersionHoverCard>
  59. ) : null;
  60. }
  61. activityBubbleRef = createRef<HTMLDivElement>();
  62. formatProjectActivity = (author, item) => {
  63. const data = item.data;
  64. const {organization} = this.props;
  65. const orgId = organization.slug;
  66. const issue = item.issue;
  67. const basePath = `/organizations/${orgId}/issues/`;
  68. const issueLink = issue ? (
  69. <IssueLink
  70. orgId={orgId}
  71. issue={issue}
  72. to={`${basePath}${issue.id}/?referrer=activity-feed-issue-link`}
  73. card
  74. >
  75. {issue.shortId}
  76. </IssueLink>
  77. ) : null;
  78. const versionLink = this.renderVersionLink(data.version, item);
  79. switch (item.type) {
  80. case 'note':
  81. return tct('[author] commented on [issue]', {
  82. author,
  83. issue: (
  84. <IssueLink
  85. card
  86. orgId={orgId}
  87. issue={issue}
  88. to={`${basePath}${issue.id}/activity/?referrer=activity-comment#event_${item.id}`}
  89. >
  90. {issue.shortId}
  91. </IssueLink>
  92. ),
  93. });
  94. case 'set_resolved':
  95. return tct('[author] marked [issue] as resolved', {
  96. author,
  97. issue: issueLink,
  98. });
  99. case 'set_resolved_by_age':
  100. return tct('[author] marked [issue] as resolved due to age', {
  101. author,
  102. issue: issueLink,
  103. });
  104. case 'set_resolved_in_release':
  105. const {current_release_version, version} = item.data;
  106. if (current_release_version) {
  107. return tct(
  108. '[author] marked [issue] as resolved in releases greater than [version]',
  109. {
  110. author,
  111. version: this.renderVersionLink(current_release_version, item),
  112. issue: issueLink,
  113. }
  114. );
  115. }
  116. if (version) {
  117. return tct('[author] marked [issue] as resolved in [version]', {
  118. author,
  119. version: versionLink,
  120. issue: issueLink,
  121. });
  122. }
  123. return tct('[author] marked [issue] as resolved in the upcoming release', {
  124. author,
  125. issue: issueLink,
  126. });
  127. case 'set_resolved_in_commit':
  128. return tct('[author] marked [issue] as resolved in [version]', {
  129. author,
  130. version: (
  131. <CommitLink
  132. inline
  133. commitId={data.commit && data.commit.id}
  134. repository={data.commit && data.commit.repository}
  135. />
  136. ),
  137. issue: issueLink,
  138. });
  139. case 'set_resolved_in_pull_request':
  140. return tct('[author] marked [issue] as resolved in [version]', {
  141. author,
  142. version: (
  143. <PullRequestLink
  144. inline
  145. pullRequest={data.pullRequest}
  146. repository={data.pullRequest && data.pullRequest.repository}
  147. />
  148. ),
  149. issue: issueLink,
  150. });
  151. case 'set_unresolved':
  152. return tct('[author] marked [issue] as unresolved', {
  153. author,
  154. issue: issueLink,
  155. });
  156. case 'set_ignored':
  157. if (data.ignoreDuration) {
  158. return tct('[author] ignored [issue] for [duration]', {
  159. author,
  160. duration: <Duration seconds={data.ignoreDuration * 60} />,
  161. issue: issueLink,
  162. });
  163. }
  164. if (data.ignoreCount && data.ignoreWindow) {
  165. return tct(
  166. '[author] ignored [issue] until it happens [count] time(s) in [duration]',
  167. {
  168. author,
  169. count: data.ignoreCount,
  170. duration: <Duration seconds={data.ignoreWindow * 60} />,
  171. issue: issueLink,
  172. }
  173. );
  174. }
  175. if (data.ignoreCount) {
  176. return tct('[author] ignored [issue] until it happens [count] time(s)', {
  177. author,
  178. count: data.ignoreCount,
  179. issue: issueLink,
  180. });
  181. }
  182. if (data.ignoreUserCount && data.ignoreUserWindow) {
  183. return tct(
  184. '[author] ignored [issue] until it affects [count] user(s) in [duration]',
  185. {
  186. author,
  187. count: data.ignoreUserCount,
  188. duration: <Duration seconds={data.ignoreUserWindow * 60} />,
  189. issue: issueLink,
  190. }
  191. );
  192. }
  193. if (data.ignoreUserCount) {
  194. return tct('[author] ignored [issue] until it affects [count] user(s)', {
  195. author,
  196. count: data.ignoreUserCount,
  197. issue: issueLink,
  198. });
  199. }
  200. return tct('[author] ignored [issue]', {
  201. author,
  202. issue: issueLink,
  203. });
  204. case 'set_public':
  205. return tct('[author] made [issue] public', {
  206. author,
  207. issue: issueLink,
  208. });
  209. case 'set_private':
  210. return tct('[author] made [issue] private', {
  211. author,
  212. issue: issueLink,
  213. });
  214. case 'set_regression':
  215. if (data.version) {
  216. return tct('[author] marked [issue] as a regression in [version]', {
  217. author,
  218. version: versionLink,
  219. issue: issueLink,
  220. });
  221. }
  222. return tct('[author] marked [issue] as a regression', {
  223. author,
  224. issue: issueLink,
  225. });
  226. case 'create_issue':
  227. return tct('[author] linked [issue] on [provider]', {
  228. author,
  229. provider: data.provider,
  230. issue: issueLink,
  231. });
  232. case 'unmerge_destination':
  233. return tn(
  234. '%2$s migrated %1$s fingerprint from %3$s to %4$s',
  235. '%2$s migrated %1$s fingerprints from %3$s to %4$s',
  236. data.fingerprints.length,
  237. author,
  238. data.source ? (
  239. <a href={`${basePath}${data.source.id}`}>{data.source.shortId}</a>
  240. ) : (
  241. t('a group')
  242. ),
  243. issueLink
  244. );
  245. case 'first_seen':
  246. return tct('[author] saw [link:issue]', {
  247. author,
  248. issue: issueLink,
  249. });
  250. case 'assigned':
  251. let assignee;
  252. if (data.assigneeType === 'team') {
  253. const team = TeamStore.getById(data.assignee);
  254. assignee = team ? team.slug : '<unknown-team>';
  255. return tct('[author] assigned [issue] to #[assignee]', {
  256. author,
  257. issue: issueLink,
  258. assignee,
  259. });
  260. }
  261. if (item.user && data.assignee === item.user.id) {
  262. return tct('[author] assigned [issue] to themselves', {
  263. author,
  264. issue: issueLink,
  265. });
  266. }
  267. assignee = MemberListStore.getById(data.assignee);
  268. if (assignee && assignee.email) {
  269. return tct('[author] assigned [issue] to [assignee]', {
  270. author,
  271. assignee: <span title={assignee.email}>{assignee.name}</span>,
  272. issue: issueLink,
  273. });
  274. }
  275. if (data.assigneeEmail) {
  276. return tct('[author] assigned [issue] to [assignee]', {
  277. author,
  278. assignee: data.assigneeEmail,
  279. issue: issueLink,
  280. });
  281. }
  282. return tct('[author] assigned [issue] to an [help:unknown user]', {
  283. author,
  284. help: <span title={data.assignee} />,
  285. issue: issueLink,
  286. });
  287. case 'unassigned':
  288. return tct('[author] unassigned [issue]', {
  289. author,
  290. issue: issueLink,
  291. });
  292. case 'merge':
  293. return tct('[author] merged [count] [link:issues]', {
  294. author,
  295. count: data.issues.length + 1,
  296. link: <Link to={`${basePath}${issue.id}/?referrer=activity-feed-merge`} />,
  297. });
  298. case 'release':
  299. return tct('[author] released version [version]', {
  300. author,
  301. version: versionLink,
  302. });
  303. case 'deploy':
  304. return tct('[author] deployed version [version] to [environment].', {
  305. author,
  306. version: versionLink,
  307. environment: data.environment || 'Default Environment',
  308. });
  309. case 'mark_reviewed':
  310. return tct('[author] marked [issue] as reviewed', {
  311. author,
  312. issue: issueLink,
  313. });
  314. default:
  315. return ''; // should never hit (?)
  316. }
  317. };
  318. render() {
  319. const {className, item} = this.props;
  320. const avatar = (
  321. <ActivityAvatar
  322. type={!item.user ? 'system' : 'user'}
  323. user={item.user ?? undefined}
  324. size={36}
  325. />
  326. );
  327. const author = {
  328. name: item.user ? item.user.name : 'Sentry',
  329. avatar,
  330. };
  331. const hasBubble = ['note', 'create_issue'].includes(item.type);
  332. const bubbleProps = {
  333. ...(item.type === 'note'
  334. ? {dangerouslySetInnerHTML: {__html: marked(item.data.text)}}
  335. : {}),
  336. ...(item.type === 'create_issue'
  337. ? {
  338. children: (
  339. <ExternalLink href={item.data.location}>{item.data.title}</ExternalLink>
  340. ),
  341. }
  342. : {}),
  343. };
  344. return (
  345. <div data-test-id="activity-feed-item" className={className}>
  346. {author.avatar}
  347. <div>
  348. {this.formatProjectActivity(
  349. <span>
  350. <ActivityAuthor>{author.name}</ActivityAuthor>
  351. </span>,
  352. item
  353. )}
  354. {hasBubble && (
  355. <Bubble
  356. ref={this.activityBubbleRef}
  357. clipped={this.state.clipped}
  358. {...bubbleProps}
  359. />
  360. )}
  361. <Meta>
  362. <Project>{item.project.slug}</Project>
  363. <StyledTimeSince date={item.dateCreated} />
  364. </Meta>
  365. </div>
  366. </div>
  367. );
  368. }
  369. }
  370. export default styled(ActivityItem)`
  371. display: grid;
  372. gap: ${space(1)};
  373. grid-template-columns: max-content auto;
  374. position: relative;
  375. margin: 0;
  376. padding: ${space(1)};
  377. border-bottom: 1px solid ${p => p.theme.innerBorder};
  378. line-height: 1.4;
  379. font-size: ${p => p.theme.fontSizeMedium};
  380. `;
  381. const ActivityAuthor = styled('span')`
  382. font-weight: 600;
  383. `;
  384. const Meta = styled('div')`
  385. color: ${p => p.theme.textColor};
  386. font-size: ${p => p.theme.fontSizeRelativeSmall};
  387. `;
  388. const Project = styled('span')`
  389. font-weight: bold;
  390. `;
  391. const Bubble = styled('div')<{clipped: boolean}>`
  392. background: ${p => p.theme.backgroundSecondary};
  393. margin: ${space(0.5)} 0;
  394. padding: ${space(1)} ${space(2)};
  395. border: 1px solid ${p => p.theme.border};
  396. border-radius: 3px;
  397. box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
  398. position: relative;
  399. overflow: hidden;
  400. a {
  401. max-width: 100%;
  402. overflow-x: hidden;
  403. text-overflow: ellipsis;
  404. }
  405. p {
  406. &:last-child {
  407. margin-bottom: 0;
  408. }
  409. }
  410. ${p =>
  411. p.clipped &&
  412. `
  413. max-height: 68px;
  414. &:after {
  415. position: absolute;
  416. content: '';
  417. display: block;
  418. bottom: 0;
  419. right: 0;
  420. left: 0;
  421. height: 36px;
  422. background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 1));
  423. border-bottom: 6px solid #fff;
  424. border-radius: 0 0 3px 3px;
  425. pointer-events: none;
  426. }
  427. `}
  428. `;
  429. const StyledTimeSince = styled(TimeSince)`
  430. color: ${p => p.theme.gray300};
  431. padding-left: ${space(1)};
  432. `;