groupEventDetails.tsx 9.0 KB

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