groupDetails.tsx 25 KB

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