header.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. import {useMemo} from 'react';
  2. import styled from '@emotion/styled';
  3. import type {LocationDescriptor} from 'history';
  4. import omit from 'lodash/omit';
  5. import GuideAnchor from 'sentry/components/assistant/guideAnchor';
  6. import Badge from 'sentry/components/badge/badge';
  7. import FeatureBadge from 'sentry/components/badge/featureBadge';
  8. import {Breadcrumbs} from 'sentry/components/breadcrumbs';
  9. import Count from 'sentry/components/count';
  10. import EventOrGroupTitle from 'sentry/components/eventOrGroupTitle';
  11. import EventMessage from 'sentry/components/events/eventMessage';
  12. import {GroupStatusBadge} from 'sentry/components/group/inboxBadges/statusBadge';
  13. import * as Layout from 'sentry/components/layouts/thirds';
  14. import Link from 'sentry/components/links/link';
  15. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  16. import ReplayCountBadge from 'sentry/components/replays/replayCountBadge';
  17. import {TabList} from 'sentry/components/tabs';
  18. import {IconChat} from 'sentry/icons';
  19. import {t} from 'sentry/locale';
  20. import {space} from 'sentry/styles/space';
  21. import type {Event, Group, Organization, Project} from 'sentry/types';
  22. import {IssueCategory} from 'sentry/types/group';
  23. import {getMessage} from 'sentry/utils/events';
  24. import {getConfigForIssueType} from 'sentry/utils/issueTypeConfig';
  25. import useReplayCountForIssues from 'sentry/utils/replayCount/useReplayCountForIssues';
  26. import {projectCanLinkToReplay} from 'sentry/utils/replays/projectSupportsReplay';
  27. import useRouteAnalyticsParams from 'sentry/utils/routeAnalytics/useRouteAnalyticsParams';
  28. import {useLocation} from 'sentry/utils/useLocation';
  29. import useOrganization from 'sentry/utils/useOrganization';
  30. import GroupPriority from 'sentry/views/issueDetails/groupPriority';
  31. import GroupActions from './actions';
  32. import {ShortIdBreadcrumb} from './shortIdBreadcrumb';
  33. import {Tab} from './types';
  34. import {ReprocessingStatus} from './utils';
  35. type Props = {
  36. baseUrl: string;
  37. group: Group;
  38. groupReprocessingStatus: ReprocessingStatus;
  39. organization: Organization;
  40. project: Project;
  41. event?: Event;
  42. };
  43. interface GroupHeaderTabsProps extends Pick<Props, 'baseUrl' | 'group' | 'project'> {
  44. disabledTabs: Tab[];
  45. eventRoute: LocationDescriptor;
  46. }
  47. function GroupHeaderTabs({
  48. baseUrl,
  49. disabledTabs,
  50. eventRoute,
  51. group,
  52. project,
  53. }: GroupHeaderTabsProps) {
  54. const organization = useOrganization();
  55. const {getReplayCountForIssue} = useReplayCountForIssues({
  56. statsPeriod: '90d',
  57. });
  58. const replaysCount = getReplayCountForIssue(group.id, group.issueCategory);
  59. const projectFeatures = new Set(project ? project.features : []);
  60. const organizationFeatures = new Set(organization ? organization.features : []);
  61. const hasSimilarView = projectFeatures.has('similarity-view');
  62. const hasEventAttachments = organizationFeatures.has('event-attachments');
  63. const hasReplaySupport =
  64. organizationFeatures.has('session-replay') && projectCanLinkToReplay(project);
  65. const issueTypeConfig = getConfigForIssueType(group, project);
  66. useRouteAnalyticsParams({
  67. group_has_replay: (replaysCount ?? 0) > 0,
  68. });
  69. return (
  70. <StyledTabList hideBorder>
  71. <TabList.Item
  72. key={Tab.DETAILS}
  73. disabled={disabledTabs.includes(Tab.DETAILS)}
  74. to={`${baseUrl}${location.search}`}
  75. >
  76. {t('Details')}
  77. </TabList.Item>
  78. <TabList.Item
  79. key={Tab.ACTIVITY}
  80. textValue={t('Activity')}
  81. disabled={disabledTabs.includes(Tab.ACTIVITY)}
  82. to={`${baseUrl}activity/${location.search}`}
  83. >
  84. {t('Activity')}
  85. <IconBadge>
  86. {group.numComments}
  87. <IconChat size="xs" />
  88. </IconBadge>
  89. </TabList.Item>
  90. <TabList.Item
  91. key={Tab.USER_FEEDBACK}
  92. textValue={t('User Feedback')}
  93. hidden={!issueTypeConfig.userFeedback.enabled}
  94. disabled={disabledTabs.includes(Tab.USER_FEEDBACK)}
  95. to={`${baseUrl}feedback/${location.search}`}
  96. >
  97. {t('User Feedback')} <Badge text={group.userReportCount} />
  98. </TabList.Item>
  99. <TabList.Item
  100. key={Tab.ATTACHMENTS}
  101. hidden={!hasEventAttachments || !issueTypeConfig.attachments.enabled}
  102. disabled={disabledTabs.includes(Tab.ATTACHMENTS)}
  103. to={`${baseUrl}attachments/${location.search}`}
  104. >
  105. {t('Attachments')}
  106. </TabList.Item>
  107. <TabList.Item
  108. key={Tab.TAGS}
  109. hidden={!issueTypeConfig.tags.enabled}
  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. hidden={!issueTypeConfig.events.enabled}
  118. disabled={disabledTabs.includes(Tab.EVENTS)}
  119. to={eventRoute}
  120. >
  121. {group.issueCategory === IssueCategory.ERROR
  122. ? t('All Events')
  123. : t('Sampled Events')}
  124. </TabList.Item>
  125. <TabList.Item
  126. key={Tab.MERGED}
  127. hidden={!issueTypeConfig.mergedIssues.enabled}
  128. disabled={disabledTabs.includes(Tab.MERGED)}
  129. to={`${baseUrl}merged/${location.search}`}
  130. >
  131. {t('Merged Issues')}
  132. </TabList.Item>
  133. <TabList.Item
  134. key={Tab.RELATED_ISSUES}
  135. hidden={!organizationFeatures.has('related-issues')}
  136. to={`${baseUrl}related/${location.search}`}
  137. >
  138. {t('Related Issues')}
  139. </TabList.Item>
  140. <TabList.Item
  141. key={Tab.SIMILAR_ISSUES}
  142. hidden={!hasSimilarView || !issueTypeConfig.similarIssues.enabled}
  143. disabled={disabledTabs.includes(Tab.SIMILAR_ISSUES)}
  144. to={`${baseUrl}similar/${location.search}`}
  145. >
  146. {t('Similar Issues')}
  147. </TabList.Item>
  148. <TabList.Item
  149. key={Tab.REPLAYS}
  150. textValue={t('Replays')}
  151. hidden={!hasReplaySupport || !issueTypeConfig.replays.enabled}
  152. to={`${baseUrl}replays/${location.search}`}
  153. >
  154. {t('Replays')}
  155. <ReplayCountBadge count={replaysCount} />
  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.SIMILAR_ISSUES,
  182. Tab.TAGS,
  183. ];
  184. }
  185. if (groupReprocessingStatus === ReprocessingStatus.REPROCESSED_AND_HASNT_EVENT) {
  186. return [
  187. Tab.DETAILS,
  188. Tab.ATTACHMENTS,
  189. Tab.EVENTS,
  190. Tab.MERGED,
  191. Tab.SIMILAR_ISSUES,
  192. Tab.TAGS,
  193. Tab.USER_FEEDBACK,
  194. ];
  195. }
  196. return [];
  197. }, [organization, groupReprocessingStatus]);
  198. const eventRoute = useMemo(() => {
  199. const searchTermWithoutQuery = omit(location.query, 'query');
  200. return {
  201. pathname: `${baseUrl}events/`,
  202. query: searchTermWithoutQuery,
  203. };
  204. }, [location, baseUrl]);
  205. const {userCount} = group;
  206. let className = 'group-detail';
  207. if (group.hasSeen) {
  208. className += ' hasSeen';
  209. }
  210. if (group.status === 'resolved') {
  211. className += ' isResolved';
  212. }
  213. const message = getMessage(group);
  214. const disableActions = !!disabledTabs.length;
  215. const shortIdBreadcrumb = (
  216. <ShortIdBreadcrumb organization={organization} project={project} group={group} />
  217. );
  218. const issueTypeConfig = getConfigForIssueType(group, project);
  219. return (
  220. <Layout.Header>
  221. <div className={className}>
  222. <BreadcrumbActionWrapper>
  223. <Breadcrumbs
  224. crumbs={[
  225. {
  226. label: 'Issues',
  227. to: {
  228. pathname: `/organizations/${organization.slug}/issues/`,
  229. // Sanitize sort queries from query
  230. query: omit(location.query, 'sort'),
  231. },
  232. },
  233. {label: shortIdBreadcrumb},
  234. ]}
  235. />
  236. <GroupActions
  237. group={group}
  238. project={project}
  239. disabled={disableActions}
  240. event={event}
  241. query={location.query}
  242. />
  243. </BreadcrumbActionWrapper>
  244. <HeaderRow>
  245. <TitleWrapper>
  246. <TitleHeading>
  247. {group.issueCategory === IssueCategory.REPLAY && (
  248. <StyledFeatureBadge type="new" />
  249. )}
  250. <h3>
  251. <StyledEventOrGroupTitle data={group} />
  252. </h3>
  253. <GroupStatusBadge
  254. status={group.status}
  255. substatus={group.substatus}
  256. fontSize="md"
  257. />
  258. </TitleHeading>
  259. <EventMessage
  260. message={message}
  261. level={group.level}
  262. levelIndicatorSize="11px"
  263. type={group.type}
  264. showUnhandled={group.isUnhandled}
  265. />
  266. </TitleWrapper>
  267. {issueTypeConfig.stats.enabled && (
  268. <StatsWrapper>
  269. <GuideAnchor target="issue_header_stats">
  270. <div className="count">
  271. <h6 className="nav-header">{t('Events')}</h6>
  272. <Link disabled={disableActions} to={eventRoute}>
  273. <Count className="count" value={group.count} />
  274. </Link>
  275. </div>
  276. </GuideAnchor>
  277. <div className="count">
  278. <h6 className="nav-header">{t('Users')}</h6>
  279. {userCount !== 0 ? (
  280. <Link
  281. disabled={disableActions}
  282. to={`${baseUrl}tags/user/${location.search}`}
  283. >
  284. <Count className="count" value={userCount} />
  285. </Link>
  286. ) : (
  287. <span>0</span>
  288. )}
  289. </div>
  290. {organization.features.includes('issue-priority-ui') && group.priority ? (
  291. <PriorityContainer>
  292. <h6 className="nav-header">{t('Priority')}</h6>
  293. <GroupPriority group={group} />
  294. </PriorityContainer>
  295. ) : null}
  296. </StatsWrapper>
  297. )}
  298. </HeaderRow>
  299. {/* Environment picker for mobile */}
  300. <HeaderRow className="hidden-sm hidden-md hidden-lg">
  301. <EnvironmentPageFilter position="bottom-end" />
  302. </HeaderRow>
  303. <GroupHeaderTabs {...{baseUrl, disabledTabs, eventRoute, group, project}} />
  304. </div>
  305. </Layout.Header>
  306. );
  307. }
  308. export default GroupHeader;
  309. const BreadcrumbActionWrapper = styled('div')`
  310. display: flex;
  311. flex-direction: row;
  312. justify-content: space-between;
  313. gap: ${space(1)};
  314. align-items: center;
  315. `;
  316. const HeaderRow = styled('div')`
  317. display: flex;
  318. gap: ${space(2)};
  319. justify-content: space-between;
  320. margin-top: ${space(2)};
  321. @media (max-width: ${p => p.theme.breakpoints.small}) {
  322. flex-direction: column;
  323. }
  324. `;
  325. const TitleWrapper = styled('div')`
  326. @media (min-width: ${p => p.theme.breakpoints.small}) {
  327. max-width: 65%;
  328. }
  329. `;
  330. const TitleHeading = styled('div')`
  331. display: flex;
  332. line-height: 2;
  333. gap: ${space(1)};
  334. `;
  335. const StyledEventOrGroupTitle = styled(EventOrGroupTitle)`
  336. font-size: inherit;
  337. `;
  338. const StatsWrapper = styled('div')`
  339. display: flex;
  340. gap: calc(${space(3)} + ${space(3)});
  341. @media (min-width: ${p => p.theme.breakpoints.small}) {
  342. justify-content: flex-end;
  343. }
  344. `;
  345. const IconBadge = styled(Badge)`
  346. display: flex;
  347. align-items: center;
  348. gap: ${space(0.5)};
  349. `;
  350. const StyledTabList = styled(TabList)`
  351. margin-top: ${space(2)};
  352. `;
  353. const PriorityContainer = styled('div')`
  354. /* Ensures that the layout doesn't shift when changing priority */
  355. min-width: 80px;
  356. `;
  357. const StyledFeatureBadge = styled(FeatureBadge)`
  358. align-items: flex-start;
  359. `;