groupEventDetails.tsx 9.5 KB

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