groupEventDetails.tsx 8.8 KB

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