groupActivityItem.tsx 18 KB

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