groupDetails.tsx 25 KB

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