header.tsx 13 KB

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