linkedIssue.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import styled from '@emotion/styled';
  2. import {Alert} from 'sentry/components/alert';
  3. import {SectionHeading} from 'sentry/components/charts/styles';
  4. import DeprecatedAsyncComponent from 'sentry/components/deprecatedAsyncComponent';
  5. import Times from 'sentry/components/group/times';
  6. import ProjectBadge from 'sentry/components/idBadge/projectBadge';
  7. import Link from 'sentry/components/links/link';
  8. import Placeholder from 'sentry/components/placeholder';
  9. import SeenByList from 'sentry/components/seenByList';
  10. import ShortId from 'sentry/components/shortId';
  11. import GroupChart from 'sentry/components/stream/groupChart';
  12. import {t} from 'sentry/locale';
  13. import {space} from 'sentry/styles/space';
  14. import {Group} from 'sentry/types';
  15. type Props = {
  16. eventId: string;
  17. groupId: string;
  18. };
  19. type State = {
  20. group: Group;
  21. };
  22. class LinkedIssue extends DeprecatedAsyncComponent<
  23. Props & DeprecatedAsyncComponent['props'],
  24. State & DeprecatedAsyncComponent['state']
  25. > {
  26. getEndpoints(): ReturnType<DeprecatedAsyncComponent['getEndpoints']> {
  27. const {groupId} = this.props;
  28. const groupUrl = `/issues/${groupId}/`;
  29. return [['group', groupUrl]];
  30. }
  31. renderLoading() {
  32. return <Placeholder height="120px" bottomGutter={2} />;
  33. }
  34. renderError(error?: Error, disableLog = false): React.ReactNode {
  35. const {errors} = this.state;
  36. const hasNotFound = Object.values(errors).find(resp => resp && resp.status === 404);
  37. if (hasNotFound) {
  38. return (
  39. <Alert type="warning" showIcon>
  40. {t('The linked issue cannot be found. It may have been deleted, or merged.')}
  41. </Alert>
  42. );
  43. }
  44. return super.renderError(error, disableLog);
  45. }
  46. renderBody() {
  47. const {eventId} = this.props;
  48. const {group} = this.state;
  49. const issueUrl = `${group.permalink}events/${eventId}/`;
  50. return (
  51. <Section>
  52. <SectionHeading>{t('Event Issue')}</SectionHeading>
  53. <StyledIssueCard>
  54. <IssueCardHeader>
  55. <StyledLink to={issueUrl} data-test-id="linked-issue">
  56. <StyledShortId
  57. shortId={group.shortId}
  58. avatar={
  59. <ProjectBadge
  60. project={group.project}
  61. avatarSize={16}
  62. hideName
  63. disableLink
  64. />
  65. }
  66. />
  67. </StyledLink>
  68. <SeenByList seenBy={group.seenBy} maxVisibleAvatars={5} />
  69. </IssueCardHeader>
  70. <IssueCardBody>
  71. <GroupChart statsPeriod="30d" data={group} height={56} />
  72. </IssueCardBody>
  73. <IssueCardFooter>
  74. <Times lastSeen={group.lastSeen} firstSeen={group.firstSeen} />
  75. </IssueCardFooter>
  76. </StyledIssueCard>
  77. </Section>
  78. );
  79. }
  80. }
  81. const Section = styled('div')`
  82. margin-bottom: ${space(4)};
  83. `;
  84. const StyledIssueCard = styled('div')`
  85. border: 1px solid ${p => p.theme.border};
  86. border-radius: ${p => p.theme.borderRadius};
  87. `;
  88. const IssueCardHeader = styled('div')`
  89. display: flex;
  90. align-items: center;
  91. justify-content: space-between;
  92. padding: ${space(1)};
  93. `;
  94. const StyledLink = styled(Link)`
  95. justify-content: flex-start;
  96. `;
  97. const IssueCardBody = styled('div')`
  98. background: ${p => p.theme.backgroundSecondary};
  99. padding-top: ${space(1)};
  100. `;
  101. const StyledShortId = styled(ShortId)`
  102. font-size: ${p => p.theme.fontSizeMedium};
  103. color: ${p => p.theme.textColor};
  104. `;
  105. const IssueCardFooter = styled('div')`
  106. color: ${p => p.theme.gray300};
  107. font-size: ${p => p.theme.fontSizeSmall};
  108. padding: ${space(0.5)} ${space(1)};
  109. `;
  110. export default LinkedIssue;