header.tsx 11 KB

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