header.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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 {TabList} from 'sentry/components/tabs';
  19. import {IconChat} from 'sentry/icons';
  20. import {t} from 'sentry/locale';
  21. import {space} from 'sentry/styles/space';
  22. import {Event, Group, IssueCategory, Organization, Project} 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 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 {getReplayCountForIssue} = useReplayCountForIssues();
  56. const replaysCount = getReplayCountForIssue(group.id);
  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 hasEscalatingIssuesUi = organization.features.includes('escalating-issues');
  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. {!hasEscalatingIssuesUi && group.inbox && (
  243. <InboxReason inbox={group.inbox} fontSize="md" />
  244. )}
  245. {hasEscalatingIssuesUi && (
  246. <GroupStatusBadge
  247. status={group.status}
  248. substatus={group.substatus}
  249. fontSize="md"
  250. />
  251. )}
  252. </TitleHeading>
  253. <StyledTagAndMessageWrapper>
  254. {group.level && <ErrorLevel level={group.level} size="11px" />}
  255. {group.isUnhandled && <UnhandledInboxTag />}
  256. <EventMessage message={message} />
  257. </StyledTagAndMessageWrapper>
  258. </TitleWrapper>
  259. {issueTypeConfig.stats.enabled && (
  260. <StatsWrapper>
  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. <div className="count">
  268. <h6 className="nav-header">{t('Users')}</h6>
  269. {userCount !== 0 ? (
  270. <Link
  271. disabled={disableActions}
  272. to={`${baseUrl}tags/user/${location.search}`}
  273. >
  274. <Count className="count" value={userCount} />
  275. </Link>
  276. ) : (
  277. <span>0</span>
  278. )}
  279. </div>
  280. </StatsWrapper>
  281. )}
  282. </HeaderRow>
  283. {/* Environment picker for mobile */}
  284. <HeaderRow className="hidden-sm hidden-md hidden-lg">
  285. <EnvironmentPageFilter position="bottom-end" />
  286. </HeaderRow>
  287. <GroupHeaderTabs {...{baseUrl, disabledTabs, eventRoute, group, project}} />
  288. </div>
  289. </Layout.Header>
  290. );
  291. }
  292. export default GroupHeader;
  293. const BreadcrumbActionWrapper = styled('div')`
  294. display: flex;
  295. flex-direction: row;
  296. justify-content: space-between;
  297. gap: ${space(1)};
  298. align-items: center;
  299. `;
  300. const HeaderRow = styled('div')`
  301. display: flex;
  302. gap: ${space(2)};
  303. justify-content: space-between;
  304. margin-top: ${space(2)};
  305. @media (max-width: ${p => p.theme.breakpoints.small}) {
  306. flex-direction: column;
  307. }
  308. `;
  309. const TitleWrapper = styled('div')`
  310. @media (min-width: ${p => p.theme.breakpoints.small}) {
  311. max-width: 65%;
  312. }
  313. `;
  314. const TitleHeading = styled('div')`
  315. display: flex;
  316. line-height: 2;
  317. gap: ${space(1)};
  318. `;
  319. const StyledEventOrGroupTitle = styled(EventOrGroupTitle)`
  320. font-size: inherit;
  321. `;
  322. const StatsWrapper = styled('div')`
  323. display: grid;
  324. grid-template-columns: repeat(2, min-content);
  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. `;