groupDetails.tsx 25 KB

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