groupEventDetails.tsx 9.5 KB

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