header.tsx 13 KB

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