header.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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 {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: `/organizations/${organization.slug}/issues/${location.search}`,
  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. <h3>
  239. <StyledEventOrGroupTitle data={group} />
  240. </h3>
  241. {!hasEscalatingIssuesUi && group.inbox && (
  242. <InboxReason inbox={group.inbox} fontSize="md" />
  243. )}
  244. {hasEscalatingIssuesUi && (
  245. <GroupStatusBadge
  246. status={group.status}
  247. substatus={group.substatus}
  248. fontSize="md"
  249. />
  250. )}
  251. </TitleHeading>
  252. <StyledTagAndMessageWrapper>
  253. {group.level && <ErrorLevel level={group.level} size="11px" />}
  254. {group.isUnhandled && <UnhandledInboxTag />}
  255. <EventMessage message={message} />
  256. </StyledTagAndMessageWrapper>
  257. </TitleWrapper>
  258. {issueTypeConfig.stats.enabled && (
  259. <StatsWrapper>
  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. <div className="count">
  267. <h6 className="nav-header">{t('Users')}</h6>
  268. {userCount !== 0 ? (
  269. <Link
  270. disabled={disableActions}
  271. to={`${baseUrl}tags/user/${location.search}`}
  272. >
  273. <Count className="count" value={userCount} />
  274. </Link>
  275. ) : (
  276. <span>0</span>
  277. )}
  278. </div>
  279. </StatsWrapper>
  280. )}
  281. </HeaderRow>
  282. {/* Environment picker for mobile */}
  283. <HeaderRow className="hidden-sm hidden-md hidden-lg">
  284. <EnvironmentPageFilter alignDropdown="right" />
  285. </HeaderRow>
  286. <GroupHeaderTabs {...{baseUrl, disabledTabs, eventRoute, group, project}} />
  287. </div>
  288. </Layout.Header>
  289. );
  290. }
  291. export default GroupHeader;
  292. const BreadcrumbActionWrapper = styled('div')`
  293. display: flex;
  294. flex-direction: row;
  295. justify-content: space-between;
  296. gap: ${space(1)};
  297. align-items: center;
  298. `;
  299. const HeaderRow = styled('div')`
  300. display: flex;
  301. gap: ${space(2)};
  302. justify-content: space-between;
  303. margin-top: ${space(2)};
  304. @media (max-width: ${p => p.theme.breakpoints.small}) {
  305. flex-direction: column;
  306. }
  307. `;
  308. const TitleWrapper = styled('div')`
  309. @media (min-width: ${p => p.theme.breakpoints.small}) {
  310. max-width: 65%;
  311. }
  312. `;
  313. const TitleHeading = styled('div')`
  314. display: flex;
  315. line-height: 2;
  316. gap: ${space(1)};
  317. `;
  318. const StyledEventOrGroupTitle = styled(EventOrGroupTitle)`
  319. font-size: inherit;
  320. `;
  321. const StatsWrapper = styled('div')`
  322. display: grid;
  323. grid-template-columns: repeat(2, min-content);
  324. gap: calc(${space(3)} + ${space(3)});
  325. @media (min-width: ${p => p.theme.breakpoints.small}) {
  326. justify-content: flex-end;
  327. }
  328. `;
  329. const StyledTagAndMessageWrapper = styled(TagAndMessageWrapper)`
  330. display: flex;
  331. gap: ${space(1)};
  332. justify-content: flex-start;
  333. line-height: 1.2;
  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. `;