groupDetails.tsx 25 KB

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