groupDetails.tsx 23 KB

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