linkedIssue.tsx 3.7 KB

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