groupEventDetails.tsx 8.4 KB

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