header.tsx 13 KB

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