header.tsx 11 KB

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