header.tsx 13 KB

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