header.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. import {Fragment, useEffect} from 'react';
  2. import styled from '@emotion/styled';
  3. import type {LocationDescriptor} from 'history';
  4. import omit from 'lodash/omit';
  5. import GuideAnchor from 'sentry/components/assistant/guideAnchor';
  6. import Badge from 'sentry/components/badge/badge';
  7. import FeatureBadge from 'sentry/components/badge/featureBadge';
  8. import {Breadcrumbs} from 'sentry/components/breadcrumbs';
  9. import Count from 'sentry/components/count';
  10. import EventOrGroupTitle from 'sentry/components/eventOrGroupTitle';
  11. import EventMessage from 'sentry/components/events/eventMessage';
  12. import {GroupStatusBadge} from 'sentry/components/group/inboxBadges/statusBadge';
  13. import * as Layout from 'sentry/components/layouts/thirds';
  14. import Link from 'sentry/components/links/link';
  15. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  16. import ReplayCountBadge from 'sentry/components/replays/replayCountBadge';
  17. import {TabList} from 'sentry/components/tabs';
  18. import {IconChat} from 'sentry/icons';
  19. import {t} from 'sentry/locale';
  20. import {space} from 'sentry/styles/space';
  21. import type {Event} from 'sentry/types/event';
  22. import type {Group} from 'sentry/types/group';
  23. import {IssueCategory, IssueType} from 'sentry/types/group';
  24. import type {Organization} from 'sentry/types/organization';
  25. import type {Project} from 'sentry/types/project';
  26. import {trackAnalytics} from 'sentry/utils/analytics';
  27. import {getConfigForIssueType} from 'sentry/utils/issueTypeConfig';
  28. import useReplayCountForIssues from 'sentry/utils/replayCount/useReplayCountForIssues';
  29. import {projectCanLinkToReplay} from 'sentry/utils/replays/projectSupportsReplay';
  30. import useRouteAnalyticsParams from 'sentry/utils/routeAnalytics/useRouteAnalyticsParams';
  31. import {useLocation} from 'sentry/utils/useLocation';
  32. import useOrganization from 'sentry/utils/useOrganization';
  33. import GroupPriority from 'sentry/views/issueDetails/groupPriority';
  34. import {useIssueDetailsHeader} from 'sentry/views/issueDetails/useIssueDetailsHeader';
  35. import {GroupActions} from './actions';
  36. import {Tab, TabPaths} from './types';
  37. import {getGroupReprocessingStatus} from './utils';
  38. type Props = {
  39. baseUrl: string;
  40. event: Event | null;
  41. group: Group;
  42. organization: Organization;
  43. project: Project;
  44. };
  45. interface GroupHeaderTabsProps extends Pick<Props, 'baseUrl' | 'group' | 'project'> {
  46. disabledTabs: Tab[];
  47. eventRoute: LocationDescriptor;
  48. }
  49. export function GroupHeaderTabs({
  50. baseUrl,
  51. disabledTabs,
  52. eventRoute,
  53. group,
  54. project,
  55. }: GroupHeaderTabsProps) {
  56. const organization = useOrganization();
  57. const location = useLocation();
  58. const {getReplayCountForIssue} = useReplayCountForIssues({
  59. statsPeriod: '90d',
  60. });
  61. const replaysCount = getReplayCountForIssue(group.id, group.issueCategory);
  62. // omit `sort` param from the URLs because it persists from the issues list,
  63. // which can cause the tab content rendering to break
  64. const queryParams = omit(location.query, ['sort']);
  65. const projectFeatures = new Set(project ? project.features : []);
  66. const organizationFeatures = new Set(organization ? organization.features : []);
  67. const hasSimilarView = projectFeatures.has('similarity-view');
  68. const hasEventAttachments = organizationFeatures.has('event-attachments');
  69. const hasReplaySupport =
  70. organizationFeatures.has('session-replay') &&
  71. projectCanLinkToReplay(organization, project);
  72. const issueTypeConfig = getConfigForIssueType(group, project);
  73. useRouteAnalyticsParams({
  74. group_has_replay: (replaysCount ?? 0) > 0,
  75. });
  76. useEffect(() => {
  77. if (group.issueType === IssueType.REPLAY_HYDRATION_ERROR) {
  78. trackAnalytics('replay.hydration-error.issue-details-opened', {organization});
  79. }
  80. }, [group.issueType, organization]);
  81. return (
  82. <StyledTabList hideBorder>
  83. <TabList.Item
  84. key={Tab.DETAILS}
  85. disabled={disabledTabs.includes(Tab.DETAILS)}
  86. to={`${baseUrl}${location.search}`}
  87. >
  88. {t('Details')}
  89. </TabList.Item>
  90. <TabList.Item
  91. key={Tab.ACTIVITY}
  92. textValue={t('Activity')}
  93. disabled={disabledTabs.includes(Tab.ACTIVITY)}
  94. to={{pathname: `${baseUrl}activity/`, query: queryParams}}
  95. >
  96. {t('Activity')}
  97. <IconBadge>
  98. {group.numComments}
  99. <IconChat size="xs" />
  100. </IconBadge>
  101. </TabList.Item>
  102. <TabList.Item
  103. key={Tab.USER_FEEDBACK}
  104. textValue={t('User Feedback')}
  105. hidden={!issueTypeConfig.pages.userFeedback.enabled}
  106. disabled={disabledTabs.includes(Tab.USER_FEEDBACK)}
  107. to={{pathname: `${baseUrl}feedback/`, query: queryParams}}
  108. >
  109. {t('User Feedback')} <Badge text={group.userReportCount} />
  110. </TabList.Item>
  111. <TabList.Item
  112. key={Tab.ATTACHMENTS}
  113. hidden={!hasEventAttachments || !issueTypeConfig.pages.attachments.enabled}
  114. disabled={disabledTabs.includes(Tab.ATTACHMENTS)}
  115. to={{pathname: `${baseUrl}attachments/`, query: queryParams}}
  116. >
  117. {t('Attachments')}
  118. </TabList.Item>
  119. <TabList.Item
  120. key={Tab.TAGS}
  121. hidden={!issueTypeConfig.pages.tagsTab.enabled}
  122. disabled={disabledTabs.includes(Tab.TAGS)}
  123. to={{pathname: `${baseUrl}tags/`, query: queryParams}}
  124. >
  125. {t('Tags')}
  126. </TabList.Item>
  127. <TabList.Item
  128. key={Tab.EVENTS}
  129. hidden={!issueTypeConfig.pages.events.enabled}
  130. disabled={disabledTabs.includes(Tab.EVENTS)}
  131. to={eventRoute}
  132. >
  133. {group.issueCategory === IssueCategory.ERROR
  134. ? t('All Events')
  135. : t('Sampled Events')}
  136. </TabList.Item>
  137. <TabList.Item
  138. key={Tab.MERGED}
  139. hidden={!issueTypeConfig.mergedIssues.enabled}
  140. disabled={disabledTabs.includes(Tab.MERGED)}
  141. to={{pathname: `${baseUrl}merged/`, query: queryParams}}
  142. >
  143. {t('Merged Issues')}
  144. </TabList.Item>
  145. <TabList.Item
  146. key={Tab.SIMILAR_ISSUES}
  147. hidden={!hasSimilarView || !issueTypeConfig.similarIssues.enabled}
  148. disabled={disabledTabs.includes(Tab.SIMILAR_ISSUES)}
  149. to={{pathname: `${baseUrl}similar/`, query: queryParams}}
  150. >
  151. {t('Similar Issues')}
  152. </TabList.Item>
  153. <TabList.Item
  154. key={Tab.REPLAYS}
  155. textValue={t('Replays')}
  156. hidden={!hasReplaySupport || !issueTypeConfig.pages.replays.enabled}
  157. to={{pathname: `${baseUrl}replays/`, query: queryParams}}
  158. >
  159. {t('Replays')}
  160. <ReplayCountBadge count={replaysCount} />
  161. </TabList.Item>
  162. <TabList.Item
  163. key={Tab.UPTIME_CHECKS}
  164. textValue={t('Uptime Checks')}
  165. hidden={!issueTypeConfig.pages.checkIns.enabled}
  166. to={{pathname: `${baseUrl}${TabPaths[Tab.UPTIME_CHECKS]}`, query: queryParams}}
  167. >
  168. {t('Uptime Checks')}
  169. </TabList.Item>
  170. </StyledTabList>
  171. );
  172. }
  173. function GroupHeader({baseUrl, group, organization, event, project}: Props) {
  174. const location = useLocation();
  175. const groupReprocessingStatus = getGroupReprocessingStatus(group);
  176. const {
  177. disabledTabs,
  178. message,
  179. eventRoute,
  180. disableActions,
  181. shortIdBreadcrumb,
  182. className,
  183. } = useIssueDetailsHeader({
  184. group,
  185. groupReprocessingStatus,
  186. baseUrl,
  187. project,
  188. });
  189. const {userCount} = group;
  190. const issueTypeConfig = getConfigForIssueType(group, project);
  191. const NEW_ISSUE_TYPES = [IssueType.REPLAY_HYDRATION_ERROR]; // adds a "new" banner next to the title
  192. return (
  193. <Layout.Header>
  194. <div className={className}>
  195. <BreadcrumbActionWrapper>
  196. <Breadcrumbs
  197. crumbs={[
  198. {
  199. label: 'Issues',
  200. to: {
  201. pathname: `/organizations/${organization.slug}/issues/`,
  202. // Sanitize sort queries from query
  203. query: omit(location.query, 'sort'),
  204. },
  205. },
  206. {label: shortIdBreadcrumb},
  207. ]}
  208. />
  209. <GroupActions
  210. group={group}
  211. project={project}
  212. disabled={disableActions}
  213. event={event}
  214. />
  215. </BreadcrumbActionWrapper>
  216. <HeaderRow>
  217. <TitleWrapper>
  218. <TitleHeading>
  219. {NEW_ISSUE_TYPES.includes(group.issueType) && (
  220. <StyledFeatureBadge type="new" />
  221. )}
  222. <h3>
  223. <StyledEventOrGroupTitle data={group} />
  224. </h3>
  225. <GroupStatusBadge
  226. status={group.status}
  227. substatus={group.substatus}
  228. fontSize="md"
  229. />
  230. </TitleHeading>
  231. <EventMessage
  232. data={group}
  233. message={message}
  234. level={group.level}
  235. levelIndicatorSize="11px"
  236. type={group.type}
  237. showUnhandled={group.isUnhandled}
  238. />
  239. </TitleWrapper>
  240. <StatsWrapper>
  241. {issueTypeConfig.stats.enabled && (
  242. <Fragment>
  243. <GuideAnchor target="issue_header_stats">
  244. <div className="count">
  245. <h6 className="nav-header">{t('Events')}</h6>
  246. <Link disabled={disableActions} to={eventRoute}>
  247. <Count className="count" value={group.count} />
  248. </Link>
  249. </div>
  250. </GuideAnchor>
  251. <div className="count">
  252. <h6 className="nav-header">{t('Users')}</h6>
  253. {userCount !== 0 ? (
  254. <Link
  255. disabled={disableActions}
  256. to={`${baseUrl}tags/user/${location.search}`}
  257. >
  258. <Count className="count" value={userCount} />
  259. </Link>
  260. ) : (
  261. <span>0</span>
  262. )}
  263. </div>
  264. </Fragment>
  265. )}
  266. <PriorityContainer>
  267. <h6 className="nav-header">{t('Priority')}</h6>
  268. <GroupPriority group={group} />
  269. </PriorityContainer>
  270. </StatsWrapper>
  271. </HeaderRow>
  272. {/* Environment picker for mobile */}
  273. <HeaderRow className="hidden-sm hidden-md hidden-lg">
  274. <EnvironmentPageFilter position="bottom-end" />
  275. </HeaderRow>
  276. <GroupHeaderTabs {...{baseUrl, disabledTabs, eventRoute, group, project}} />
  277. </div>
  278. </Layout.Header>
  279. );
  280. }
  281. export default GroupHeader;
  282. const BreadcrumbActionWrapper = styled('div')`
  283. display: flex;
  284. flex-direction: row;
  285. justify-content: space-between;
  286. gap: ${space(1)};
  287. align-items: center;
  288. `;
  289. const HeaderRow = styled('div')`
  290. display: flex;
  291. gap: ${space(2)};
  292. justify-content: space-between;
  293. margin-top: ${space(2)};
  294. @media (max-width: ${p => p.theme.breakpoints.small}) {
  295. flex-direction: column;
  296. }
  297. `;
  298. const TitleWrapper = styled('div')`
  299. @media (min-width: ${p => p.theme.breakpoints.small}) {
  300. max-width: 65%;
  301. }
  302. `;
  303. const TitleHeading = styled('div')`
  304. display: flex;
  305. line-height: 2;
  306. gap: ${space(1)};
  307. `;
  308. const StyledEventOrGroupTitle = styled(EventOrGroupTitle)`
  309. font-size: inherit;
  310. `;
  311. const StatsWrapper = styled('div')`
  312. display: flex;
  313. gap: calc(${space(3)} + ${space(3)});
  314. @media (min-width: ${p => p.theme.breakpoints.small}) {
  315. justify-content: flex-end;
  316. }
  317. `;
  318. const IconBadge = styled(Badge)`
  319. display: flex;
  320. align-items: center;
  321. gap: ${space(0.5)};
  322. `;
  323. const StyledTabList = styled(TabList)`
  324. margin-top: ${space(2)};
  325. `;
  326. const PriorityContainer = styled('div')`
  327. /* Ensures that the layout doesn't shift when changing priority */
  328. min-width: 80px;
  329. `;
  330. const StyledFeatureBadge = styled(FeatureBadge)`
  331. align-items: flex-start;
  332. `;