header.tsx 12 KB

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