header.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. import {useMemo} from 'react';
  2. import styled from '@emotion/styled';
  3. import {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 InboxReason from 'sentry/components/group/inboxBadges/inboxReason';
  12. import {GroupStatusBadge} from 'sentry/components/group/inboxBadges/statusBadge';
  13. import UnhandledInboxTag from 'sentry/components/group/inboxBadges/unhandledTag';
  14. import * as Layout from 'sentry/components/layouts/thirds';
  15. import Link from 'sentry/components/links/link';
  16. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  17. import ReplayCountBadge from 'sentry/components/replays/replayCountBadge';
  18. import useReplaysCount from 'sentry/components/replays/useReplaysCount';
  19. import {TabList} from 'sentry/components/tabs';
  20. import {IconChat} from 'sentry/icons';
  21. import {t} from 'sentry/locale';
  22. import {space} from 'sentry/styles/space';
  23. import {Event, Group, IssueCategory, Organization, Project} from 'sentry/types';
  24. import {getMessage} from 'sentry/utils/events';
  25. import {getConfigForIssueType} from 'sentry/utils/issueTypeConfig';
  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 GroupActions from './actions';
  31. import {ShortIdBreadrcumb} from './shortIdBreadcrumb';
  32. import {Tab} from './types';
  33. import {TagAndMessageWrapper} from './unhandledTag';
  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 replaysCount = useReplaysCount({
  56. issueCategory: group.issueCategory,
  57. groupIds: group.id,
  58. organization,
  59. })[group.id];
  60. const projectFeatures = new Set(project ? project.features : []);
  61. const organizationFeatures = new Set(organization ? organization.features : []);
  62. const hasSimilarView = projectFeatures.has('similarity-view');
  63. const hasEventAttachments = organizationFeatures.has('event-attachments');
  64. const hasReplaySupport =
  65. organizationFeatures.has('session-replay') && projectCanLinkToReplay(project);
  66. const issueTypeConfig = getConfigForIssueType(group);
  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 hasEscalatingIssuesUi = organization.features.includes('escalating-issues');
  164. const disabledTabs = useMemo(() => {
  165. const hasReprocessingV2Feature = organization.features.includes('reprocessing-v2');
  166. if (!hasReprocessingV2Feature) {
  167. return [];
  168. }
  169. if (groupReprocessingStatus === ReprocessingStatus.REPROCESSING) {
  170. return [
  171. Tab.ACTIVITY,
  172. Tab.USER_FEEDBACK,
  173. Tab.ATTACHMENTS,
  174. Tab.EVENTS,
  175. Tab.MERGED,
  176. Tab.SIMILAR_ISSUES,
  177. Tab.TAGS,
  178. ];
  179. }
  180. if (groupReprocessingStatus === ReprocessingStatus.REPROCESSED_AND_HASNT_EVENT) {
  181. return [
  182. Tab.DETAILS,
  183. Tab.ATTACHMENTS,
  184. Tab.EVENTS,
  185. Tab.MERGED,
  186. Tab.SIMILAR_ISSUES,
  187. Tab.TAGS,
  188. Tab.USER_FEEDBACK,
  189. ];
  190. }
  191. return [];
  192. }, [organization, groupReprocessingStatus]);
  193. const eventRoute = useMemo(() => {
  194. const searchTermWithoutQuery = omit(location.query, 'query');
  195. return {
  196. pathname: `${baseUrl}events/`,
  197. query: searchTermWithoutQuery,
  198. };
  199. }, [location, baseUrl]);
  200. const {userCount} = group;
  201. let className = 'group-detail';
  202. if (group.hasSeen) {
  203. className += ' hasSeen';
  204. }
  205. if (group.status === 'resolved') {
  206. className += ' isResolved';
  207. }
  208. const message = getMessage(group);
  209. const disableActions = !!disabledTabs.length;
  210. const shortIdBreadcrumb = (
  211. <ShortIdBreadrcumb organization={organization} project={project} group={group} />
  212. );
  213. const issueTypeConfig = getConfigForIssueType(group);
  214. return (
  215. <Layout.Header>
  216. <div className={className}>
  217. <BreadcrumbActionWrapper>
  218. <Breadcrumbs
  219. crumbs={[
  220. {
  221. label: 'Issues',
  222. to: {
  223. pathname: `/organizations/${organization.slug}/issues/`,
  224. // Sanitize sort queries from query
  225. query: omit(location.query, 'sort'),
  226. },
  227. },
  228. {label: shortIdBreadcrumb},
  229. ]}
  230. />
  231. <GroupActions
  232. group={group}
  233. project={project}
  234. disabled={disableActions}
  235. event={event}
  236. query={location.query}
  237. />
  238. </BreadcrumbActionWrapper>
  239. <HeaderRow>
  240. <TitleWrapper>
  241. <TitleHeading>
  242. <h3>
  243. <StyledEventOrGroupTitle data={group} />
  244. </h3>
  245. {!hasEscalatingIssuesUi && group.inbox && (
  246. <InboxReason inbox={group.inbox} fontSize="md" />
  247. )}
  248. {hasEscalatingIssuesUi && (
  249. <GroupStatusBadge
  250. status={group.status}
  251. substatus={group.substatus}
  252. fontSize="md"
  253. />
  254. )}
  255. </TitleHeading>
  256. <StyledTagAndMessageWrapper>
  257. {group.level && <ErrorLevel level={group.level} size="11px" />}
  258. {group.isUnhandled && <UnhandledInboxTag />}
  259. <EventMessage message={message} />
  260. </StyledTagAndMessageWrapper>
  261. </TitleWrapper>
  262. {issueTypeConfig.stats.enabled && (
  263. <StatsWrapper>
  264. <div className="count">
  265. <h6 className="nav-header">{t('Events')}</h6>
  266. <Link disabled={disableActions} to={eventRoute}>
  267. <Count className="count" value={group.count} />
  268. </Link>
  269. </div>
  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. </StatsWrapper>
  284. )}
  285. </HeaderRow>
  286. {/* Environment picker for mobile */}
  287. <HeaderRow className="hidden-sm hidden-md hidden-lg">
  288. <EnvironmentPageFilter position="bottom-end" />
  289. </HeaderRow>
  290. <GroupHeaderTabs {...{baseUrl, disabledTabs, eventRoute, group, project}} />
  291. </div>
  292. </Layout.Header>
  293. );
  294. }
  295. export default GroupHeader;
  296. const BreadcrumbActionWrapper = styled('div')`
  297. display: flex;
  298. flex-direction: row;
  299. justify-content: space-between;
  300. gap: ${space(1)};
  301. align-items: center;
  302. `;
  303. const HeaderRow = styled('div')`
  304. display: flex;
  305. gap: ${space(2)};
  306. justify-content: space-between;
  307. margin-top: ${space(2)};
  308. @media (max-width: ${p => p.theme.breakpoints.small}) {
  309. flex-direction: column;
  310. }
  311. `;
  312. const TitleWrapper = styled('div')`
  313. @media (min-width: ${p => p.theme.breakpoints.small}) {
  314. max-width: 65%;
  315. }
  316. `;
  317. const TitleHeading = styled('div')`
  318. display: flex;
  319. line-height: 2;
  320. gap: ${space(1)};
  321. `;
  322. const StyledEventOrGroupTitle = styled(EventOrGroupTitle)`
  323. font-size: inherit;
  324. `;
  325. const StatsWrapper = styled('div')`
  326. display: grid;
  327. grid-template-columns: repeat(2, min-content);
  328. gap: calc(${space(3)} + ${space(3)});
  329. @media (min-width: ${p => p.theme.breakpoints.small}) {
  330. justify-content: flex-end;
  331. }
  332. `;
  333. const StyledTagAndMessageWrapper = styled(TagAndMessageWrapper)`
  334. display: flex;
  335. gap: ${space(1)};
  336. justify-content: flex-start;
  337. line-height: 1.2;
  338. `;
  339. const IconBadge = styled(Badge)`
  340. display: flex;
  341. align-items: center;
  342. gap: ${space(0.5)};
  343. `;
  344. const StyledTabList = styled(TabList)`
  345. margin-top: ${space(2)};
  346. `;