groupEventDetails.tsx 9.6 KB

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