groupActivityItem.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import moment from 'moment';
  4. import CommitLink from 'sentry/components/commitLink';
  5. import Duration from 'sentry/components/duration';
  6. import ExternalLink from 'sentry/components/links/externalLink';
  7. import Link from 'sentry/components/links/link';
  8. import PullRequestLink from 'sentry/components/pullRequestLink';
  9. import Version from 'sentry/components/version';
  10. import {t, tct, tn} from 'sentry/locale';
  11. import TeamStore from 'sentry/stores/teamStore';
  12. import {
  13. GroupActivity,
  14. GroupActivityAssigned,
  15. GroupActivitySetIgnored,
  16. GroupActivityType,
  17. Organization,
  18. Project,
  19. User,
  20. } from 'sentry/types';
  21. type Props = {
  22. activity: GroupActivity;
  23. author: React.ReactNode;
  24. orgSlug: Organization['slug'];
  25. projectId: Project['id'];
  26. };
  27. function GroupActivityItem({activity, orgSlug, projectId, author}: Props) {
  28. const issuesLink = `/organizations/${orgSlug}/issues/`;
  29. function getIgnoredMessage(data: GroupActivitySetIgnored['data']) {
  30. if (data.ignoreDuration) {
  31. return tct('[author] ignored this issue for [duration]', {
  32. author,
  33. duration: <Duration seconds={data.ignoreDuration * 60} />,
  34. });
  35. }
  36. if (data.ignoreCount && data.ignoreWindow) {
  37. return tct(
  38. '[author] ignored this issue until it happens [count] time(s) in [duration]',
  39. {
  40. author,
  41. count: data.ignoreCount,
  42. duration: <Duration seconds={data.ignoreWindow * 60} />,
  43. }
  44. );
  45. }
  46. if (data.ignoreCount) {
  47. return tct('[author] ignored this issue until it happens [count] time(s)', {
  48. author,
  49. count: data.ignoreCount,
  50. });
  51. }
  52. if (data.ignoreUserCount && data.ignoreUserWindow) {
  53. return tct(
  54. '[author] ignored this issue until it affects [count] user(s) in [duration]',
  55. {
  56. author,
  57. count: data.ignoreUserCount,
  58. duration: <Duration seconds={data.ignoreUserWindow * 60} />,
  59. }
  60. );
  61. }
  62. if (data.ignoreUserCount) {
  63. return tct('[author] ignored this issue until it affects [count] user(s)', {
  64. author,
  65. count: data.ignoreUserCount,
  66. });
  67. }
  68. return tct('[author] ignored this issue', {author});
  69. }
  70. function getAssignedMessage(data: GroupActivityAssigned['data']) {
  71. let assignee: string | User | undefined = undefined;
  72. if (data.assigneeType === 'team') {
  73. const team = TeamStore.getById(data.assignee);
  74. assignee = team ? `#${team.slug}` : '<unknown-team>';
  75. } else if (activity.user && data.assignee === activity.user.id) {
  76. assignee = t('themselves');
  77. } else if (data.assigneeType === 'user' && data.assigneeEmail) {
  78. assignee = data.assigneeEmail;
  79. } else {
  80. assignee = t('an unknown user');
  81. }
  82. const isAutoAssigned = ['projectOwnership', 'codeowners'].includes(
  83. data.integration as string
  84. );
  85. const integrationName: Record<
  86. NonNullable<GroupActivityAssigned['data']['integration']>,
  87. string
  88. > = {
  89. msteams: t('Microsoft Teams'),
  90. slack: t('Slack'),
  91. projectOwnership: t('Ownership Rule'),
  92. codeowners: t('Codeowners Rule'),
  93. };
  94. return (
  95. <Fragment>
  96. <div>
  97. {tct('[author] [action] this issue to [assignee]', {
  98. action: isAutoAssigned ? t('auto-assigned') : t('assigned'),
  99. author,
  100. assignee,
  101. })}
  102. </div>
  103. {data.integration && (
  104. <CodeWrapper>
  105. {t('Assigned via %s', integrationName[data.integration])}
  106. {data.rule && (
  107. <Fragment>
  108. : <StyledRuleSpan>{data.rule}</StyledRuleSpan>
  109. </Fragment>
  110. )}
  111. </CodeWrapper>
  112. )}
  113. </Fragment>
  114. );
  115. }
  116. function renderContent() {
  117. switch (activity.type) {
  118. case GroupActivityType.NOTE:
  119. return tct('[author] left a comment', {author});
  120. case GroupActivityType.SET_RESOLVED:
  121. return tct('[author] marked this issue as resolved', {author});
  122. case GroupActivityType.SET_RESOLVED_BY_AGE:
  123. return tct('[author] marked this issue as resolved due to inactivity', {
  124. author,
  125. });
  126. case GroupActivityType.SET_RESOLVED_IN_RELEASE:
  127. const {current_release_version, version} = activity.data;
  128. if (current_release_version) {
  129. return tct(
  130. '[author] marked this issue as resolved in releases greater than [version]',
  131. {
  132. author,
  133. version: (
  134. <Version
  135. version={current_release_version}
  136. projectId={projectId}
  137. tooltipRawVersion
  138. />
  139. ),
  140. }
  141. );
  142. }
  143. return version
  144. ? tct('[author] marked this issue as resolved in [version]', {
  145. author,
  146. version: (
  147. <Version version={version} projectId={projectId} tooltipRawVersion />
  148. ),
  149. })
  150. : tct('[author] marked this issue as resolved in the upcoming release', {
  151. author,
  152. });
  153. case GroupActivityType.SET_RESOLVED_IN_COMMIT:
  154. const deployedReleases = (activity.data.commit?.releases || [])
  155. .filter(r => r.dateReleased !== null)
  156. .sort(
  157. (a, b) => moment(a.dateReleased).valueOf() - moment(b.dateReleased).valueOf()
  158. );
  159. if (deployedReleases.length === 1) {
  160. return tct(
  161. '[author] marked this issue as resolved in [version] [break]' +
  162. 'This commit was released in [release]',
  163. {
  164. author,
  165. version: (
  166. <CommitLink
  167. inline
  168. commitId={activity.data.commit.id}
  169. repository={activity.data.commit.repository}
  170. />
  171. ),
  172. break: <br />,
  173. release: (
  174. <Version
  175. version={deployedReleases[0].version}
  176. projectId={projectId}
  177. tooltipRawVersion
  178. />
  179. ),
  180. }
  181. );
  182. }
  183. if (deployedReleases.length > 1) {
  184. return tct(
  185. '[author] marked this issue as resolved in [version] [break]' +
  186. 'This commit was released in [release] and ' +
  187. (deployedReleases.length - 1) +
  188. ' others',
  189. {
  190. author,
  191. version: (
  192. <CommitLink
  193. inline
  194. commitId={activity.data.commit.id}
  195. repository={activity.data.commit.repository}
  196. />
  197. ),
  198. break: <br />,
  199. release: (
  200. <Version
  201. version={deployedReleases[0].version}
  202. projectId={projectId}
  203. tooltipRawVersion
  204. />
  205. ),
  206. }
  207. );
  208. }
  209. return tct('[author] marked this issue as resolved in [version]', {
  210. author,
  211. version: (
  212. <CommitLink
  213. inline
  214. commitId={activity.data.commit.id}
  215. repository={activity.data.commit.repository}
  216. />
  217. ),
  218. });
  219. case GroupActivityType.SET_RESOLVED_IN_PULL_REQUEST: {
  220. const {data} = activity;
  221. const {pullRequest} = data;
  222. return tct('[author] marked this issue as resolved in [version]', {
  223. author,
  224. version: (
  225. <PullRequestLink
  226. inline
  227. pullRequest={pullRequest}
  228. repository={pullRequest.repository}
  229. />
  230. ),
  231. });
  232. }
  233. case GroupActivityType.SET_UNRESOLVED:
  234. return tct('[author] marked this issue as unresolved', {author});
  235. case GroupActivityType.SET_IGNORED: {
  236. const {data} = activity;
  237. return getIgnoredMessage(data);
  238. }
  239. case GroupActivityType.SET_PUBLIC:
  240. return tct('[author] made this issue public', {author});
  241. case GroupActivityType.SET_PRIVATE:
  242. return tct('[author] made this issue private', {author});
  243. case GroupActivityType.SET_REGRESSION: {
  244. const {data} = activity;
  245. return data.version
  246. ? tct('[author] marked this issue as a regression in [version]', {
  247. author,
  248. version: (
  249. <Version version={data.version} projectId={projectId} tooltipRawVersion />
  250. ),
  251. })
  252. : tct('[author] marked this issue as a regression', {author});
  253. }
  254. case GroupActivityType.CREATE_ISSUE: {
  255. const {data} = activity;
  256. return tct('[author] created an issue on [provider] titled [title]', {
  257. author,
  258. provider: data.provider,
  259. title: <ExternalLink href={data.location}>{data.title}</ExternalLink>,
  260. });
  261. }
  262. case GroupActivityType.UNMERGE_SOURCE: {
  263. const {data} = activity;
  264. const {destination, fingerprints} = data;
  265. return tn(
  266. '%2$s migrated %1$s fingerprint to %3$s',
  267. '%2$s migrated %1$s fingerprints to %3$s',
  268. fingerprints.length,
  269. author,
  270. destination ? (
  271. <Link to={`${issuesLink}${destination.id}`}>{destination.shortId}</Link>
  272. ) : (
  273. t('a group')
  274. )
  275. );
  276. }
  277. case GroupActivityType.UNMERGE_DESTINATION: {
  278. const {data} = activity;
  279. const {source, fingerprints} = data;
  280. return tn(
  281. '%2$s migrated %1$s fingerprint from %3$s',
  282. '%2$s migrated %1$s fingerprints from %3$s',
  283. fingerprints.length,
  284. author,
  285. source ? (
  286. <Link to={`${issuesLink}${source.id}`}>{source.shortId}</Link>
  287. ) : (
  288. t('a group')
  289. )
  290. );
  291. }
  292. case GroupActivityType.FIRST_SEEN:
  293. return tct('[author] first saw this issue', {author});
  294. case GroupActivityType.ASSIGNED: {
  295. const {data} = activity;
  296. return getAssignedMessage(data);
  297. }
  298. case GroupActivityType.UNASSIGNED:
  299. return tct('[author] unassigned this issue', {author});
  300. case GroupActivityType.MERGE:
  301. return tn(
  302. '%2$s merged %1$s issue into this issue',
  303. '%2$s merged %1$s issues into this issue',
  304. activity.data.issues.length,
  305. author
  306. );
  307. case GroupActivityType.REPROCESS: {
  308. const {data} = activity;
  309. const {oldGroupId, eventCount} = data;
  310. return tct('[author] reprocessed the events in this issue. [new-events]', {
  311. author,
  312. ['new-events']: (
  313. <Link
  314. to={`/organizations/${orgSlug}/issues/?query=reprocessing.original_issue_id:${oldGroupId}`}
  315. >
  316. {tn('See %s new event', 'See %s new events', eventCount)}
  317. </Link>
  318. ),
  319. });
  320. }
  321. case GroupActivityType.MARK_REVIEWED: {
  322. return tct('[author] marked this issue as reviewed', {
  323. author,
  324. });
  325. }
  326. default:
  327. return ''; // should never hit (?)
  328. }
  329. }
  330. return <Fragment>{renderContent()}</Fragment>;
  331. }
  332. export default GroupActivityItem;
  333. const CodeWrapper = styled('div')`
  334. overflow-wrap: anywhere;
  335. font-size: ${p => p.theme.fontSizeSmall};
  336. `;
  337. const StyledRuleSpan = styled('span')`
  338. font-family: ${p => p.theme.text.familyMono};
  339. `;