header.tsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  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-ui') && 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_SLOW_DB_QUERY && (
  240. <FeatureBadge
  241. type="alpha"
  242. title={t(
  243. 'Slow DB Query Performance Issues are in active development and may change'
  244. )}
  245. />
  246. )}
  247. {group.issueType === IssueType.PERFORMANCE_CONSECUTIVE_DB_QUERIES && (
  248. <FeatureBadge
  249. type="beta"
  250. title={t(
  251. 'Consecutive DB Query Performance Issues are in active development and may change'
  252. )}
  253. />
  254. )}
  255. {group.issueType === IssueType.PERFORMANCE_RENDER_BLOCKING_ASSET && (
  256. <FeatureBadge
  257. type="alpha"
  258. title={t(
  259. 'Large Render Blocking Asset Performance Issues are in active development and may change'
  260. )}
  261. />
  262. )}
  263. </ShortIdBreadrcumb>
  264. </GuideAnchor>
  265. );
  266. return (
  267. <Layout.Header>
  268. <div className={className}>
  269. <BreadcrumbActionWrapper>
  270. <Breadcrumbs
  271. crumbs={[
  272. {
  273. label: 'Issues',
  274. to: `/organizations/${organization.slug}/issues/${location.search}`,
  275. },
  276. {label: shortIdBreadCrumb},
  277. ]}
  278. />
  279. <GroupActions
  280. group={group}
  281. project={project}
  282. disabled={disableActions}
  283. event={event}
  284. query={location.query}
  285. />
  286. </BreadcrumbActionWrapper>
  287. <HeaderRow>
  288. <TitleWrapper>
  289. <TitleHeading>
  290. <h3>
  291. <StyledEventOrGroupTitle hasGuideAnchor data={group} />
  292. </h3>
  293. {group.inbox && <InboxReason inbox={group.inbox} fontSize="md" />}
  294. </TitleHeading>
  295. <StyledTagAndMessageWrapper>
  296. {group.level && <ErrorLevel level={group.level} size="11px" />}
  297. {group.isUnhandled && <UnhandledInboxTag />}
  298. <EventMessage message={message} />
  299. </StyledTagAndMessageWrapper>
  300. </TitleWrapper>
  301. <StatsWrapper>
  302. <div className="count">
  303. <h6 className="nav-header">{t('Events')}</h6>
  304. <Link disabled={disableActions} to={eventRoute}>
  305. <Count className="count" value={group.count} />
  306. </Link>
  307. </div>
  308. <div className="count">
  309. <h6 className="nav-header">{t('Users')}</h6>
  310. {userCount !== 0 ? (
  311. <Link
  312. disabled={disableActions}
  313. to={`${baseUrl}tags/user/${location.search}`}
  314. >
  315. <Count className="count" value={userCount} />
  316. </Link>
  317. ) : (
  318. <span>0</span>
  319. )}
  320. </div>
  321. </StatsWrapper>
  322. </HeaderRow>
  323. {/* Environment picker for mobile */}
  324. <HeaderRow className="hidden-sm hidden-md hidden-lg">
  325. <EnvironmentPageFilter alignDropdown="right" />
  326. </HeaderRow>
  327. <GroupHeaderTabs {...{baseUrl, disabledTabs, eventRoute, group, project}} />
  328. </div>
  329. </Layout.Header>
  330. );
  331. }
  332. export default GroupHeader;
  333. const BreadcrumbActionWrapper = styled('div')`
  334. display: flex;
  335. flex-direction: row;
  336. justify-content: space-between;
  337. gap: ${space(1)};
  338. align-items: center;
  339. `;
  340. const ShortIdBreadrcumb = styled('div')`
  341. display: flex;
  342. gap: ${space(1)};
  343. align-items: center;
  344. `;
  345. const StyledShortId = styled(ShortId)`
  346. font-family: ${p => p.theme.text.family};
  347. font-size: ${p => p.theme.fontSizeMedium};
  348. line-height: 1;
  349. `;
  350. const HeaderRow = styled('div')`
  351. display: flex;
  352. gap: ${space(2)};
  353. justify-content: space-between;
  354. margin-top: ${space(2)};
  355. @media (max-width: ${p => p.theme.breakpoints.small}) {
  356. flex-direction: column;
  357. }
  358. `;
  359. const TitleWrapper = styled('div')`
  360. @media (min-width: ${p => p.theme.breakpoints.small}) {
  361. max-width: 65%;
  362. }
  363. `;
  364. const TitleHeading = styled('div')`
  365. display: flex;
  366. line-height: 2;
  367. gap: ${space(1)};
  368. `;
  369. const StyledEventOrGroupTitle = styled(EventOrGroupTitle)`
  370. font-size: inherit;
  371. `;
  372. const StatsWrapper = styled('div')`
  373. display: grid;
  374. grid-template-columns: repeat(2, min-content);
  375. gap: calc(${space(3)} + ${space(3)});
  376. @media (min-width: ${p => p.theme.breakpoints.small}) {
  377. justify-content: flex-end;
  378. }
  379. `;
  380. const StyledTagAndMessageWrapper = styled(TagAndMessageWrapper)`
  381. display: flex;
  382. gap: ${space(1)};
  383. justify-content: flex-start;
  384. line-height: 1.2;
  385. `;
  386. const IconBadge = styled(Badge)`
  387. display: flex;
  388. align-items: center;
  389. gap: ${space(0.5)};
  390. `;
  391. const StyledTabList = styled(TabList)`
  392. margin-top: ${space(2)};
  393. `;