groupDetails.tsx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  1. import {
  2. cloneElement,
  3. Fragment,
  4. isValidElement,
  5. useCallback,
  6. useEffect,
  7. useRef,
  8. useState,
  9. } from 'react';
  10. import {browserHistory, 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 pick from 'lodash/pick';
  15. import * as qs from 'query-string';
  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 {Group, IssueCategory, Organization, Project} from 'sentry/types';
  26. import {Event} from 'sentry/types/event';
  27. import {defined} from 'sentry/utils';
  28. import {trackAnalytics} from 'sentry/utils/analytics';
  29. import {getUtcDateString} from 'sentry/utils/dates';
  30. import {
  31. getAnalyticsDataForEvent,
  32. getAnalyticsDataForGroup,
  33. getMessage,
  34. getTitle,
  35. } from 'sentry/utils/events';
  36. import {getAnalyicsDataForProject} from 'sentry/utils/projects';
  37. import {
  38. ApiQueryKey,
  39. setApiQueryData,
  40. useApiQuery,
  41. useQueryClient,
  42. } from 'sentry/utils/queryClient';
  43. import recreateRoute from 'sentry/utils/recreateRoute';
  44. import RequestError from 'sentry/utils/requestError/requestError';
  45. import useDisableRouteAnalytics from 'sentry/utils/routeAnalytics/useDisableRouteAnalytics';
  46. import useRouteAnalyticsEventNames from 'sentry/utils/routeAnalytics/useRouteAnalyticsEventNames';
  47. import useRouteAnalyticsParams from 'sentry/utils/routeAnalytics/useRouteAnalyticsParams';
  48. import useApi from 'sentry/utils/useApi';
  49. import {useLocation} from 'sentry/utils/useLocation';
  50. import useOrganization from 'sentry/utils/useOrganization';
  51. import useProjects from 'sentry/utils/useProjects';
  52. import useRouter from 'sentry/utils/useRouter';
  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. useEnvironmentsFromUrl,
  65. useFetchIssueTagsForDetailsPage,
  66. } from './utils';
  67. type Error = (typeof ERROR_TYPES)[keyof typeof ERROR_TYPES] | null;
  68. type RouterParams = {groupId: string; eventId?: string};
  69. type RouteProps = RouteComponentProps<RouterParams, {}>;
  70. type GroupDetailsProps = {
  71. children: React.ReactNode;
  72. organization: Organization;
  73. projects: Project[];
  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 hasMostHelpfulEventFeature = organization.features.includes(
  221. 'issue-details-most-helpful-event'
  222. );
  223. const eventIdUrl = eventId ?? (hasMostHelpfulEventFeature ? 'helpful' : 'latest');
  224. const helpfulEventQuery =
  225. hasMostHelpfulEventFeature && typeof location.query.query === 'string'
  226. ? location.query.query
  227. : undefined;
  228. const queryKey: ApiQueryKey = [
  229. `/issues/${groupId}/events/${eventIdUrl}/`,
  230. {
  231. query: getGroupEventDetailsQueryData({
  232. environments,
  233. query: helpfulEventQuery,
  234. }),
  235. },
  236. ];
  237. const tab = getCurrentTab({router});
  238. const isOnDetailsTab = tab === Tab.DETAILS;
  239. const isLatestOrHelpfulEvent = eventIdUrl === 'latest' || eventIdUrl === 'helpful';
  240. const latestOrHelpfulEvent = useApiQuery<Event>(queryKey, {
  241. // Latest/helpful event will change over time, so only cache for 30 seconds
  242. staleTime: 30000,
  243. cacheTime: 30000,
  244. enabled: isOnDetailsTab && isLatestOrHelpfulEvent,
  245. retry: false,
  246. });
  247. const otherEventQuery = useApiQuery<Event>(queryKey, {
  248. // Oldest/specific events will never change
  249. staleTime: Infinity,
  250. enabled: isOnDetailsTab && !isLatestOrHelpfulEvent,
  251. retry: false,
  252. });
  253. useEffect(() => {
  254. if (latestOrHelpfulEvent.isError) {
  255. // If we get an error from the helpful event endpoint, it probably means
  256. // the query failed validation. We should remove the query to try again.
  257. if (hasMostHelpfulEventFeature) {
  258. browserHistory.replace({
  259. ...window.location,
  260. query: omit(qs.parse(window.location.search), 'query'),
  261. });
  262. const scope = new Sentry.Scope();
  263. scope.setExtras({
  264. groupId,
  265. query: helpfulEventQuery,
  266. ...pick(latestOrHelpfulEvent.error, ['message', 'status', 'responseJSON']),
  267. });
  268. scope.setFingerprint(['issue-details-helpful-event-request-failed']);
  269. Sentry.captureException(
  270. new Error('Issue Details: Helpful event request failed'),
  271. scope
  272. );
  273. }
  274. }
  275. }, [
  276. latestOrHelpfulEvent.isError,
  277. latestOrHelpfulEvent.error,
  278. hasMostHelpfulEventFeature,
  279. groupId,
  280. helpfulEventQuery,
  281. ]);
  282. return isLatestOrHelpfulEvent ? latestOrHelpfulEvent : otherEventQuery;
  283. }
  284. type FetchGroupQueryParameters = {
  285. environments: string[];
  286. groupId: string;
  287. };
  288. function makeFetchGroupQueryKey({
  289. groupId,
  290. environments,
  291. }: FetchGroupQueryParameters): ApiQueryKey {
  292. return [`/issues/${groupId}/`, {query: getGroupDetailsQueryData({environments})}];
  293. }
  294. /**
  295. * This is a temporary measure to ensure that the GroupStore and query cache
  296. * are both up to date while we are still using both in the issue details page.
  297. * Once we remove all references to GroupStore in the issue details page we
  298. * should remove this.
  299. */
  300. function useSyncGroupStore(incomingEnvs: string[]) {
  301. const queryClient = useQueryClient();
  302. const environmentsRef = useRef<string[]>(incomingEnvs);
  303. environmentsRef.current = incomingEnvs;
  304. const unlisten = useRef<Function>();
  305. if (unlisten.current === undefined) {
  306. unlisten.current = GroupStore.listen(() => {
  307. const [storeGroup] = GroupStore.getState();
  308. const environments = environmentsRef.current;
  309. if (defined(storeGroup)) {
  310. setApiQueryData(
  311. queryClient,
  312. makeFetchGroupQueryKey({groupId: storeGroup.id, environments}),
  313. storeGroup
  314. );
  315. }
  316. }, undefined);
  317. }
  318. useEffect(() => {
  319. return () => unlisten.current?.();
  320. }, []);
  321. }
  322. function useFetchGroupDetails(): FetchGroupDetailsState {
  323. const api = useApi();
  324. const organization = useOrganization();
  325. const router = useRouter();
  326. const params = router.params;
  327. const [error, setError] = useState<boolean>(false);
  328. const [errorType, setErrorType] = useState<Error | null>(null);
  329. const [event, setEvent] = useState<Event | null>(null);
  330. const [allProjectChanged, setAllProjectChanged] = useState<boolean>(false);
  331. const environments = useEnvironmentsFromUrl();
  332. const groupId = params.groupId;
  333. const {
  334. data: eventData,
  335. isLoading: loadingEvent,
  336. isError,
  337. refetch: refetchEvent,
  338. } = useEventApiQuery({
  339. groupId,
  340. eventId: params.eventId,
  341. environments,
  342. });
  343. const {
  344. data: groupData,
  345. isLoading: loadingGroup,
  346. isError: isGroupError,
  347. error: groupError,
  348. refetch: refetchGroupCall,
  349. } = useApiQuery<Group>(makeFetchGroupQueryKey({groupId, environments}), {
  350. staleTime: 30000,
  351. cacheTime: 30000,
  352. retry: false,
  353. });
  354. const group = groupData ?? null;
  355. useEffect(() => {
  356. if (defined(group)) {
  357. GroupStore.loadInitialData([group]);
  358. }
  359. }, [groupId, group]);
  360. useSyncGroupStore(environments);
  361. useEffect(() => {
  362. if (eventData) {
  363. setEvent(eventData);
  364. }
  365. }, [eventData]);
  366. useEffect(() => {
  367. if (group && event) {
  368. const reprocessingNewRoute = getReprocessingNewRoute({
  369. group,
  370. event,
  371. router,
  372. organization,
  373. });
  374. if (reprocessingNewRoute) {
  375. browserHistory.push(reprocessingNewRoute);
  376. return;
  377. }
  378. }
  379. }, [group, event, router, organization]);
  380. useEffect(() => {
  381. const matchingProjectSlug = group?.project?.slug;
  382. if (!matchingProjectSlug) {
  383. return;
  384. }
  385. if (!group.hasSeen) {
  386. markEventSeen(api, organization.slug, matchingProjectSlug, params.groupId);
  387. }
  388. }, [
  389. api,
  390. group?.hasSeen,
  391. group?.project?.id,
  392. group?.project?.slug,
  393. organization.slug,
  394. params.groupId,
  395. ]);
  396. const allProjectsFlag = router.location.query._allp;
  397. useEffect(() => {
  398. const locationQuery = qs.parse(window.location.search) || {};
  399. // We use _allp as a temporary measure to know they came from the
  400. // issue list page with no project selected (all projects included in
  401. // filter).
  402. //
  403. // If it is not defined, we add the locked project id to the URL
  404. // (this is because if someone navigates directly to an issue on
  405. // single-project priveleges, then goes back - they were getting
  406. // assigned to the first project).
  407. //
  408. // If it is defined, we do not so that our back button will bring us
  409. // to the issue list page with no project selected instead of the
  410. // locked project.
  411. if (
  412. locationQuery.project === undefined &&
  413. !allProjectsFlag &&
  414. !allProjectChanged &&
  415. group?.project.id
  416. ) {
  417. locationQuery.project = group?.project.id;
  418. browserHistory.replace({...window.location, query: locationQuery});
  419. }
  420. if (allProjectsFlag && !allProjectChanged) {
  421. delete locationQuery.project;
  422. // We delete _allp from the URL to keep the hack a bit cleaner, but
  423. // this is not an ideal solution and will ultimately be replaced with
  424. // something smarter.
  425. delete locationQuery._allp;
  426. browserHistory.replace({...window.location, query: locationQuery});
  427. setAllProjectChanged(true);
  428. }
  429. }, [allProjectsFlag, group?.project.id, allProjectChanged]);
  430. const handleError = useCallback((e: RequestError) => {
  431. Sentry.captureException(e);
  432. setErrorType(getFetchDataRequestErrorType(e?.status));
  433. setError(true);
  434. }, []);
  435. useEffect(() => {
  436. if (isGroupError) {
  437. handleError(groupError);
  438. }
  439. }, [isGroupError, groupError, handleError]);
  440. const refetchGroup = useCallback(() => {
  441. if (
  442. group?.status !== ReprocessingStatus.REPROCESSING ||
  443. loadingGroup ||
  444. loadingEvent
  445. ) {
  446. return;
  447. }
  448. refetchGroupCall();
  449. }, [group, loadingGroup, loadingEvent, refetchGroupCall]);
  450. const refetchData = useCallback(() => {
  451. // Set initial state
  452. setError(false);
  453. setErrorType(null);
  454. refetchEvent();
  455. refetchGroup();
  456. }, [refetchGroup, refetchEvent]);
  457. // Refetch when group is stale
  458. useEffect(() => {
  459. if (group) {
  460. if ((group as Group & {stale?: boolean}).stale) {
  461. refetchGroup();
  462. return;
  463. }
  464. }
  465. }, [refetchGroup, group]);
  466. useRefetchGroupForReprocessing({refetchGroup});
  467. useEffect(() => {
  468. return () => {
  469. GroupStore.reset();
  470. };
  471. }, []);
  472. return {
  473. loadingGroup,
  474. loadingEvent,
  475. group,
  476. event,
  477. errorType,
  478. error,
  479. eventError: isError,
  480. refetchData,
  481. refetchGroup,
  482. };
  483. }
  484. function useTrackView({
  485. group,
  486. event,
  487. project,
  488. tab,
  489. }: {
  490. event: Event | null;
  491. group: Group | null;
  492. tab: Tab;
  493. project?: Project;
  494. }) {
  495. const location = useLocation();
  496. const {alert_date, alert_rule_id, alert_type, ref_fallback, stream_index, query} =
  497. location.query;
  498. useRouteAnalyticsEventNames('issue_details.viewed', 'Issue Details: Viewed');
  499. useRouteAnalyticsParams({
  500. ...getAnalyticsDataForGroup(group),
  501. ...getAnalyticsDataForEvent(event),
  502. ...getAnalyicsDataForProject(project),
  503. tab,
  504. stream_index: typeof stream_index === 'string' ? Number(stream_index) : undefined,
  505. query: typeof query === 'string' ? query : undefined,
  506. // Alert properties track if the user came from email/slack alerts
  507. alert_date:
  508. typeof alert_date === 'string' ? getUtcDateString(Number(alert_date)) : undefined,
  509. alert_rule_id: typeof alert_rule_id === 'string' ? alert_rule_id : undefined,
  510. alert_type: typeof alert_type === 'string' ? alert_type : undefined,
  511. ref_fallback,
  512. // Will be updated by StacktraceLink if there is a stacktrace link
  513. stacktrace_link_viewed: false,
  514. // Will be updated by IssueQuickTrace if there is a trace
  515. trace_status: 'none',
  516. // Will be updated in GroupDetailsHeader if there are replays
  517. group_has_replay: false,
  518. });
  519. useDisableRouteAnalytics(!group || !event || !project);
  520. }
  521. const trackTabChanged = ({
  522. organization,
  523. project,
  524. group,
  525. event,
  526. tab,
  527. }: {
  528. event: Event | null;
  529. group: Group;
  530. organization: Organization;
  531. project: Project;
  532. tab: Tab;
  533. }) => {
  534. if (!project || !group) {
  535. return;
  536. }
  537. trackAnalytics('issue_details.tab_changed', {
  538. organization,
  539. project_id: parseInt(project.id, 10),
  540. tab,
  541. ...getAnalyticsDataForGroup(group),
  542. });
  543. if (group.issueCategory !== IssueCategory.ERROR) {
  544. return;
  545. }
  546. const analyticsData = event
  547. ? event.tags
  548. .filter(({key}) => ['device', 'os', 'browser'].includes(key))
  549. .reduce((acc, {key, value}) => {
  550. acc[key] = value;
  551. return acc;
  552. }, {})
  553. : {};
  554. trackAnalytics('issue_group_details.tab.clicked', {
  555. organization,
  556. tab,
  557. platform: project.platform,
  558. ...analyticsData,
  559. });
  560. };
  561. function GroupDetailsContentError({
  562. errorType,
  563. onRetry,
  564. }: {
  565. errorType: Error;
  566. onRetry: () => void;
  567. }) {
  568. const organization = useOrganization();
  569. const location = useLocation();
  570. const projectId = location.query.project;
  571. const {projects} = useProjects();
  572. const project = projects.find(proj => proj.id === projectId);
  573. switch (errorType) {
  574. case ERROR_TYPES.GROUP_NOT_FOUND:
  575. return (
  576. <StyledLoadingError
  577. message={t('The issue you were looking for was not found.')}
  578. />
  579. );
  580. case ERROR_TYPES.MISSING_MEMBERSHIP:
  581. return <MissingProjectMembership organization={organization} project={project} />;
  582. default:
  583. return <StyledLoadingError onRetry={onRetry} />;
  584. }
  585. }
  586. function GroupDetailsContent({
  587. children,
  588. group,
  589. project,
  590. loadingEvent,
  591. eventError,
  592. event,
  593. refetchData,
  594. }: GroupDetailsContentProps) {
  595. const organization = useOrganization();
  596. const router = useRouter();
  597. const {currentTab, baseUrl} = getCurrentRouteInfo({group, event, router, organization});
  598. const groupReprocessingStatus = getGroupReprocessingStatus(group);
  599. const environments = useEnvironmentsFromUrl();
  600. useTrackView({group, event, project, tab: currentTab});
  601. useEffect(() => {
  602. if (
  603. currentTab === Tab.DETAILS &&
  604. group &&
  605. event &&
  606. group.id !== event?.groupID &&
  607. !eventError
  608. ) {
  609. // if user pastes only the event id into the url, but it's from another group, redirect to correct group/event
  610. const redirectUrl = `/organizations/${organization.slug}/issues/${event.groupID}/events/${event.id}/`;
  611. router.push(normalizeUrl(redirectUrl));
  612. }
  613. }, [currentTab, event, eventError, group, organization.slug, router]);
  614. const childProps = {
  615. environments,
  616. group,
  617. project,
  618. event,
  619. loadingEvent,
  620. eventError,
  621. groupReprocessingStatus,
  622. onRetry: refetchData,
  623. baseUrl,
  624. };
  625. return (
  626. <Tabs
  627. value={currentTab}
  628. onChange={tab => trackTabChanged({tab, group, project, event, organization})}
  629. >
  630. <GroupHeader
  631. organization={organization}
  632. groupReprocessingStatus={groupReprocessingStatus}
  633. event={event ?? undefined}
  634. group={group}
  635. baseUrl={baseUrl}
  636. project={project as Project}
  637. />
  638. <GroupTabPanels>
  639. <TabPanels.Item key={currentTab}>
  640. {isValidElement(children) ? cloneElement(children, childProps) : children}
  641. </TabPanels.Item>
  642. </GroupTabPanels>
  643. </Tabs>
  644. );
  645. }
  646. function GroupDetailsPageContent(props: GroupDetailsProps & FetchGroupDetailsState) {
  647. const projectSlug = props.group?.project?.slug;
  648. const {
  649. projects,
  650. initiallyLoaded: projectsLoaded,
  651. fetchError: errorFetchingProjects,
  652. } = useProjects({slugs: projectSlug ? [projectSlug] : []});
  653. const project = projects.find(({slug}) => slug === projectSlug);
  654. const projectWithFallback = project ?? projects[0];
  655. useEffect(() => {
  656. if (props.group && projectsLoaded && !project) {
  657. Sentry.withScope(scope => {
  658. const projectIds = projects.map(item => item.id);
  659. scope.setContext('missingProject', {
  660. projectId: props.group?.project.id,
  661. availableProjects: projectIds,
  662. });
  663. Sentry.captureException(new Error('Project not found'));
  664. });
  665. }
  666. }, [props.group, project, projects, projectsLoaded]);
  667. if (props.error) {
  668. return (
  669. <GroupDetailsContentError errorType={props.errorType} onRetry={props.refetchData} />
  670. );
  671. }
  672. if (errorFetchingProjects) {
  673. return <StyledLoadingError message={t('Error loading the specified project')} />;
  674. }
  675. if (projectSlug && !errorFetchingProjects && projectsLoaded && !projectWithFallback) {
  676. return (
  677. <StyledLoadingError message={t('The project %s does not exist', projectSlug)} />
  678. );
  679. }
  680. if (!projectsLoaded || !projectWithFallback || !props.group) {
  681. return <LoadingIndicator />;
  682. }
  683. return (
  684. <GroupDetailsContent {...props} project={projectWithFallback} group={props.group} />
  685. );
  686. }
  687. function GroupDetails(props: GroupDetailsProps) {
  688. const organization = useOrganization();
  689. const router = useRouter();
  690. const {group, ...fetchGroupDetailsProps} = useFetchGroupDetails();
  691. const environments = useEnvironmentsFromUrl();
  692. const {data} = useFetchIssueTagsForDetailsPage(
  693. {
  694. groupId: router.params.groupId,
  695. environment: environments,
  696. },
  697. // Don't want this query to take precedence over the main requests
  698. {enabled: defined(group)}
  699. );
  700. const isSampleError = data?.some(tag => tag.key === 'sample_event') ?? false;
  701. const getGroupDetailsTitle = () => {
  702. const defaultTitle = 'Sentry';
  703. if (!group) {
  704. return defaultTitle;
  705. }
  706. const {title} = getTitle(group, organization?.features);
  707. const message = getMessage(group);
  708. const eventDetails = `${organization.slug} — ${group.project.slug}`;
  709. if (title && message) {
  710. return `${title}: ${message} — ${eventDetails}`;
  711. }
  712. return `${title || message || defaultTitle} — ${eventDetails}`;
  713. };
  714. return (
  715. <Fragment>
  716. {isSampleError && group && (
  717. <SampleEventAlert project={group.project} organization={organization} />
  718. )}
  719. <SentryDocumentTitle noSuffix title={getGroupDetailsTitle()}>
  720. <PageFiltersContainer
  721. skipLoadLastUsed
  722. forceProject={group?.project}
  723. shouldForceProject
  724. >
  725. <GroupDetailsPageContent
  726. {...props}
  727. {...{
  728. group,
  729. ...fetchGroupDetailsProps,
  730. }}
  731. />
  732. </PageFiltersContainer>
  733. </SentryDocumentTitle>
  734. </Fragment>
  735. );
  736. }
  737. export default Sentry.withProfiler(GroupDetails);
  738. const StyledLoadingError = styled(LoadingError)`
  739. margin: ${space(2)};
  740. `;
  741. const GroupTabPanels = styled(TabPanels)`
  742. flex-grow: 1;
  743. display: flex;
  744. flex-direction: column;
  745. justify-content: stretch;
  746. `;