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