groupDetails.tsx 22 KB

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