index.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import {Component} from 'react';
  2. import type {RouteComponentProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import type {Client} from 'sentry/api';
  5. import NotFound from 'sentry/components/errors/notFound';
  6. import {BorderlessEventEntries} from 'sentry/components/events/eventEntries';
  7. import Footer from 'sentry/components/footer';
  8. import Link from 'sentry/components/links/link';
  9. import LoadingError from 'sentry/components/loadingError';
  10. import LoadingIndicator from 'sentry/components/loadingIndicator';
  11. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  12. import {t} from 'sentry/locale';
  13. import {SentryPropTypeValidators} from 'sentry/sentryPropTypeValidators';
  14. import {space} from 'sentry/styles/space';
  15. import type {Group} from 'sentry/types';
  16. import withApi from 'sentry/utils/withApi';
  17. import {OrganizationContext} from '../organizationContext';
  18. import SharedGroupHeader from './sharedGroupHeader';
  19. type Props = RouteComponentProps<{shareId: string; orgId?: string}, {}> & {
  20. api: Client;
  21. };
  22. type State = {
  23. error: boolean;
  24. group: Group | null;
  25. loading: boolean;
  26. };
  27. class SharedGroupDetails extends Component<Props, State> {
  28. static childContextTypes = {
  29. group: SentryPropTypeValidators.isGroup,
  30. };
  31. state: State = this.getInitialState();
  32. getInitialState() {
  33. return {
  34. group: null,
  35. loading: true,
  36. error: false,
  37. };
  38. }
  39. getChildContext() {
  40. return {
  41. group: this.state.group,
  42. };
  43. }
  44. UNSAFE_componentWillMount() {
  45. document.body.classList.add('shared-group');
  46. }
  47. componentDidMount() {
  48. this.fetchData();
  49. }
  50. componentWillUnmount() {
  51. document.body.classList.remove('shared-group');
  52. }
  53. orgSlug(): string | null {
  54. const {params} = this.props;
  55. if (params.orgId) {
  56. return params.orgId;
  57. }
  58. const {customerDomain} = window.__initialData || {};
  59. if (customerDomain?.subdomain) {
  60. return customerDomain.subdomain;
  61. }
  62. return null;
  63. }
  64. async fetchData() {
  65. const {params, api} = this.props;
  66. const {shareId} = params;
  67. const orgSlug = this.orgSlug();
  68. try {
  69. if (orgSlug) {
  70. const group = await api.requestPromise(
  71. `/organizations/${orgSlug}/shared/issues/${shareId}/`
  72. );
  73. this.setState({loading: false, group});
  74. } else {
  75. const group = await api.requestPromise(`/shared/issues/${shareId}/`);
  76. this.setState({loading: false, group});
  77. }
  78. } catch {
  79. this.setState({loading: false, error: true});
  80. }
  81. }
  82. handleRetry = () => {
  83. this.setState(this.getInitialState());
  84. this.fetchData();
  85. };
  86. getTitle() {
  87. const {group} = this.state;
  88. return group?.title ?? 'Sentry';
  89. }
  90. render() {
  91. const {group, loading, error} = this.state;
  92. if (loading) {
  93. return <LoadingIndicator />;
  94. }
  95. if (!group) {
  96. return <NotFound />;
  97. }
  98. if (error) {
  99. return <LoadingError onRetry={this.handleRetry} />;
  100. }
  101. const {location} = this.props;
  102. const {permalink, latestEvent, project} = group;
  103. const title = this.getTitle();
  104. // project.organization is not a real organization, it's just the slug and name
  105. // Add the features array to avoid errors when using OrganizationContext
  106. const org = {...project.organization, features: []};
  107. return (
  108. <SentryDocumentTitle noSuffix title={title}>
  109. <OrganizationContext.Provider value={org}>
  110. <div className="app">
  111. <div className="pattern-bg" />
  112. <div className="container">
  113. <div className="box box-modal">
  114. <div className="box-header">
  115. <Link className="logo" to="/">
  116. <span className="icon-sentry-logo-full" />
  117. </Link>
  118. {permalink && (
  119. <Link className="details" to={permalink}>
  120. {t('Details')}
  121. </Link>
  122. )}
  123. </div>
  124. <div className="box-content">
  125. <SharedGroupHeader group={group} />
  126. <Container className="group-overview event-details-container">
  127. <BorderlessEventEntries
  128. location={location}
  129. organization={org}
  130. group={group}
  131. event={latestEvent}
  132. project={project}
  133. isShare
  134. />
  135. </Container>
  136. <Footer />
  137. </div>
  138. </div>
  139. </div>
  140. </div>
  141. </OrganizationContext.Provider>
  142. </SentryDocumentTitle>
  143. );
  144. }
  145. }
  146. const Container = styled('div')`
  147. padding: ${space(4)};
  148. `;
  149. export {SharedGroupDetails};
  150. export default withApi(SharedGroupDetails);