header.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  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 {GroupStatusBadge} from 'sentry/components/group/inboxBadges/statusBadge';
  16. import UnhandledInboxTag from 'sentry/components/group/inboxBadges/unhandledTag';
  17. import ProjectBadge from 'sentry/components/idBadge/projectBadge';
  18. import * as Layout from 'sentry/components/layouts/thirds';
  19. import Link from 'sentry/components/links/link';
  20. import ReplayCountBadge from 'sentry/components/replays/replayCountBadge';
  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. </TabList.Item>
  169. </StyledTabList>
  170. );
  171. }
  172. function GroupHeader({
  173. baseUrl,
  174. group,
  175. groupReprocessingStatus,
  176. organization,
  177. event,
  178. project,
  179. }: Props) {
  180. const location = useLocation();
  181. const hasEscalatingIssuesUi = organization.features.includes('escalating-issues-ui');
  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 data={group} />
  309. </h3>
  310. {!hasEscalatingIssuesUi && group.inbox && (
  311. <InboxReason inbox={group.inbox} fontSize="md" />
  312. )}
  313. {hasEscalatingIssuesUi && (
  314. <GroupStatusBadge
  315. status={group.status}
  316. substatus={group.substatus}
  317. fontSize="md"
  318. />
  319. )}
  320. </TitleHeading>
  321. <StyledTagAndMessageWrapper>
  322. {group.level && <ErrorLevel level={group.level} size="11px" />}
  323. {group.isUnhandled && <UnhandledInboxTag />}
  324. <EventMessage message={message} />
  325. </StyledTagAndMessageWrapper>
  326. </TitleWrapper>
  327. <StatsWrapper>
  328. <div className="count">
  329. <h6 className="nav-header">{t('Events')}</h6>
  330. <Link disabled={disableActions} to={eventRoute}>
  331. <Count className="count" value={group.count} />
  332. </Link>
  333. </div>
  334. <div className="count">
  335. <h6 className="nav-header">{t('Users')}</h6>
  336. {userCount !== 0 ? (
  337. <Link
  338. disabled={disableActions}
  339. to={`${baseUrl}tags/user/${location.search}`}
  340. >
  341. <Count className="count" value={userCount} />
  342. </Link>
  343. ) : (
  344. <span>0</span>
  345. )}
  346. </div>
  347. </StatsWrapper>
  348. </HeaderRow>
  349. {/* Environment picker for mobile */}
  350. <HeaderRow className="hidden-sm hidden-md hidden-lg">
  351. <EnvironmentPageFilter alignDropdown="right" />
  352. </HeaderRow>
  353. <GroupHeaderTabs {...{baseUrl, disabledTabs, eventRoute, group, project}} />
  354. </div>
  355. </Layout.Header>
  356. );
  357. }
  358. export default GroupHeader;
  359. const BreadcrumbActionWrapper = styled('div')`
  360. display: flex;
  361. flex-direction: row;
  362. justify-content: space-between;
  363. gap: ${space(1)};
  364. align-items: center;
  365. `;
  366. const ShortIdBreadrcumb = styled('div')`
  367. display: flex;
  368. gap: ${space(1)};
  369. align-items: center;
  370. `;
  371. const StyledShortId = styled(ShortId)`
  372. font-family: ${p => p.theme.text.family};
  373. font-size: ${p => p.theme.fontSizeMedium};
  374. line-height: 1;
  375. `;
  376. const HeaderRow = styled('div')`
  377. display: flex;
  378. gap: ${space(2)};
  379. justify-content: space-between;
  380. margin-top: ${space(2)};
  381. @media (max-width: ${p => p.theme.breakpoints.small}) {
  382. flex-direction: column;
  383. }
  384. `;
  385. const TitleWrapper = styled('div')`
  386. @media (min-width: ${p => p.theme.breakpoints.small}) {
  387. max-width: 65%;
  388. }
  389. `;
  390. const TitleHeading = styled('div')`
  391. display: flex;
  392. line-height: 2;
  393. gap: ${space(1)};
  394. `;
  395. const StyledEventOrGroupTitle = styled(EventOrGroupTitle)`
  396. font-size: inherit;
  397. `;
  398. const StatsWrapper = styled('div')`
  399. display: grid;
  400. grid-template-columns: repeat(2, min-content);
  401. gap: calc(${space(3)} + ${space(3)});
  402. @media (min-width: ${p => p.theme.breakpoints.small}) {
  403. justify-content: flex-end;
  404. }
  405. `;
  406. const StyledTagAndMessageWrapper = styled(TagAndMessageWrapper)`
  407. display: flex;
  408. gap: ${space(1)};
  409. justify-content: flex-start;
  410. line-height: 1.2;
  411. `;
  412. const IconBadge = styled(Badge)`
  413. display: flex;
  414. align-items: center;
  415. gap: ${space(0.5)};
  416. `;
  417. const StyledTabList = styled(TabList)`
  418. margin-top: ${space(2)};
  419. `;