header.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. import {useEffect, useMemo} from 'react';
  2. import styled from '@emotion/styled';
  3. import {LocationDescriptor} from 'history';
  4. import omit from 'lodash/omit';
  5. import GuideAnchor from 'sentry/components/assistant/guideAnchor';
  6. import Badge from 'sentry/components/badge';
  7. import Breadcrumbs from 'sentry/components/breadcrumbs';
  8. import Count from 'sentry/components/count';
  9. import EnvironmentPageFilter from 'sentry/components/environmentPageFilter';
  10. import EventOrGroupTitle from 'sentry/components/eventOrGroupTitle';
  11. import ErrorLevel from 'sentry/components/events/errorLevel';
  12. import EventMessage from 'sentry/components/events/eventMessage';
  13. import FeatureBadge from 'sentry/components/featureBadge';
  14. import InboxReason from 'sentry/components/group/inboxBadges/inboxReason';
  15. import {GroupStatusBadge} from 'sentry/components/group/inboxBadges/statusBadge';
  16. import UnhandledInboxTag from 'sentry/components/group/inboxBadges/unhandledTag';
  17. import ProjectBadge from 'sentry/components/idBadge/projectBadge';
  18. import * as Layout from 'sentry/components/layouts/thirds';
  19. import Link from 'sentry/components/links/link';
  20. import ReplayCountBadge from 'sentry/components/replays/replayCountBadge';
  21. import ReplaysFeatureBadge from 'sentry/components/replays/replaysFeatureBadge';
  22. import useReplaysCount from 'sentry/components/replays/useReplaysCount';
  23. import ShortId from 'sentry/components/shortId';
  24. import {TabList} from 'sentry/components/tabs';
  25. import {Tooltip} from 'sentry/components/tooltip';
  26. import {IconChat} from 'sentry/icons';
  27. import {t} from 'sentry/locale';
  28. import {space} from 'sentry/styles/space';
  29. import {Event, Group, IssueType, Organization, Project} from 'sentry/types';
  30. import {trackAnalytics} from 'sentry/utils/analytics';
  31. import {getMessage} from 'sentry/utils/events';
  32. import {getConfigForIssueType} from 'sentry/utils/issueTypeConfig';
  33. import useRouteAnalyticsParams from 'sentry/utils/routeAnalytics/useRouteAnalyticsParams';
  34. import {useLocation} from 'sentry/utils/useLocation';
  35. import useOrganization from 'sentry/utils/useOrganization';
  36. import GroupActions from './actions';
  37. import {Tab} from './types';
  38. import {TagAndMessageWrapper} from './unhandledTag';
  39. import {ReprocessingStatus} from './utils';
  40. type Props = {
  41. baseUrl: string;
  42. group: Group;
  43. groupReprocessingStatus: ReprocessingStatus;
  44. organization: Organization;
  45. project: Project;
  46. event?: Event;
  47. };
  48. interface GroupHeaderTabsProps extends Pick<Props, 'baseUrl' | 'group' | 'project'> {
  49. disabledTabs: Tab[];
  50. eventRoute: LocationDescriptor;
  51. }
  52. function GroupHeaderTabs({
  53. baseUrl,
  54. disabledTabs,
  55. eventRoute,
  56. group,
  57. project,
  58. }: GroupHeaderTabsProps) {
  59. const organization = useOrganization();
  60. const replaysCount = useReplaysCount({
  61. groupIds: group.id,
  62. organization,
  63. })[group.id];
  64. const projectFeatures = new Set(project ? project.features : []);
  65. const organizationFeatures = new Set(organization ? organization.features : []);
  66. const hasGroupingTreeUI = organizationFeatures.has('grouping-tree-ui');
  67. const hasSimilarView = projectFeatures.has('similarity-view');
  68. const hasEventAttachments = organizationFeatures.has('event-attachments');
  69. const hasReplaySupport = organizationFeatures.has('session-replay');
  70. const issueTypeConfig = getConfigForIssueType(group);
  71. useEffect(() => {
  72. if (!hasReplaySupport || typeof replaysCount === 'undefined') {
  73. return;
  74. }
  75. trackAnalytics('replay.render-issues-detail-count', {
  76. platform: project.platform!,
  77. project_id: project.id,
  78. count: replaysCount,
  79. organization,
  80. });
  81. }, [hasReplaySupport, replaysCount, project, organization]);
  82. useRouteAnalyticsParams({
  83. group_has_replay: (replaysCount ?? 0) > 0,
  84. });
  85. return (
  86. <StyledTabList hideBorder>
  87. <TabList.Item
  88. key={Tab.DETAILS}
  89. disabled={disabledTabs.includes(Tab.DETAILS)}
  90. to={`${baseUrl}${location.search}`}
  91. >
  92. {t('Details')}
  93. </TabList.Item>
  94. <TabList.Item
  95. key={Tab.ACTIVITY}
  96. textValue={t('Activity')}
  97. disabled={disabledTabs.includes(Tab.ACTIVITY)}
  98. to={`${baseUrl}activity/${location.search}`}
  99. >
  100. {t('Activity')}
  101. <IconBadge>
  102. {group.numComments}
  103. <IconChat size="xs" />
  104. </IconBadge>
  105. </TabList.Item>
  106. <TabList.Item
  107. key={Tab.USER_FEEDBACK}
  108. textValue={t('User Feedback')}
  109. hidden={!issueTypeConfig.userFeedback.enabled}
  110. disabled={disabledTabs.includes(Tab.USER_FEEDBACK)}
  111. to={`${baseUrl}feedback/${location.search}`}
  112. >
  113. {t('User Feedback')} <Badge text={group.userReportCount} />
  114. </TabList.Item>
  115. <TabList.Item
  116. key={Tab.ATTACHMENTS}
  117. hidden={!hasEventAttachments || !issueTypeConfig.attachments.enabled}
  118. disabled={disabledTabs.includes(Tab.ATTACHMENTS)}
  119. to={`${baseUrl}attachments/${location.search}`}
  120. >
  121. {t('Attachments')}
  122. </TabList.Item>
  123. <TabList.Item
  124. key={Tab.TAGS}
  125. disabled={disabledTabs.includes(Tab.TAGS)}
  126. to={`${baseUrl}tags/${location.search}`}
  127. >
  128. {t('Tags')}
  129. </TabList.Item>
  130. <TabList.Item
  131. key={Tab.EVENTS}
  132. disabled={disabledTabs.includes(Tab.EVENTS)}
  133. to={eventRoute}
  134. >
  135. {t('All Events')}
  136. </TabList.Item>
  137. <TabList.Item
  138. key={Tab.MERGED}
  139. hidden={!issueTypeConfig.mergedIssues.enabled}
  140. disabled={disabledTabs.includes(Tab.MERGED)}
  141. to={`${baseUrl}merged/${location.search}`}
  142. >
  143. {t('Merged Issues')}
  144. </TabList.Item>
  145. <TabList.Item
  146. key={Tab.GROUPING}
  147. hidden={!hasGroupingTreeUI || !issueTypeConfig.grouping.enabled}
  148. disabled={disabledTabs.includes(Tab.GROUPING)}
  149. to={`${baseUrl}grouping/${location.search}`}
  150. >
  151. {t('Grouping')}
  152. </TabList.Item>
  153. <TabList.Item
  154. key={Tab.SIMILAR_ISSUES}
  155. hidden={!hasSimilarView || !issueTypeConfig.similarIssues.enabled}
  156. disabled={disabledTabs.includes(Tab.SIMILAR_ISSUES)}
  157. to={`${baseUrl}similar/${location.search}`}
  158. >
  159. {t('Similar Issues')}
  160. </TabList.Item>
  161. <TabList.Item
  162. key={Tab.REPLAYS}
  163. textValue={t('Replays')}
  164. hidden={!hasReplaySupport || !issueTypeConfig.replays.enabled}
  165. to={`${baseUrl}replays/${location.search}`}
  166. >
  167. {t('Replays')}
  168. <ReplayCountBadge count={replaysCount} />
  169. <ReplaysFeatureBadge tooltipProps={{disabled: true}} />
  170. </TabList.Item>
  171. </StyledTabList>
  172. );
  173. }
  174. function GroupHeader({
  175. baseUrl,
  176. group,
  177. groupReprocessingStatus,
  178. organization,
  179. event,
  180. project,
  181. }: Props) {
  182. const location = useLocation();
  183. const hasEscalatingIssuesUi = organization.features.includes('escalating-issues-ui');
  184. const disabledTabs = useMemo(() => {
  185. const hasReprocessingV2Feature = organization.features.includes('reprocessing-v2');
  186. if (!hasReprocessingV2Feature) {
  187. return [];
  188. }
  189. if (groupReprocessingStatus === ReprocessingStatus.REPROCESSING) {
  190. return [
  191. Tab.ACTIVITY,
  192. Tab.USER_FEEDBACK,
  193. Tab.ATTACHMENTS,
  194. Tab.EVENTS,
  195. Tab.MERGED,
  196. Tab.GROUPING,
  197. Tab.SIMILAR_ISSUES,
  198. Tab.TAGS,
  199. ];
  200. }
  201. if (groupReprocessingStatus === ReprocessingStatus.REPROCESSED_AND_HASNT_EVENT) {
  202. return [
  203. Tab.DETAILS,
  204. Tab.ATTACHMENTS,
  205. Tab.EVENTS,
  206. Tab.MERGED,
  207. Tab.GROUPING,
  208. Tab.SIMILAR_ISSUES,
  209. Tab.TAGS,
  210. Tab.USER_FEEDBACK,
  211. ];
  212. }
  213. return [];
  214. }, [organization, groupReprocessingStatus]);
  215. const eventRoute = useMemo(() => {
  216. const searchTermWithoutQuery = omit(location.query, 'query');
  217. return {
  218. pathname: `${baseUrl}events/`,
  219. query: searchTermWithoutQuery,
  220. };
  221. }, [location, baseUrl]);
  222. const {userCount} = group;
  223. let className = 'group-detail';
  224. if (group.hasSeen) {
  225. className += ' hasSeen';
  226. }
  227. if (group.status === 'resolved') {
  228. className += ' isResolved';
  229. }
  230. const message = getMessage(group);
  231. const disableActions = !!disabledTabs.length;
  232. const shortIdBreadCrumb = group.shortId && (
  233. <GuideAnchor target="issue_number" position="bottom">
  234. <ShortIdBreadrcumb>
  235. <ProjectBadge
  236. project={project}
  237. avatarSize={16}
  238. hideName
  239. avatarProps={{hasTooltip: true, tooltip: project.slug}}
  240. />
  241. <Tooltip
  242. className="help-link"
  243. title={t(
  244. 'This identifier is unique across your organization, and can be used to reference an issue in various places, like commit messages.'
  245. )}
  246. position="bottom"
  247. >
  248. <StyledShortId shortId={group.shortId} />
  249. </Tooltip>
  250. {group.issueType === IssueType.PERFORMANCE_CONSECUTIVE_DB_QUERIES && (
  251. <FeatureBadge
  252. type="alpha"
  253. title={t(
  254. 'Consecutive HTTP Performance Issues are in active development and may change'
  255. )}
  256. />
  257. )}
  258. {group.issueType === IssueType.PERFORMANCE_SLOW_DB_QUERY && (
  259. <FeatureBadge
  260. type="alpha"
  261. title={t(
  262. 'Slow DB Query Performance Issues are in active development and may change'
  263. )}
  264. />
  265. )}
  266. {group.issueType === IssueType.PERFORMANCE_CONSECUTIVE_DB_QUERIES && (
  267. <FeatureBadge
  268. type="beta"
  269. title={t(
  270. 'Consecutive DB Query Performance Issues are in active development and may change'
  271. )}
  272. />
  273. )}
  274. {group.issueType === IssueType.PERFORMANCE_RENDER_BLOCKING_ASSET && (
  275. <FeatureBadge
  276. type="alpha"
  277. title={t(
  278. 'Large Render Blocking Asset Performance Issues are in active development and may change'
  279. )}
  280. />
  281. )}
  282. </ShortIdBreadrcumb>
  283. </GuideAnchor>
  284. );
  285. return (
  286. <Layout.Header>
  287. <div className={className}>
  288. <BreadcrumbActionWrapper>
  289. <Breadcrumbs
  290. crumbs={[
  291. {
  292. label: 'Issues',
  293. to: `/organizations/${organization.slug}/issues/${location.search}`,
  294. },
  295. {label: shortIdBreadCrumb},
  296. ]}
  297. />
  298. <GroupActions
  299. group={group}
  300. project={project}
  301. disabled={disableActions}
  302. event={event}
  303. query={location.query}
  304. />
  305. </BreadcrumbActionWrapper>
  306. <HeaderRow>
  307. <TitleWrapper>
  308. <TitleHeading>
  309. <h3>
  310. <StyledEventOrGroupTitle data={group} />
  311. </h3>
  312. {!hasEscalatingIssuesUi && group.inbox && (
  313. <InboxReason inbox={group.inbox} fontSize="md" />
  314. )}
  315. {hasEscalatingIssuesUi && (
  316. <GroupStatusBadge
  317. status={group.status}
  318. substatus={group.substatus}
  319. fontSize="md"
  320. />
  321. )}
  322. </TitleHeading>
  323. <StyledTagAndMessageWrapper>
  324. {group.level && <ErrorLevel level={group.level} size="11px" />}
  325. {group.isUnhandled && <UnhandledInboxTag />}
  326. <EventMessage message={message} />
  327. </StyledTagAndMessageWrapper>
  328. </TitleWrapper>
  329. <StatsWrapper>
  330. <div className="count">
  331. <h6 className="nav-header">{t('Events')}</h6>
  332. <Link disabled={disableActions} to={eventRoute}>
  333. <Count className="count" value={group.count} />
  334. </Link>
  335. </div>
  336. <div className="count">
  337. <h6 className="nav-header">{t('Users')}</h6>
  338. {userCount !== 0 ? (
  339. <Link
  340. disabled={disableActions}
  341. to={`${baseUrl}tags/user/${location.search}`}
  342. >
  343. <Count className="count" value={userCount} />
  344. </Link>
  345. ) : (
  346. <span>0</span>
  347. )}
  348. </div>
  349. </StatsWrapper>
  350. </HeaderRow>
  351. {/* Environment picker for mobile */}
  352. <HeaderRow className="hidden-sm hidden-md hidden-lg">
  353. <EnvironmentPageFilter alignDropdown="right" />
  354. </HeaderRow>
  355. <GroupHeaderTabs {...{baseUrl, disabledTabs, eventRoute, group, project}} />
  356. </div>
  357. </Layout.Header>
  358. );
  359. }
  360. export default GroupHeader;
  361. const BreadcrumbActionWrapper = styled('div')`
  362. display: flex;
  363. flex-direction: row;
  364. justify-content: space-between;
  365. gap: ${space(1)};
  366. align-items: center;
  367. `;
  368. const ShortIdBreadrcumb = styled('div')`
  369. display: flex;
  370. gap: ${space(1)};
  371. align-items: center;
  372. `;
  373. const StyledShortId = styled(ShortId)`
  374. font-family: ${p => p.theme.text.family};
  375. font-size: ${p => p.theme.fontSizeMedium};
  376. line-height: 1;
  377. `;
  378. const HeaderRow = styled('div')`
  379. display: flex;
  380. gap: ${space(2)};
  381. justify-content: space-between;
  382. margin-top: ${space(2)};
  383. @media (max-width: ${p => p.theme.breakpoints.small}) {
  384. flex-direction: column;
  385. }
  386. `;
  387. const TitleWrapper = styled('div')`
  388. @media (min-width: ${p => p.theme.breakpoints.small}) {
  389. max-width: 65%;
  390. }
  391. `;
  392. const TitleHeading = styled('div')`
  393. display: flex;
  394. line-height: 2;
  395. gap: ${space(1)};
  396. `;
  397. const StyledEventOrGroupTitle = styled(EventOrGroupTitle)`
  398. font-size: inherit;
  399. `;
  400. const StatsWrapper = styled('div')`
  401. display: grid;
  402. grid-template-columns: repeat(2, min-content);
  403. gap: calc(${space(3)} + ${space(3)});
  404. @media (min-width: ${p => p.theme.breakpoints.small}) {
  405. justify-content: flex-end;
  406. }
  407. `;
  408. const StyledTagAndMessageWrapper = styled(TagAndMessageWrapper)`
  409. display: flex;
  410. gap: ${space(1)};
  411. justify-content: flex-start;
  412. line-height: 1.2;
  413. `;
  414. const IconBadge = styled(Badge)`
  415. display: flex;
  416. align-items: center;
  417. gap: ${space(0.5)};
  418. `;
  419. const StyledTabList = styled(TabList)`
  420. margin-top: ${space(2)};
  421. `;