header.tsx 12 KB

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