header.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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 InboxReason from 'sentry/components/group/inboxBadges/inboxReason';
  14. import {GroupStatusBadge} from 'sentry/components/group/inboxBadges/statusBadge';
  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 useReplaysCount from 'sentry/components/replays/useReplaysCount';
  21. import ShortId from 'sentry/components/shortId';
  22. import {TabList} from 'sentry/components/tabs';
  23. import {Tooltip} from 'sentry/components/tooltip';
  24. import {IconChat} from 'sentry/icons';
  25. import {t} from 'sentry/locale';
  26. import {space} from 'sentry/styles/space';
  27. import {Event, Group, Organization, Project} from 'sentry/types';
  28. import {getMessage} from 'sentry/utils/events';
  29. import {getConfigForIssueType} from 'sentry/utils/issueTypeConfig';
  30. import useRouteAnalyticsParams from 'sentry/utils/routeAnalytics/useRouteAnalyticsParams';
  31. import {useLocation} from 'sentry/utils/useLocation';
  32. import useOrganization from 'sentry/utils/useOrganization';
  33. import GroupActions from './actions';
  34. import {Tab} from './types';
  35. import {TagAndMessageWrapper} from './unhandledTag';
  36. import {ReprocessingStatus} from './utils';
  37. type Props = {
  38. baseUrl: string;
  39. group: Group;
  40. groupReprocessingStatus: ReprocessingStatus;
  41. organization: Organization;
  42. project: Project;
  43. event?: Event;
  44. };
  45. interface GroupHeaderTabsProps extends Pick<Props, 'baseUrl' | 'group' | 'project'> {
  46. disabledTabs: Tab[];
  47. eventRoute: LocationDescriptor;
  48. }
  49. function GroupHeaderTabs({
  50. baseUrl,
  51. disabledTabs,
  52. eventRoute,
  53. group,
  54. project,
  55. }: GroupHeaderTabsProps) {
  56. const organization = useOrganization();
  57. const replaysCount = useReplaysCount({
  58. groupIds: group.id,
  59. organization,
  60. })[group.id];
  61. const projectFeatures = new Set(project ? project.features : []);
  62. const organizationFeatures = new Set(organization ? organization.features : []);
  63. const hasGroupingTreeUI = organizationFeatures.has('grouping-tree-ui');
  64. const hasSimilarView = projectFeatures.has('similarity-view');
  65. const hasEventAttachments = organizationFeatures.has('event-attachments');
  66. const hasReplaySupport = organizationFeatures.has('session-replay');
  67. const issueTypeConfig = getConfigForIssueType(group);
  68. useRouteAnalyticsParams({
  69. group_has_replay: (replaysCount ?? 0) > 0,
  70. });
  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={!hasReplaySupport || !issueTypeConfig.replays.enabled}
  151. to={`${baseUrl}replays/${location.search}`}
  152. >
  153. {t('Replays')}
  154. <ReplayCountBadge count={replaysCount} />
  155. </TabList.Item>
  156. </StyledTabList>
  157. );
  158. }
  159. function GroupHeader({
  160. baseUrl,
  161. group,
  162. groupReprocessingStatus,
  163. organization,
  164. event,
  165. project,
  166. }: Props) {
  167. const location = useLocation();
  168. const hasEscalatingIssuesUi = organization.features.includes('escalating-issues-ui');
  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. </ShortIdBreadrcumb>
  236. </GuideAnchor>
  237. );
  238. return (
  239. <Layout.Header>
  240. <div className={className}>
  241. <BreadcrumbActionWrapper>
  242. <Breadcrumbs
  243. crumbs={[
  244. {
  245. label: 'Issues',
  246. to: `/organizations/${organization.slug}/issues/${location.search}`,
  247. },
  248. {label: shortIdBreadCrumb},
  249. ]}
  250. />
  251. <GroupActions
  252. group={group}
  253. project={project}
  254. disabled={disableActions}
  255. event={event}
  256. query={location.query}
  257. />
  258. </BreadcrumbActionWrapper>
  259. <HeaderRow>
  260. <TitleWrapper>
  261. <TitleHeading>
  262. <h3>
  263. <StyledEventOrGroupTitle data={group} />
  264. </h3>
  265. {!hasEscalatingIssuesUi && group.inbox && (
  266. <InboxReason inbox={group.inbox} fontSize="md" />
  267. )}
  268. {hasEscalatingIssuesUi && (
  269. <GroupStatusBadge
  270. status={group.status}
  271. substatus={group.substatus}
  272. fontSize="md"
  273. />
  274. )}
  275. </TitleHeading>
  276. <StyledTagAndMessageWrapper>
  277. {group.level && <ErrorLevel level={group.level} size="11px" />}
  278. {group.isUnhandled && <UnhandledInboxTag />}
  279. <EventMessage message={message} />
  280. </StyledTagAndMessageWrapper>
  281. </TitleWrapper>
  282. <StatsWrapper>
  283. <div className="count">
  284. <h6 className="nav-header">{t('Events')}</h6>
  285. <Link disabled={disableActions} to={eventRoute}>
  286. <Count className="count" value={group.count} />
  287. </Link>
  288. </div>
  289. <div className="count">
  290. <h6 className="nav-header">{t('Users')}</h6>
  291. {userCount !== 0 ? (
  292. <Link
  293. disabled={disableActions}
  294. to={`${baseUrl}tags/user/${location.search}`}
  295. >
  296. <Count className="count" value={userCount} />
  297. </Link>
  298. ) : (
  299. <span>0</span>
  300. )}
  301. </div>
  302. </StatsWrapper>
  303. </HeaderRow>
  304. {/* Environment picker for mobile */}
  305. <HeaderRow className="hidden-sm hidden-md hidden-lg">
  306. <EnvironmentPageFilter alignDropdown="right" />
  307. </HeaderRow>
  308. <GroupHeaderTabs {...{baseUrl, disabledTabs, eventRoute, group, project}} />
  309. </div>
  310. </Layout.Header>
  311. );
  312. }
  313. export default GroupHeader;
  314. const BreadcrumbActionWrapper = styled('div')`
  315. display: flex;
  316. flex-direction: row;
  317. justify-content: space-between;
  318. gap: ${space(1)};
  319. align-items: center;
  320. `;
  321. const ShortIdBreadrcumb = styled('div')`
  322. display: flex;
  323. gap: ${space(1)};
  324. align-items: center;
  325. `;
  326. const StyledShortId = styled(ShortId)`
  327. font-family: ${p => p.theme.text.family};
  328. font-size: ${p => p.theme.fontSizeMedium};
  329. line-height: 1;
  330. `;
  331. const HeaderRow = styled('div')`
  332. display: flex;
  333. gap: ${space(2)};
  334. justify-content: space-between;
  335. margin-top: ${space(2)};
  336. @media (max-width: ${p => p.theme.breakpoints.small}) {
  337. flex-direction: column;
  338. }
  339. `;
  340. const TitleWrapper = styled('div')`
  341. @media (min-width: ${p => p.theme.breakpoints.small}) {
  342. max-width: 65%;
  343. }
  344. `;
  345. const TitleHeading = styled('div')`
  346. display: flex;
  347. line-height: 2;
  348. gap: ${space(1)};
  349. `;
  350. const StyledEventOrGroupTitle = styled(EventOrGroupTitle)`
  351. font-size: inherit;
  352. `;
  353. const StatsWrapper = styled('div')`
  354. display: grid;
  355. grid-template-columns: repeat(2, min-content);
  356. gap: calc(${space(3)} + ${space(3)});
  357. @media (min-width: ${p => p.theme.breakpoints.small}) {
  358. justify-content: flex-end;
  359. }
  360. `;
  361. const StyledTagAndMessageWrapper = styled(TagAndMessageWrapper)`
  362. display: flex;
  363. gap: ${space(1)};
  364. justify-content: flex-start;
  365. line-height: 1.2;
  366. `;
  367. const IconBadge = styled(Badge)`
  368. display: flex;
  369. align-items: center;
  370. gap: ${space(0.5)};
  371. `;
  372. const StyledTabList = styled(TabList)`
  373. margin-top: ${space(2)};
  374. `;