groupEventDetails.tsx 9.0 KB

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