groupActivityItem.tsx 13 KB

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