header.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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, IssueType, 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. groupIds: group.id,
  57. organization,
  58. })[group.id];
  59. const projectFeatures = new Set(project ? project.features : []);
  60. const organizationFeatures = new Set(organization ? organization.features : []);
  61. const hasSimilarView = projectFeatures.has('similarity-view');
  62. const hasEventAttachments = organizationFeatures.has('event-attachments');
  63. const hasReplaySupport =
  64. organizationFeatures.has('session-replay') && projectCanLinkToReplay(project);
  65. const issueTypeConfig = getConfigForIssueType(group);
  66. useRouteAnalyticsParams({
  67. group_has_replay: (replaysCount ?? 0) > 0,
  68. });
  69. return (
  70. <StyledTabList hideBorder>
  71. <TabList.Item
  72. key={Tab.DETAILS}
  73. disabled={disabledTabs.includes(Tab.DETAILS)}
  74. to={`${baseUrl}${location.search}`}
  75. >
  76. {t('Details')}
  77. </TabList.Item>
  78. <TabList.Item
  79. key={Tab.ACTIVITY}
  80. textValue={t('Activity')}
  81. disabled={disabledTabs.includes(Tab.ACTIVITY)}
  82. to={`${baseUrl}activity/${location.search}`}
  83. >
  84. {t('Activity')}
  85. <IconBadge>
  86. {group.numComments}
  87. <IconChat size="xs" />
  88. </IconBadge>
  89. </TabList.Item>
  90. <TabList.Item
  91. key={Tab.USER_FEEDBACK}
  92. textValue={t('User Feedback')}
  93. hidden={!issueTypeConfig.userFeedback.enabled}
  94. disabled={disabledTabs.includes(Tab.USER_FEEDBACK)}
  95. to={`${baseUrl}feedback/${location.search}`}
  96. >
  97. {t('User Feedback')} <Badge text={group.userReportCount} />
  98. </TabList.Item>
  99. <TabList.Item
  100. key={Tab.ATTACHMENTS}
  101. hidden={!hasEventAttachments || !issueTypeConfig.attachments.enabled}
  102. disabled={disabledTabs.includes(Tab.ATTACHMENTS)}
  103. to={`${baseUrl}attachments/${location.search}`}
  104. >
  105. {t('Attachments')}
  106. </TabList.Item>
  107. <TabList.Item
  108. key={Tab.TAGS}
  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. disabled={disabledTabs.includes(Tab.EVENTS)}
  117. to={eventRoute}
  118. >
  119. {t('All Events')}
  120. </TabList.Item>
  121. <TabList.Item
  122. key={Tab.MERGED}
  123. hidden={!issueTypeConfig.mergedIssues.enabled}
  124. disabled={disabledTabs.includes(Tab.MERGED)}
  125. to={`${baseUrl}merged/${location.search}`}
  126. >
  127. {t('Merged Issues')}
  128. </TabList.Item>
  129. <TabList.Item
  130. key={Tab.SIMILAR_ISSUES}
  131. hidden={!hasSimilarView || !issueTypeConfig.similarIssues.enabled}
  132. disabled={disabledTabs.includes(Tab.SIMILAR_ISSUES)}
  133. to={`${baseUrl}similar/${location.search}`}
  134. >
  135. {t('Similar Issues')}
  136. </TabList.Item>
  137. <TabList.Item
  138. key={Tab.REPLAYS}
  139. textValue={t('Replays')}
  140. hidden={!hasReplaySupport || !issueTypeConfig.replays.enabled}
  141. to={`${baseUrl}replays/${location.search}`}
  142. >
  143. {t('Replays')}
  144. <ReplayCountBadge count={replaysCount} />
  145. </TabList.Item>
  146. </StyledTabList>
  147. );
  148. }
  149. function GroupHeader({
  150. baseUrl,
  151. group,
  152. groupReprocessingStatus,
  153. organization,
  154. event,
  155. project,
  156. }: Props) {
  157. const location = useLocation();
  158. const hasEscalatingIssuesUi = organization.features.includes('escalating-issues');
  159. const disabledTabs = useMemo(() => {
  160. const hasReprocessingV2Feature = organization.features.includes('reprocessing-v2');
  161. if (!hasReprocessingV2Feature) {
  162. return [];
  163. }
  164. if (groupReprocessingStatus === ReprocessingStatus.REPROCESSING) {
  165. return [
  166. Tab.ACTIVITY,
  167. Tab.USER_FEEDBACK,
  168. Tab.ATTACHMENTS,
  169. Tab.EVENTS,
  170. Tab.MERGED,
  171. Tab.SIMILAR_ISSUES,
  172. Tab.TAGS,
  173. ];
  174. }
  175. if (groupReprocessingStatus === ReprocessingStatus.REPROCESSED_AND_HASNT_EVENT) {
  176. return [
  177. Tab.DETAILS,
  178. Tab.ATTACHMENTS,
  179. Tab.EVENTS,
  180. Tab.MERGED,
  181. Tab.SIMILAR_ISSUES,
  182. Tab.TAGS,
  183. Tab.USER_FEEDBACK,
  184. ];
  185. }
  186. return [];
  187. }, [organization, groupReprocessingStatus]);
  188. const eventRoute = useMemo(() => {
  189. const searchTermWithoutQuery = omit(location.query, 'query');
  190. return {
  191. pathname: `${baseUrl}events/`,
  192. query: searchTermWithoutQuery,
  193. };
  194. }, [location, baseUrl]);
  195. const {userCount} = group;
  196. let className = 'group-detail';
  197. if (group.hasSeen) {
  198. className += ' hasSeen';
  199. }
  200. if (group.status === 'resolved') {
  201. className += ' isResolved';
  202. }
  203. const message = getMessage(group);
  204. const disableActions = !!disabledTabs.length;
  205. const shortIdBreadcrumb = (
  206. <ShortIdBreadrcumb organization={organization} project={project} group={group} />
  207. );
  208. return (
  209. <Layout.Header>
  210. <div className={className}>
  211. <BreadcrumbActionWrapper>
  212. <Breadcrumbs
  213. crumbs={[
  214. {
  215. label: 'Issues',
  216. to: `/organizations/${organization.slug}/issues/${location.search}`,
  217. },
  218. {label: shortIdBreadcrumb},
  219. ]}
  220. />
  221. <GroupActions
  222. group={group}
  223. project={project}
  224. disabled={disableActions}
  225. event={event}
  226. query={location.query}
  227. />
  228. </BreadcrumbActionWrapper>
  229. <HeaderRow>
  230. <TitleWrapper>
  231. <TitleHeading>
  232. <h3>
  233. <StyledEventOrGroupTitle data={group} />
  234. </h3>
  235. {!hasEscalatingIssuesUi && group.inbox && (
  236. <InboxReason inbox={group.inbox} fontSize="md" />
  237. )}
  238. {hasEscalatingIssuesUi && (
  239. <GroupStatusBadge
  240. status={group.status}
  241. substatus={group.substatus}
  242. fontSize="md"
  243. />
  244. )}
  245. </TitleHeading>
  246. <StyledTagAndMessageWrapper>
  247. {group.level && <ErrorLevel level={group.level} size="11px" />}
  248. {group.isUnhandled && <UnhandledInboxTag />}
  249. <EventMessage message={message} />
  250. </StyledTagAndMessageWrapper>
  251. </TitleWrapper>
  252. <StatsWrapper
  253. hasGrid={group.issueType !== IssueType.PERFORMANCE_DURATION_REGRESSION}
  254. >
  255. <div className="count">
  256. <h6 className="nav-header">{t('Events')}</h6>
  257. <Link disabled={disableActions} to={eventRoute}>
  258. <Count className="count" value={group.count} />
  259. </Link>
  260. </div>
  261. {group.issueType !== IssueType.PERFORMANCE_DURATION_REGRESSION && (
  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. )}
  276. </StatsWrapper>
  277. </HeaderRow>
  278. {/* Environment picker for mobile */}
  279. <HeaderRow className="hidden-sm hidden-md hidden-lg">
  280. <EnvironmentPageFilter alignDropdown="right" />
  281. </HeaderRow>
  282. <GroupHeaderTabs {...{baseUrl, disabledTabs, eventRoute, group, project}} />
  283. </div>
  284. </Layout.Header>
  285. );
  286. }
  287. export default GroupHeader;
  288. const BreadcrumbActionWrapper = styled('div')`
  289. display: flex;
  290. flex-direction: row;
  291. justify-content: space-between;
  292. gap: ${space(1)};
  293. align-items: center;
  294. `;
  295. const HeaderRow = styled('div')`
  296. display: flex;
  297. gap: ${space(2)};
  298. justify-content: space-between;
  299. margin-top: ${space(2)};
  300. @media (max-width: ${p => p.theme.breakpoints.small}) {
  301. flex-direction: column;
  302. }
  303. `;
  304. const TitleWrapper = styled('div')`
  305. @media (min-width: ${p => p.theme.breakpoints.small}) {
  306. max-width: 65%;
  307. }
  308. `;
  309. const TitleHeading = styled('div')`
  310. display: flex;
  311. line-height: 2;
  312. gap: ${space(1)};
  313. `;
  314. const StyledEventOrGroupTitle = styled(EventOrGroupTitle)`
  315. font-size: inherit;
  316. `;
  317. const StatsWrapper = styled('div')<{hasGrid?: boolean}>`
  318. ${p =>
  319. p.hasGrid &&
  320. `
  321. display: grid;
  322. grid-template-columns: repeat(2, min-content);
  323. gap: calc(${space(3)} + ${space(3)});
  324. `}
  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. `;