groupDetails.tsx 23 KB

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