groupEventDetails.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. import {Component, Fragment} from 'react';
  2. import {browserHistory, RouteComponentProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import * as Sentry from '@sentry/react';
  5. import isEqual from 'lodash/isEqual';
  6. import {fetchSentryAppComponents} from 'sentry/actionCreators/sentryAppComponents';
  7. import {Client} from 'sentry/api';
  8. import GroupEventDetailsLoadingError from 'sentry/components/errors/groupEventDetailsLoadingError';
  9. import {withMeta} from 'sentry/components/events/meta/metaProxy';
  10. import GroupSidebar from 'sentry/components/group/sidebar';
  11. import * as Layout from 'sentry/components/layouts/thirds';
  12. import LoadingIndicator from 'sentry/components/loadingIndicator';
  13. import MutedBox from 'sentry/components/mutedBox';
  14. import {TransactionProfileIdProvider} from 'sentry/components/profiling/transactionProfileIdProvider';
  15. import ReprocessedBox from 'sentry/components/reprocessedBox';
  16. import ResolutionBox from 'sentry/components/resolutionBox';
  17. import {space} from 'sentry/styles/space';
  18. import {
  19. BaseGroupStatusReprocessing,
  20. Environment,
  21. Group,
  22. GroupActivityReprocess,
  23. Organization,
  24. Project,
  25. } from 'sentry/types';
  26. import {Event} from 'sentry/types/event';
  27. import {defined} from 'sentry/utils';
  28. import fetchSentryAppInstallations from 'sentry/utils/fetchSentryAppInstallations';
  29. import {QuickTraceContext} from 'sentry/utils/performance/quickTrace/quickTraceContext';
  30. import QuickTraceQuery from 'sentry/utils/performance/quickTrace/quickTraceQuery';
  31. import {VisuallyCompleteWithData} from 'sentry/utils/performanceForSentry';
  32. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  33. import GroupEventDetailsContent from 'sentry/views/issueDetails/groupEventDetails/groupEventDetailsContent';
  34. import GroupEventHeader from 'sentry/views/issueDetails/groupEventHeader';
  35. import ReprocessingProgress from '../reprocessingProgress';
  36. import {
  37. getEventEnvironment,
  38. getGroupMostRecentActivity,
  39. ReprocessingStatus,
  40. } from '../utils';
  41. export interface GroupEventDetailsProps
  42. extends RouteComponentProps<{groupId: string; eventId?: string}, {}> {
  43. api: Client;
  44. environments: Environment[];
  45. eventError: boolean;
  46. group: Group;
  47. groupReprocessingStatus: ReprocessingStatus;
  48. loadingEvent: boolean;
  49. onRetry: () => void;
  50. organization: Organization;
  51. project: Project;
  52. event?: Event;
  53. }
  54. type State = {
  55. eventNavLinks: string;
  56. releasesCompletion: any;
  57. };
  58. class GroupEventDetails extends Component<GroupEventDetailsProps, State> {
  59. state: State = {
  60. eventNavLinks: '',
  61. releasesCompletion: null,
  62. };
  63. componentDidMount() {
  64. this.fetchData();
  65. }
  66. componentDidUpdate(prevProps: GroupEventDetailsProps) {
  67. const {environments, params, location, organization, project} = this.props;
  68. const environmentsHaveChanged = !isEqual(prevProps.environments, environments);
  69. // If environments are being actively changed and will no longer contain the
  70. // current event's environment, redirect to latest
  71. if (
  72. environmentsHaveChanged &&
  73. prevProps.event &&
  74. params.eventId &&
  75. !['latest', 'oldest'].includes(params.eventId)
  76. ) {
  77. const shouldRedirect =
  78. environments.length > 0 &&
  79. !environments.find(
  80. env => env.name === getEventEnvironment(prevProps.event as Event)
  81. );
  82. if (shouldRedirect) {
  83. browserHistory.replace(
  84. normalizeUrl({
  85. pathname: `/organizations/${organization.slug}/issues/${params.groupId}/`,
  86. query: location.query,
  87. })
  88. );
  89. return;
  90. }
  91. }
  92. if (
  93. prevProps.organization.slug !== organization.slug ||
  94. prevProps.project.slug !== project.slug
  95. ) {
  96. this.fetchData();
  97. }
  98. }
  99. componentWillUnmount() {
  100. this.props.api.clear();
  101. }
  102. fetchData = async () => {
  103. const {api, project, organization} = this.props;
  104. const orgSlug = organization.slug;
  105. const projSlug = project.slug;
  106. const projectId = project.id;
  107. /**
  108. * Perform below requests in parallel
  109. */
  110. const releasesCompletionPromise = api.requestPromise(
  111. `/projects/${orgSlug}/${projSlug}/releases/completion/`
  112. );
  113. fetchSentryAppInstallations(api, orgSlug);
  114. // TODO(marcos): Sometimes PageFiltersStore cannot pick a project.
  115. if (projectId) {
  116. fetchSentryAppComponents(api, orgSlug, projectId);
  117. } else {
  118. Sentry.withScope(scope => {
  119. scope.setExtra('props', this.props);
  120. scope.setExtra('state', this.state);
  121. Sentry.captureMessage('Project ID was not set');
  122. });
  123. }
  124. const releasesCompletion = await releasesCompletionPromise;
  125. this.setState({releasesCompletion});
  126. };
  127. renderContent(eventWithMeta?: Event) {
  128. const {group, project, environments, loadingEvent, onRetry, eventError} = this.props;
  129. if (loadingEvent) {
  130. return <LoadingIndicator />;
  131. }
  132. if (eventError) {
  133. return (
  134. <GroupEventDetailsLoadingError environments={environments} onRetry={onRetry} />
  135. );
  136. }
  137. return (
  138. <GroupEventDetailsContent group={group} event={eventWithMeta} project={project} />
  139. );
  140. }
  141. renderReprocessedBox(
  142. reprocessStatus: ReprocessingStatus,
  143. mostRecentActivity: GroupActivityReprocess
  144. ) {
  145. if (
  146. reprocessStatus !== ReprocessingStatus.REPROCESSED_AND_HASNT_EVENT &&
  147. reprocessStatus !== ReprocessingStatus.REPROCESSED_AND_HAS_EVENT
  148. ) {
  149. return null;
  150. }
  151. const {group, organization} = this.props;
  152. const {count, id: groupId} = group;
  153. const groupCount = Number(count);
  154. return (
  155. <ReprocessedBox
  156. reprocessActivity={mostRecentActivity}
  157. groupCount={groupCount}
  158. groupId={groupId}
  159. orgSlug={organization.slug}
  160. />
  161. );
  162. }
  163. renderGroupStatusBanner() {
  164. if (this.props.group.status === 'ignored') {
  165. return (
  166. <GroupStatusBannerWrapper>
  167. <MutedBox statusDetails={this.props.group.statusDetails} />
  168. </GroupStatusBannerWrapper>
  169. );
  170. }
  171. if (this.props.group.status === 'resolved') {
  172. return (
  173. <GroupStatusBannerWrapper>
  174. <ResolutionBox
  175. statusDetails={this.props.group.statusDetails}
  176. activities={this.props.group.activity}
  177. projectId={this.props.project.id}
  178. />
  179. </GroupStatusBannerWrapper>
  180. );
  181. }
  182. return null;
  183. }
  184. render() {
  185. const {
  186. group,
  187. project,
  188. organization,
  189. environments,
  190. location,
  191. event,
  192. groupReprocessingStatus,
  193. loadingEvent,
  194. eventError,
  195. } = this.props;
  196. const eventWithMeta = withMeta(event);
  197. // Reprocessing
  198. const hasReprocessingV2Feature = organization.features?.includes('reprocessing-v2');
  199. const {activity: activities} = group;
  200. const mostRecentActivity = getGroupMostRecentActivity(activities);
  201. return (
  202. <TransactionProfileIdProvider
  203. projectId={event?.projectID}
  204. transactionId={event?.type === 'transaction' ? event.id : undefined}
  205. timestamp={event?.dateReceived}
  206. >
  207. <VisuallyCompleteWithData
  208. id="IssueDetails-EventBody"
  209. hasData={!loadingEvent && !eventError && defined(eventWithMeta)}
  210. >
  211. <StyledLayoutBody data-test-id="group-event-details">
  212. {hasReprocessingV2Feature &&
  213. groupReprocessingStatus === ReprocessingStatus.REPROCESSING ? (
  214. <ReprocessingProgress
  215. totalEvents={
  216. (mostRecentActivity as GroupActivityReprocess).data.eventCount
  217. }
  218. pendingEvents={
  219. (group.statusDetails as BaseGroupStatusReprocessing['statusDetails'])
  220. .pendingEvents
  221. }
  222. />
  223. ) : (
  224. <Fragment>
  225. <QuickTraceQuery
  226. event={eventWithMeta}
  227. location={location}
  228. orgSlug={organization.slug}
  229. >
  230. {results => {
  231. return (
  232. <StyledLayoutMain>
  233. {this.renderGroupStatusBanner()}
  234. <QuickTraceContext.Provider value={results}>
  235. {eventWithMeta && (
  236. <GroupEventHeader
  237. group={group}
  238. event={eventWithMeta}
  239. project={project}
  240. />
  241. )}
  242. {this.renderReprocessedBox(
  243. groupReprocessingStatus,
  244. mostRecentActivity as GroupActivityReprocess
  245. )}
  246. {this.renderContent(eventWithMeta)}
  247. </QuickTraceContext.Provider>
  248. </StyledLayoutMain>
  249. );
  250. }}
  251. </QuickTraceQuery>
  252. <StyledLayoutSide>
  253. <GroupSidebar
  254. organization={organization}
  255. project={project}
  256. group={group}
  257. event={eventWithMeta}
  258. environments={environments}
  259. />
  260. </StyledLayoutSide>
  261. </Fragment>
  262. )}
  263. </StyledLayoutBody>
  264. </VisuallyCompleteWithData>
  265. </TransactionProfileIdProvider>
  266. );
  267. }
  268. }
  269. const StyledLayoutBody = styled(Layout.Body)`
  270. /* Makes the borders align correctly */
  271. padding: 0 !important;
  272. @media (min-width: ${p => p.theme.breakpoints.large}) {
  273. align-content: stretch;
  274. }
  275. `;
  276. const GroupStatusBannerWrapper = styled('div')`
  277. margin-bottom: ${space(2)};
  278. `;
  279. const StyledLayoutMain = styled(Layout.Main)`
  280. padding-top: ${space(2)};
  281. @media (max-width: ${p => p.theme.breakpoints.medium}) {
  282. padding-top: ${space(1)};
  283. }
  284. @media (min-width: ${p => p.theme.breakpoints.large}) {
  285. border-right: 1px solid ${p => p.theme.border};
  286. padding-right: 0;
  287. }
  288. `;
  289. const StyledLayoutSide = styled(Layout.Side)`
  290. padding: ${space(3)} ${space(2)} ${space(3)};
  291. @media (min-width: ${p => p.theme.breakpoints.large}) {
  292. padding-right: ${space(4)};
  293. padding-left: 0;
  294. }
  295. `;
  296. export default GroupEventDetails;