groupEventDetails.tsx 8.2 KB

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