groupDetails.tsx 22 KB

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