header.tsx 13 KB

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