groupDetails.tsx 25 KB

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