header.tsx 13 KB

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