groupDetails.tsx 25 KB

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