groupDetails.tsx 22 KB

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