groupDetails.tsx 24 KB

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