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, 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. 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. disabled={disabledTabs.includes(Tab.TAGS)}
  111. to={`${baseUrl}tags/${location.search}`}
  112. >
  113. {t('Tags')}
  114. </TabList.Item>
  115. <TabList.Item
  116. key={Tab.EVENTS}
  117. disabled={disabledTabs.includes(Tab.EVENTS)}
  118. to={eventRoute}
  119. >
  120. {t('All Events')}
  121. </TabList.Item>
  122. <TabList.Item
  123. key={Tab.MERGED}
  124. hidden={!issueTypeConfig.mergedIssues.enabled}
  125. disabled={disabledTabs.includes(Tab.MERGED)}
  126. to={`${baseUrl}merged/${location.search}`}
  127. >
  128. {t('Merged Issues')}
  129. </TabList.Item>
  130. <TabList.Item
  131. key={Tab.SIMILAR_ISSUES}
  132. hidden={!hasSimilarView || !issueTypeConfig.similarIssues.enabled}
  133. disabled={disabledTabs.includes(Tab.SIMILAR_ISSUES)}
  134. to={`${baseUrl}similar/${location.search}`}
  135. >
  136. {t('Similar Issues')}
  137. </TabList.Item>
  138. <TabList.Item
  139. key={Tab.REPLAYS}
  140. textValue={t('Replays')}
  141. hidden={!hasReplaySupport || !issueTypeConfig.replays.enabled}
  142. to={`${baseUrl}replays/${location.search}`}
  143. >
  144. {t('Replays')}
  145. <ReplayCountBadge count={replaysCount} />
  146. </TabList.Item>
  147. </StyledTabList>
  148. );
  149. }
  150. function GroupHeader({
  151. baseUrl,
  152. group,
  153. groupReprocessingStatus,
  154. organization,
  155. event,
  156. project,
  157. }: Props) {
  158. const location = useLocation();
  159. const hasEscalatingIssuesUi = organization.features.includes('escalating-issues');
  160. const disabledTabs = useMemo(() => {
  161. const hasReprocessingV2Feature = organization.features.includes('reprocessing-v2');
  162. if (!hasReprocessingV2Feature) {
  163. return [];
  164. }
  165. if (groupReprocessingStatus === ReprocessingStatus.REPROCESSING) {
  166. return [
  167. Tab.ACTIVITY,
  168. Tab.USER_FEEDBACK,
  169. Tab.ATTACHMENTS,
  170. Tab.EVENTS,
  171. Tab.MERGED,
  172. Tab.SIMILAR_ISSUES,
  173. Tab.TAGS,
  174. ];
  175. }
  176. if (groupReprocessingStatus === ReprocessingStatus.REPROCESSED_AND_HASNT_EVENT) {
  177. return [
  178. Tab.DETAILS,
  179. Tab.ATTACHMENTS,
  180. Tab.EVENTS,
  181. Tab.MERGED,
  182. Tab.SIMILAR_ISSUES,
  183. Tab.TAGS,
  184. Tab.USER_FEEDBACK,
  185. ];
  186. }
  187. return [];
  188. }, [organization, groupReprocessingStatus]);
  189. const eventRoute = useMemo(() => {
  190. const searchTermWithoutQuery = omit(location.query, 'query');
  191. return {
  192. pathname: `${baseUrl}events/`,
  193. query: searchTermWithoutQuery,
  194. };
  195. }, [location, baseUrl]);
  196. const {userCount} = group;
  197. let className = 'group-detail';
  198. if (group.hasSeen) {
  199. className += ' hasSeen';
  200. }
  201. if (group.status === 'resolved') {
  202. className += ' isResolved';
  203. }
  204. const message = getMessage(group);
  205. const disableActions = !!disabledTabs.length;
  206. const shortIdBreadcrumb = (
  207. <ShortIdBreadrcumb organization={organization} project={project} group={group} />
  208. );
  209. return (
  210. <Layout.Header>
  211. <div className={className}>
  212. <BreadcrumbActionWrapper>
  213. <Breadcrumbs
  214. crumbs={[
  215. {
  216. label: 'Issues',
  217. to: `/organizations/${organization.slug}/issues/${location.search}`,
  218. },
  219. {label: shortIdBreadcrumb},
  220. ]}
  221. />
  222. <GroupActions
  223. group={group}
  224. project={project}
  225. disabled={disableActions}
  226. event={event}
  227. query={location.query}
  228. />
  229. </BreadcrumbActionWrapper>
  230. <HeaderRow>
  231. <TitleWrapper>
  232. <TitleHeading>
  233. <h3>
  234. <StyledEventOrGroupTitle data={group} />
  235. </h3>
  236. {!hasEscalatingIssuesUi && group.inbox && (
  237. <InboxReason inbox={group.inbox} fontSize="md" />
  238. )}
  239. {hasEscalatingIssuesUi && (
  240. <GroupStatusBadge
  241. status={group.status}
  242. substatus={group.substatus}
  243. fontSize="md"
  244. />
  245. )}
  246. </TitleHeading>
  247. <StyledTagAndMessageWrapper>
  248. {group.level && <ErrorLevel level={group.level} size="11px" />}
  249. {group.isUnhandled && <UnhandledInboxTag />}
  250. <EventMessage message={message} />
  251. </StyledTagAndMessageWrapper>
  252. </TitleWrapper>
  253. <StatsWrapper
  254. hasGrid={group.issueType !== IssueType.PERFORMANCE_DURATION_REGRESSION}
  255. >
  256. <div className="count">
  257. <h6 className="nav-header">{t('Events')}</h6>
  258. <Link disabled={disableActions} to={eventRoute}>
  259. <Count className="count" value={group.count} />
  260. </Link>
  261. </div>
  262. {group.issueType !== IssueType.PERFORMANCE_DURATION_REGRESSION && (
  263. <div className="count">
  264. <h6 className="nav-header">{t('Users')}</h6>
  265. {userCount !== 0 ? (
  266. <Link
  267. disabled={disableActions}
  268. to={`${baseUrl}tags/user/${location.search}`}
  269. >
  270. <Count className="count" value={userCount} />
  271. </Link>
  272. ) : (
  273. <span>0</span>
  274. )}
  275. </div>
  276. )}
  277. </StatsWrapper>
  278. </HeaderRow>
  279. {/* Environment picker for mobile */}
  280. <HeaderRow className="hidden-sm hidden-md hidden-lg">
  281. <EnvironmentPageFilter alignDropdown="right" />
  282. </HeaderRow>
  283. <GroupHeaderTabs {...{baseUrl, disabledTabs, eventRoute, group, project}} />
  284. </div>
  285. </Layout.Header>
  286. );
  287. }
  288. export default GroupHeader;
  289. const BreadcrumbActionWrapper = styled('div')`
  290. display: flex;
  291. flex-direction: row;
  292. justify-content: space-between;
  293. gap: ${space(1)};
  294. align-items: center;
  295. `;
  296. const HeaderRow = styled('div')`
  297. display: flex;
  298. gap: ${space(2)};
  299. justify-content: space-between;
  300. margin-top: ${space(2)};
  301. @media (max-width: ${p => p.theme.breakpoints.small}) {
  302. flex-direction: column;
  303. }
  304. `;
  305. const TitleWrapper = styled('div')`
  306. @media (min-width: ${p => p.theme.breakpoints.small}) {
  307. max-width: 65%;
  308. }
  309. `;
  310. const TitleHeading = styled('div')`
  311. display: flex;
  312. line-height: 2;
  313. gap: ${space(1)};
  314. `;
  315. const StyledEventOrGroupTitle = styled(EventOrGroupTitle)`
  316. font-size: inherit;
  317. `;
  318. const StatsWrapper = styled('div')<{hasGrid?: boolean}>`
  319. ${p =>
  320. p.hasGrid &&
  321. `
  322. display: grid;
  323. grid-template-columns: repeat(2, min-content);
  324. gap: calc(${space(3)} + ${space(3)});
  325. `}
  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. `;