groupEventDetails.tsx 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. import {Fragment, useEffect} from 'react';
  2. import type {RouteComponentProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import isEqual from 'lodash/isEqual';
  5. import ArchivedBox from 'sentry/components/archivedBox';
  6. import GroupEventDetailsLoadingError from 'sentry/components/errors/groupEventDetailsLoadingError';
  7. import {withMeta} from 'sentry/components/events/meta/metaProxy';
  8. import HookOrDefault from 'sentry/components/hookOrDefault';
  9. import * as Layout from 'sentry/components/layouts/thirds';
  10. import LoadingIndicator from 'sentry/components/loadingIndicator';
  11. import {TransactionProfileIdProvider} from 'sentry/components/profiling/transactionProfileIdProvider';
  12. import ResolutionBox from 'sentry/components/resolutionBox';
  13. import useSentryAppComponentsData from 'sentry/stores/useSentryAppComponentsData';
  14. import {space} from 'sentry/styles/space';
  15. import type {
  16. Group,
  17. GroupActivityReprocess,
  18. GroupReprocessing,
  19. Organization,
  20. Project,
  21. } from 'sentry/types';
  22. import type {Event} from 'sentry/types/event';
  23. import {defined} from 'sentry/utils';
  24. import {browserHistory} from 'sentry/utils/browserHistory';
  25. import {getConfigForIssueType} from 'sentry/utils/issueTypeConfig';
  26. import {QuickTraceContext} from 'sentry/utils/performance/quickTrace/quickTraceContext';
  27. import QuickTraceQuery from 'sentry/utils/performance/quickTrace/quickTraceQuery';
  28. import {VisuallyCompleteWithData} from 'sentry/utils/performanceForSentry';
  29. import usePrevious from 'sentry/utils/usePrevious';
  30. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  31. import GroupEventDetailsContent from 'sentry/views/issueDetails/groupEventDetails/groupEventDetailsContent';
  32. import GroupEventHeader from 'sentry/views/issueDetails/groupEventHeader';
  33. import GroupSidebar from 'sentry/views/issueDetails/groupSidebar';
  34. import ReprocessingProgress from '../reprocessingProgress';
  35. import {
  36. getEventEnvironment,
  37. getGroupMostRecentActivity,
  38. ReprocessingStatus,
  39. useEnvironmentsFromUrl,
  40. } from '../utils';
  41. const EscalatingIssuesFeedback = HookOrDefault({
  42. hookName: 'component:escalating-issues-banner-feedback',
  43. });
  44. export interface GroupEventDetailsProps
  45. extends RouteComponentProps<{groupId: string; eventId?: string}, {}> {
  46. eventError: boolean;
  47. group: Group;
  48. groupReprocessingStatus: ReprocessingStatus;
  49. loadingEvent: boolean;
  50. onRetry: () => void;
  51. organization: Organization;
  52. project: Project;
  53. event?: Event;
  54. }
  55. function GroupEventDetails(props: GroupEventDetailsProps) {
  56. const {
  57. group,
  58. project,
  59. organization,
  60. location,
  61. event,
  62. groupReprocessingStatus,
  63. loadingEvent,
  64. onRetry,
  65. eventError,
  66. params,
  67. } = props;
  68. // Reprocessing
  69. const hasReprocessingV2Feature = organization.features?.includes('reprocessing-v2');
  70. const projectId = project.id;
  71. const environments = useEnvironmentsFromUrl();
  72. const prevEnvironment = usePrevious(environments);
  73. const prevEvent = usePrevious(event);
  74. // load the data
  75. useSentryAppComponentsData({projectId});
  76. // If environments are being actively changed and will no longer contain the
  77. // current event's environment, redirect to latest
  78. useEffect(() => {
  79. const environmentsHaveChanged = !isEqual(prevEnvironment, environments);
  80. // If environments are being actively changed and will no longer contain the
  81. // current event's environment, redirect to latest
  82. if (
  83. environmentsHaveChanged &&
  84. prevEvent &&
  85. params.eventId &&
  86. !['latest', 'oldest'].includes(params.eventId)
  87. ) {
  88. const shouldRedirect =
  89. environments.length > 0 &&
  90. !environments.find(env => env === getEventEnvironment(prevEvent as Event));
  91. if (shouldRedirect) {
  92. browserHistory.replace(
  93. normalizeUrl({
  94. pathname: `/organizations/${organization.slug}/issues/${params.groupId}/`,
  95. query: location.query,
  96. })
  97. );
  98. return;
  99. }
  100. }
  101. }, [
  102. prevEnvironment,
  103. environments,
  104. location.query,
  105. organization.slug,
  106. params,
  107. prevEvent,
  108. ]);
  109. const renderGroupStatusBanner = () => {
  110. if (group.status === 'ignored') {
  111. return (
  112. <GroupStatusBannerWrapper>
  113. <ArchivedBox
  114. substatus={group.substatus}
  115. statusDetails={group.statusDetails}
  116. organization={organization}
  117. />
  118. </GroupStatusBannerWrapper>
  119. );
  120. }
  121. if (group.status === 'resolved') {
  122. return (
  123. <GroupStatusBannerWrapper>
  124. <ResolutionBox
  125. statusDetails={group.statusDetails}
  126. activities={group.activity}
  127. projectId={project.id}
  128. />
  129. </GroupStatusBannerWrapper>
  130. );
  131. }
  132. return null;
  133. };
  134. const renderContent = () => {
  135. if (loadingEvent) {
  136. return <LoadingIndicator />;
  137. }
  138. if (eventError) {
  139. return (
  140. <GroupEventDetailsLoadingError environments={environments} onRetry={onRetry} />
  141. );
  142. }
  143. return (
  144. <GroupEventDetailsContent group={group} event={eventWithMeta} project={project} />
  145. );
  146. };
  147. const eventWithMeta = withMeta(event);
  148. const issueTypeConfig = getConfigForIssueType(group, project);
  149. return (
  150. <TransactionProfileIdProvider
  151. projectId={event?.projectID}
  152. transactionId={event?.type === 'transaction' ? event.id : undefined}
  153. timestamp={event?.dateReceived}
  154. >
  155. <VisuallyCompleteWithData
  156. id="IssueDetails-EventBody"
  157. hasData={!loadingEvent && !eventError && defined(eventWithMeta)}
  158. isLoading={loadingEvent}
  159. >
  160. <StyledLayoutBody data-test-id="group-event-details">
  161. {hasReprocessingV2Feature &&
  162. groupReprocessingStatus === ReprocessingStatus.REPROCESSING ? (
  163. <ReprocessingProgress
  164. totalEvents={
  165. (getGroupMostRecentActivity(group.activity) as GroupActivityReprocess)
  166. .data.eventCount
  167. }
  168. pendingEvents={
  169. (group.statusDetails as GroupReprocessing['statusDetails']).pendingEvents
  170. }
  171. />
  172. ) : (
  173. <Fragment>
  174. <QuickTraceQuery
  175. event={eventWithMeta}
  176. location={location}
  177. orgSlug={organization.slug}
  178. >
  179. {results => {
  180. return (
  181. <StyledLayoutMain>
  182. {renderGroupStatusBanner()}
  183. <EscalatingIssuesFeedback
  184. organization={organization}
  185. group={group}
  186. />
  187. <QuickTraceContext.Provider value={results}>
  188. {eventWithMeta && issueTypeConfig.stats.enabled && (
  189. <GroupEventHeader
  190. group={group}
  191. event={eventWithMeta}
  192. project={project}
  193. />
  194. )}
  195. {renderContent()}
  196. </QuickTraceContext.Provider>
  197. </StyledLayoutMain>
  198. );
  199. }}
  200. </QuickTraceQuery>
  201. <StyledLayoutSide>
  202. <GroupSidebar
  203. organization={organization}
  204. project={project}
  205. group={group}
  206. event={eventWithMeta}
  207. environments={environments}
  208. />
  209. </StyledLayoutSide>
  210. </Fragment>
  211. )}
  212. </StyledLayoutBody>
  213. </VisuallyCompleteWithData>
  214. </TransactionProfileIdProvider>
  215. );
  216. }
  217. const StyledLayoutBody = styled(Layout.Body)`
  218. /* Makes the borders align correctly */
  219. padding: 0 !important;
  220. @media (min-width: ${p => p.theme.breakpoints.large}) {
  221. align-content: stretch;
  222. }
  223. `;
  224. const GroupStatusBannerWrapper = styled('div')`
  225. margin-bottom: ${space(2)};
  226. `;
  227. const StyledLayoutMain = styled(Layout.Main)`
  228. padding-top: ${space(2)};
  229. @media (max-width: ${p => p.theme.breakpoints.medium}) {
  230. padding-top: ${space(1)};
  231. }
  232. @media (min-width: ${p => p.theme.breakpoints.large}) {
  233. border-right: 1px solid ${p => p.theme.border};
  234. padding-right: 0;
  235. }
  236. `;
  237. const StyledLayoutSide = styled(Layout.Side)`
  238. padding: ${space(3)} ${space(2)} ${space(3)};
  239. @media (min-width: ${p => p.theme.breakpoints.large}) {
  240. padding-right: ${space(4)};
  241. padding-left: 0;
  242. }
  243. `;
  244. export default GroupEventDetails;