groupEventDetails.tsx 8.3 KB

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