reprocessedBox.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import {Component} from 'react';
  2. import styled from '@emotion/styled';
  3. import {BannerContainer, BannerSummary} from 'sentry/components/events/styles';
  4. import Link from 'sentry/components/links/link';
  5. import {IconCheckmark, IconClose} from 'sentry/icons';
  6. import {t, tct, tn} from 'sentry/locale';
  7. import space from 'sentry/styles/space';
  8. import {GroupActivityReprocess, Organization} from 'sentry/types';
  9. import localStorage from 'sentry/utils/localStorage';
  10. type Props = {
  11. groupCount: number;
  12. groupId: string;
  13. orgSlug: Organization['slug'];
  14. reprocessActivity: GroupActivityReprocess;
  15. className?: string;
  16. };
  17. type State = {
  18. isBannerHidden: boolean;
  19. };
  20. class ReprocessedBox extends Component<Props, State> {
  21. state: State = {
  22. isBannerHidden: localStorage.getItem(this.getBannerUniqueId()) === 'true',
  23. };
  24. getBannerUniqueId() {
  25. const {reprocessActivity} = this.props;
  26. const {id} = reprocessActivity;
  27. return `reprocessed-activity-${id}-banner-dismissed`;
  28. }
  29. handleBannerDismiss = () => {
  30. localStorage.setItem(this.getBannerUniqueId(), 'true');
  31. this.setState({isBannerHidden: true});
  32. };
  33. renderMessage() {
  34. const {orgSlug, reprocessActivity, groupCount, groupId} = this.props;
  35. const {data} = reprocessActivity;
  36. const {eventCount, oldGroupId, newGroupId} = data;
  37. const reprocessedEventsRoute = `/organizations/${orgSlug}/issues/?query=reprocessing.original_issue_id:${oldGroupId}`;
  38. if (groupCount === 0) {
  39. return tct('All events in this issue were moved during reprocessing. [link]', {
  40. link: (
  41. <Link to={reprocessedEventsRoute}>
  42. {tn('See %s new event', 'See %s new events', eventCount)}
  43. </Link>
  44. ),
  45. });
  46. }
  47. return tct('Events in this issue were successfully reprocessed. [link]', {
  48. link: (
  49. <Link to={reprocessedEventsRoute}>
  50. {newGroupId === Number(groupId)
  51. ? tn('See %s reprocessed event', 'See %s reprocessed events', eventCount)
  52. : tn('See %s new event', 'See %s new events', eventCount)}
  53. </Link>
  54. ),
  55. });
  56. }
  57. render() {
  58. const {isBannerHidden} = this.state;
  59. if (isBannerHidden) {
  60. return null;
  61. }
  62. const {className} = this.props;
  63. return (
  64. <BannerContainer priority="success" className={className}>
  65. <StyledBannerSummary>
  66. <IconCheckmark color="green300" isCircled />
  67. <span>{this.renderMessage()}</span>
  68. <StyledIconClose
  69. color="green300"
  70. aria-label={t('Dismiss')}
  71. isCircled
  72. onClick={this.handleBannerDismiss}
  73. />
  74. </StyledBannerSummary>
  75. </BannerContainer>
  76. );
  77. }
  78. }
  79. export default ReprocessedBox;
  80. const StyledBannerSummary = styled(BannerSummary)`
  81. & > svg:last-child {
  82. margin-right: 0;
  83. margin-left: ${space(1)};
  84. }
  85. `;
  86. const StyledIconClose = styled(IconClose)`
  87. cursor: pointer;
  88. `;