groupDetails.tsx 24 KB

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