groupActivityItem.tsx 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  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. GroupActivitySetEscalating,
  17. GroupActivitySetIgnored,
  18. GroupActivityType,
  19. Organization,
  20. Project,
  21. User,
  22. } from 'sentry/types';
  23. import {isSemverRelease} from 'sentry/utils/formatters';
  24. type Props = {
  25. activity: GroupActivity;
  26. author: React.ReactNode;
  27. organization: Organization;
  28. projectId: Project['id'];
  29. };
  30. function GroupActivityItem({activity, organization, projectId, author}: Props) {
  31. const issuesLink = `/organizations/${organization.slug}/issues/`;
  32. const hasEscalatingIssuesUi = organization.features.includes('escalating-issues');
  33. function getIgnoredMessage(data: GroupActivitySetIgnored['data']) {
  34. const ignoredOrArchived = hasEscalatingIssuesUi ? t('archived') : t('ignored');
  35. if (data.ignoreDuration) {
  36. return tct('[author] [action] this issue for [duration]', {
  37. author,
  38. action: ignoredOrArchived,
  39. duration: <Duration seconds={data.ignoreDuration * 60} />,
  40. });
  41. }
  42. if (data.ignoreCount && data.ignoreWindow) {
  43. return tct(
  44. '[author] [action] this issue until it happens [count] time(s) in [duration]',
  45. {
  46. author,
  47. action: ignoredOrArchived,
  48. count: data.ignoreCount,
  49. duration: <Duration seconds={data.ignoreWindow * 60} />,
  50. }
  51. );
  52. }
  53. if (data.ignoreCount) {
  54. return tct('[author] [action] this issue until it happens [count] time(s)', {
  55. author,
  56. action: ignoredOrArchived,
  57. count: data.ignoreCount,
  58. });
  59. }
  60. if (data.ignoreUserCount && data.ignoreUserWindow) {
  61. return tct(
  62. '[author] [action] this issue until it affects [count] user(s) in [duration]',
  63. {
  64. author,
  65. action: ignoredOrArchived,
  66. count: data.ignoreUserCount,
  67. duration: <Duration seconds={data.ignoreUserWindow * 60} />,
  68. }
  69. );
  70. }
  71. if (data.ignoreUserCount) {
  72. return tct('[author] [action] this issue until it affects [count] user(s)', {
  73. author,
  74. action: ignoredOrArchived,
  75. count: data.ignoreUserCount,
  76. });
  77. }
  78. if (data.ignoreUntil) {
  79. return tct('[author] [action] this issue until [date]', {
  80. author,
  81. action: ignoredOrArchived,
  82. date: <DateTime date={data.ignoreUntil} />,
  83. });
  84. }
  85. if (hasEscalatingIssuesUi && data.ignoreUntilEscalating) {
  86. return tct('[author] archived this issue until it escalates', {
  87. author,
  88. });
  89. }
  90. return tct('[author] [action] this issue forever', {
  91. author,
  92. action: ignoredOrArchived,
  93. });
  94. }
  95. function getAssignedMessage(data: GroupActivityAssigned['data']) {
  96. let assignee: string | User | undefined = undefined;
  97. if (data.assigneeType === 'team') {
  98. const team = TeamStore.getById(data.assignee);
  99. assignee = team ? `#${team.slug}` : '<unknown-team>';
  100. } else if (activity.user && data.assignee === activity.user.id) {
  101. assignee = t('themselves');
  102. } else if (data.assigneeType === 'user' && data.assigneeEmail) {
  103. assignee = data.assigneeEmail;
  104. } else {
  105. assignee = t('an unknown user');
  106. }
  107. const isAutoAssigned = ['projectOwnership', 'codeowners'].includes(
  108. data.integration as string
  109. );
  110. const integrationName: Record<
  111. NonNullable<GroupActivityAssigned['data']['integration']>,
  112. string
  113. > = {
  114. msteams: t('Microsoft Teams'),
  115. slack: t('Slack'),
  116. projectOwnership: t('Ownership Rule'),
  117. codeowners: t('Codeowners Rule'),
  118. };
  119. return (
  120. <Fragment>
  121. <div>
  122. {tct('[author] [action] this issue to [assignee]', {
  123. action: isAutoAssigned ? t('auto-assigned') : t('assigned'),
  124. author,
  125. assignee,
  126. })}
  127. </div>
  128. {data.integration && (
  129. <CodeWrapper>
  130. {t('Assigned via %s', integrationName[data.integration])}
  131. {data.rule && (
  132. <Fragment>
  133. : <StyledRuleSpan>{data.rule}</StyledRuleSpan>
  134. </Fragment>
  135. )}
  136. </CodeWrapper>
  137. )}
  138. </Fragment>
  139. );
  140. }
  141. function getEscalatingMessage(data: GroupActivitySetEscalating['data']) {
  142. if (data.forecast) {
  143. return tct(
  144. '[author] flagged this issue as escalating because over [forecast] [event] happened in an hour',
  145. {
  146. author,
  147. forecast: data.forecast,
  148. event: data.forecast === 1 ? 'event' : 'events',
  149. }
  150. );
  151. }
  152. if (data.expired_snooze) {
  153. if (data.expired_snooze.count && data.expired_snooze.window) {
  154. return tct(
  155. '[author] flagged this issue as escalating because [count] [event] happened in [duration]',
  156. {
  157. author,
  158. count: data.expired_snooze.count,
  159. event: data.expired_snooze.count === 1 ? 'event' : 'events',
  160. duration: <Duration seconds={data.expired_snooze.window * 60} />,
  161. }
  162. );
  163. }
  164. if (data.expired_snooze.count) {
  165. return tct(
  166. '[author] flagged this issue as escalating because [count] [event] happened',
  167. {
  168. author,
  169. count: data.expired_snooze.count,
  170. event: data.expired_snooze.count === 1 ? 'event' : 'events',
  171. }
  172. );
  173. }
  174. if (data.expired_snooze.user_count && data.expired_snooze.user_window) {
  175. return tct(
  176. '[author] flagged this issue as escalating because [count] [user] affected in [duration]',
  177. {
  178. author,
  179. count: data.expired_snooze.user_count,
  180. user: data.expired_snooze.user_count === 1 ? 'user was' : 'users were',
  181. duration: <Duration seconds={data.expired_snooze.user_window * 60} />,
  182. }
  183. );
  184. }
  185. if (data.expired_snooze.user_count) {
  186. return tct(
  187. '[author] flagged this issue as escalating because [count] [user] affected',
  188. {
  189. author,
  190. count: data.expired_snooze.user_count,
  191. user: data.expired_snooze.user_count === 1 ? 'user was' : 'users were',
  192. }
  193. );
  194. }
  195. if (data.expired_snooze.until) {
  196. return tct('[author] flagged this issue as escalating because [date] passed', {
  197. author,
  198. date: <DateTime date={data.expired_snooze.until} />,
  199. });
  200. }
  201. }
  202. return tct('[author] flagged this issue as escalating', {author}); // should not reach this
  203. }
  204. function renderContent() {
  205. switch (activity.type) {
  206. case GroupActivityType.NOTE:
  207. return tct('[author] left a comment', {author});
  208. case GroupActivityType.SET_RESOLVED:
  209. return tct('[author] marked this issue as resolved', {author});
  210. case GroupActivityType.SET_RESOLVED_BY_AGE:
  211. return tct('[author] marked this issue as resolved due to inactivity', {
  212. author,
  213. });
  214. case GroupActivityType.SET_RESOLVED_IN_RELEASE:
  215. // Resolved in the next release
  216. if ('current_release_version' in activity.data) {
  217. const currentVersion = activity.data.current_release_version;
  218. return tct(
  219. '[author] marked this issue as resolved in releases greater than [version] [semver]',
  220. {
  221. author,
  222. version: (
  223. <Version
  224. version={currentVersion}
  225. projectId={projectId}
  226. tooltipRawVersion
  227. />
  228. ),
  229. semver: isSemverRelease(currentVersion) ? t('(semver)') : t('(non-semver)'),
  230. }
  231. );
  232. }
  233. const version = activity.data.version;
  234. return version
  235. ? tct('[author] marked this issue as resolved in [version] [semver]', {
  236. author,
  237. version: (
  238. <Version version={version} projectId={projectId} tooltipRawVersion />
  239. ),
  240. semver: isSemverRelease(version) ? t('(semver)') : t('(non-semver)'),
  241. })
  242. : tct('[author] marked this issue as resolved in the upcoming release', {
  243. author,
  244. });
  245. case GroupActivityType.SET_RESOLVED_IN_COMMIT:
  246. const deployedReleases = (activity.data.commit?.releases || [])
  247. .filter(r => r.dateReleased !== null)
  248. .sort(
  249. (a, b) => moment(a.dateReleased).valueOf() - moment(b.dateReleased).valueOf()
  250. );
  251. if (deployedReleases.length === 1 && activity.data.commit) {
  252. return tct(
  253. '[author] marked this issue as resolved in [version] [break]This commit was released in [release]',
  254. {
  255. author,
  256. version: (
  257. <CommitLink
  258. inline
  259. commitId={activity.data.commit.id}
  260. repository={activity.data.commit.repository}
  261. />
  262. ),
  263. break: <br />,
  264. release: (
  265. <Version
  266. version={deployedReleases[0].version}
  267. projectId={projectId}
  268. tooltipRawVersion
  269. />
  270. ),
  271. }
  272. );
  273. }
  274. if (deployedReleases.length > 1 && activity.data.commit) {
  275. return tct(
  276. '[author] marked this issue as resolved in [version] [break]This commit was released in [release] and [otherCount] others',
  277. {
  278. author,
  279. otherCount: deployedReleases.length - 1,
  280. version: (
  281. <CommitLink
  282. inline
  283. commitId={activity.data.commit.id}
  284. repository={activity.data.commit.repository}
  285. />
  286. ),
  287. break: <br />,
  288. release: (
  289. <Version
  290. version={deployedReleases[0].version}
  291. projectId={projectId}
  292. tooltipRawVersion
  293. />
  294. ),
  295. }
  296. );
  297. }
  298. if (activity.data.commit) {
  299. return tct('[author] marked this issue as resolved in [commit]', {
  300. author,
  301. commit: (
  302. <CommitLink
  303. inline
  304. commitId={activity.data.commit.id}
  305. repository={activity.data.commit.repository}
  306. />
  307. ),
  308. });
  309. }
  310. return tct('[author] marked this issue as resolved in a commit', {author});
  311. case GroupActivityType.SET_RESOLVED_IN_PULL_REQUEST: {
  312. const {data} = activity;
  313. const {pullRequest} = data;
  314. return tct('[author] has created a PR for this issue: [pullRequest]', {
  315. author,
  316. pullRequest: pullRequest ? (
  317. <PullRequestLink
  318. inline
  319. pullRequest={pullRequest}
  320. repository={pullRequest.repository}
  321. />
  322. ) : (
  323. t('PR not available')
  324. ),
  325. });
  326. }
  327. case GroupActivityType.SET_UNRESOLVED: {
  328. // TODO(nisanthan): Remove after migrating records to SET_ESCALATING
  329. const {data} = activity;
  330. if (data.forecast) {
  331. return tct(
  332. '[author] flagged this issue as escalating because over [forecast] [event] happened in an hour',
  333. {
  334. author,
  335. forecast: data.forecast,
  336. event: data.forecast === 1 ? 'event' : 'events',
  337. }
  338. );
  339. }
  340. return tct('[author] marked this issue as unresolved', {author});
  341. }
  342. case GroupActivityType.SET_IGNORED: {
  343. const {data} = activity;
  344. return getIgnoredMessage(data);
  345. }
  346. case GroupActivityType.SET_PUBLIC:
  347. return tct('[author] made this issue public', {author});
  348. case GroupActivityType.SET_PRIVATE:
  349. return tct('[author] made this issue private', {author});
  350. case GroupActivityType.SET_REGRESSION: {
  351. const {data} = activity;
  352. let subtext: React.ReactNode = null;
  353. if (data.version && data.resolved_in_version && 'follows_semver' in data) {
  354. subtext = (
  355. <Subtext>
  356. {tct(
  357. '[regressionVersion] is greater than or equal to [resolvedVersion] compared via [comparison]',
  358. {
  359. regressionVersion: (
  360. <Version
  361. version={data.version}
  362. projectId={projectId}
  363. tooltipRawVersion
  364. />
  365. ),
  366. resolvedVersion: (
  367. <Version
  368. version={data.resolved_in_version}
  369. projectId={projectId}
  370. tooltipRawVersion
  371. />
  372. ),
  373. comparison: data.follows_semver ? t('semver') : t('release date'),
  374. }
  375. )}
  376. </Subtext>
  377. );
  378. }
  379. return data.version ? (
  380. <Fragment>
  381. {tct('[author] marked this issue as a regression in [version]', {
  382. author,
  383. version: (
  384. <Version version={data.version} projectId={projectId} tooltipRawVersion />
  385. ),
  386. })}
  387. {subtext}
  388. </Fragment>
  389. ) : (
  390. <Fragment>
  391. {tct('[author] marked this issue as a regression', {
  392. author,
  393. })}
  394. {subtext}
  395. </Fragment>
  396. );
  397. }
  398. case GroupActivityType.CREATE_ISSUE: {
  399. const {data} = activity;
  400. return tct('[author] created an issue on [provider] titled [title]', {
  401. author,
  402. provider: data.provider,
  403. title: <ExternalLink href={data.location}>{data.title}</ExternalLink>,
  404. });
  405. }
  406. case GroupActivityType.UNMERGE_SOURCE: {
  407. const {data} = activity;
  408. const {destination, fingerprints} = data;
  409. return tn(
  410. '%2$s migrated %1$s fingerprint to %3$s',
  411. '%2$s migrated %1$s fingerprints to %3$s',
  412. fingerprints.length,
  413. author,
  414. destination ? (
  415. <Link
  416. to={`${issuesLink}${destination.id}?referrer=group-activity-unmerged-source`}
  417. >
  418. {destination.shortId}
  419. </Link>
  420. ) : (
  421. t('a group')
  422. )
  423. );
  424. }
  425. case GroupActivityType.UNMERGE_DESTINATION: {
  426. const {data} = activity;
  427. const {source, fingerprints} = data;
  428. return tn(
  429. '%2$s migrated %1$s fingerprint from %3$s',
  430. '%2$s migrated %1$s fingerprints from %3$s',
  431. fingerprints.length,
  432. author,
  433. source ? (
  434. <Link
  435. to={`${issuesLink}${source.id}?referrer=group-activity-unmerged-destination`}
  436. >
  437. {source.shortId}
  438. </Link>
  439. ) : (
  440. t('a group')
  441. )
  442. );
  443. }
  444. case GroupActivityType.FIRST_SEEN:
  445. return tct('[author] first saw this issue', {author});
  446. case GroupActivityType.ASSIGNED: {
  447. const {data} = activity;
  448. return getAssignedMessage(data);
  449. }
  450. case GroupActivityType.UNASSIGNED:
  451. return tct('[author] unassigned this issue', {author});
  452. case GroupActivityType.MERGE:
  453. return tn(
  454. '%2$s merged %1$s issue into this issue',
  455. '%2$s merged %1$s issues into this issue',
  456. activity.data.issues.length,
  457. author
  458. );
  459. case GroupActivityType.REPROCESS: {
  460. const {data} = activity;
  461. const {oldGroupId, eventCount} = data;
  462. return tct('[author] reprocessed the events in this issue. [new-events]', {
  463. author,
  464. ['new-events']: (
  465. <Link
  466. to={`/organizations/${organization.slug}/issues/?query=reprocessing.original_issue_id:${oldGroupId}&referrer=group-activity-reprocesses`}
  467. >
  468. {tn('See %s new event', 'See %s new events', eventCount)}
  469. </Link>
  470. ),
  471. });
  472. }
  473. case GroupActivityType.MARK_REVIEWED: {
  474. return tct('[author] marked this issue as reviewed', {
  475. author,
  476. });
  477. }
  478. case GroupActivityType.AUTO_SET_ONGOING: {
  479. return activity.data?.afterDays
  480. ? tct(
  481. '[author] automatically marked this issue as ongoing after [afterDays] days',
  482. {author, afterDays: activity.data.afterDays}
  483. )
  484. : tct('[author] automatically marked this issue as ongoing', {
  485. author,
  486. });
  487. }
  488. case GroupActivityType.SET_ESCALATING: {
  489. return getEscalatingMessage(activity.data);
  490. }
  491. default:
  492. return ''; // should never hit (?)
  493. }
  494. }
  495. return <Fragment>{renderContent()}</Fragment>;
  496. }
  497. export default GroupActivityItem;
  498. const Subtext = styled('div')`
  499. font-size: ${p => p.theme.fontSizeSmall};
  500. `;
  501. const CodeWrapper = styled('div')`
  502. overflow-wrap: anywhere;
  503. font-size: ${p => p.theme.fontSizeSmall};
  504. `;
  505. const StyledRuleSpan = styled('span')`
  506. font-family: ${p => p.theme.text.familyMono};
  507. `;