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