header.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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';
  7. import {Breadcrumbs} from 'sentry/components/breadcrumbs';
  8. import Count from 'sentry/components/count';
  9. import EventOrGroupTitle from 'sentry/components/eventOrGroupTitle';
  10. import EventMessage from 'sentry/components/events/eventMessage';
  11. import FeatureBadge from 'sentry/components/featureBadge';
  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';
  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. const replaysCount = getReplayCountForIssue(group.id, group.issueCategory);
  57. const projectFeatures = new Set(project ? project.features : []);
  58. const organizationFeatures = new Set(organization ? organization.features : []);
  59. const hasSimilarView = projectFeatures.has('similarity-view');
  60. const hasEventAttachments = organizationFeatures.has('event-attachments');
  61. const hasReplaySupport =
  62. organizationFeatures.has('session-replay') && projectCanLinkToReplay(project);
  63. const issueTypeConfig = getConfigForIssueType(group, project);
  64. useRouteAnalyticsParams({
  65. group_has_replay: (replaysCount ?? 0) > 0,
  66. });
  67. return (
  68. <StyledTabList hideBorder>
  69. <TabList.Item
  70. key={Tab.DETAILS}
  71. disabled={disabledTabs.includes(Tab.DETAILS)}
  72. to={`${baseUrl}${location.search}`}
  73. >
  74. {t('Details')}
  75. </TabList.Item>
  76. <TabList.Item
  77. key={Tab.ACTIVITY}
  78. textValue={t('Activity')}
  79. disabled={disabledTabs.includes(Tab.ACTIVITY)}
  80. to={`${baseUrl}activity/${location.search}`}
  81. >
  82. {t('Activity')}
  83. <IconBadge>
  84. {group.numComments}
  85. <IconChat size="xs" />
  86. </IconBadge>
  87. </TabList.Item>
  88. <TabList.Item
  89. key={Tab.USER_FEEDBACK}
  90. textValue={t('User Feedback')}
  91. hidden={!issueTypeConfig.userFeedback.enabled}
  92. disabled={disabledTabs.includes(Tab.USER_FEEDBACK)}
  93. to={`${baseUrl}feedback/${location.search}`}
  94. >
  95. {t('User Feedback')} <Badge text={group.userReportCount} />
  96. </TabList.Item>
  97. <TabList.Item
  98. key={Tab.ATTACHMENTS}
  99. hidden={!hasEventAttachments || !issueTypeConfig.attachments.enabled}
  100. disabled={disabledTabs.includes(Tab.ATTACHMENTS)}
  101. to={`${baseUrl}attachments/${location.search}`}
  102. >
  103. {t('Attachments')}
  104. </TabList.Item>
  105. <TabList.Item
  106. key={Tab.TAGS}
  107. hidden={!issueTypeConfig.tags.enabled}
  108. disabled={disabledTabs.includes(Tab.TAGS)}
  109. to={`${baseUrl}tags/${location.search}`}
  110. >
  111. {t('Tags')}
  112. </TabList.Item>
  113. <TabList.Item
  114. key={Tab.EVENTS}
  115. hidden={!issueTypeConfig.events.enabled}
  116. disabled={disabledTabs.includes(Tab.EVENTS)}
  117. to={eventRoute}
  118. >
  119. {group.issueCategory === IssueCategory.ERROR
  120. ? t('All Events')
  121. : t('Sampled 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.RELATED_ISSUES}
  133. hidden={!organizationFeatures.has('related-issues')}
  134. to={`${baseUrl}related/${location.search}`}
  135. >
  136. {t('Related Issues')}
  137. </TabList.Item>
  138. <TabList.Item
  139. key={Tab.SIMILAR_ISSUES}
  140. hidden={!hasSimilarView || !issueTypeConfig.similarIssues.enabled}
  141. disabled={disabledTabs.includes(Tab.SIMILAR_ISSUES)}
  142. to={`${baseUrl}similar/${location.search}`}
  143. >
  144. {t('Similar Issues')}
  145. </TabList.Item>
  146. <TabList.Item
  147. key={Tab.REPLAYS}
  148. textValue={t('Replays')}
  149. hidden={!hasReplaySupport || !issueTypeConfig.replays.enabled}
  150. to={`${baseUrl}replays/${location.search}`}
  151. >
  152. {t('Replays')}
  153. <ReplayCountBadge count={replaysCount} />
  154. </TabList.Item>
  155. </StyledTabList>
  156. );
  157. }
  158. function GroupHeader({
  159. baseUrl,
  160. group,
  161. groupReprocessingStatus,
  162. organization,
  163. event,
  164. project,
  165. }: Props) {
  166. const location = useLocation();
  167. const disabledTabs = useMemo(() => {
  168. const hasReprocessingV2Feature = organization.features.includes('reprocessing-v2');
  169. if (!hasReprocessingV2Feature) {
  170. return [];
  171. }
  172. if (groupReprocessingStatus === ReprocessingStatus.REPROCESSING) {
  173. return [
  174. Tab.ACTIVITY,
  175. Tab.USER_FEEDBACK,
  176. Tab.ATTACHMENTS,
  177. Tab.EVENTS,
  178. Tab.MERGED,
  179. Tab.SIMILAR_ISSUES,
  180. Tab.TAGS,
  181. ];
  182. }
  183. if (groupReprocessingStatus === ReprocessingStatus.REPROCESSED_AND_HASNT_EVENT) {
  184. return [
  185. Tab.DETAILS,
  186. Tab.ATTACHMENTS,
  187. Tab.EVENTS,
  188. Tab.MERGED,
  189. Tab.SIMILAR_ISSUES,
  190. Tab.TAGS,
  191. Tab.USER_FEEDBACK,
  192. ];
  193. }
  194. return [];
  195. }, [organization, groupReprocessingStatus]);
  196. const eventRoute = useMemo(() => {
  197. const searchTermWithoutQuery = omit(location.query, 'query');
  198. return {
  199. pathname: `${baseUrl}events/`,
  200. query: searchTermWithoutQuery,
  201. };
  202. }, [location, baseUrl]);
  203. const {userCount} = group;
  204. let className = 'group-detail';
  205. if (group.hasSeen) {
  206. className += ' hasSeen';
  207. }
  208. if (group.status === 'resolved') {
  209. className += ' isResolved';
  210. }
  211. const message = getMessage(group);
  212. const disableActions = !!disabledTabs.length;
  213. const shortIdBreadcrumb = (
  214. <ShortIdBreadcrumb organization={organization} project={project} group={group} />
  215. );
  216. const issueTypeConfig = getConfigForIssueType(group, project);
  217. return (
  218. <Layout.Header>
  219. <div className={className}>
  220. <BreadcrumbActionWrapper>
  221. <Breadcrumbs
  222. crumbs={[
  223. {
  224. label: 'Issues',
  225. to: {
  226. pathname: `/organizations/${organization.slug}/issues/`,
  227. // Sanitize sort queries from query
  228. query: omit(location.query, 'sort'),
  229. },
  230. },
  231. {label: shortIdBreadcrumb},
  232. ]}
  233. />
  234. <GroupActions
  235. group={group}
  236. project={project}
  237. disabled={disableActions}
  238. event={event}
  239. query={location.query}
  240. />
  241. </BreadcrumbActionWrapper>
  242. <HeaderRow>
  243. <TitleWrapper>
  244. <TitleHeading>
  245. {group.issueCategory === IssueCategory.REPLAY && (
  246. <StyledFeatureBadge type="new" />
  247. )}
  248. <h3>
  249. <StyledEventOrGroupTitle data={group} />
  250. </h3>
  251. <GroupStatusBadge
  252. status={group.status}
  253. substatus={group.substatus}
  254. fontSize="md"
  255. />
  256. </TitleHeading>
  257. <EventMessage
  258. message={message}
  259. level={group.level}
  260. levelIndicatorSize="11px"
  261. type={group.type}
  262. showUnhandled={group.isUnhandled}
  263. />
  264. </TitleWrapper>
  265. {issueTypeConfig.stats.enabled && (
  266. <StatsWrapper>
  267. <GuideAnchor target="issue_header_stats">
  268. <div className="count">
  269. <h6 className="nav-header">{t('Events')}</h6>
  270. <Link disabled={disableActions} to={eventRoute}>
  271. <Count className="count" value={group.count} />
  272. </Link>
  273. </div>
  274. </GuideAnchor>
  275. <div className="count">
  276. <h6 className="nav-header">{t('Users')}</h6>
  277. {userCount !== 0 ? (
  278. <Link
  279. disabled={disableActions}
  280. to={`${baseUrl}tags/user/${location.search}`}
  281. >
  282. <Count className="count" value={userCount} />
  283. </Link>
  284. ) : (
  285. <span>0</span>
  286. )}
  287. </div>
  288. {organization.features.includes('issue-priority-ui') && group.priority ? (
  289. <PriorityContainer>
  290. <h6 className="nav-header">{t('Priority')}</h6>
  291. <GroupPriority group={group} />
  292. </PriorityContainer>
  293. ) : null}
  294. </StatsWrapper>
  295. )}
  296. </HeaderRow>
  297. {/* Environment picker for mobile */}
  298. <HeaderRow className="hidden-sm hidden-md hidden-lg">
  299. <EnvironmentPageFilter position="bottom-end" />
  300. </HeaderRow>
  301. <GroupHeaderTabs {...{baseUrl, disabledTabs, eventRoute, group, project}} />
  302. </div>
  303. </Layout.Header>
  304. );
  305. }
  306. export default GroupHeader;
  307. const BreadcrumbActionWrapper = styled('div')`
  308. display: flex;
  309. flex-direction: row;
  310. justify-content: space-between;
  311. gap: ${space(1)};
  312. align-items: center;
  313. `;
  314. const HeaderRow = styled('div')`
  315. display: flex;
  316. gap: ${space(2)};
  317. justify-content: space-between;
  318. margin-top: ${space(2)};
  319. @media (max-width: ${p => p.theme.breakpoints.small}) {
  320. flex-direction: column;
  321. }
  322. `;
  323. const TitleWrapper = styled('div')`
  324. @media (min-width: ${p => p.theme.breakpoints.small}) {
  325. max-width: 65%;
  326. }
  327. `;
  328. const TitleHeading = styled('div')`
  329. display: flex;
  330. line-height: 2;
  331. gap: ${space(1)};
  332. `;
  333. const StyledEventOrGroupTitle = styled(EventOrGroupTitle)`
  334. font-size: inherit;
  335. `;
  336. const StatsWrapper = styled('div')`
  337. display: flex;
  338. gap: calc(${space(3)} + ${space(3)});
  339. @media (min-width: ${p => p.theme.breakpoints.small}) {
  340. justify-content: flex-end;
  341. }
  342. `;
  343. const IconBadge = styled(Badge)`
  344. display: flex;
  345. align-items: center;
  346. gap: ${space(0.5)};
  347. `;
  348. const StyledTabList = styled(TabList)`
  349. margin-top: ${space(2)};
  350. `;
  351. const PriorityContainer = styled('div')`
  352. /* Ensures that the layout doesn't shift when changing priority */
  353. min-width: 80px;
  354. `;
  355. const StyledFeatureBadge = styled(FeatureBadge)`
  356. align-items: flex-start;
  357. `;