activityFeedItem.tsx 13 KB

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