groupDetails.tsx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  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 defaultIssueEvent = useDefaultIssueEvent();
  223. const eventIdUrl = eventId ?? defaultIssueEvent;
  224. const helpfulEventQuery =
  225. typeof location.query.query === 'string' ? location.query.query : undefined;
  226. const endpointEventId = eventIdUrl === 'recommended' ? 'helpful' : eventIdUrl;
  227. const queryKey: ApiQueryKey = [
  228. `/organizations/${organization.slug}/issues/${groupId}/events/${endpointEventId}/`,
  229. {
  230. query: getGroupEventDetailsQueryData({
  231. environments,
  232. query: helpfulEventQuery,
  233. }),
  234. },
  235. ];
  236. const tab = getCurrentTab({router});
  237. const isOnDetailsTab = tab === Tab.DETAILS;
  238. const isLatestOrHelpfulEvent = eventIdUrl === 'latest' || eventIdUrl === 'recommended';
  239. const latestOrHelpfulEvent = useApiQuery<Event>(queryKey, {
  240. // Latest/helpful event will change over time, so only cache for 30 seconds
  241. staleTime: 30000,
  242. cacheTime: 30000,
  243. enabled: isOnDetailsTab && isLatestOrHelpfulEvent,
  244. retry: false,
  245. });
  246. const otherEventQuery = useApiQuery<Event>(queryKey, {
  247. // Oldest/specific events will never change
  248. staleTime: Infinity,
  249. enabled: isOnDetailsTab && !isLatestOrHelpfulEvent,
  250. retry: false,
  251. });
  252. useEffect(() => {
  253. if (latestOrHelpfulEvent.isError) {
  254. // If we get an error from the helpful event endpoint, it probably means
  255. // the query failed validation. We should remove the query to try again.
  256. browserHistory.replace({
  257. ...window.location,
  258. query: omit(qs.parse(window.location.search), 'query'),
  259. });
  260. // 404s are expected if all events have exceeded retention
  261. if (latestOrHelpfulEvent.error.status === 404) {
  262. return;
  263. }
  264. const scope = new Sentry.Scope();
  265. scope.setExtras({
  266. groupId,
  267. query: helpfulEventQuery,
  268. ...pick(latestOrHelpfulEvent.error, ['message', 'status', 'responseJSON']),
  269. });
  270. scope.setFingerprint(['issue-details-helpful-event-request-failed']);
  271. Sentry.captureException(
  272. new Error('Issue Details: Helpful event request failed'),
  273. scope
  274. );
  275. }
  276. }, [
  277. latestOrHelpfulEvent.isError,
  278. latestOrHelpfulEvent.error,
  279. groupId,
  280. helpfulEventQuery,
  281. ]);
  282. return isLatestOrHelpfulEvent ? latestOrHelpfulEvent : otherEventQuery;
  283. }
  284. type FetchGroupQueryParameters = {
  285. environments: string[];
  286. groupId: string;
  287. organizationSlug: string;
  288. };
  289. function makeFetchGroupQueryKey({
  290. groupId,
  291. organizationSlug,
  292. environments,
  293. }: FetchGroupQueryParameters): ApiQueryKey {
  294. return [
  295. `/organizations/${organizationSlug}/issues/${groupId}/`,
  296. {query: getGroupDetailsQueryData({environments})},
  297. ];
  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 organization = useOrganization();
  308. const environmentsRef = useRef<string[]>(incomingEnvs);
  309. environmentsRef.current = incomingEnvs;
  310. const unlisten = useRef<Function>();
  311. if (unlisten.current === undefined) {
  312. unlisten.current = GroupStore.listen(() => {
  313. const [storeGroup] = GroupStore.getState();
  314. const environments = environmentsRef.current;
  315. if (defined(storeGroup)) {
  316. setApiQueryData(
  317. queryClient,
  318. makeFetchGroupQueryKey({
  319. groupId: storeGroup.id,
  320. organizationSlug: organization.slug,
  321. environments,
  322. }),
  323. storeGroup
  324. );
  325. }
  326. }, undefined);
  327. }
  328. useEffect(() => {
  329. return () => unlisten.current?.();
  330. }, []);
  331. }
  332. function useFetchGroupDetails(): FetchGroupDetailsState {
  333. const api = useApi();
  334. const organization = useOrganization();
  335. const router = useRouter();
  336. const params = router.params;
  337. const [error, setError] = useState<boolean>(false);
  338. const [errorType, setErrorType] = useState<Error | null>(null);
  339. const [event, setEvent] = useState<Event | null>(null);
  340. const [allProjectChanged, setAllProjectChanged] = useState<boolean>(false);
  341. const environments = useEnvironmentsFromUrl();
  342. const groupId = params.groupId;
  343. const {
  344. data: eventData,
  345. isLoading: loadingEvent,
  346. isError,
  347. refetch: refetchEvent,
  348. } = useEventApiQuery({
  349. groupId,
  350. eventId: params.eventId,
  351. environments,
  352. });
  353. const {
  354. data: groupData,
  355. isLoading: loadingGroup,
  356. isError: isGroupError,
  357. error: groupError,
  358. refetch: refetchGroupCall,
  359. } = useApiQuery<Group>(
  360. makeFetchGroupQueryKey({organizationSlug: organization.slug, groupId, environments}),
  361. {
  362. staleTime: 30000,
  363. cacheTime: 30000,
  364. retry: false,
  365. }
  366. );
  367. const group = groupData ?? null;
  368. useEffect(() => {
  369. if (defined(group)) {
  370. GroupStore.loadInitialData([group]);
  371. }
  372. }, [groupId, group]);
  373. useSyncGroupStore(environments);
  374. useEffect(() => {
  375. if (eventData) {
  376. setEvent(eventData);
  377. }
  378. }, [eventData]);
  379. useEffect(() => {
  380. if (group && event) {
  381. const reprocessingNewRoute = getReprocessingNewRoute({
  382. group,
  383. event,
  384. router,
  385. organization,
  386. });
  387. if (reprocessingNewRoute) {
  388. browserHistory.push(reprocessingNewRoute);
  389. return;
  390. }
  391. }
  392. }, [group, event, router, organization]);
  393. useEffect(() => {
  394. const matchingProjectSlug = group?.project?.slug;
  395. if (!matchingProjectSlug) {
  396. return;
  397. }
  398. if (!group.hasSeen) {
  399. markEventSeen(api, organization.slug, matchingProjectSlug, params.groupId);
  400. }
  401. }, [
  402. api,
  403. group?.hasSeen,
  404. group?.project?.id,
  405. group?.project?.slug,
  406. organization.slug,
  407. params.groupId,
  408. ]);
  409. const allProjectsFlag = router.location.query._allp;
  410. useEffect(() => {
  411. const locationQuery = qs.parse(window.location.search) || {};
  412. // We use _allp as a temporary measure to know they came from the
  413. // issue list page with no project selected (all projects included in
  414. // filter).
  415. //
  416. // If it is not defined, we add the locked project id to the URL
  417. // (this is because if someone navigates directly to an issue on
  418. // single-project priveleges, then goes back - they were getting
  419. // assigned to the first project).
  420. //
  421. // If it is defined, we do not so that our back button will bring us
  422. // to the issue list page with no project selected instead of the
  423. // locked project.
  424. if (
  425. locationQuery.project === undefined &&
  426. !allProjectsFlag &&
  427. !allProjectChanged &&
  428. group?.project.id
  429. ) {
  430. locationQuery.project = group?.project.id;
  431. browserHistory.replace({...window.location, query: locationQuery});
  432. }
  433. if (allProjectsFlag && !allProjectChanged) {
  434. delete locationQuery.project;
  435. // We delete _allp from the URL to keep the hack a bit cleaner, but
  436. // this is not an ideal solution and will ultimately be replaced with
  437. // something smarter.
  438. delete locationQuery._allp;
  439. browserHistory.replace({...window.location, query: locationQuery});
  440. setAllProjectChanged(true);
  441. }
  442. }, [allProjectsFlag, group?.project.id, allProjectChanged]);
  443. const handleError = useCallback((e: RequestError) => {
  444. Sentry.captureException(e);
  445. setErrorType(getFetchDataRequestErrorType(e?.status));
  446. setError(true);
  447. }, []);
  448. useEffect(() => {
  449. if (isGroupError) {
  450. handleError(groupError);
  451. }
  452. }, [isGroupError, groupError, handleError]);
  453. const refetchGroup = useCallback(() => {
  454. if (group?.status !== GroupStatus.REPROCESSING || loadingGroup || loadingEvent) {
  455. return;
  456. }
  457. refetchGroupCall();
  458. }, [group, loadingGroup, loadingEvent, refetchGroupCall]);
  459. const refetchData = useCallback(() => {
  460. // Set initial state
  461. setError(false);
  462. setErrorType(null);
  463. refetchEvent();
  464. refetchGroup();
  465. }, [refetchGroup, refetchEvent]);
  466. // Refetch when group is stale
  467. useEffect(() => {
  468. if (group) {
  469. if ((group as Group & {stale?: boolean}).stale) {
  470. refetchGroup();
  471. return;
  472. }
  473. }
  474. }, [refetchGroup, group]);
  475. useRefetchGroupForReprocessing({refetchGroup});
  476. useEffect(() => {
  477. return () => {
  478. GroupStore.reset();
  479. };
  480. }, []);
  481. return {
  482. loadingGroup,
  483. loadingEvent,
  484. group,
  485. event,
  486. errorType,
  487. error,
  488. eventError: isError,
  489. refetchData,
  490. refetchGroup,
  491. };
  492. }
  493. function useLoadedEventType() {
  494. const params = useParams<{eventId?: string}>();
  495. const defaultIssueEvent = useDefaultIssueEvent();
  496. switch (params.eventId) {
  497. case undefined:
  498. return defaultIssueEvent;
  499. case 'latest':
  500. case 'oldest':
  501. return params.eventId;
  502. default:
  503. return 'event_id';
  504. }
  505. }
  506. function useTrackView({
  507. group,
  508. event,
  509. project,
  510. tab,
  511. }: {
  512. event: Event | null;
  513. group: Group | null;
  514. tab: Tab;
  515. project?: Project;
  516. }) {
  517. const location = useLocation();
  518. const {alert_date, alert_rule_id, alert_type, ref_fallback, stream_index, query} =
  519. location.query;
  520. const groupEventType = useLoadedEventType();
  521. useRouteAnalyticsEventNames('issue_details.viewed', 'Issue Details: Viewed');
  522. useRouteAnalyticsParams({
  523. ...getAnalyticsDataForGroup(group),
  524. ...getAnalyticsDataForEvent(event),
  525. ...getAnalyicsDataForProject(project),
  526. tab,
  527. stream_index: typeof stream_index === 'string' ? Number(stream_index) : undefined,
  528. query: typeof query === 'string' ? query : undefined,
  529. // Alert properties track if the user came from email/slack alerts
  530. alert_date:
  531. typeof alert_date === 'string' ? getUtcDateString(Number(alert_date)) : undefined,
  532. alert_rule_id: typeof alert_rule_id === 'string' ? alert_rule_id : undefined,
  533. alert_type: typeof alert_type === 'string' ? alert_type : undefined,
  534. ref_fallback,
  535. group_event_type: groupEventType,
  536. // Will be updated by StacktraceLink if there is a stacktrace link
  537. stacktrace_link_viewed: false,
  538. // Will be updated by IssueQuickTrace if there is a trace
  539. trace_status: 'none',
  540. // Will be updated in GroupDetailsHeader if there are replays
  541. group_has_replay: false,
  542. });
  543. useDisableRouteAnalytics(!group || !event || !project);
  544. }
  545. const trackTabChanged = ({
  546. organization,
  547. project,
  548. group,
  549. event,
  550. tab,
  551. }: {
  552. event: Event | null;
  553. group: Group;
  554. organization: Organization;
  555. project: Project;
  556. tab: Tab;
  557. }) => {
  558. if (!project || !group) {
  559. return;
  560. }
  561. trackAnalytics('issue_details.tab_changed', {
  562. organization,
  563. project_id: parseInt(project.id, 10),
  564. tab,
  565. ...getAnalyticsDataForGroup(group),
  566. });
  567. if (group.issueCategory !== IssueCategory.ERROR) {
  568. return;
  569. }
  570. const analyticsData = event
  571. ? event.tags
  572. .filter(({key}) => ['device', 'os', 'browser'].includes(key))
  573. .reduce((acc, {key, value}) => {
  574. acc[key] = value;
  575. return acc;
  576. }, {})
  577. : {};
  578. trackAnalytics('issue_group_details.tab.clicked', {
  579. organization,
  580. tab,
  581. platform: project.platform,
  582. ...analyticsData,
  583. });
  584. };
  585. function GroupDetailsContentError({
  586. errorType,
  587. onRetry,
  588. }: {
  589. errorType: Error;
  590. onRetry: () => void;
  591. }) {
  592. const organization = useOrganization();
  593. const location = useLocation();
  594. const projectId = location.query.project;
  595. const {projects} = useProjects();
  596. const project = projects.find(proj => proj.id === projectId);
  597. switch (errorType) {
  598. case ERROR_TYPES.GROUP_NOT_FOUND:
  599. return (
  600. <StyledLoadingError
  601. message={t('The issue you were looking for was not found.')}
  602. />
  603. );
  604. case ERROR_TYPES.MISSING_MEMBERSHIP:
  605. return <MissingProjectMembership organization={organization} project={project} />;
  606. default:
  607. return <StyledLoadingError onRetry={onRetry} />;
  608. }
  609. }
  610. function GroupDetailsContent({
  611. children,
  612. group,
  613. project,
  614. loadingEvent,
  615. eventError,
  616. event,
  617. refetchData,
  618. }: GroupDetailsContentProps) {
  619. const organization = useOrganization();
  620. const router = useRouter();
  621. const {currentTab, baseUrl} = getCurrentRouteInfo({group, event, router, organization});
  622. const groupReprocessingStatus = getGroupReprocessingStatus(group);
  623. const environments = useEnvironmentsFromUrl();
  624. useTrackView({group, event, project, tab: currentTab});
  625. const childProps = {
  626. environments,
  627. group,
  628. project,
  629. event,
  630. loadingEvent,
  631. eventError,
  632. groupReprocessingStatus,
  633. onRetry: refetchData,
  634. baseUrl,
  635. };
  636. return (
  637. <Tabs
  638. value={currentTab}
  639. onChange={tab => trackTabChanged({tab, group, project, event, organization})}
  640. >
  641. <GroupHeader
  642. organization={organization}
  643. groupReprocessingStatus={groupReprocessingStatus}
  644. event={event ?? undefined}
  645. group={group}
  646. baseUrl={baseUrl}
  647. project={project as Project}
  648. />
  649. <GroupTabPanels>
  650. <TabPanels.Item key={currentTab}>
  651. {isValidElement(children) ? cloneElement(children, childProps) : children}
  652. </TabPanels.Item>
  653. </GroupTabPanels>
  654. </Tabs>
  655. );
  656. }
  657. function GroupDetailsPageContent(props: GroupDetailsProps & FetchGroupDetailsState) {
  658. const projectSlug = props.group?.project?.slug;
  659. const {
  660. projects,
  661. initiallyLoaded: projectsLoaded,
  662. fetchError: errorFetchingProjects,
  663. } = useProjects({slugs: projectSlug ? [projectSlug] : []});
  664. const project = projects.find(({slug}) => slug === projectSlug);
  665. const projectWithFallback = project ?? projects[0];
  666. useEffect(() => {
  667. if (props.group && projectsLoaded && !project) {
  668. Sentry.withScope(scope => {
  669. const projectIds = projects.map(item => item.id);
  670. scope.setContext('missingProject', {
  671. projectId: props.group?.project.id,
  672. availableProjects: projectIds,
  673. });
  674. scope.setFingerprint(['group-details-project-not-found']);
  675. Sentry.captureException(new Error('Project not found'));
  676. });
  677. }
  678. }, [props.group, project, projects, projectsLoaded]);
  679. if (props.error) {
  680. return (
  681. <GroupDetailsContentError errorType={props.errorType} onRetry={props.refetchData} />
  682. );
  683. }
  684. if (errorFetchingProjects) {
  685. return <StyledLoadingError message={t('Error loading the specified project')} />;
  686. }
  687. if (projectSlug && !errorFetchingProjects && projectsLoaded && !projectWithFallback) {
  688. return (
  689. <StyledLoadingError message={t('The project %s does not exist', projectSlug)} />
  690. );
  691. }
  692. if (!projectsLoaded || !projectWithFallback || !props.group) {
  693. return <LoadingIndicator />;
  694. }
  695. return (
  696. <GroupDetailsContent {...props} project={projectWithFallback} group={props.group} />
  697. );
  698. }
  699. function GroupDetails(props: GroupDetailsProps) {
  700. const organization = useOrganization();
  701. const router = useRouter();
  702. const {group, ...fetchGroupDetailsProps} = useFetchGroupDetails();
  703. const environments = useEnvironmentsFromUrl();
  704. const {data} = useFetchIssueTagsForDetailsPage(
  705. {
  706. groupId: router.params.groupId,
  707. orgSlug: organization.slug,
  708. environment: environments,
  709. },
  710. // Don't want this query to take precedence over the main requests
  711. {enabled: defined(group)}
  712. );
  713. const isSampleError = data?.some(tag => tag.key === 'sample_event') ?? false;
  714. const getGroupDetailsTitle = () => {
  715. const defaultTitle = 'Sentry';
  716. if (!group) {
  717. return defaultTitle;
  718. }
  719. const {title} = getTitle(group, organization?.features);
  720. const message = getMessage(group);
  721. const eventDetails = `${organization.slug} — ${group.project.slug}`;
  722. if (title && message) {
  723. return `${title}: ${message} — ${eventDetails}`;
  724. }
  725. return `${title || message || defaultTitle} — ${eventDetails}`;
  726. };
  727. return (
  728. <Fragment>
  729. {isSampleError && group && (
  730. <SampleEventAlert project={group.project} organization={organization} />
  731. )}
  732. <SentryDocumentTitle noSuffix title={getGroupDetailsTitle()}>
  733. <PageFiltersContainer
  734. skipLoadLastUsed
  735. forceProject={group?.project}
  736. shouldForceProject
  737. >
  738. <GroupDetailsPageContent
  739. {...props}
  740. {...{
  741. group,
  742. ...fetchGroupDetailsProps,
  743. }}
  744. />
  745. </PageFiltersContainer>
  746. </SentryDocumentTitle>
  747. </Fragment>
  748. );
  749. }
  750. export default Sentry.withProfiler(GroupDetails);
  751. const StyledLoadingError = styled(LoadingError)`
  752. margin: ${space(2)};
  753. `;
  754. const GroupTabPanels = styled(TabPanels)`
  755. flex-grow: 1;
  756. display: flex;
  757. flex-direction: column;
  758. justify-content: stretch;
  759. `;