index.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import {Component} from 'react';
  2. import {RouteComponentProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import {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 SentryTypes from 'sentry/sentryTypes';
  14. import {space} from 'sentry/styles/space';
  15. import {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: SentryTypes.Group,
  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. 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. return (
  105. <SentryDocumentTitle noSuffix title={title}>
  106. <OrganizationContext.Provider value={project.organization}>
  107. <div className="app">
  108. <div className="pattern-bg" />
  109. <div className="container">
  110. <div className="box box-modal">
  111. <div className="box-header">
  112. <Link className="logo" to="/">
  113. <span className="icon-sentry-logo-full" />
  114. </Link>
  115. {permalink && (
  116. <Link className="details" to={permalink}>
  117. {t('Details')}
  118. </Link>
  119. )}
  120. </div>
  121. <div className="box-content">
  122. <SharedGroupHeader group={group} />
  123. <Container className="group-overview event-details-container">
  124. <BorderlessEventEntries
  125. location={location}
  126. organization={project.organization}
  127. group={group}
  128. event={latestEvent}
  129. project={project}
  130. isShare
  131. />
  132. </Container>
  133. <Footer />
  134. </div>
  135. </div>
  136. </div>
  137. </div>
  138. </OrganizationContext.Provider>
  139. </SentryDocumentTitle>
  140. );
  141. }
  142. }
  143. const Container = styled('div')`
  144. padding: ${space(4)};
  145. `;
  146. export {SharedGroupDetails};
  147. export default withApi(SharedGroupDetails);