header.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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.SIMILAR_ISSUES}
  135. hidden={!hasSimilarView || !issueTypeConfig.similarIssues.enabled}
  136. disabled={disabledTabs.includes(Tab.SIMILAR_ISSUES)}
  137. to={`${baseUrl}similar/${location.search}`}
  138. >
  139. {t('Similar Issues')}
  140. </TabList.Item>
  141. <TabList.Item
  142. key={Tab.REPLAYS}
  143. textValue={t('Replays')}
  144. hidden={!hasReplaySupport || !issueTypeConfig.replays.enabled}
  145. to={`${baseUrl}replays/${location.search}`}
  146. >
  147. {t('Replays')}
  148. <ReplayCountBadge count={replaysCount} />
  149. </TabList.Item>
  150. </StyledTabList>
  151. );
  152. }
  153. function GroupHeader({
  154. baseUrl,
  155. group,
  156. groupReprocessingStatus,
  157. organization,
  158. event,
  159. project,
  160. }: Props) {
  161. const location = useLocation();
  162. const disabledTabs = useMemo(() => {
  163. const hasReprocessingV2Feature = organization.features.includes('reprocessing-v2');
  164. if (!hasReprocessingV2Feature) {
  165. return [];
  166. }
  167. if (groupReprocessingStatus === ReprocessingStatus.REPROCESSING) {
  168. return [
  169. Tab.ACTIVITY,
  170. Tab.USER_FEEDBACK,
  171. Tab.ATTACHMENTS,
  172. Tab.EVENTS,
  173. Tab.MERGED,
  174. Tab.SIMILAR_ISSUES,
  175. Tab.TAGS,
  176. ];
  177. }
  178. if (groupReprocessingStatus === ReprocessingStatus.REPROCESSED_AND_HASNT_EVENT) {
  179. return [
  180. Tab.DETAILS,
  181. Tab.ATTACHMENTS,
  182. Tab.EVENTS,
  183. Tab.MERGED,
  184. Tab.SIMILAR_ISSUES,
  185. Tab.TAGS,
  186. Tab.USER_FEEDBACK,
  187. ];
  188. }
  189. return [];
  190. }, [organization, groupReprocessingStatus]);
  191. const eventRoute = useMemo(() => {
  192. const searchTermWithoutQuery = omit(location.query, 'query');
  193. return {
  194. pathname: `${baseUrl}events/`,
  195. query: searchTermWithoutQuery,
  196. };
  197. }, [location, baseUrl]);
  198. const {userCount} = group;
  199. let className = 'group-detail';
  200. if (group.hasSeen) {
  201. className += ' hasSeen';
  202. }
  203. if (group.status === 'resolved') {
  204. className += ' isResolved';
  205. }
  206. const message = getMessage(group);
  207. const disableActions = !!disabledTabs.length;
  208. const shortIdBreadcrumb = (
  209. <ShortIdBreadcrumb organization={organization} project={project} group={group} />
  210. );
  211. const issueTypeConfig = getConfigForIssueType(group, project);
  212. return (
  213. <Layout.Header>
  214. <div className={className}>
  215. <BreadcrumbActionWrapper>
  216. <Breadcrumbs
  217. crumbs={[
  218. {
  219. label: 'Issues',
  220. to: {
  221. pathname: `/organizations/${organization.slug}/issues/`,
  222. // Sanitize sort queries from query
  223. query: omit(location.query, 'sort'),
  224. },
  225. },
  226. {label: shortIdBreadcrumb},
  227. ]}
  228. />
  229. <GroupActions
  230. group={group}
  231. project={project}
  232. disabled={disableActions}
  233. event={event}
  234. query={location.query}
  235. />
  236. </BreadcrumbActionWrapper>
  237. <HeaderRow>
  238. <TitleWrapper>
  239. <TitleHeading>
  240. {group.issueCategory === IssueCategory.REPLAY && (
  241. <StyledFeatureBadge type="new" />
  242. )}
  243. <h3>
  244. <StyledEventOrGroupTitle data={group} />
  245. </h3>
  246. <GroupStatusBadge
  247. status={group.status}
  248. substatus={group.substatus}
  249. fontSize="md"
  250. />
  251. </TitleHeading>
  252. <EventMessage
  253. message={message}
  254. level={group.level}
  255. levelIndicatorSize="11px"
  256. type={group.type}
  257. showUnhandled={group.isUnhandled}
  258. />
  259. </TitleWrapper>
  260. {issueTypeConfig.stats.enabled && (
  261. <StatsWrapper>
  262. <GuideAnchor target="issue_header_stats">
  263. <div className="count">
  264. <h6 className="nav-header">{t('Events')}</h6>
  265. <Link disabled={disableActions} to={eventRoute}>
  266. <Count className="count" value={group.count} />
  267. </Link>
  268. </div>
  269. </GuideAnchor>
  270. <div className="count">
  271. <h6 className="nav-header">{t('Users')}</h6>
  272. {userCount !== 0 ? (
  273. <Link
  274. disabled={disableActions}
  275. to={`${baseUrl}tags/user/${location.search}`}
  276. >
  277. <Count className="count" value={userCount} />
  278. </Link>
  279. ) : (
  280. <span>0</span>
  281. )}
  282. </div>
  283. {organization.features.includes('issue-priority-ui') && group.priority ? (
  284. <PriorityContainer>
  285. <h6 className="nav-header">{t('Priority')}</h6>
  286. <GroupPriority group={group} />
  287. </PriorityContainer>
  288. ) : null}
  289. </StatsWrapper>
  290. )}
  291. </HeaderRow>
  292. {/* Environment picker for mobile */}
  293. <HeaderRow className="hidden-sm hidden-md hidden-lg">
  294. <EnvironmentPageFilter position="bottom-end" />
  295. </HeaderRow>
  296. <GroupHeaderTabs {...{baseUrl, disabledTabs, eventRoute, group, project}} />
  297. </div>
  298. </Layout.Header>
  299. );
  300. }
  301. export default GroupHeader;
  302. const BreadcrumbActionWrapper = styled('div')`
  303. display: flex;
  304. flex-direction: row;
  305. justify-content: space-between;
  306. gap: ${space(1)};
  307. align-items: center;
  308. `;
  309. const HeaderRow = styled('div')`
  310. display: flex;
  311. gap: ${space(2)};
  312. justify-content: space-between;
  313. margin-top: ${space(2)};
  314. @media (max-width: ${p => p.theme.breakpoints.small}) {
  315. flex-direction: column;
  316. }
  317. `;
  318. const TitleWrapper = styled('div')`
  319. @media (min-width: ${p => p.theme.breakpoints.small}) {
  320. max-width: 65%;
  321. }
  322. `;
  323. const TitleHeading = styled('div')`
  324. display: flex;
  325. line-height: 2;
  326. gap: ${space(1)};
  327. `;
  328. const StyledEventOrGroupTitle = styled(EventOrGroupTitle)`
  329. font-size: inherit;
  330. `;
  331. const StatsWrapper = styled('div')`
  332. display: flex;
  333. gap: calc(${space(3)} + ${space(3)});
  334. @media (min-width: ${p => p.theme.breakpoints.small}) {
  335. justify-content: flex-end;
  336. }
  337. `;
  338. const IconBadge = styled(Badge)`
  339. display: flex;
  340. align-items: center;
  341. gap: ${space(0.5)};
  342. `;
  343. const StyledTabList = styled(TabList)`
  344. margin-top: ${space(2)};
  345. `;
  346. const PriorityContainer = styled('div')`
  347. /* Ensures that the layout doesn't shift when changing priority */
  348. min-width: 80px;
  349. `;
  350. const StyledFeatureBadge = styled(FeatureBadge)`
  351. align-items: flex-start;
  352. `;