groupDetails.tsx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802
  1. import {Fragment, useCallback, useEffect, useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import * as Sentry from '@sentry/react';
  4. import * as qs from 'query-string';
  5. import FloatingFeedbackWidget from 'sentry/components/feedback/widget/floatingFeedbackWidget';
  6. import useDrawer from 'sentry/components/globalDrawer';
  7. import LoadingError from 'sentry/components/loadingError';
  8. import LoadingIndicator from 'sentry/components/loadingIndicator';
  9. import PageFiltersContainer from 'sentry/components/organizations/pageFilters/container';
  10. import MissingProjectMembership from 'sentry/components/projects/missingProjectMembership';
  11. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  12. import {TabPanels, Tabs} from 'sentry/components/tabs';
  13. import {t} from 'sentry/locale';
  14. import GroupStore from 'sentry/stores/groupStore';
  15. import {space} from 'sentry/styles/space';
  16. import type {Event} from 'sentry/types/event';
  17. import type {Group} from 'sentry/types/group';
  18. import {GroupStatus, IssueCategory, IssueType} from 'sentry/types/group';
  19. import type {RouteComponentProps} from 'sentry/types/legacyReactRouter';
  20. import type {Organization} from 'sentry/types/organization';
  21. import type {Project} from 'sentry/types/project';
  22. import {defined} from 'sentry/utils';
  23. import {trackAnalytics} from 'sentry/utils/analytics';
  24. import {browserHistory} from 'sentry/utils/browserHistory';
  25. import {getUtcDateString} from 'sentry/utils/dates';
  26. import {
  27. getAnalyticsDataForEvent,
  28. getAnalyticsDataForGroup,
  29. getMessage,
  30. getTitle,
  31. } from 'sentry/utils/events';
  32. import {getConfigForIssueType} from 'sentry/utils/issueTypeConfig';
  33. import {getAnalyicsDataForProject} from 'sentry/utils/projects';
  34. import {setApiQueryData, useQueryClient} from 'sentry/utils/queryClient';
  35. import recreateRoute from 'sentry/utils/recreateRoute';
  36. import useDisableRouteAnalytics from 'sentry/utils/routeAnalytics/useDisableRouteAnalytics';
  37. import useRouteAnalyticsEventNames from 'sentry/utils/routeAnalytics/useRouteAnalyticsEventNames';
  38. import useRouteAnalyticsParams from 'sentry/utils/routeAnalytics/useRouteAnalyticsParams';
  39. import useApi from 'sentry/utils/useApi';
  40. import {useDetailedProject} from 'sentry/utils/useDetailedProject';
  41. import {useLocation} from 'sentry/utils/useLocation';
  42. import {useMemoWithPrevious} from 'sentry/utils/useMemoWithPrevious';
  43. import {useNavigate} from 'sentry/utils/useNavigate';
  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/useIssueActivityDrawer';
  56. import {useMergedIssuesDrawer} from 'sentry/views/issueDetails/streamline/useMergedIssuesDrawer';
  57. import {useSimilarIssuesDrawer} from 'sentry/views/issueDetails/streamline/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 navigate = useNavigate();
  204. const defaultIssueEvent = useDefaultIssueEvent();
  205. const [allProjectChanged, setAllProjectChanged] = useState<boolean>(false);
  206. const {currentTab, baseUrl} = useGroupDetailsRoute();
  207. const environments = useEnvironmentsFromUrl();
  208. const groupId = params.groupId;
  209. const {
  210. data: event,
  211. isPending: loadingEvent,
  212. isError: isEventError,
  213. refetch: refetchEvent,
  214. } = useGroupEvent({
  215. groupId,
  216. eventId: params.eventId,
  217. environments,
  218. });
  219. const {
  220. data: groupData,
  221. isPending: loadingGroup,
  222. isError: isGroupError,
  223. error: groupError,
  224. refetch: refetchGroupCall,
  225. } = useGroup({groupId});
  226. useEffect(() => {
  227. const eventIdUrl = params.eventId ?? defaultIssueEvent;
  228. const isLatestOrRecommendedEvent =
  229. eventIdUrl === 'latest' || eventIdUrl === 'recommended';
  230. if (isLatestOrRecommendedEvent && isEventError && router.location.query.query) {
  231. // If we get an error from the helpful event endpoint, it probably means
  232. // the query failed validation. We should remove the query to try again.
  233. navigate(
  234. {
  235. ...router.location,
  236. query: {
  237. ...router.location.query,
  238. query: undefined,
  239. },
  240. },
  241. {replace: true}
  242. );
  243. }
  244. }, [defaultIssueEvent, isEventError, navigate, router.location, params.eventId]);
  245. /**
  246. * Allows the GroupEventHeader to display the previous event while the new event is loading.
  247. * This is not closer to the GroupEventHeader because it is unmounted
  248. * between route changes like latest event => eventId
  249. */
  250. const previousEvent = useMemoWithPrevious<typeof event | null>(
  251. previousInstance => {
  252. if (event) {
  253. return event;
  254. }
  255. return previousInstance;
  256. },
  257. [event]
  258. );
  259. const group = groupData ?? null;
  260. useEffect(() => {
  261. if (defined(group)) {
  262. GroupStore.loadInitialData([group]);
  263. }
  264. }, [groupId, group]);
  265. useSyncGroupStore(groupId, environments);
  266. useEffect(() => {
  267. if (group && event) {
  268. const reprocessingNewRoute = getReprocessingNewRoute({
  269. group,
  270. currentTab,
  271. router,
  272. baseUrl,
  273. });
  274. if (reprocessingNewRoute) {
  275. browserHistory.push(reprocessingNewRoute);
  276. }
  277. }
  278. }, [group, event, router, currentTab, baseUrl]);
  279. useEffect(() => {
  280. const matchingProjectSlug = group?.project?.slug;
  281. if (!matchingProjectSlug) {
  282. return;
  283. }
  284. if (!group.hasSeen) {
  285. markEventSeen(api, organization.slug, matchingProjectSlug, params.groupId);
  286. }
  287. }, [
  288. api,
  289. group?.hasSeen,
  290. group?.project?.id,
  291. group?.project?.slug,
  292. organization.slug,
  293. params.groupId,
  294. ]);
  295. const allProjectsFlag = router.location.query._allp;
  296. useEffect(() => {
  297. const locationQuery = qs.parse(window.location.search) || {};
  298. // We use _allp as a temporary measure to know they came from the
  299. // issue list page with no project selected (all projects included in
  300. // filter).
  301. //
  302. // If it is not defined, we add the locked project id to the URL
  303. // (this is because if someone navigates directly to an issue on
  304. // single-project priveleges, then goes back - they were getting
  305. // assigned to the first project).
  306. //
  307. // If it is defined, we do not so that our back button will bring us
  308. // to the issue list page with no project selected instead of the
  309. // locked project.
  310. if (
  311. locationQuery.project === undefined &&
  312. !allProjectsFlag &&
  313. !allProjectChanged &&
  314. group?.project.id
  315. ) {
  316. locationQuery.project = group?.project.id;
  317. browserHistory.replace({...window.location, query: locationQuery});
  318. }
  319. if (allProjectsFlag && !allProjectChanged) {
  320. delete locationQuery.project;
  321. // We delete _allp from the URL to keep the hack a bit cleaner, but
  322. // this is not an ideal solution and will ultimately be replaced with
  323. // something smarter.
  324. delete locationQuery._allp;
  325. browserHistory.replace({...window.location, query: locationQuery});
  326. setAllProjectChanged(true);
  327. }
  328. }, [allProjectsFlag, group?.project.id, allProjectChanged]);
  329. const errorType = groupError ? getFetchDataRequestErrorType(groupError.status) : null;
  330. useEffect(() => {
  331. if (isGroupError) {
  332. Sentry.captureException(groupError);
  333. }
  334. }, [isGroupError, groupError]);
  335. const refetchGroup = useCallback(() => {
  336. if (group?.status !== GroupStatus.REPROCESSING || loadingGroup || loadingEvent) {
  337. return;
  338. }
  339. refetchGroupCall();
  340. }, [group, loadingGroup, loadingEvent, refetchGroupCall]);
  341. const refetchData = useCallback(() => {
  342. refetchEvent();
  343. refetchGroup();
  344. }, [refetchGroup, refetchEvent]);
  345. // Refetch when group is stale
  346. useEffect(() => {
  347. if (group && (group as Group & {stale?: boolean}).stale) {
  348. refetchGroup();
  349. }
  350. }, [refetchGroup, group]);
  351. useRefetchGroupForReprocessing({refetchGroup});
  352. useEffect(() => {
  353. return () => {
  354. GroupStore.reset();
  355. };
  356. }, []);
  357. return {
  358. loadingGroup,
  359. group,
  360. // Allow previous event to be displayed while new event is loading
  361. event: (loadingEvent ? event ?? previousEvent : event) ?? null,
  362. errorType,
  363. error: isGroupError,
  364. refetchData,
  365. refetchGroup,
  366. };
  367. }
  368. function useLoadedEventType() {
  369. const params = useParams<{eventId?: string}>();
  370. const defaultIssueEvent = useDefaultIssueEvent();
  371. switch (params.eventId) {
  372. case undefined:
  373. return defaultIssueEvent;
  374. case 'latest':
  375. case 'oldest':
  376. return params.eventId;
  377. default:
  378. return 'event_id';
  379. }
  380. }
  381. function useTrackView({
  382. group,
  383. event,
  384. project,
  385. tab,
  386. }: {
  387. event: Event | null;
  388. group: Group | null;
  389. tab: Tab;
  390. project?: Project;
  391. }) {
  392. const location = useLocation();
  393. const {alert_date, alert_rule_id, alert_type, ref_fallback, stream_index, query} =
  394. location.query;
  395. const groupEventType = useLoadedEventType();
  396. const user = useUser();
  397. useRouteAnalyticsEventNames('issue_details.viewed', 'Issue Details: Viewed');
  398. useRouteAnalyticsParams({
  399. ...getAnalyticsDataForGroup(group),
  400. ...getAnalyticsDataForEvent(event),
  401. ...getAnalyicsDataForProject(project),
  402. tab,
  403. stream_index: typeof stream_index === 'string' ? Number(stream_index) : undefined,
  404. query: typeof query === 'string' ? query : undefined,
  405. // Alert properties track if the user came from email/slack alerts
  406. alert_date:
  407. typeof alert_date === 'string' ? getUtcDateString(Number(alert_date)) : undefined,
  408. alert_rule_id: typeof alert_rule_id === 'string' ? alert_rule_id : undefined,
  409. alert_type: typeof alert_type === 'string' ? alert_type : undefined,
  410. ref_fallback,
  411. group_event_type: groupEventType,
  412. prefers_streamlined_ui: user?.options?.prefersIssueDetailsStreamlinedUI ?? false,
  413. });
  414. // Set default values for properties that may be updated in subcomponents.
  415. // Must be separate from the above values, otherwise the actual values filled in
  416. // by subcomponents may be overwritten when the above values change.
  417. useRouteAnalyticsParams({
  418. // Will be updated by StacktraceLink if there is a stacktrace link
  419. stacktrace_link_viewed: false,
  420. // Will be updated by IssueQuickTrace if there is a trace
  421. trace_status: 'none',
  422. // Will be updated in GroupDetailsHeader if there are replays
  423. group_has_replay: false,
  424. // Will be updated in ReplayPreview if there is a replay
  425. event_replay_status: 'none',
  426. // Will be updated in SuspectCommits if there are suspect commits
  427. num_suspect_commits: 0,
  428. suspect_commit_calculation: 'no suspect commit',
  429. // Will be updated in Autofix if enabled
  430. autofix_status: 'none',
  431. });
  432. useDisableRouteAnalytics(!group || !event || !project);
  433. }
  434. const trackTabChanged = ({
  435. organization,
  436. project,
  437. group,
  438. event,
  439. tab,
  440. }: {
  441. event: Event | null;
  442. group: Group;
  443. organization: Organization;
  444. project: Project;
  445. tab: Tab;
  446. }) => {
  447. if (!project || !group) {
  448. return;
  449. }
  450. trackAnalytics('issue_details.tab_changed', {
  451. organization,
  452. project_id: parseInt(project.id, 10),
  453. tab,
  454. ...getAnalyticsDataForGroup(group),
  455. });
  456. if (group.issueCategory !== IssueCategory.ERROR) {
  457. return;
  458. }
  459. const analyticsData = event
  460. ? event.tags
  461. .filter(({key}) => ['device', 'os', 'browser'].includes(key))
  462. .reduce((acc, {key, value}) => {
  463. acc[key] = value;
  464. return acc;
  465. }, {})
  466. : {};
  467. trackAnalytics('issue_group_details.tab.clicked', {
  468. organization,
  469. tab,
  470. platform: project.platform,
  471. ...analyticsData,
  472. });
  473. };
  474. function GroupDetailsContentError({
  475. errorType,
  476. onRetry,
  477. }: {
  478. errorType: Error;
  479. onRetry: () => void;
  480. }) {
  481. const organization = useOrganization();
  482. const location = useLocation();
  483. const projectId = location.query.project;
  484. const {projects} = useProjects();
  485. const project = projects.find(proj => proj.id === projectId);
  486. switch (errorType) {
  487. case ERROR_TYPES.GROUP_NOT_FOUND:
  488. return (
  489. <StyledLoadingError
  490. message={t('The issue you were looking for was not found.')}
  491. />
  492. );
  493. case ERROR_TYPES.MISSING_MEMBERSHIP:
  494. return <MissingProjectMembership organization={organization} project={project} />;
  495. default:
  496. return <StyledLoadingError onRetry={onRetry} />;
  497. }
  498. }
  499. function GroupDetailsContent({
  500. children,
  501. group,
  502. project,
  503. event,
  504. }: GroupDetailsContentProps) {
  505. const organization = useOrganization();
  506. const {openTagsDrawer} = useGroupTagsDrawer({group});
  507. const {openSimilarIssuesDrawer} = useSimilarIssuesDrawer({group, project});
  508. const {openMergedIssuesDrawer} = useMergedIssuesDrawer({group, project});
  509. const {openIssueActivityDrawer} = useIssueActivityDrawer({group, project});
  510. const {isDrawerOpen} = useDrawer();
  511. const {currentTab, baseUrl} = useGroupDetailsRoute();
  512. const hasStreamlinedUI = useHasStreamlinedUI();
  513. useEffect(() => {
  514. if (!hasStreamlinedUI || isDrawerOpen) {
  515. return;
  516. }
  517. if (currentTab === Tab.TAGS) {
  518. openTagsDrawer();
  519. } else if (currentTab === Tab.SIMILAR_ISSUES) {
  520. openSimilarIssuesDrawer();
  521. } else if (currentTab === Tab.MERGED) {
  522. openMergedIssuesDrawer();
  523. } else if (currentTab === Tab.ACTIVITY) {
  524. openIssueActivityDrawer();
  525. }
  526. }, [
  527. currentTab,
  528. hasStreamlinedUI,
  529. isDrawerOpen,
  530. openTagsDrawer,
  531. openSimilarIssuesDrawer,
  532. openMergedIssuesDrawer,
  533. openIssueActivityDrawer,
  534. ]);
  535. useTrackView({group, event, project, tab: currentTab});
  536. const isDisplayingEventDetails = [
  537. Tab.DETAILS,
  538. Tab.TAGS,
  539. Tab.SIMILAR_ISSUES,
  540. Tab.MERGED,
  541. Tab.ACTIVITY,
  542. ].includes(currentTab);
  543. return hasStreamlinedUI ? (
  544. <GroupDetailsLayout group={group} event={event ?? undefined} project={project}>
  545. {isDisplayingEventDetails ? (
  546. // The router displays a loading indicator when switching to any of these tabs
  547. // Avoid lazy loading spinner by force rendering the GroupEventDetails component
  548. <GroupEventDetails />
  549. ) : (
  550. children
  551. )}
  552. </GroupDetailsLayout>
  553. ) : (
  554. <Tabs
  555. value={currentTab}
  556. onChange={tab => trackTabChanged({tab, group, project, event, organization})}
  557. >
  558. <GroupHeader
  559. organization={organization}
  560. event={event}
  561. group={group}
  562. baseUrl={baseUrl}
  563. project={project as Project}
  564. />
  565. <GroupTabPanels>
  566. <TabPanels.Item key={currentTab}>{children}</TabPanels.Item>
  567. </GroupTabPanels>
  568. </Tabs>
  569. );
  570. }
  571. function GroupDetailsPageContent(props: GroupDetailsProps & FetchGroupDetailsState) {
  572. const projectSlug = props.group?.project?.slug;
  573. const api = useApi();
  574. const organization = useOrganization();
  575. const [injectedEvent, setInjectedEvent] = useState(null);
  576. const {
  577. projects,
  578. initiallyLoaded: projectsLoaded,
  579. fetchError: errorFetchingProjects,
  580. } = useProjects({slugs: projectSlug ? [projectSlug] : []});
  581. // Preload detailed project data for highlighted data section
  582. useDetailedProject(
  583. {
  584. orgSlug: organization.slug,
  585. projectSlug: projectSlug ?? '',
  586. },
  587. {enabled: !!projectSlug}
  588. );
  589. const project = projects.find(({slug}) => slug === projectSlug);
  590. const projectWithFallback = project ?? projects[0];
  591. const isRegressionIssue =
  592. props.group?.issueType === IssueType.PERFORMANCE_DURATION_REGRESSION ||
  593. props.group?.issueType === IssueType.PERFORMANCE_ENDPOINT_REGRESSION;
  594. useEffect(() => {
  595. if (props.group && projectsLoaded && !project) {
  596. Sentry.withScope(scope => {
  597. const projectIds = projects.map(item => item.id);
  598. scope.setContext('missingProject', {
  599. projectId: props.group?.project.id,
  600. availableProjects: projectIds,
  601. });
  602. scope.setFingerprint(['group-details-project-not-found']);
  603. Sentry.captureException(new Error('Project not found'));
  604. });
  605. }
  606. }, [props.group, project, projects, projectsLoaded]);
  607. useEffect(() => {
  608. const fetchLatestEvent = async () => {
  609. const event = await api.requestPromise(
  610. `/organizations/${organization.slug}/issues/${props.group?.id}/events/latest/`
  611. );
  612. setInjectedEvent(event);
  613. };
  614. if (isRegressionIssue && !defined(props.event)) {
  615. fetchLatestEvent();
  616. }
  617. }, [
  618. api,
  619. organization.slug,
  620. props.event,
  621. props.group,
  622. props.group?.id,
  623. isRegressionIssue,
  624. ]);
  625. if (props.error) {
  626. return (
  627. <GroupDetailsContentError errorType={props.errorType} onRetry={props.refetchData} />
  628. );
  629. }
  630. if (errorFetchingProjects) {
  631. return <StyledLoadingError message={t('Error loading the specified project')} />;
  632. }
  633. if (projectSlug && !errorFetchingProjects && projectsLoaded && !projectWithFallback) {
  634. return (
  635. <StyledLoadingError message={t('The project %s does not exist', projectSlug)} />
  636. );
  637. }
  638. const regressionIssueLoaded = defined(injectedEvent ?? props.event);
  639. if (
  640. !projectsLoaded ||
  641. !projectWithFallback ||
  642. !props.group ||
  643. (isRegressionIssue && !regressionIssueLoaded)
  644. ) {
  645. return <LoadingIndicator />;
  646. }
  647. return (
  648. <GroupDetailsContent
  649. {...props}
  650. project={projectWithFallback}
  651. group={props.group}
  652. event={props.event ?? injectedEvent}
  653. />
  654. );
  655. }
  656. function GroupDetails(props: GroupDetailsProps) {
  657. const organization = useOrganization();
  658. const {group, ...fetchGroupDetailsProps} = useFetchGroupDetails();
  659. const isSampleError = useIsSampleEvent();
  660. const getGroupDetailsTitle = () => {
  661. const defaultTitle = 'Sentry';
  662. if (!group) {
  663. return defaultTitle;
  664. }
  665. const {title} = getTitle(group);
  666. const message = getMessage(group);
  667. const eventDetails = `${organization.slug} — ${group.project.slug}`;
  668. if (title && message) {
  669. return `${title}: ${message} — ${eventDetails}`;
  670. }
  671. return `${title || message || defaultTitle} — ${eventDetails}`;
  672. };
  673. const config = group && getConfigForIssueType(group, group.project);
  674. return (
  675. <Fragment>
  676. {isSampleError && group && (
  677. <SampleEventAlert project={group.project} organization={organization} />
  678. )}
  679. <SentryDocumentTitle noSuffix title={getGroupDetailsTitle()}>
  680. <PageFiltersContainer
  681. skipLoadLastUsed
  682. forceProject={group?.project}
  683. shouldForceProject
  684. >
  685. {config?.showFeedbackWidget && <FloatingFeedbackWidget />}
  686. <GroupDetailsPageContent
  687. {...props}
  688. {...{
  689. group,
  690. ...fetchGroupDetailsProps,
  691. }}
  692. />
  693. </PageFiltersContainer>
  694. </SentryDocumentTitle>
  695. </Fragment>
  696. );
  697. }
  698. export default Sentry.withProfiler(GroupDetails);
  699. const StyledLoadingError = styled(LoadingError)`
  700. margin: ${space(2)};
  701. `;
  702. const GroupTabPanels = styled(TabPanels)`
  703. flex-grow: 1;
  704. display: flex;
  705. flex-direction: column;
  706. justify-content: stretch;
  707. `;