groupDetails.tsx 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  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 isEmpty from 'lodash/isEmpty';
  14. import * as qs from 'query-string';
  15. import {fetchOrganizationEnvironments} from 'sentry/actionCreators/environments';
  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, GroupRelease, 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 useRouteAnalyticsEventNames from 'sentry/utils/routeAnalytics/useRouteAnalyticsEventNames';
  46. import useRouteAnalyticsParams from 'sentry/utils/routeAnalytics/useRouteAnalyticsParams';
  47. import useApi from 'sentry/utils/useApi';
  48. import {useLocation} from 'sentry/utils/useLocation';
  49. import useOrganization from 'sentry/utils/useOrganization';
  50. import useProjects from 'sentry/utils/useProjects';
  51. import useRouter from 'sentry/utils/useRouter';
  52. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  53. import {ERROR_TYPES} from './constants';
  54. import GroupHeader from './header';
  55. import SampleEventAlert from './sampleEventAlert';
  56. import {Tab, TabPaths} from './types';
  57. import {
  58. getGroupReprocessingStatus,
  59. markEventSeen,
  60. ReprocessingStatus,
  61. useFetchIssueTagsForDetailsPage,
  62. } from './utils';
  63. type Error = (typeof ERROR_TYPES)[keyof typeof ERROR_TYPES] | null;
  64. type RouterParams = {groupId: string; eventId?: string};
  65. type RouteProps = RouteComponentProps<RouterParams, {}>;
  66. type GroupDetailsProps = {
  67. children: React.ReactNode;
  68. environments: string[];
  69. isGlobalSelectionReady: boolean;
  70. organization: Organization;
  71. projects: Project[];
  72. };
  73. type FetchGroupDetailsState = {
  74. error: boolean;
  75. errorType: Error;
  76. event: Event | null;
  77. eventError: boolean;
  78. group: Group | null;
  79. loadingEvent: boolean;
  80. loadingGroup: boolean;
  81. project: Project | null;
  82. refetchData: () => void;
  83. refetchGroup: () => void;
  84. };
  85. interface GroupDetailsContentProps extends GroupDetailsProps, FetchGroupDetailsState {
  86. group: Group;
  87. project: Project;
  88. }
  89. function getGroupQuery({
  90. environments,
  91. }: Pick<GroupDetailsProps, 'environments'>): Record<string, string | string[]> {
  92. // Note, we do not want to include the environment key at all if there are no environments
  93. const query: Record<string, string | string[]> = {
  94. ...(!isEmpty(environments) ? {environment: environments} : {}),
  95. expand: ['inbox', 'owners'],
  96. collapse: ['release', 'tags'],
  97. };
  98. return query;
  99. }
  100. function getFetchDataRequestErrorType(status?: number | null): Error {
  101. if (!status) {
  102. return null;
  103. }
  104. if (status === 404) {
  105. return ERROR_TYPES.GROUP_NOT_FOUND;
  106. }
  107. if (status === 403) {
  108. return ERROR_TYPES.MISSING_MEMBERSHIP;
  109. }
  110. return null;
  111. }
  112. function getCurrentTab({router}: {router: RouteProps['router']}) {
  113. const currentRoute = router.routes[router.routes.length - 1];
  114. // If we're in the tag details page ("/tags/:tagKey/")
  115. if (router.params.tagKey) {
  116. return Tab.TAGS;
  117. }
  118. return (
  119. Object.values(Tab).find(tab => currentRoute.path === TabPaths[tab]) ?? Tab.DETAILS
  120. );
  121. }
  122. function getCurrentRouteInfo({
  123. group,
  124. event,
  125. organization,
  126. router,
  127. }: {
  128. event: Event | null;
  129. group: Group;
  130. organization: Organization;
  131. router: RouteProps['router'];
  132. }): {
  133. baseUrl: string;
  134. currentTab: Tab;
  135. } {
  136. const currentTab = getCurrentTab({router});
  137. const baseUrl = normalizeUrl(
  138. `/organizations/${organization.slug}/issues/${group.id}/${
  139. router.params.eventId && event ? `events/${event.id}/` : ''
  140. }`
  141. );
  142. return {baseUrl, currentTab};
  143. }
  144. function getReprocessingNewRoute({
  145. group,
  146. event,
  147. organization,
  148. router,
  149. }: {
  150. event: Event | null;
  151. group: Group;
  152. organization: Organization;
  153. router: RouteProps['router'];
  154. }) {
  155. const {routes, params, location} = router;
  156. const {groupId} = params;
  157. const {currentTab, baseUrl} = getCurrentRouteInfo({group, event, organization, router});
  158. const hasReprocessingV2Feature = organization.features?.includes('reprocessing-v2');
  159. const {id: nextGroupId} = group;
  160. const reprocessingStatus = getGroupReprocessingStatus(group);
  161. if (groupId !== nextGroupId) {
  162. if (hasReprocessingV2Feature) {
  163. // Redirects to the Activities tab
  164. if (
  165. reprocessingStatus === ReprocessingStatus.REPROCESSED_AND_HASNT_EVENT &&
  166. currentTab !== Tab.ACTIVITY
  167. ) {
  168. return {
  169. pathname: `${baseUrl}${Tab.ACTIVITY}/`,
  170. query: {...params, groupId: nextGroupId},
  171. };
  172. }
  173. }
  174. return recreateRoute('', {
  175. routes,
  176. location,
  177. params: {...params, groupId: nextGroupId},
  178. });
  179. }
  180. if (hasReprocessingV2Feature) {
  181. if (
  182. reprocessingStatus === ReprocessingStatus.REPROCESSING &&
  183. currentTab !== Tab.DETAILS
  184. ) {
  185. return {
  186. pathname: baseUrl,
  187. query: params,
  188. };
  189. }
  190. if (
  191. reprocessingStatus === ReprocessingStatus.REPROCESSED_AND_HASNT_EVENT &&
  192. currentTab !== Tab.ACTIVITY &&
  193. currentTab !== Tab.USER_FEEDBACK
  194. ) {
  195. return {
  196. pathname: `${baseUrl}${Tab.ACTIVITY}/`,
  197. query: params,
  198. };
  199. }
  200. }
  201. return undefined;
  202. }
  203. function useRefetchGroupForReprocessing({
  204. refetchGroup,
  205. }: Pick<FetchGroupDetailsState, 'refetchGroup'>) {
  206. const organization = useOrganization();
  207. const hasReprocessingV2Feature = organization.features?.includes('reprocessing-v2');
  208. useEffect(() => {
  209. let refetchInterval: number;
  210. if (hasReprocessingV2Feature) {
  211. refetchInterval = window.setInterval(refetchGroup, 30000);
  212. }
  213. return () => {
  214. window.clearInterval(refetchInterval);
  215. };
  216. }, [hasReprocessingV2Feature, refetchGroup]);
  217. }
  218. function useFetchOnMount() {
  219. const api = useApi();
  220. const organization = useOrganization();
  221. useEffect(() => {
  222. // Fetch environments early - used in GroupEventDetailsContainer
  223. fetchOrganizationEnvironments(api, organization.slug);
  224. // eslint-disable-next-line react-hooks/exhaustive-deps
  225. }, []);
  226. }
  227. function useEventApiQuery(
  228. eventID: string,
  229. queryKey: [string, {query: {environment?: string[]}}]
  230. ) {
  231. const isLatest = eventID === 'latest';
  232. const latestEventQuery = useApiQuery<Event>(queryKey, {
  233. staleTime: 30000,
  234. cacheTime: 30000,
  235. enabled: isLatest,
  236. retry: (_, error) => error.status !== 404,
  237. });
  238. const otherEventQuery = useApiQuery<Event>(queryKey, {
  239. staleTime: Infinity,
  240. enabled: !isLatest,
  241. retry: (_, error) => error.status !== 404,
  242. });
  243. return isLatest ? latestEventQuery : otherEventQuery;
  244. }
  245. type FetchGroupQueryParameters = {
  246. environments: string[];
  247. groupId: string;
  248. };
  249. function makeFetchGroupQueryKey({
  250. groupId,
  251. environments,
  252. }: FetchGroupQueryParameters): ApiQueryKey {
  253. return [`/issues/${groupId}/`, {query: getGroupQuery({environments})}];
  254. }
  255. /**
  256. * This is a temporary measure to ensure that the GroupStore and query cache
  257. * are both up to date while we are still using both in the issue details page.
  258. * Once we remove all references to GroupStore in the issue details page we
  259. * should remove this.
  260. */
  261. function useSyncGroupStore(incomingEnvs: string[]) {
  262. const queryClient = useQueryClient();
  263. const environmentsRef = useRef<string[]>(incomingEnvs);
  264. environmentsRef.current = incomingEnvs;
  265. const unlisten = useRef<Function>();
  266. if (unlisten.current === undefined) {
  267. unlisten.current = GroupStore.listen(() => {
  268. const [storeGroup] = GroupStore.getState();
  269. const environments = environmentsRef.current;
  270. if (defined(storeGroup)) {
  271. setApiQueryData(
  272. queryClient,
  273. makeFetchGroupQueryKey({groupId: storeGroup.id, environments}),
  274. storeGroup
  275. );
  276. }
  277. }, undefined);
  278. }
  279. useEffect(() => {
  280. return () => unlisten.current?.();
  281. }, []);
  282. }
  283. function useFetchGroupDetails({
  284. isGlobalSelectionReady,
  285. environments,
  286. }: Pick<
  287. GroupDetailsProps,
  288. 'isGlobalSelectionReady' | 'environments'
  289. >): FetchGroupDetailsState {
  290. const api = useApi();
  291. const organization = useOrganization();
  292. const router = useRouter();
  293. const params = router.params;
  294. const {projects} = useProjects();
  295. const [error, setError] = useState<boolean>(false);
  296. const [errorType, setErrorType] = useState<Error | null>(null);
  297. const [event, setEvent] = useState<Event | null>(null);
  298. const [allProjectChanged, setAllProjectChanged] = useState<boolean>(false);
  299. const groupId = params.groupId;
  300. const eventId = params.eventId ?? 'latest';
  301. const eventUrl = `/issues/${groupId}/events/${eventId}/`;
  302. const eventQuery: {environment?: string[]} = {};
  303. if (environments.length !== 0) {
  304. eventQuery.environment = environments;
  305. }
  306. const {
  307. data: eventData,
  308. isLoading: loadingEvent,
  309. isError,
  310. refetch: refetchEvent,
  311. } = useEventApiQuery(eventId, [eventUrl, {query: eventQuery}]);
  312. const {
  313. data: groupData,
  314. isLoading: loadingGroup,
  315. isError: isGroupError,
  316. error: groupError,
  317. refetch: refetchGroupCall,
  318. } = useApiQuery<Group>(makeFetchGroupQueryKey({groupId, environments}), {
  319. staleTime: 30000,
  320. cacheTime: 30000,
  321. enabled: isGlobalSelectionReady,
  322. });
  323. const {data: groupReleaseData} = useApiQuery<GroupRelease>(
  324. [`/issues/${groupId}/first-last-release/`],
  325. {
  326. staleTime: 30000,
  327. cacheTime: 30000,
  328. enabled: defined(groupData),
  329. }
  330. );
  331. const group = groupData ?? null;
  332. useEffect(() => {
  333. if (defined(group)) {
  334. GroupStore.loadInitialData([group]);
  335. if (defined(groupReleaseData)) {
  336. GroupStore.onPopulateReleases(groupId, groupReleaseData);
  337. }
  338. }
  339. }, [groupReleaseData, groupId, group]);
  340. const project =
  341. projects?.find(({id}) => id === group?.project?.id) ?? group?.project ?? null;
  342. useSyncGroupStore(environments);
  343. useEffect(() => {
  344. if (eventData) {
  345. setEvent(eventData);
  346. }
  347. }, [eventData]);
  348. useEffect(() => {
  349. if (group && event) {
  350. const reprocessingNewRoute = getReprocessingNewRoute({
  351. group,
  352. event,
  353. router,
  354. organization,
  355. });
  356. if (reprocessingNewRoute) {
  357. browserHistory.push(reprocessingNewRoute);
  358. return;
  359. }
  360. }
  361. }, [group, event, router, organization]);
  362. useEffect(() => {
  363. const matchingProject = projects?.find(p => p.id === group?.project.id);
  364. if (group && !matchingProject) {
  365. Sentry.withScope(scope => {
  366. const projectIds = projects.map(item => item.id);
  367. scope.setContext('missingProject', {
  368. projectId: group?.project.id,
  369. availableProjects: projectIds,
  370. });
  371. Sentry.captureException(new Error('Project not found'));
  372. });
  373. }
  374. }, [projects, group]);
  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 handleError = useCallback((e: RequestError) => {
  426. Sentry.captureException(e);
  427. setErrorType(getFetchDataRequestErrorType(e?.status));
  428. setError(true);
  429. }, []);
  430. useEffect(() => {
  431. if (isGroupError) {
  432. handleError(groupError);
  433. }
  434. }, [isGroupError, groupError, handleError]);
  435. useTrackView({group, event, project});
  436. const refetchGroup = useCallback(() => {
  437. if (
  438. group?.status !== ReprocessingStatus.REPROCESSING ||
  439. loadingGroup ||
  440. loadingEvent
  441. ) {
  442. return;
  443. }
  444. refetchGroupCall();
  445. }, [group, loadingGroup, loadingEvent, refetchGroupCall]);
  446. const refetchData = useCallback(() => {
  447. // Set initial state
  448. setError(false);
  449. setErrorType(null);
  450. // refetchEvent comes from useApiQuery since event and group data are separately fetched
  451. refetchEvent();
  452. refetchGroup();
  453. }, [refetchGroup, refetchEvent]);
  454. // Refetch when group is stale
  455. useEffect(() => {
  456. if (group) {
  457. if ((group as Group & {stale?: boolean}).stale) {
  458. refetchGroup();
  459. return;
  460. }
  461. }
  462. }, [refetchGroup, group]);
  463. useFetchOnMount();
  464. useRefetchGroupForReprocessing({refetchGroup});
  465. useEffect(() => {
  466. return () => {
  467. GroupStore.reset();
  468. };
  469. }, []);
  470. return {
  471. project,
  472. loadingGroup,
  473. loadingEvent,
  474. group,
  475. event,
  476. errorType,
  477. error,
  478. eventError: isError,
  479. refetchData,
  480. refetchGroup,
  481. };
  482. }
  483. function useTrackView({
  484. group,
  485. event,
  486. project,
  487. }: {
  488. event: Event | null;
  489. group: Group | null;
  490. project: Project | null;
  491. }) {
  492. const location = useLocation();
  493. const {alert_date, alert_rule_id, alert_type, ref_fallback, stream_index, query} =
  494. location.query;
  495. useRouteAnalyticsEventNames('issue_details.viewed', 'Issue Details: Viewed');
  496. useRouteAnalyticsParams({
  497. ...getAnalyticsDataForGroup(group),
  498. ...getAnalyticsDataForEvent(event),
  499. ...getAnalyicsDataForProject(project),
  500. stream_index: typeof stream_index === 'string' ? Number(stream_index) : undefined,
  501. query: typeof query === 'string' ? query : undefined,
  502. // Alert properties track if the user came from email/slack alerts
  503. alert_date:
  504. typeof alert_date === 'string' ? getUtcDateString(Number(alert_date)) : undefined,
  505. alert_rule_id: typeof alert_rule_id === 'string' ? alert_rule_id : undefined,
  506. alert_type: typeof alert_type === 'string' ? alert_type : undefined,
  507. ref_fallback,
  508. // Will be updated by StacktraceLink if there is a stacktrace link
  509. stacktrace_link_viewed: false,
  510. // Will be updated by IssueQuickTrace if there is a trace
  511. trace_status: 'none',
  512. // Will be updated in GroupDetailsHeader if there are replays
  513. group_has_replay: false,
  514. });
  515. }
  516. const trackTabChanged = ({
  517. organization,
  518. project,
  519. group,
  520. event,
  521. tab,
  522. }: {
  523. event: Event | null;
  524. group: Group;
  525. organization: Organization;
  526. project: Project;
  527. tab: Tab;
  528. }) => {
  529. if (!project || !group) {
  530. return;
  531. }
  532. trackAnalytics('issue_details.tab_changed', {
  533. organization,
  534. project_id: parseInt(project.id, 10),
  535. tab,
  536. ...getAnalyticsDataForGroup(group),
  537. });
  538. if (group.issueCategory !== IssueCategory.ERROR) {
  539. return;
  540. }
  541. const analyticsData = event
  542. ? event.tags
  543. .filter(({key}) => ['device', 'os', 'browser'].includes(key))
  544. .reduce((acc, {key, value}) => {
  545. acc[key] = value;
  546. return acc;
  547. }, {})
  548. : {};
  549. trackAnalytics('issue_group_details.tab.clicked', {
  550. organization,
  551. tab,
  552. platform: project.platform,
  553. ...analyticsData,
  554. });
  555. };
  556. function GroupDetailsContentError({
  557. errorType,
  558. onRetry,
  559. }: {
  560. errorType: Error;
  561. onRetry: () => void;
  562. }) {
  563. const organization = useOrganization();
  564. const location = useLocation();
  565. const projectId = location.query.project;
  566. const {projects} = useProjects();
  567. const project = projects.find(proj => proj.id === projectId);
  568. switch (errorType) {
  569. case ERROR_TYPES.GROUP_NOT_FOUND:
  570. return (
  571. <StyledLoadingError
  572. message={t('The issue you were looking for was not found.')}
  573. />
  574. );
  575. case ERROR_TYPES.MISSING_MEMBERSHIP:
  576. return <MissingProjectMembership organization={organization} project={project} />;
  577. default:
  578. return <StyledLoadingError onRetry={onRetry} />;
  579. }
  580. }
  581. function GroupDetailsContent({
  582. environments,
  583. children,
  584. group,
  585. project,
  586. loadingEvent,
  587. eventError,
  588. event,
  589. refetchData,
  590. }: GroupDetailsContentProps) {
  591. const organization = useOrganization();
  592. const router = useRouter();
  593. const {currentTab, baseUrl} = getCurrentRouteInfo({group, event, router, organization});
  594. const groupReprocessingStatus = getGroupReprocessingStatus(group);
  595. useEffect(() => {
  596. if (
  597. currentTab === Tab.DETAILS &&
  598. group &&
  599. event &&
  600. group.id !== event?.groupID &&
  601. !eventError
  602. ) {
  603. // if user pastes only the event id into the url, but it's from another group, redirect to correct group/event
  604. const redirectUrl = `/organizations/${organization.slug}/issues/${event.groupID}/events/${event.id}/`;
  605. router.push(normalizeUrl(redirectUrl));
  606. }
  607. }, [currentTab, event, eventError, group, organization.slug, router]);
  608. const childProps = {
  609. environments,
  610. group,
  611. project,
  612. event,
  613. loadingEvent,
  614. eventError,
  615. groupReprocessingStatus,
  616. onRetry: refetchData,
  617. baseUrl,
  618. };
  619. return (
  620. <Tabs
  621. value={currentTab}
  622. onChange={tab => trackTabChanged({tab, group, project, event, organization})}
  623. >
  624. <GroupHeader
  625. organization={organization}
  626. groupReprocessingStatus={groupReprocessingStatus}
  627. event={event ?? undefined}
  628. group={group}
  629. baseUrl={baseUrl}
  630. project={project as Project}
  631. />
  632. <GroupTabPanels>
  633. <TabPanels.Item key={currentTab}>
  634. {isValidElement(children) ? cloneElement(children, childProps) : children}
  635. </TabPanels.Item>
  636. </GroupTabPanels>
  637. </Tabs>
  638. );
  639. }
  640. function GroupDetailsPageContent(props: GroupDetailsProps & FetchGroupDetailsState) {
  641. const {
  642. projects,
  643. initiallyLoaded: projectsLoaded,
  644. fetchError: errorFetchingProjects,
  645. } = useProjects({slugs: props.project?.slug ? [props.project.slug] : []});
  646. const project =
  647. (props.project?.slug
  648. ? projects.find(({slug}) => slug === props.project?.slug)
  649. : undefined) ?? projects[0];
  650. if (props.error) {
  651. return (
  652. <GroupDetailsContentError errorType={props.errorType} onRetry={props.refetchData} />
  653. );
  654. }
  655. if (errorFetchingProjects) {
  656. return <StyledLoadingError message={t('Error loading the specified project')} />;
  657. }
  658. if (!projectsLoaded || !project || !props.group) {
  659. return <LoadingIndicator />;
  660. }
  661. return <GroupDetailsContent {...props} project={project} group={props.group} />;
  662. }
  663. function GroupDetails(props: GroupDetailsProps) {
  664. const organization = useOrganization();
  665. const router = useRouter();
  666. const {project, group, ...fetchGroupDetailsProps} = useFetchGroupDetails(props);
  667. const {data} = useFetchIssueTagsForDetailsPage(
  668. {
  669. groupId: router.params.groupId,
  670. environment: props.environments,
  671. },
  672. // Don't want this query to take precedence over the main requests
  673. {enabled: props.isGlobalSelectionReady && defined(group)}
  674. );
  675. const isSampleError = data?.some(tag => tag.key === 'sample_event') ?? false;
  676. const getGroupDetailsTitle = () => {
  677. const defaultTitle = 'Sentry';
  678. if (!group) {
  679. return defaultTitle;
  680. }
  681. const {title} = getTitle(group, organization?.features);
  682. const message = getMessage(group);
  683. const eventDetails = `${organization.slug} - ${group.project.slug}`;
  684. if (title && message) {
  685. return `${title}: ${message} - ${eventDetails}`;
  686. }
  687. return `${title || message || defaultTitle} - ${eventDetails}`;
  688. };
  689. return (
  690. <Fragment>
  691. {isSampleError && project && (
  692. <SampleEventAlert project={project} organization={organization} />
  693. )}
  694. <SentryDocumentTitle noSuffix title={getGroupDetailsTitle()}>
  695. <PageFiltersContainer skipLoadLastUsed forceProject={project} shouldForceProject>
  696. <GroupDetailsPageContent
  697. {...props}
  698. {...{
  699. group,
  700. project,
  701. ...fetchGroupDetailsProps,
  702. }}
  703. />
  704. </PageFiltersContainer>
  705. </SentryDocumentTitle>
  706. </Fragment>
  707. );
  708. }
  709. export default Sentry.withProfiler(GroupDetails);
  710. const StyledLoadingError = styled(LoadingError)`
  711. margin: ${space(2)};
  712. `;
  713. const GroupTabPanels = styled(TabPanels)`
  714. flex-grow: 1;
  715. display: flex;
  716. flex-direction: column;
  717. justify-content: stretch;
  718. `;