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. 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 {getConfigForIssueType} from 'sentry/utils/issueTypeConfig';
  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. const issueTypeConfig = getConfigForIssueType(group);
  174. return (
  175. <TransactionProfileIdProvider
  176. projectId={event?.projectID}
  177. transactionId={event?.type === 'transaction' ? event.id : undefined}
  178. timestamp={event?.dateReceived}
  179. >
  180. <VisuallyCompleteWithData
  181. id="IssueDetails-EventBody"
  182. hasData={!loadingEvent && !eventError && defined(eventWithMeta)}
  183. isLoading={loadingEvent}
  184. >
  185. <StyledLayoutBody data-test-id="group-event-details">
  186. {hasReprocessingV2Feature &&
  187. groupReprocessingStatus === ReprocessingStatus.REPROCESSING ? (
  188. <ReprocessingProgress
  189. totalEvents={(mostRecentActivity as GroupActivityReprocess).data.eventCount}
  190. pendingEvents={
  191. (group.statusDetails as GroupReprocessing['statusDetails']).pendingEvents
  192. }
  193. />
  194. ) : (
  195. <Fragment>
  196. <QuickTraceQuery
  197. event={eventWithMeta}
  198. location={location}
  199. orgSlug={organization.slug}
  200. >
  201. {results => {
  202. return (
  203. <StyledLayoutMain>
  204. {renderGroupStatusBanner()}
  205. <EscalatingIssuesFeedback
  206. organization={organization}
  207. group={group}
  208. />
  209. <QuickTraceContext.Provider value={results}>
  210. {eventWithMeta && issueTypeConfig.stats.enabled && (
  211. <GroupEventHeader
  212. group={group}
  213. event={eventWithMeta}
  214. project={project}
  215. />
  216. )}
  217. {renderContent()}
  218. </QuickTraceContext.Provider>
  219. </StyledLayoutMain>
  220. );
  221. }}
  222. </QuickTraceQuery>
  223. <StyledLayoutSide>
  224. <GroupSidebar
  225. organization={organization}
  226. project={project}
  227. group={group}
  228. event={eventWithMeta}
  229. environments={environments}
  230. />
  231. </StyledLayoutSide>
  232. </Fragment>
  233. )}
  234. </StyledLayoutBody>
  235. </VisuallyCompleteWithData>
  236. </TransactionProfileIdProvider>
  237. );
  238. }
  239. const StyledLayoutBody = styled(Layout.Body)`
  240. /* Makes the borders align correctly */
  241. padding: 0 !important;
  242. @media (min-width: ${p => p.theme.breakpoints.large}) {
  243. align-content: stretch;
  244. }
  245. `;
  246. const GroupStatusBannerWrapper = styled('div')`
  247. margin-bottom: ${space(2)};
  248. `;
  249. const StyledLayoutMain = styled(Layout.Main)`
  250. padding-top: ${space(2)};
  251. @media (max-width: ${p => p.theme.breakpoints.medium}) {
  252. padding-top: ${space(1)};
  253. }
  254. @media (min-width: ${p => p.theme.breakpoints.large}) {
  255. border-right: 1px solid ${p => p.theme.border};
  256. padding-right: 0;
  257. }
  258. `;
  259. const StyledLayoutSide = styled(Layout.Side)`
  260. padding: ${space(3)} ${space(2)} ${space(3)};
  261. @media (min-width: ${p => p.theme.breakpoints.large}) {
  262. padding-right: ${space(4)};
  263. padding-left: 0;
  264. }
  265. `;
  266. export default GroupEventDetails;