groupDetails.tsx 24 KB

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