groupEventDetails.tsx 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. import {Fragment, useEffect} from 'react';
  2. import type {RouteComponentProps} from 'react-router';
  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 {
  16. Group,
  17. GroupActivityReprocess,
  18. GroupReprocessing,
  19. Organization,
  20. Project,
  21. } from 'sentry/types';
  22. import type {Event} from 'sentry/types/event';
  23. import {defined} from 'sentry/utils';
  24. import {browserHistory} from 'sentry/utils/browserHistory';
  25. import {getConfigForIssueType} from 'sentry/utils/issueTypeConfig';
  26. import {VisuallyCompleteWithData} from 'sentry/utils/performanceForSentry';
  27. import usePrevious from 'sentry/utils/usePrevious';
  28. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  29. import GroupEventDetailsContent from 'sentry/views/issueDetails/groupEventDetails/groupEventDetailsContent';
  30. import GroupEventHeader from 'sentry/views/issueDetails/groupEventHeader';
  31. import GroupSidebar from 'sentry/views/issueDetails/groupSidebar';
  32. import ReprocessingProgress from '../reprocessingProgress';
  33. import {
  34. getEventEnvironment,
  35. getGroupMostRecentActivity,
  36. ReprocessingStatus,
  37. useEnvironmentsFromUrl,
  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. // load the data
  71. useSentryAppComponentsData({projectId});
  72. // If environments are being actively changed and will no longer contain the
  73. // current event's environment, redirect to latest
  74. useEffect(() => {
  75. const environmentsHaveChanged = !isEqual(prevEnvironment, environments);
  76. // If environments are being actively changed and will no longer contain the
  77. // current event's environment, redirect to latest
  78. if (
  79. environmentsHaveChanged &&
  80. prevEvent &&
  81. params.eventId &&
  82. !['latest', 'oldest'].includes(params.eventId)
  83. ) {
  84. const shouldRedirect =
  85. environments.length > 0 &&
  86. !environments.find(env => env === getEventEnvironment(prevEvent as Event));
  87. if (shouldRedirect) {
  88. browserHistory.replace(
  89. normalizeUrl({
  90. pathname: `/organizations/${organization.slug}/issues/${params.groupId}/`,
  91. query: location.query,
  92. })
  93. );
  94. return;
  95. }
  96. }
  97. }, [
  98. prevEnvironment,
  99. environments,
  100. location.query,
  101. organization.slug,
  102. params,
  103. prevEvent,
  104. ]);
  105. const renderGroupStatusBanner = () => {
  106. if (group.status === 'ignored') {
  107. return (
  108. <GroupStatusBannerWrapper>
  109. <ArchivedBox
  110. substatus={group.substatus}
  111. statusDetails={group.statusDetails}
  112. organization={organization}
  113. />
  114. </GroupStatusBannerWrapper>
  115. );
  116. }
  117. if (group.status === 'resolved') {
  118. return (
  119. <GroupStatusBannerWrapper>
  120. <ResolutionBox
  121. statusDetails={group.statusDetails}
  122. activities={group.activity}
  123. projectId={project.id}
  124. />
  125. </GroupStatusBannerWrapper>
  126. );
  127. }
  128. return null;
  129. };
  130. const renderContent = () => {
  131. if (loadingEvent) {
  132. return <LoadingIndicator />;
  133. }
  134. if (eventError) {
  135. return (
  136. <GroupEventDetailsLoadingError environments={environments} onRetry={onRetry} />
  137. );
  138. }
  139. return (
  140. <GroupEventDetailsContent group={group} event={eventWithMeta} project={project} />
  141. );
  142. };
  143. const eventWithMeta = withMeta(event);
  144. const issueTypeConfig = getConfigForIssueType(group, project);
  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 data-test-id="group-event-details">
  157. {groupReprocessingStatus === ReprocessingStatus.REPROCESSING ? (
  158. <ReprocessingProgress
  159. totalEvents={
  160. (getGroupMostRecentActivity(group.activity) as GroupActivityReprocess)
  161. .data.eventCount
  162. }
  163. pendingEvents={
  164. (group.statusDetails as GroupReprocessing['statusDetails']).pendingEvents
  165. }
  166. />
  167. ) : (
  168. <Fragment>
  169. <StyledLayoutMain>
  170. {renderGroupStatusBanner()}
  171. <EscalatingIssuesFeedback organization={organization} group={group} />
  172. {eventWithMeta && issueTypeConfig.stats.enabled && (
  173. <GroupEventHeader
  174. group={group}
  175. event={eventWithMeta}
  176. project={project}
  177. />
  178. )}
  179. {renderContent()}
  180. </StyledLayoutMain>
  181. <StyledLayoutSide>
  182. <GroupSidebar
  183. organization={organization}
  184. project={project}
  185. group={group}
  186. event={eventWithMeta}
  187. environments={environments}
  188. />
  189. </StyledLayoutSide>
  190. </Fragment>
  191. )}
  192. </StyledLayoutBody>
  193. </VisuallyCompleteWithData>
  194. </TransactionProfileIdProvider>
  195. );
  196. }
  197. const StyledLayoutBody = styled(Layout.Body)`
  198. /* Makes the borders align correctly */
  199. padding: 0 !important;
  200. @media (min-width: ${p => p.theme.breakpoints.large}) {
  201. align-content: stretch;
  202. }
  203. `;
  204. const GroupStatusBannerWrapper = styled('div')`
  205. margin-bottom: ${space(2)};
  206. `;
  207. const StyledLayoutMain = styled(Layout.Main)`
  208. padding-top: ${space(2)};
  209. @media (max-width: ${p => p.theme.breakpoints.medium}) {
  210. padding-top: ${space(1)};
  211. }
  212. @media (min-width: ${p => p.theme.breakpoints.large}) {
  213. border-right: 1px solid ${p => p.theme.border};
  214. padding-right: 0;
  215. }
  216. `;
  217. const StyledLayoutSide = styled(Layout.Side)`
  218. padding: ${space(3)} ${space(2)} ${space(3)};
  219. @media (min-width: ${p => p.theme.breakpoints.large}) {
  220. padding-right: ${space(4)};
  221. padding-left: 0;
  222. }
  223. `;
  224. export default GroupEventDetails;