groupEventDetails.tsx 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. import {Fragment, useEffect} from 'react';
  2. import type {RouteComponentProps} from 'react-router';
  3. import {css} from '@emotion/react';
  4. import styled from '@emotion/styled';
  5. import isEqual from 'lodash/isEqual';
  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 HookOrDefault from 'sentry/components/hookOrDefault';
  10. import * as Layout from 'sentry/components/layouts/thirds';
  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 {Group, GroupActivityReprocess, GroupReprocessing} from 'sentry/types/group';
  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 GroupEventDetailsContent from 'sentry/views/issueDetails/groupEventDetails/groupEventDetailsContent';
  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. const EscalatingIssuesFeedback = HookOrDefault({
  38. hookName: 'component:escalating-issues-banner-feedback',
  39. });
  40. export interface GroupEventDetailsProps
  41. extends RouteComponentProps<{groupId: string; eventId?: string}, {}> {
  42. eventError: boolean;
  43. group: Group;
  44. groupReprocessingStatus: ReprocessingStatus;
  45. loadingEvent: boolean;
  46. onRetry: () => void;
  47. organization: Organization;
  48. project: Project;
  49. event?: Event;
  50. }
  51. function GroupEventDetails(props: GroupEventDetailsProps) {
  52. const {
  53. group,
  54. project,
  55. organization,
  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. return <LoadingIndicator />;
  132. }
  133. if (eventError) {
  134. return (
  135. <GroupEventDetailsLoadingError environments={environments} onRetry={onRetry} />
  136. );
  137. }
  138. return (
  139. <GroupEventDetailsContent group={group} event={eventWithMeta} project={project} />
  140. );
  141. };
  142. const eventWithMeta = withMeta(event);
  143. const issueTypeConfig = getConfigForIssueType(group, project);
  144. const MainLayoutComponent = hasStreamlinedUI ? GroupContent : 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. <StyledLayoutBody
  157. data-test-id="group-event-details"
  158. hasStreamlinedUi={hasStreamlinedUI}
  159. >
  160. {groupReprocessingStatus === ReprocessingStatus.REPROCESSING ? (
  161. <ReprocessingProgress
  162. totalEvents={
  163. (getGroupMostRecentActivity(group.activity) as GroupActivityReprocess)
  164. .data.eventCount
  165. }
  166. pendingEvents={
  167. (group.statusDetails as GroupReprocessing['statusDetails']).pendingEvents
  168. }
  169. />
  170. ) : (
  171. <Fragment>
  172. <MainLayoutComponent>
  173. {!hasStreamlinedUI && renderGroupStatusBanner()}
  174. <EscalatingIssuesFeedback organization={organization} group={group} />
  175. {eventWithMeta && issueTypeConfig.stats.enabled && !hasStreamlinedUI && (
  176. <GroupEventHeader
  177. group={group}
  178. event={eventWithMeta}
  179. project={project}
  180. />
  181. )}
  182. {renderContent()}
  183. </MainLayoutComponent>
  184. <StyledLayoutSide hasStreamlinedUi={hasStreamlinedUI}>
  185. <GroupSidebar
  186. organization={organization}
  187. project={project}
  188. group={group}
  189. event={eventWithMeta}
  190. environments={environments}
  191. />
  192. </StyledLayoutSide>
  193. </Fragment>
  194. )}
  195. </StyledLayoutBody>
  196. </VisuallyCompleteWithData>
  197. </TransactionProfileIdProvider>
  198. );
  199. }
  200. const StyledLayoutBody = styled(Layout.Body)<{hasStreamlinedUi: boolean}>`
  201. /* Makes the borders align correctly */
  202. padding: 0 !important;
  203. @media (min-width: ${p => p.theme.breakpoints.large}) {
  204. align-content: stretch;
  205. }
  206. ${p =>
  207. p.hasStreamlinedUi &&
  208. css`
  209. @media (min-width: ${p.theme.breakpoints.large}) {
  210. gap: ${space(2)};
  211. }
  212. `}
  213. `;
  214. const GroupStatusBannerWrapper = styled('div')`
  215. margin-bottom: ${space(2)};
  216. `;
  217. const StyledLayoutMain = styled(Layout.Main)`
  218. padding-top: ${space(2)};
  219. @media (max-width: ${p => p.theme.breakpoints.medium}) {
  220. padding-top: ${space(1)};
  221. }
  222. @media (min-width: ${p => p.theme.breakpoints.large}) {
  223. border-right: 1px solid ${p => p.theme.border};
  224. padding-right: 0;
  225. }
  226. `;
  227. const GroupContent = styled(Layout.Main)`
  228. background: ${p => p.theme.backgroundSecondary};
  229. display: flex;
  230. flex-direction: column;
  231. gap: ${space(1.5)};
  232. padding: ${space(1.5)};
  233. `;
  234. const StyledLayoutSide = styled(Layout.Side)<{hasStreamlinedUi: boolean}>`
  235. ${p =>
  236. p.hasStreamlinedUi
  237. ? css`
  238. padding: ${space(1.5)} ${space(2)} ${space(3)};
  239. `
  240. : css`
  241. padding: ${space(3)} ${space(2)} ${space(3)};
  242. @media (min-width: ${p.theme.breakpoints.large}) {
  243. padding-right: ${space(4)};
  244. }
  245. `}
  246. @media (min-width: ${p => p.theme.breakpoints.large}) {
  247. padding-left: 0;
  248. }
  249. `;
  250. export default GroupEventDetails;