groupEventDetails.tsx 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. import {Component, Fragment} from 'react';
  2. import {browserHistory, RouteComponentProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import * as Sentry from '@sentry/react';
  5. import isEqual from 'lodash/isEqual';
  6. import {fetchSentryAppComponents} from 'sentry/actionCreators/sentryAppComponents';
  7. import {Client} from 'sentry/api';
  8. import GroupEventDetailsLoadingError from 'sentry/components/errors/groupEventDetailsLoadingError';
  9. import {withMeta} from 'sentry/components/events/meta/metaProxy';
  10. import GroupSidebar from 'sentry/components/group/sidebar';
  11. import * as Layout from 'sentry/components/layouts/thirds';
  12. import LoadingIndicator from 'sentry/components/loadingIndicator';
  13. import MutedBox from 'sentry/components/mutedBox';
  14. import {TransactionProfileIdProvider} from 'sentry/components/profiling/transactionProfileIdProvider';
  15. import ReprocessedBox from 'sentry/components/reprocessedBox';
  16. import ResolutionBox from 'sentry/components/resolutionBox';
  17. import {space} from 'sentry/styles/space';
  18. import {
  19. BaseGroupStatusReprocessing,
  20. Environment,
  21. Group,
  22. GroupActivityReprocess,
  23. Organization,
  24. Project,
  25. } from 'sentry/types';
  26. import {Event} from 'sentry/types/event';
  27. import fetchSentryAppInstallations from 'sentry/utils/fetchSentryAppInstallations';
  28. import {QuickTraceContext} from 'sentry/utils/performance/quickTrace/quickTraceContext';
  29. import QuickTraceQuery from 'sentry/utils/performance/quickTrace/quickTraceQuery';
  30. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  31. import GroupEventDetailsContent from 'sentry/views/issueDetails/groupEventDetails/groupEventDetailsContent';
  32. import GroupEventToolbar from '../eventToolbar';
  33. import ReprocessingProgress from '../reprocessingProgress';
  34. import {
  35. getEventEnvironment,
  36. getGroupMostRecentActivity,
  37. ReprocessingStatus,
  38. } from '../utils';
  39. export interface GroupEventDetailsProps
  40. extends RouteComponentProps<{groupId: string; eventId?: string}, {}> {
  41. api: Client;
  42. environments: Environment[];
  43. eventError: boolean;
  44. group: Group;
  45. groupReprocessingStatus: ReprocessingStatus;
  46. loadingEvent: boolean;
  47. onRetry: () => void;
  48. organization: Organization;
  49. project: Project;
  50. event?: Event;
  51. }
  52. type State = {
  53. eventNavLinks: string;
  54. releasesCompletion: any;
  55. };
  56. class GroupEventDetails extends Component<GroupEventDetailsProps, State> {
  57. state: State = {
  58. eventNavLinks: '',
  59. releasesCompletion: null,
  60. };
  61. componentDidMount() {
  62. this.fetchData();
  63. }
  64. componentDidUpdate(prevProps: GroupEventDetailsProps) {
  65. const {environments, params, location, organization, project} = this.props;
  66. const environmentsHaveChanged = !isEqual(prevProps.environments, environments);
  67. // If environments are being actively changed and will no longer contain the
  68. // current event's environment, redirect to latest
  69. if (
  70. environmentsHaveChanged &&
  71. prevProps.event &&
  72. params.eventId &&
  73. !['latest', 'oldest'].includes(params.eventId)
  74. ) {
  75. const shouldRedirect =
  76. environments.length > 0 &&
  77. !environments.find(
  78. env => env.name === getEventEnvironment(prevProps.event as Event)
  79. );
  80. if (shouldRedirect) {
  81. browserHistory.replace(
  82. normalizeUrl({
  83. pathname: `/organizations/${organization.slug}/issues/${params.groupId}/`,
  84. query: location.query,
  85. })
  86. );
  87. return;
  88. }
  89. }
  90. if (
  91. prevProps.organization.slug !== organization.slug ||
  92. prevProps.project.slug !== project.slug
  93. ) {
  94. this.fetchData();
  95. }
  96. }
  97. componentWillUnmount() {
  98. this.props.api.clear();
  99. }
  100. fetchData = async () => {
  101. const {api, project, organization} = this.props;
  102. const orgSlug = organization.slug;
  103. const projSlug = project.slug;
  104. const projectId = project.id;
  105. /**
  106. * Perform below requests in parallel
  107. */
  108. const releasesCompletionPromise = api.requestPromise(
  109. `/projects/${orgSlug}/${projSlug}/releases/completion/`
  110. );
  111. fetchSentryAppInstallations(api, orgSlug);
  112. // TODO(marcos): Sometimes PageFiltersStore cannot pick a project.
  113. if (projectId) {
  114. fetchSentryAppComponents(api, orgSlug, projectId);
  115. } else {
  116. Sentry.withScope(scope => {
  117. scope.setExtra('props', this.props);
  118. scope.setExtra('state', this.state);
  119. Sentry.captureMessage('Project ID was not set');
  120. });
  121. }
  122. const releasesCompletion = await releasesCompletionPromise;
  123. this.setState({releasesCompletion});
  124. };
  125. renderContent(eventWithMeta?: Event) {
  126. const {group, project, environments, loadingEvent, onRetry, eventError} = this.props;
  127. if (loadingEvent) {
  128. return <LoadingIndicator />;
  129. }
  130. if (eventError) {
  131. return (
  132. <GroupEventDetailsLoadingError environments={environments} onRetry={onRetry} />
  133. );
  134. }
  135. return (
  136. <GroupEventDetailsContent group={group} event={eventWithMeta} project={project} />
  137. );
  138. }
  139. renderReprocessedBox(
  140. reprocessStatus: ReprocessingStatus,
  141. mostRecentActivity: GroupActivityReprocess
  142. ) {
  143. if (
  144. reprocessStatus !== ReprocessingStatus.REPROCESSED_AND_HASNT_EVENT &&
  145. reprocessStatus !== ReprocessingStatus.REPROCESSED_AND_HAS_EVENT
  146. ) {
  147. return null;
  148. }
  149. const {group, organization} = this.props;
  150. const {count, id: groupId} = group;
  151. const groupCount = Number(count);
  152. return (
  153. <ReprocessedBox
  154. reprocessActivity={mostRecentActivity}
  155. groupCount={groupCount}
  156. groupId={groupId}
  157. orgSlug={organization.slug}
  158. />
  159. );
  160. }
  161. renderGroupStatusBanner() {
  162. if (this.props.group.status === 'ignored') {
  163. return (
  164. <GroupStatusBannerWrapper>
  165. <MutedBox statusDetails={this.props.group.statusDetails} />
  166. </GroupStatusBannerWrapper>
  167. );
  168. }
  169. if (this.props.group.status === 'resolved') {
  170. return (
  171. <GroupStatusBannerWrapper>
  172. <ResolutionBox
  173. statusDetails={this.props.group.statusDetails}
  174. activities={this.props.group.activity}
  175. projectId={this.props.project.id}
  176. />
  177. </GroupStatusBannerWrapper>
  178. );
  179. }
  180. return null;
  181. }
  182. render() {
  183. const {
  184. group,
  185. project,
  186. organization,
  187. environments,
  188. location,
  189. event,
  190. groupReprocessingStatus,
  191. } = this.props;
  192. const eventWithMeta = withMeta(event);
  193. // Reprocessing
  194. const hasReprocessingV2Feature = organization.features?.includes('reprocessing-v2');
  195. const {activity: activities} = group;
  196. const mostRecentActivity = getGroupMostRecentActivity(activities);
  197. const hasReplay = Boolean(event?.tags?.find(({key}) => key === 'replayId')?.value);
  198. return (
  199. <TransactionProfileIdProvider
  200. projectId={event?.projectID}
  201. transactionId={event?.type === 'transaction' ? event.id : undefined}
  202. timestamp={event?.dateReceived}
  203. >
  204. <StyledLayoutBody data-test-id="group-event-details">
  205. {hasReprocessingV2Feature &&
  206. groupReprocessingStatus === ReprocessingStatus.REPROCESSING ? (
  207. <ReprocessingProgress
  208. totalEvents={(mostRecentActivity as GroupActivityReprocess).data.eventCount}
  209. pendingEvents={
  210. (group.statusDetails as BaseGroupStatusReprocessing['statusDetails'])
  211. .pendingEvents
  212. }
  213. />
  214. ) : (
  215. <Fragment>
  216. <QuickTraceQuery
  217. event={eventWithMeta}
  218. location={location}
  219. orgSlug={organization.slug}
  220. >
  221. {results => {
  222. return (
  223. <StyledLayoutMain>
  224. {this.renderGroupStatusBanner()}
  225. <QuickTraceContext.Provider value={results}>
  226. {eventWithMeta && (
  227. <GroupEventToolbar
  228. group={group}
  229. event={eventWithMeta}
  230. organization={organization}
  231. location={location}
  232. project={project}
  233. hasReplay={hasReplay}
  234. />
  235. )}
  236. {this.renderReprocessedBox(
  237. groupReprocessingStatus,
  238. mostRecentActivity as GroupActivityReprocess
  239. )}
  240. {this.renderContent(eventWithMeta)}
  241. </QuickTraceContext.Provider>
  242. </StyledLayoutMain>
  243. );
  244. }}
  245. </QuickTraceQuery>
  246. <StyledLayoutSide>
  247. <GroupSidebar
  248. organization={organization}
  249. project={project}
  250. group={group}
  251. event={eventWithMeta}
  252. environments={environments}
  253. />
  254. </StyledLayoutSide>
  255. </Fragment>
  256. )}
  257. </StyledLayoutBody>
  258. </TransactionProfileIdProvider>
  259. );
  260. }
  261. }
  262. const StyledLayoutBody = styled(Layout.Body)`
  263. /* Makes the borders align correctly */
  264. padding: 0 !important;
  265. @media (min-width: ${p => p.theme.breakpoints.large}) {
  266. align-content: stretch;
  267. }
  268. `;
  269. const GroupStatusBannerWrapper = styled('div')`
  270. margin-bottom: ${space(2)};
  271. `;
  272. const StyledLayoutMain = styled(Layout.Main)`
  273. padding-top: ${space(2)};
  274. @media (max-width: ${p => p.theme.breakpoints.medium}) {
  275. padding-top: ${space(1)};
  276. }
  277. @media (min-width: ${p => p.theme.breakpoints.large}) {
  278. border-right: 1px solid ${p => p.theme.border};
  279. padding-right: 0;
  280. }
  281. `;
  282. const StyledLayoutSide = styled(Layout.Side)`
  283. padding: ${space(3)} ${space(2)} ${space(3)};
  284. @media (min-width: ${p => p.theme.breakpoints.large}) {
  285. padding-right: ${space(4)};
  286. padding-left: 0;
  287. }
  288. `;
  289. export default GroupEventDetails;