header.tsx 14 KB

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