groupDetails.tsx 25 KB

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