groupDetails.tsx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. import {cloneElement, Component, Fragment, isValidElement} from 'react';
  2. import {browserHistory, RouteComponentProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import * as Sentry from '@sentry/react';
  5. import * as PropTypes from 'prop-types';
  6. import {fetchOrganizationEnvironments} from 'sentry/actionCreators/environments';
  7. import {Client} from 'sentry/api';
  8. import LoadingError from 'sentry/components/loadingError';
  9. import LoadingIndicator from 'sentry/components/loadingIndicator';
  10. import PageFiltersContainer from 'sentry/components/organizations/pageFilters/container';
  11. import MissingProjectMembership from 'sentry/components/projects/missingProjectMembership';
  12. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  13. import {Item, TabPanels, Tabs} from 'sentry/components/tabs';
  14. import {t} from 'sentry/locale';
  15. import SentryTypes from 'sentry/sentryTypes';
  16. import GroupStore from 'sentry/stores/groupStore';
  17. import space from 'sentry/styles/space';
  18. import {
  19. AvatarProject,
  20. Group,
  21. GroupActivityAssigned,
  22. GroupActivityType,
  23. IssueCategory,
  24. Organization,
  25. Project,
  26. } from 'sentry/types';
  27. import {Event} from 'sentry/types/event';
  28. import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
  29. import {getUtcDateString} from 'sentry/utils/dates';
  30. import {TableData} from 'sentry/utils/discover/discoverQuery';
  31. import EventView from 'sentry/utils/discover/eventView';
  32. import {doDiscoverQuery} from 'sentry/utils/discover/genericDiscoverQuery';
  33. import {getAnalyicsDataForEvent, getMessage, getTitle} from 'sentry/utils/events';
  34. import getDaysSinceDate from 'sentry/utils/getDaysSinceDate';
  35. import Projects from 'sentry/utils/projects';
  36. import recreateRoute from 'sentry/utils/recreateRoute';
  37. import withRouteAnalytics, {
  38. WithRouteAnalyticsProps,
  39. } from 'sentry/utils/routeAnalytics/withRouteAnalytics';
  40. import withApi from 'sentry/utils/withApi';
  41. import {ERROR_TYPES} from './constants';
  42. import GroupHeader from './header';
  43. import SampleEventAlert from './sampleEventAlert';
  44. import {Tab, TabPaths} from './types';
  45. import {
  46. fetchGroupEvent,
  47. getGroupReprocessingStatus,
  48. markEventSeen,
  49. ReprocessingStatus,
  50. } from './utils';
  51. /**
  52. * Return the integration type for the first assignment via integration
  53. */
  54. function getAssignmentIntegration(group: Group) {
  55. if (!group.activity) {
  56. return '';
  57. }
  58. const assignmentAcitivies = group.activity.filter(
  59. activity => activity.type === GroupActivityType.ASSIGNED
  60. ) as GroupActivityAssigned[];
  61. const integrationAssignments = assignmentAcitivies.find(
  62. activity => !!activity.data.integration
  63. );
  64. return integrationAssignments?.data.integration || '';
  65. }
  66. type Error = typeof ERROR_TYPES[keyof typeof ERROR_TYPES] | null;
  67. type Props = {
  68. api: Client;
  69. children: React.ReactNode;
  70. environments: string[];
  71. isGlobalSelectionReady: boolean;
  72. organization: Organization;
  73. projects: Project[];
  74. } & WithRouteAnalyticsProps &
  75. RouteComponentProps<{groupId: string; orgId: string; eventId?: string}, {}>;
  76. type State = {
  77. error: boolean;
  78. errorType: Error;
  79. eventError: boolean;
  80. group: Group | null;
  81. loading: boolean;
  82. loadingEvent: boolean;
  83. loadingGroup: boolean;
  84. loadingReplayIds: boolean;
  85. project: null | (Pick<Project, 'id' | 'slug'> & Partial<Pick<Project, 'platform'>>);
  86. replayIds: null | string[];
  87. event?: Event;
  88. };
  89. class GroupDetails extends Component<Props, State> {
  90. static childContextTypes = {
  91. group: SentryTypes.Group,
  92. location: PropTypes.object,
  93. };
  94. state = this.initialState;
  95. getChildContext() {
  96. return {
  97. group: this.state.group,
  98. location: this.props.location,
  99. };
  100. }
  101. componentDidMount() {
  102. // prevent duplicate analytics
  103. this.props.setDisableRouteAnalytics();
  104. // only track the view if we are loading the event early
  105. this.fetchData(this.canLoadEventEarly(this.props));
  106. if (this.props.organization.features.includes('session-replay-ui')) {
  107. this.fetchReplayIds();
  108. }
  109. this.updateReprocessingProgress();
  110. // Fetch environments early - used in GroupEventDetailsContainer
  111. fetchOrganizationEnvironments(this.props.api, this.props.organization.slug);
  112. }
  113. componentDidUpdate(prevProps: Props, prevState: State) {
  114. const globalSelectionReadyChanged =
  115. prevProps.isGlobalSelectionReady !== this.props.isGlobalSelectionReady;
  116. if (
  117. globalSelectionReadyChanged ||
  118. prevProps.location.pathname !== this.props.location.pathname
  119. ) {
  120. // Skip tracking for other navigation events like switching events
  121. this.fetchData(globalSelectionReadyChanged && this.canLoadEventEarly(this.props));
  122. }
  123. if (
  124. (!this.canLoadEventEarly(prevProps) && !prevState?.group && this.state.group) ||
  125. (prevProps.params?.eventId !== this.props.params?.eventId && this.state.group)
  126. ) {
  127. // if we are loading events we should record analytics after it's loaded
  128. this.getEvent(this.state.group).then(
  129. () => this.state.group?.project && this.trackView(this.state.group?.project)
  130. );
  131. }
  132. }
  133. componentWillUnmount() {
  134. GroupStore.reset();
  135. this.listener?.();
  136. if (this.refetchInterval) {
  137. window.clearInterval(this.refetchInterval);
  138. }
  139. }
  140. refetchInterval: number | null = null;
  141. get initialState(): State {
  142. return {
  143. group: null,
  144. loading: true,
  145. loadingReplayIds: true,
  146. loadingEvent: true,
  147. loadingGroup: true,
  148. error: false,
  149. eventError: false,
  150. errorType: null,
  151. project: null,
  152. replayIds: null,
  153. };
  154. }
  155. trackView(project: Project) {
  156. const {group, event} = this.state;
  157. const {organization, params, location} = this.props;
  158. const {alert_date, alert_rule_id, alert_type} = location.query;
  159. trackAdvancedAnalyticsEvent('issue_details.viewed', {
  160. organization,
  161. project_id: parseInt(project.id, 10),
  162. group_id: parseInt(params.groupId, 10),
  163. // group properties
  164. issue_category: group?.issueCategory ?? IssueCategory.ERROR,
  165. issue_status: group?.status,
  166. issue_age: group?.firstSeen ? getDaysSinceDate(group.firstSeen) : -1,
  167. issue_level: group?.level,
  168. is_assigned: !!group?.assignedTo,
  169. error_count: Number(group?.count || -1),
  170. error_has_replay: Boolean(event?.tags?.find(({key}) => key === 'replayId')),
  171. group_has_replay: Boolean(group?.tags?.find(({key}) => key === 'replayId')),
  172. num_comments: group ? group.numComments : -1,
  173. project_has_replay: group?.project.hasReplays,
  174. project_platform: group?.project.platform,
  175. has_external_issue: group?.annotations ? group?.annotations.length > 0 : false,
  176. has_owner: group?.owners ? group?.owners.length > 0 : false,
  177. integration_assignment_source: group ? getAssignmentIntegration(group) : '',
  178. // event properties
  179. ...getAnalyicsDataForEvent(event),
  180. // Alert properties track if the user came from email/slack alerts
  181. alert_date:
  182. typeof alert_date === 'string' ? getUtcDateString(Number(alert_date)) : undefined,
  183. alert_rule_id: typeof alert_rule_id === 'string' ? alert_rule_id : undefined,
  184. alert_type: typeof alert_type === 'string' ? alert_type : undefined,
  185. });
  186. }
  187. remountComponent = () => {
  188. this.setState(this.initialState);
  189. this.fetchData();
  190. };
  191. canLoadEventEarly(props: Props) {
  192. return !props.params.eventId || ['oldest', 'latest'].includes(props.params.eventId);
  193. }
  194. get groupDetailsEndpoint() {
  195. return `/issues/${this.props.params.groupId}/`;
  196. }
  197. get groupReleaseEndpoint() {
  198. return `/issues/${this.props.params.groupId}/first-last-release/`;
  199. }
  200. async getEvent(group?: Group) {
  201. if (group) {
  202. this.setState({loadingEvent: true, eventError: false});
  203. }
  204. const {params, environments, api} = this.props;
  205. const orgSlug = params.orgId;
  206. const groupId = params.groupId;
  207. const eventId = params.eventId ?? 'latest';
  208. const projectId = group?.project?.slug;
  209. try {
  210. const event = await fetchGroupEvent(
  211. api,
  212. orgSlug,
  213. groupId,
  214. eventId,
  215. environments,
  216. projectId
  217. );
  218. this.setState({event, loading: false, eventError: false, loadingEvent: false});
  219. } catch (err) {
  220. // This is an expected error, capture to Sentry so that it is not considered as an unhandled error
  221. Sentry.captureException(err);
  222. this.setState({eventError: true, loading: false, loadingEvent: false});
  223. }
  224. }
  225. getCurrentRouteInfo(group: Group): {baseUrl: string; currentTab: Tab} {
  226. const {organization, router, routes} = this.props;
  227. const {event} = this.state;
  228. const currentRoute = routes[routes.length - 1];
  229. let currentTab: Tab;
  230. // If we're in the tag details page ("/tags/:tagKey/")
  231. if (router.params.tagKey) {
  232. currentTab = Tab.TAGS;
  233. } else {
  234. currentTab =
  235. Object.values(Tab).find(tab => currentRoute.path === TabPaths[tab]) ??
  236. Tab.DETAILS;
  237. }
  238. const baseUrl = `/organizations/${organization.slug}/issues/${group.id}/${
  239. router.params.eventId && event ? `events/${event.id}/` : ''
  240. }`;
  241. return {baseUrl, currentTab};
  242. }
  243. updateReprocessingProgress() {
  244. const hasReprocessingV2Feature = this.hasReprocessingV2Feature();
  245. if (!hasReprocessingV2Feature) {
  246. return;
  247. }
  248. if (this.refetchInterval) {
  249. window.clearInterval(this.refetchInterval);
  250. }
  251. this.refetchInterval = window.setInterval(this.refetchGroup, 30000);
  252. }
  253. hasReprocessingV2Feature() {
  254. const {organization} = this.props;
  255. return organization.features?.includes('reprocessing-v2');
  256. }
  257. getReprocessingNewRoute(data: Group) {
  258. const {routes, location, params} = this.props;
  259. const {groupId} = params;
  260. const {id: nextGroupId} = data;
  261. const hasReprocessingV2Feature = this.hasReprocessingV2Feature();
  262. const reprocessingStatus = getGroupReprocessingStatus(data);
  263. const {currentTab, baseUrl} = this.getCurrentRouteInfo(data);
  264. if (groupId !== nextGroupId) {
  265. if (hasReprocessingV2Feature) {
  266. // Redirects to the Activities tab
  267. if (
  268. reprocessingStatus === ReprocessingStatus.REPROCESSED_AND_HASNT_EVENT &&
  269. currentTab !== Tab.ACTIVITY
  270. ) {
  271. return {
  272. pathname: `${baseUrl}${Tab.ACTIVITY}/`,
  273. query: {...params, groupId: nextGroupId},
  274. };
  275. }
  276. }
  277. return recreateRoute('', {
  278. routes,
  279. location,
  280. params: {...params, groupId: nextGroupId},
  281. });
  282. }
  283. if (hasReprocessingV2Feature) {
  284. if (
  285. reprocessingStatus === ReprocessingStatus.REPROCESSING &&
  286. currentTab !== Tab.DETAILS
  287. ) {
  288. return {
  289. pathname: baseUrl,
  290. query: params,
  291. };
  292. }
  293. if (
  294. reprocessingStatus === ReprocessingStatus.REPROCESSED_AND_HASNT_EVENT &&
  295. currentTab !== Tab.ACTIVITY &&
  296. currentTab !== Tab.USER_FEEDBACK
  297. ) {
  298. return {
  299. pathname: `${baseUrl}${Tab.ACTIVITY}/`,
  300. query: params,
  301. };
  302. }
  303. }
  304. return undefined;
  305. }
  306. getGroupQuery(): Record<string, string | string[]> {
  307. const {environments} = this.props;
  308. // Note, we do not want to include the environment key at all if there are no environments
  309. const query: Record<string, string | string[]> = {
  310. ...(environments ? {environment: environments} : {}),
  311. expand: ['inbox', 'owners'],
  312. collapse: 'release',
  313. };
  314. return query;
  315. }
  316. getFetchDataRequestErrorType(status: any): Error {
  317. if (!status) {
  318. return null;
  319. }
  320. if (status === 404) {
  321. return ERROR_TYPES.GROUP_NOT_FOUND;
  322. }
  323. if (status === 403) {
  324. return ERROR_TYPES.MISSING_MEMBERSHIP;
  325. }
  326. return null;
  327. }
  328. handleRequestError(error: any) {
  329. Sentry.captureException(error);
  330. const errorType = this.getFetchDataRequestErrorType(error?.status);
  331. this.setState({
  332. loadingGroup: false,
  333. loading: false,
  334. error: true,
  335. errorType,
  336. });
  337. }
  338. refetchGroup = async () => {
  339. const {loadingGroup, loading, loadingEvent, group} = this.state;
  340. if (
  341. group?.status !== ReprocessingStatus.REPROCESSING ||
  342. loadingGroup ||
  343. loading ||
  344. loadingEvent
  345. ) {
  346. return;
  347. }
  348. const {api} = this.props;
  349. this.setState({loadingGroup: true});
  350. try {
  351. const updatedGroup = await api.requestPromise(this.groupDetailsEndpoint, {
  352. query: this.getGroupQuery(),
  353. });
  354. const reprocessingNewRoute = this.getReprocessingNewRoute(updatedGroup);
  355. if (reprocessingNewRoute) {
  356. browserHistory.push(reprocessingNewRoute);
  357. return;
  358. }
  359. this.setState({group: updatedGroup, loadingGroup: false});
  360. } catch (error) {
  361. this.handleRequestError(error);
  362. }
  363. };
  364. async fetchGroupReleases() {
  365. const {api} = this.props;
  366. const releases = await api.requestPromise(this.groupReleaseEndpoint);
  367. GroupStore.onPopulateReleases(this.props.params.groupId, releases);
  368. }
  369. async fetchReplayIds() {
  370. const {api, location, organization, params} = this.props;
  371. const {groupId} = params;
  372. this.setState({loadingReplayIds: true});
  373. const eventView = EventView.fromNewQueryWithLocation(
  374. {
  375. id: '',
  376. name: `Errors within replay`,
  377. version: 2,
  378. fields: ['replayId', 'count()'],
  379. query: `issue.id:${groupId} !replayId:""`,
  380. projects: [],
  381. },
  382. location
  383. );
  384. try {
  385. const [data] = await doDiscoverQuery<TableData>(
  386. api,
  387. `/organizations/${organization.slug}/events/`,
  388. eventView.getEventsAPIPayload(location)
  389. );
  390. const replayIds = data.data.map(record => String(record.replayId));
  391. this.setState({
  392. replayIds,
  393. loadingReplayIds: false,
  394. });
  395. } catch (err) {
  396. this.setState({loadingReplayIds: false});
  397. }
  398. }
  399. async fetchData(trackView = false) {
  400. const {api, isGlobalSelectionReady, params} = this.props;
  401. // Need to wait for global selection store to be ready before making request
  402. if (!isGlobalSelectionReady) {
  403. return;
  404. }
  405. try {
  406. const eventPromise = this.canLoadEventEarly(this.props)
  407. ? this.getEvent()
  408. : undefined;
  409. const groupPromise = await api.requestPromise(this.groupDetailsEndpoint, {
  410. query: this.getGroupQuery(),
  411. });
  412. const [data] = await Promise.all([groupPromise, eventPromise]);
  413. const groupReleasePromise = this.fetchGroupReleases();
  414. const reprocessingNewRoute = this.getReprocessingNewRoute(data);
  415. if (reprocessingNewRoute) {
  416. browserHistory.push(reprocessingNewRoute);
  417. return;
  418. }
  419. const project = data.project;
  420. markEventSeen(api, params.orgId, project.slug, params.groupId);
  421. if (!project) {
  422. Sentry.withScope(() => {
  423. Sentry.captureException(new Error('Project not found'));
  424. });
  425. } else {
  426. const locationWithProject = {...this.props.location};
  427. if (
  428. locationWithProject.query.project === undefined &&
  429. locationWithProject.query._allp === undefined
  430. ) {
  431. // We use _allp as a temporary measure to know they came from the
  432. // issue list page with no project selected (all projects included in
  433. // filter).
  434. //
  435. // If it is not defined, we add the locked project id to the URL
  436. // (this is because if someone navigates directly to an issue on
  437. // single-project priveleges, then goes back - they were getting
  438. // assigned to the first project).
  439. //
  440. // If it is defined, we do not so that our back button will bring us
  441. // to the issue list page with no project selected instead of the
  442. // locked project.
  443. locationWithProject.query = {...locationWithProject.query, project: project.id};
  444. }
  445. // We delete _allp from the URL to keep the hack a bit cleaner, but
  446. // this is not an ideal solution and will ultimately be replaced with
  447. // something smarter.
  448. delete locationWithProject.query._allp;
  449. browserHistory.replace(locationWithProject);
  450. }
  451. this.setState({project, loadingGroup: false});
  452. GroupStore.loadInitialData([data]);
  453. if (trackView) {
  454. // make sure releases have loaded before we track the view
  455. groupReleasePromise.then(() => this.trackView(project));
  456. }
  457. } catch (error) {
  458. this.handleRequestError(error);
  459. }
  460. }
  461. listener = GroupStore.listen(itemIds => this.onGroupChange(itemIds), undefined);
  462. onGroupChange(itemIds: Set<string>) {
  463. const id = this.props.params.groupId;
  464. if (itemIds.has(id)) {
  465. const group = GroupStore.get(id) as Group;
  466. if (group) {
  467. // TODO(ts) This needs a better approach. issueActions is splicing attributes onto
  468. // group objects to cheat here.
  469. if ((group as Group & {stale?: boolean}).stale) {
  470. this.fetchData();
  471. return;
  472. }
  473. this.setState({
  474. group,
  475. });
  476. }
  477. }
  478. }
  479. getTitle() {
  480. const {organization} = this.props;
  481. const {group} = this.state;
  482. const defaultTitle = 'Sentry';
  483. if (!group) {
  484. return defaultTitle;
  485. }
  486. const {title} = getTitle(group, organization?.features);
  487. const message = getMessage(group);
  488. const {project} = group;
  489. const eventDetails = `${organization.slug} - ${project.slug}`;
  490. if (title && message) {
  491. return `${title}: ${message} - ${eventDetails}`;
  492. }
  493. return `${title || message || defaultTitle} - ${eventDetails}`;
  494. }
  495. tabClickAnalyticsEvent(tab: Tab) {
  496. const {organization} = this.props;
  497. const {project, group, event} = this.state;
  498. if (!project || !group) {
  499. return;
  500. }
  501. trackAdvancedAnalyticsEvent('issue_details.tab_changed', {
  502. organization,
  503. group_id: parseInt(group.id, 10),
  504. issue_category: group.issueCategory,
  505. project_id: parseInt(project.id, 10),
  506. tab,
  507. });
  508. if (group.issueCategory !== IssueCategory.ERROR) {
  509. return;
  510. }
  511. const analyticsData = event
  512. ? event.tags
  513. .filter(({key}) => ['device', 'os', 'browser'].includes(key))
  514. .reduce((acc, {key, value}) => {
  515. acc[key] = value;
  516. return acc;
  517. }, {})
  518. : {};
  519. trackAdvancedAnalyticsEvent('issue_group_details.tab.clicked', {
  520. organization,
  521. tab,
  522. platform: project.platform,
  523. ...analyticsData,
  524. });
  525. }
  526. renderError() {
  527. const {projects, location} = this.props;
  528. const projectId = location.query.project;
  529. const project = projects.find(proj => proj.id === projectId);
  530. switch (this.state.errorType) {
  531. case ERROR_TYPES.GROUP_NOT_FOUND:
  532. return (
  533. <StyledLoadingError
  534. message={t('The issue you were looking for was not found.')}
  535. />
  536. );
  537. case ERROR_TYPES.MISSING_MEMBERSHIP:
  538. return (
  539. <MissingProjectMembership
  540. organization={this.props.organization}
  541. project={project}
  542. />
  543. );
  544. default:
  545. return <StyledLoadingError onRetry={this.remountComponent} />;
  546. }
  547. }
  548. renderContent(project: AvatarProject, group: Group) {
  549. const {children, environments, organization, router} = this.props;
  550. const {loadingEvent, eventError, event, replayIds} = this.state;
  551. const {currentTab, baseUrl} = this.getCurrentRouteInfo(group);
  552. const groupReprocessingStatus = getGroupReprocessingStatus(group);
  553. let childProps: Record<string, any> = {
  554. environments,
  555. group,
  556. project,
  557. };
  558. if (currentTab === Tab.DETAILS) {
  559. if (group.id !== event?.groupID && !eventError) {
  560. // if user pastes only the event id into the url, but it's from another group, redirect to correct group/event
  561. const redirectUrl = `/organizations/${organization.slug}/issues/${event?.groupID}/events/${event?.id}/`;
  562. router.push(redirectUrl);
  563. } else {
  564. childProps = {
  565. ...childProps,
  566. event,
  567. loadingEvent,
  568. eventError,
  569. groupReprocessingStatus,
  570. onRetry: () => this.remountComponent(),
  571. };
  572. }
  573. }
  574. if (currentTab === Tab.TAGS) {
  575. childProps = {...childProps, event, baseUrl};
  576. } else if (currentTab === Tab.REPLAYS) {
  577. childProps = {...childProps, replayIds};
  578. }
  579. return (
  580. <Tabs value={currentTab} onChange={tab => this.tabClickAnalyticsEvent(tab)}>
  581. <GroupHeader
  582. organization={organization}
  583. groupReprocessingStatus={groupReprocessingStatus}
  584. event={event}
  585. group={group}
  586. replaysCount={replayIds?.length}
  587. baseUrl={baseUrl}
  588. project={project as Project}
  589. />
  590. <GroupTabPanels>
  591. <Item key={currentTab}>
  592. {isValidElement(children) ? cloneElement(children, childProps) : children}
  593. </Item>
  594. </GroupTabPanels>
  595. </Tabs>
  596. );
  597. }
  598. renderPageContent() {
  599. const {error: isError, group, project, loading} = this.state;
  600. const isLoading = loading || (!group && !isError);
  601. if (isLoading) {
  602. return <LoadingIndicator />;
  603. }
  604. if (isError) {
  605. return this.renderError();
  606. }
  607. const {organization} = this.props;
  608. return (
  609. <Projects
  610. orgId={organization.slug}
  611. slugs={[project?.slug ?? '']}
  612. data-test-id="group-projects-container"
  613. >
  614. {({projects, initiallyLoaded, fetchError}) =>
  615. initiallyLoaded ? (
  616. fetchError ? (
  617. <StyledLoadingError message={t('Error loading the specified project')} />
  618. ) : (
  619. // TODO(ts): Update renderContent function to deal with empty group
  620. this.renderContent(projects[0], group!)
  621. )
  622. ) : (
  623. <LoadingIndicator />
  624. )
  625. }
  626. </Projects>
  627. );
  628. }
  629. render() {
  630. const {project, group} = this.state;
  631. const {organization} = this.props;
  632. const isSampleError = group?.tags?.some(tag => tag.key === 'sample_event');
  633. return (
  634. <Fragment>
  635. {isSampleError && project && (
  636. <SampleEventAlert project={project} organization={organization} />
  637. )}
  638. <SentryDocumentTitle noSuffix title={this.getTitle()}>
  639. <PageFiltersContainer
  640. skipLoadLastUsed
  641. forceProject={project}
  642. shouldForceProject
  643. >
  644. {this.renderPageContent()}
  645. </PageFiltersContainer>
  646. </SentryDocumentTitle>
  647. </Fragment>
  648. );
  649. }
  650. }
  651. export default withRouteAnalytics(withApi(Sentry.withProfiler(GroupDetails)));
  652. const StyledLoadingError = styled(LoadingError)`
  653. margin: ${space(2)};
  654. `;
  655. const GroupTabPanels = styled(TabPanels)`
  656. flex-grow: 1;
  657. display: flex;
  658. flex-direction: column;
  659. justify-content: stretch;
  660. `;