groupEventDetails.tsx 9.2 KB

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