groupDetails.tsx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  1. import {
  2. cloneElement,
  3. Fragment,
  4. isValidElement,
  5. useCallback,
  6. useEffect,
  7. useRef,
  8. useState,
  9. } from 'react';
  10. import {browserHistory, RouteComponentProps} from 'react-router';
  11. import styled from '@emotion/styled';
  12. import * as Sentry from '@sentry/react';
  13. import omit from 'lodash/omit';
  14. import pick from 'lodash/pick';
  15. import * as qs from 'query-string';
  16. import LoadingError from 'sentry/components/loadingError';
  17. import LoadingIndicator from 'sentry/components/loadingIndicator';
  18. import PageFiltersContainer from 'sentry/components/organizations/pageFilters/container';
  19. import MissingProjectMembership from 'sentry/components/projects/missingProjectMembership';
  20. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  21. import {TabPanels, Tabs} from 'sentry/components/tabs';
  22. import {t} from 'sentry/locale';
  23. import GroupStore from 'sentry/stores/groupStore';
  24. import {space} from 'sentry/styles/space';
  25. import {Group, GroupStatus, IssueCategory, Organization, Project} from 'sentry/types';
  26. import {Event} from 'sentry/types/event';
  27. import {defined} from 'sentry/utils';
  28. import {trackAnalytics} from 'sentry/utils/analytics';
  29. import {getUtcDateString} from 'sentry/utils/dates';
  30. import {
  31. getAnalyticsDataForEvent,
  32. getAnalyticsDataForGroup,
  33. getMessage,
  34. getTitle,
  35. } from 'sentry/utils/events';
  36. import {getAnalyicsDataForProject} from 'sentry/utils/projects';
  37. import {
  38. ApiQueryKey,
  39. setApiQueryData,
  40. useApiQuery,
  41. useQueryClient,
  42. } from 'sentry/utils/queryClient';
  43. import recreateRoute from 'sentry/utils/recreateRoute';
  44. import RequestError from 'sentry/utils/requestError/requestError';
  45. import useDisableRouteAnalytics from 'sentry/utils/routeAnalytics/useDisableRouteAnalytics';
  46. import useRouteAnalyticsEventNames from 'sentry/utils/routeAnalytics/useRouteAnalyticsEventNames';
  47. import useRouteAnalyticsParams from 'sentry/utils/routeAnalytics/useRouteAnalyticsParams';
  48. import useApi from 'sentry/utils/useApi';
  49. import {useLocation} from 'sentry/utils/useLocation';
  50. import useOrganization from 'sentry/utils/useOrganization';
  51. import useProjects from 'sentry/utils/useProjects';
  52. import useRouter from 'sentry/utils/useRouter';
  53. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  54. import {ERROR_TYPES} from './constants';
  55. import GroupHeader from './header';
  56. import SampleEventAlert from './sampleEventAlert';
  57. import {Tab, TabPaths} from './types';
  58. import {
  59. getGroupDetailsQueryData,
  60. getGroupEventDetailsQueryData,
  61. getGroupReprocessingStatus,
  62. markEventSeen,
  63. ReprocessingStatus,
  64. useDefaultIssueEvent,
  65. useEnvironmentsFromUrl,
  66. useFetchIssueTagsForDetailsPage,
  67. } from './utils';
  68. type Error = (typeof ERROR_TYPES)[keyof typeof ERROR_TYPES] | null;
  69. type RouterParams = {groupId: string; eventId?: string};
  70. type RouteProps = RouteComponentProps<RouterParams, {}>;
  71. type GroupDetailsProps = {
  72. children: React.ReactNode;
  73. organization: Organization;
  74. projects: Project[];
  75. };
  76. type FetchGroupDetailsState = {
  77. error: boolean;
  78. errorType: Error;
  79. event: Event | null;
  80. eventError: boolean;
  81. group: Group | null;
  82. loadingEvent: boolean;
  83. loadingGroup: boolean;
  84. refetchData: () => void;
  85. refetchGroup: () => void;
  86. };
  87. interface GroupDetailsContentProps extends GroupDetailsProps, FetchGroupDetailsState {
  88. group: Group;
  89. project: Project;
  90. }
  91. function getFetchDataRequestErrorType(status?: number | null): Error {
  92. if (!status) {
  93. return null;
  94. }
  95. if (status === 404) {
  96. return ERROR_TYPES.GROUP_NOT_FOUND;
  97. }
  98. if (status === 403) {
  99. return ERROR_TYPES.MISSING_MEMBERSHIP;
  100. }
  101. return null;
  102. }
  103. function getCurrentTab({router}: {router: RouteProps['router']}) {
  104. const currentRoute = router.routes[router.routes.length - 1];
  105. // If we're in the tag details page ("/tags/:tagKey/")
  106. if (router.params.tagKey) {
  107. return Tab.TAGS;
  108. }
  109. return (
  110. Object.values(Tab).find(tab => currentRoute.path === TabPaths[tab]) ?? Tab.DETAILS
  111. );
  112. }
  113. function getCurrentRouteInfo({
  114. group,
  115. event,
  116. organization,
  117. router,
  118. }: {
  119. event: Event | null;
  120. group: Group;
  121. organization: Organization;
  122. router: RouteProps['router'];
  123. }): {
  124. baseUrl: string;
  125. currentTab: Tab;
  126. } {
  127. const currentTab = getCurrentTab({router});
  128. const baseUrl = normalizeUrl(
  129. `/organizations/${organization.slug}/issues/${group.id}/${
  130. router.params.eventId && event ? `events/${event.id}/` : ''
  131. }`
  132. );
  133. return {baseUrl, currentTab};
  134. }
  135. function getReprocessingNewRoute({
  136. group,
  137. event,
  138. organization,
  139. router,
  140. }: {
  141. event: Event | null;
  142. group: Group;
  143. organization: Organization;
  144. router: RouteProps['router'];
  145. }) {
  146. const {routes, params, location} = router;
  147. const {groupId} = params;
  148. const {currentTab, baseUrl} = getCurrentRouteInfo({group, event, organization, router});
  149. const hasReprocessingV2Feature = organization.features?.includes('reprocessing-v2');
  150. const {id: nextGroupId} = group;
  151. const reprocessingStatus = getGroupReprocessingStatus(group);
  152. if (groupId !== nextGroupId) {
  153. if (hasReprocessingV2Feature) {
  154. // Redirects to the Activities tab
  155. if (
  156. reprocessingStatus === ReprocessingStatus.REPROCESSED_AND_HASNT_EVENT &&
  157. currentTab !== Tab.ACTIVITY
  158. ) {
  159. return {
  160. pathname: `${baseUrl}${Tab.ACTIVITY}/`,
  161. query: {...params, groupId: nextGroupId},
  162. };
  163. }
  164. }
  165. return recreateRoute('', {
  166. routes,
  167. location,
  168. params: {...params, groupId: nextGroupId},
  169. });
  170. }
  171. if (hasReprocessingV2Feature) {
  172. if (
  173. reprocessingStatus === ReprocessingStatus.REPROCESSING &&
  174. currentTab !== Tab.DETAILS
  175. ) {
  176. return {
  177. pathname: baseUrl,
  178. query: params,
  179. };
  180. }
  181. if (
  182. reprocessingStatus === ReprocessingStatus.REPROCESSED_AND_HASNT_EVENT &&
  183. currentTab !== Tab.ACTIVITY &&
  184. currentTab !== Tab.USER_FEEDBACK
  185. ) {
  186. return {
  187. pathname: `${baseUrl}${Tab.ACTIVITY}/`,
  188. query: params,
  189. };
  190. }
  191. }
  192. return undefined;
  193. }
  194. function useRefetchGroupForReprocessing({
  195. refetchGroup,
  196. }: Pick<FetchGroupDetailsState, 'refetchGroup'>) {
  197. const organization = useOrganization();
  198. const hasReprocessingV2Feature = organization.features?.includes('reprocessing-v2');
  199. useEffect(() => {
  200. let refetchInterval: number;
  201. if (hasReprocessingV2Feature) {
  202. refetchInterval = window.setInterval(refetchGroup, 30000);
  203. }
  204. return () => {
  205. window.clearInterval(refetchInterval);
  206. };
  207. }, [hasReprocessingV2Feature, refetchGroup]);
  208. }
  209. function useEventApiQuery({
  210. groupId,
  211. eventId,
  212. environments,
  213. }: {
  214. environments: string[];
  215. groupId: string;
  216. eventId?: string;
  217. }) {
  218. const organization = useOrganization();
  219. const location = useLocation<{query?: string}>();
  220. const router = useRouter();
  221. const hasMostHelpfulEventFeature = organization.features.includes(
  222. 'issue-details-most-helpful-event'
  223. );
  224. const defaultIssueEvent = useDefaultIssueEvent();
  225. const eventIdUrl =
  226. eventId ?? (hasMostHelpfulEventFeature ? defaultIssueEvent : 'latest');
  227. const helpfulEventQuery =
  228. hasMostHelpfulEventFeature && typeof location.query.query === 'string'
  229. ? location.query.query
  230. : undefined;
  231. const endpointEventId = eventIdUrl === 'recommended' ? 'helpful' : eventIdUrl;
  232. const queryKey: ApiQueryKey = [
  233. `/issues/${groupId}/events/${endpointEventId}/`,
  234. {
  235. query: getGroupEventDetailsQueryData({
  236. environments,
  237. query: helpfulEventQuery,
  238. }),
  239. },
  240. ];
  241. const tab = getCurrentTab({router});
  242. const isOnDetailsTab = tab === Tab.DETAILS;
  243. const isLatestOrHelpfulEvent = eventIdUrl === 'latest' || eventIdUrl === 'recommended';
  244. const latestOrHelpfulEvent = useApiQuery<Event>(queryKey, {
  245. // Latest/helpful event will change over time, so only cache for 30 seconds
  246. staleTime: 30000,
  247. cacheTime: 30000,
  248. enabled: isOnDetailsTab && isLatestOrHelpfulEvent,
  249. retry: false,
  250. });
  251. const otherEventQuery = useApiQuery<Event>(queryKey, {
  252. // Oldest/specific events will never change
  253. staleTime: Infinity,
  254. enabled: isOnDetailsTab && !isLatestOrHelpfulEvent,
  255. retry: false,
  256. });
  257. useEffect(() => {
  258. if (latestOrHelpfulEvent.isError) {
  259. // If we get an error from the helpful event endpoint, it probably means
  260. // the query failed validation. We should remove the query to try again.
  261. if (hasMostHelpfulEventFeature) {
  262. browserHistory.replace({
  263. ...window.location,
  264. query: omit(qs.parse(window.location.search), 'query'),
  265. });
  266. const scope = new Sentry.Scope();
  267. scope.setExtras({
  268. groupId,
  269. query: helpfulEventQuery,
  270. ...pick(latestOrHelpfulEvent.error, ['message', 'status', 'responseJSON']),
  271. });
  272. scope.setFingerprint(['issue-details-helpful-event-request-failed']);
  273. Sentry.captureException(
  274. new Error('Issue Details: Helpful event request failed'),
  275. scope
  276. );
  277. }
  278. }
  279. }, [
  280. latestOrHelpfulEvent.isError,
  281. latestOrHelpfulEvent.error,
  282. hasMostHelpfulEventFeature,
  283. groupId,
  284. helpfulEventQuery,
  285. ]);
  286. return isLatestOrHelpfulEvent ? latestOrHelpfulEvent : otherEventQuery;
  287. }
  288. type FetchGroupQueryParameters = {
  289. environments: string[];
  290. groupId: string;
  291. };
  292. function makeFetchGroupQueryKey({
  293. groupId,
  294. environments,
  295. }: FetchGroupQueryParameters): ApiQueryKey {
  296. return [`/issues/${groupId}/`, {query: getGroupDetailsQueryData({environments})}];
  297. }
  298. /**
  299. * This is a temporary measure to ensure that the GroupStore and query cache
  300. * are both up to date while we are still using both in the issue details page.
  301. * Once we remove all references to GroupStore in the issue details page we
  302. * should remove this.
  303. */
  304. function useSyncGroupStore(incomingEnvs: string[]) {
  305. const queryClient = useQueryClient();
  306. const environmentsRef = useRef<string[]>(incomingEnvs);
  307. environmentsRef.current = incomingEnvs;
  308. const unlisten = useRef<Function>();
  309. if (unlisten.current === undefined) {
  310. unlisten.current = GroupStore.listen(() => {
  311. const [storeGroup] = GroupStore.getState();
  312. const environments = environmentsRef.current;
  313. if (defined(storeGroup)) {
  314. setApiQueryData(
  315. queryClient,
  316. makeFetchGroupQueryKey({groupId: storeGroup.id, environments}),
  317. storeGroup
  318. );
  319. }
  320. }, undefined);
  321. }
  322. useEffect(() => {
  323. return () => unlisten.current?.();
  324. }, []);
  325. }
  326. function useFetchGroupDetails(): FetchGroupDetailsState {
  327. const api = useApi();
  328. const organization = useOrganization();
  329. const router = useRouter();
  330. const params = router.params;
  331. const [error, setError] = useState<boolean>(false);
  332. const [errorType, setErrorType] = useState<Error | null>(null);
  333. const [event, setEvent] = useState<Event | null>(null);
  334. const [allProjectChanged, setAllProjectChanged] = useState<boolean>(false);
  335. const environments = useEnvironmentsFromUrl();
  336. const groupId = params.groupId;
  337. const {
  338. data: eventData,
  339. isLoading: loadingEvent,
  340. isError,
  341. refetch: refetchEvent,
  342. } = useEventApiQuery({
  343. groupId,
  344. eventId: params.eventId,
  345. environments,
  346. });
  347. const {
  348. data: groupData,
  349. isLoading: loadingGroup,
  350. isError: isGroupError,
  351. error: groupError,
  352. refetch: refetchGroupCall,
  353. } = useApiQuery<Group>(makeFetchGroupQueryKey({groupId, environments}), {
  354. staleTime: 30000,
  355. cacheTime: 30000,
  356. retry: false,
  357. });
  358. const group = groupData ?? null;
  359. useEffect(() => {
  360. if (defined(group)) {
  361. GroupStore.loadInitialData([group]);
  362. }
  363. }, [groupId, group]);
  364. useSyncGroupStore(environments);
  365. useEffect(() => {
  366. if (eventData) {
  367. setEvent(eventData);
  368. }
  369. }, [eventData]);
  370. useEffect(() => {
  371. if (group && event) {
  372. const reprocessingNewRoute = getReprocessingNewRoute({
  373. group,
  374. event,
  375. router,
  376. organization,
  377. });
  378. if (reprocessingNewRoute) {
  379. browserHistory.push(reprocessingNewRoute);
  380. return;
  381. }
  382. }
  383. }, [group, event, router, organization]);
  384. useEffect(() => {
  385. const matchingProjectSlug = group?.project?.slug;
  386. if (!matchingProjectSlug) {
  387. return;
  388. }
  389. if (!group.hasSeen) {
  390. markEventSeen(api, organization.slug, matchingProjectSlug, params.groupId);
  391. }
  392. }, [
  393. api,
  394. group?.hasSeen,
  395. group?.project?.id,
  396. group?.project?.slug,
  397. organization.slug,
  398. params.groupId,
  399. ]);
  400. const allProjectsFlag = router.location.query._allp;
  401. useEffect(() => {
  402. const locationQuery = qs.parse(window.location.search) || {};
  403. // We use _allp as a temporary measure to know they came from the
  404. // issue list page with no project selected (all projects included in
  405. // filter).
  406. //
  407. // If it is not defined, we add the locked project id to the URL
  408. // (this is because if someone navigates directly to an issue on
  409. // single-project priveleges, then goes back - they were getting
  410. // assigned to the first project).
  411. //
  412. // If it is defined, we do not so that our back button will bring us
  413. // to the issue list page with no project selected instead of the
  414. // locked project.
  415. if (
  416. locationQuery.project === undefined &&
  417. !allProjectsFlag &&
  418. !allProjectChanged &&
  419. group?.project.id
  420. ) {
  421. locationQuery.project = group?.project.id;
  422. browserHistory.replace({...window.location, query: locationQuery});
  423. }
  424. if (allProjectsFlag && !allProjectChanged) {
  425. delete locationQuery.project;
  426. // We delete _allp from the URL to keep the hack a bit cleaner, but
  427. // this is not an ideal solution and will ultimately be replaced with
  428. // something smarter.
  429. delete locationQuery._allp;
  430. browserHistory.replace({...window.location, query: locationQuery});
  431. setAllProjectChanged(true);
  432. }
  433. }, [allProjectsFlag, group?.project.id, allProjectChanged]);
  434. const handleError = useCallback((e: RequestError) => {
  435. Sentry.captureException(e);
  436. setErrorType(getFetchDataRequestErrorType(e?.status));
  437. setError(true);
  438. }, []);
  439. useEffect(() => {
  440. if (isGroupError) {
  441. handleError(groupError);
  442. }
  443. }, [isGroupError, groupError, handleError]);
  444. const refetchGroup = useCallback(() => {
  445. if (group?.status !== GroupStatus.REPROCESSING || loadingGroup || loadingEvent) {
  446. return;
  447. }
  448. refetchGroupCall();
  449. }, [group, loadingGroup, loadingEvent, refetchGroupCall]);
  450. const refetchData = useCallback(() => {
  451. // Set initial state
  452. setError(false);
  453. setErrorType(null);
  454. refetchEvent();
  455. refetchGroup();
  456. }, [refetchGroup, refetchEvent]);
  457. // Refetch when group is stale
  458. useEffect(() => {
  459. if (group) {
  460. if ((group as Group & {stale?: boolean}).stale) {
  461. refetchGroup();
  462. return;
  463. }
  464. }
  465. }, [refetchGroup, group]);
  466. useRefetchGroupForReprocessing({refetchGroup});
  467. useEffect(() => {
  468. return () => {
  469. GroupStore.reset();
  470. };
  471. }, []);
  472. return {
  473. loadingGroup,
  474. loadingEvent,
  475. group,
  476. event,
  477. errorType,
  478. error,
  479. eventError: isError,
  480. refetchData,
  481. refetchGroup,
  482. };
  483. }
  484. function useTrackView({
  485. group,
  486. event,
  487. project,
  488. tab,
  489. }: {
  490. event: Event | null;
  491. group: Group | null;
  492. tab: Tab;
  493. project?: Project;
  494. }) {
  495. const location = useLocation();
  496. const {alert_date, alert_rule_id, alert_type, ref_fallback, stream_index, query} =
  497. location.query;
  498. useRouteAnalyticsEventNames('issue_details.viewed', 'Issue Details: Viewed');
  499. useRouteAnalyticsParams({
  500. ...getAnalyticsDataForGroup(group),
  501. ...getAnalyticsDataForEvent(event),
  502. ...getAnalyicsDataForProject(project),
  503. tab,
  504. stream_index: typeof stream_index === 'string' ? Number(stream_index) : undefined,
  505. query: typeof query === 'string' ? query : undefined,
  506. // Alert properties track if the user came from email/slack alerts
  507. alert_date:
  508. typeof alert_date === 'string' ? getUtcDateString(Number(alert_date)) : undefined,
  509. alert_rule_id: typeof alert_rule_id === 'string' ? alert_rule_id : undefined,
  510. alert_type: typeof alert_type === 'string' ? alert_type : undefined,
  511. ref_fallback,
  512. // Will be updated by StacktraceLink if there is a stacktrace link
  513. stacktrace_link_viewed: false,
  514. // Will be updated by IssueQuickTrace if there is a trace
  515. trace_status: 'none',
  516. // Will be updated in GroupDetailsHeader if there are replays
  517. group_has_replay: false,
  518. });
  519. useDisableRouteAnalytics(!group || !event || !project);
  520. }
  521. const trackTabChanged = ({
  522. organization,
  523. project,
  524. group,
  525. event,
  526. tab,
  527. }: {
  528. event: Event | null;
  529. group: Group;
  530. organization: Organization;
  531. project: Project;
  532. tab: Tab;
  533. }) => {
  534. if (!project || !group) {
  535. return;
  536. }
  537. trackAnalytics('issue_details.tab_changed', {
  538. organization,
  539. project_id: parseInt(project.id, 10),
  540. tab,
  541. ...getAnalyticsDataForGroup(group),
  542. });
  543. if (group.issueCategory !== IssueCategory.ERROR) {
  544. return;
  545. }
  546. const analyticsData = event
  547. ? event.tags
  548. .filter(({key}) => ['device', 'os', 'browser'].includes(key))
  549. .reduce((acc, {key, value}) => {
  550. acc[key] = value;
  551. return acc;
  552. }, {})
  553. : {};
  554. trackAnalytics('issue_group_details.tab.clicked', {
  555. organization,
  556. tab,
  557. platform: project.platform,
  558. ...analyticsData,
  559. });
  560. };
  561. function GroupDetailsContentError({
  562. errorType,
  563. onRetry,
  564. }: {
  565. errorType: Error;
  566. onRetry: () => void;
  567. }) {
  568. const organization = useOrganization();
  569. const location = useLocation();
  570. const projectId = location.query.project;
  571. const {projects} = useProjects();
  572. const project = projects.find(proj => proj.id === projectId);
  573. switch (errorType) {
  574. case ERROR_TYPES.GROUP_NOT_FOUND:
  575. return (
  576. <StyledLoadingError
  577. message={t('The issue you were looking for was not found.')}
  578. />
  579. );
  580. case ERROR_TYPES.MISSING_MEMBERSHIP:
  581. return <MissingProjectMembership organization={organization} project={project} />;
  582. default:
  583. return <StyledLoadingError onRetry={onRetry} />;
  584. }
  585. }
  586. function GroupDetailsContent({
  587. children,
  588. group,
  589. project,
  590. loadingEvent,
  591. eventError,
  592. event,
  593. refetchData,
  594. }: GroupDetailsContentProps) {
  595. const organization = useOrganization();
  596. const router = useRouter();
  597. const {currentTab, baseUrl} = getCurrentRouteInfo({group, event, router, organization});
  598. const groupReprocessingStatus = getGroupReprocessingStatus(group);
  599. const environments = useEnvironmentsFromUrl();
  600. useTrackView({group, event, project, tab: currentTab});
  601. useEffect(() => {
  602. if (
  603. currentTab === Tab.DETAILS &&
  604. group &&
  605. event &&
  606. group.id !== event?.groupID &&
  607. !eventError
  608. ) {
  609. // if user pastes only the event id into the url, but it's from another group, redirect to correct group/event
  610. const redirectUrl = `/organizations/${organization.slug}/issues/${event.groupID}/events/${event.id}/`;
  611. router.push(normalizeUrl(redirectUrl));
  612. }
  613. }, [currentTab, event, eventError, group, organization.slug, router]);
  614. const childProps = {
  615. environments,
  616. group,
  617. project,
  618. event,
  619. loadingEvent,
  620. eventError,
  621. groupReprocessingStatus,
  622. onRetry: refetchData,
  623. baseUrl,
  624. };
  625. return (
  626. <Tabs
  627. value={currentTab}
  628. onChange={tab => trackTabChanged({tab, group, project, event, organization})}
  629. >
  630. <GroupHeader
  631. organization={organization}
  632. groupReprocessingStatus={groupReprocessingStatus}
  633. event={event ?? undefined}
  634. group={group}
  635. baseUrl={baseUrl}
  636. project={project as Project}
  637. />
  638. <GroupTabPanels>
  639. <TabPanels.Item key={currentTab}>
  640. {isValidElement(children) ? cloneElement(children, childProps) : children}
  641. </TabPanels.Item>
  642. </GroupTabPanels>
  643. </Tabs>
  644. );
  645. }
  646. function GroupDetailsPageContent(props: GroupDetailsProps & FetchGroupDetailsState) {
  647. const projectSlug = props.group?.project?.slug;
  648. const {
  649. projects,
  650. initiallyLoaded: projectsLoaded,
  651. fetchError: errorFetchingProjects,
  652. } = useProjects({slugs: projectSlug ? [projectSlug] : []});
  653. const project = projects.find(({slug}) => slug === projectSlug);
  654. const projectWithFallback = project ?? projects[0];
  655. useEffect(() => {
  656. if (props.group && projectsLoaded && !project) {
  657. Sentry.withScope(scope => {
  658. const projectIds = projects.map(item => item.id);
  659. scope.setContext('missingProject', {
  660. projectId: props.group?.project.id,
  661. availableProjects: projectIds,
  662. });
  663. scope.setFingerprint(['group-details-project-not-found']);
  664. Sentry.captureException(new Error('Project not found'));
  665. });
  666. }
  667. }, [props.group, project, projects, projectsLoaded]);
  668. if (props.error) {
  669. return (
  670. <GroupDetailsContentError errorType={props.errorType} onRetry={props.refetchData} />
  671. );
  672. }
  673. if (errorFetchingProjects) {
  674. return <StyledLoadingError message={t('Error loading the specified project')} />;
  675. }
  676. if (projectSlug && !errorFetchingProjects && projectsLoaded && !projectWithFallback) {
  677. return (
  678. <StyledLoadingError message={t('The project %s does not exist', projectSlug)} />
  679. );
  680. }
  681. if (!projectsLoaded || !projectWithFallback || !props.group) {
  682. return <LoadingIndicator />;
  683. }
  684. return (
  685. <GroupDetailsContent {...props} project={projectWithFallback} group={props.group} />
  686. );
  687. }
  688. function GroupDetails(props: GroupDetailsProps) {
  689. const organization = useOrganization();
  690. const router = useRouter();
  691. const {group, ...fetchGroupDetailsProps} = useFetchGroupDetails();
  692. const environments = useEnvironmentsFromUrl();
  693. const {data} = useFetchIssueTagsForDetailsPage(
  694. {
  695. groupId: router.params.groupId,
  696. environment: environments,
  697. },
  698. // Don't want this query to take precedence over the main requests
  699. {enabled: defined(group)}
  700. );
  701. const isSampleError = data?.some(tag => tag.key === 'sample_event') ?? false;
  702. const getGroupDetailsTitle = () => {
  703. const defaultTitle = 'Sentry';
  704. if (!group) {
  705. return defaultTitle;
  706. }
  707. const {title} = getTitle(group, organization?.features);
  708. const message = getMessage(group);
  709. const eventDetails = `${organization.slug} — ${group.project.slug}`;
  710. if (title && message) {
  711. return `${title}: ${message} — ${eventDetails}`;
  712. }
  713. return `${title || message || defaultTitle} — ${eventDetails}`;
  714. };
  715. return (
  716. <Fragment>
  717. {isSampleError && group && (
  718. <SampleEventAlert project={group.project} organization={organization} />
  719. )}
  720. <SentryDocumentTitle noSuffix title={getGroupDetailsTitle()}>
  721. <PageFiltersContainer
  722. skipLoadLastUsed
  723. forceProject={group?.project}
  724. shouldForceProject
  725. >
  726. <GroupDetailsPageContent
  727. {...props}
  728. {...{
  729. group,
  730. ...fetchGroupDetailsProps,
  731. }}
  732. />
  733. </PageFiltersContainer>
  734. </SentryDocumentTitle>
  735. </Fragment>
  736. );
  737. }
  738. export default Sentry.withProfiler(GroupDetails);
  739. const StyledLoadingError = styled(LoadingError)`
  740. margin: ${space(2)};
  741. `;
  742. const GroupTabPanels = styled(TabPanels)`
  743. flex-grow: 1;
  744. display: flex;
  745. flex-direction: column;
  746. justify-content: stretch;
  747. `;