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