header.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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} 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.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.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.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.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.replays.enabled}
  157. to={{pathname: `${baseUrl}replays/`, query: queryParams}}
  158. >
  159. {t('Replays')}
  160. <ReplayCountBadge count={replaysCount} />
  161. </TabList.Item>
  162. </StyledTabList>
  163. );
  164. }
  165. function GroupHeader({baseUrl, group, organization, event, project}: Props) {
  166. const location = useLocation();
  167. const groupReprocessingStatus = getGroupReprocessingStatus(group);
  168. const {
  169. disabledTabs,
  170. message,
  171. eventRoute,
  172. disableActions,
  173. shortIdBreadcrumb,
  174. className,
  175. } = useIssueDetailsHeader({
  176. group,
  177. groupReprocessingStatus,
  178. baseUrl,
  179. project,
  180. });
  181. const {userCount} = group;
  182. const issueTypeConfig = getConfigForIssueType(group, project);
  183. const NEW_ISSUE_TYPES = [IssueType.REPLAY_HYDRATION_ERROR]; // adds a "new" banner next to the title
  184. return (
  185. <Layout.Header>
  186. <div className={className}>
  187. <BreadcrumbActionWrapper>
  188. <Breadcrumbs
  189. crumbs={[
  190. {
  191. label: 'Issues',
  192. to: {
  193. pathname: `/organizations/${organization.slug}/issues/`,
  194. // Sanitize sort queries from query
  195. query: omit(location.query, 'sort'),
  196. },
  197. },
  198. {label: shortIdBreadcrumb},
  199. ]}
  200. />
  201. <GroupActions
  202. group={group}
  203. project={project}
  204. disabled={disableActions}
  205. event={event}
  206. query={location.query}
  207. />
  208. </BreadcrumbActionWrapper>
  209. <HeaderRow>
  210. <TitleWrapper>
  211. <TitleHeading>
  212. {NEW_ISSUE_TYPES.includes(group.issueType) && (
  213. <StyledFeatureBadge type="new" />
  214. )}
  215. <h3>
  216. <StyledEventOrGroupTitle data={group} />
  217. </h3>
  218. <GroupStatusBadge
  219. status={group.status}
  220. substatus={group.substatus}
  221. fontSize="md"
  222. />
  223. </TitleHeading>
  224. <EventMessage
  225. data={group}
  226. message={message}
  227. level={group.level}
  228. levelIndicatorSize="11px"
  229. type={group.type}
  230. showUnhandled={group.isUnhandled}
  231. />
  232. </TitleWrapper>
  233. <StatsWrapper>
  234. {issueTypeConfig.stats.enabled && (
  235. <Fragment>
  236. <GuideAnchor target="issue_header_stats">
  237. <div className="count">
  238. <h6 className="nav-header">{t('Events')}</h6>
  239. <Link disabled={disableActions} to={eventRoute}>
  240. <Count className="count" value={group.count} />
  241. </Link>
  242. </div>
  243. </GuideAnchor>
  244. <div className="count">
  245. <h6 className="nav-header">{t('Users')}</h6>
  246. {userCount !== 0 ? (
  247. <Link
  248. disabled={disableActions}
  249. to={`${baseUrl}tags/user/${location.search}`}
  250. >
  251. <Count className="count" value={userCount} />
  252. </Link>
  253. ) : (
  254. <span>0</span>
  255. )}
  256. </div>
  257. </Fragment>
  258. )}
  259. <PriorityContainer>
  260. <h6 className="nav-header">{t('Priority')}</h6>
  261. <GroupPriority group={group} />
  262. </PriorityContainer>
  263. </StatsWrapper>
  264. </HeaderRow>
  265. {/* Environment picker for mobile */}
  266. <HeaderRow className="hidden-sm hidden-md hidden-lg">
  267. <EnvironmentPageFilter position="bottom-end" />
  268. </HeaderRow>
  269. <GroupHeaderTabs {...{baseUrl, disabledTabs, eventRoute, group, project}} />
  270. </div>
  271. </Layout.Header>
  272. );
  273. }
  274. export default GroupHeader;
  275. const BreadcrumbActionWrapper = styled('div')`
  276. display: flex;
  277. flex-direction: row;
  278. justify-content: space-between;
  279. gap: ${space(1)};
  280. align-items: center;
  281. `;
  282. const HeaderRow = styled('div')`
  283. display: flex;
  284. gap: ${space(2)};
  285. justify-content: space-between;
  286. margin-top: ${space(2)};
  287. @media (max-width: ${p => p.theme.breakpoints.small}) {
  288. flex-direction: column;
  289. }
  290. `;
  291. const TitleWrapper = styled('div')`
  292. @media (min-width: ${p => p.theme.breakpoints.small}) {
  293. max-width: 65%;
  294. }
  295. `;
  296. const TitleHeading = styled('div')`
  297. display: flex;
  298. line-height: 2;
  299. gap: ${space(1)};
  300. `;
  301. const StyledEventOrGroupTitle = styled(EventOrGroupTitle)`
  302. font-size: inherit;
  303. `;
  304. const StatsWrapper = styled('div')`
  305. display: flex;
  306. gap: calc(${space(3)} + ${space(3)});
  307. @media (min-width: ${p => p.theme.breakpoints.small}) {
  308. justify-content: flex-end;
  309. }
  310. `;
  311. const IconBadge = styled(Badge)`
  312. display: flex;
  313. align-items: center;
  314. gap: ${space(0.5)};
  315. `;
  316. const StyledTabList = styled(TabList)`
  317. margin-top: ${space(2)};
  318. `;
  319. const PriorityContainer = styled('div')`
  320. /* Ensures that the layout doesn't shift when changing priority */
  321. min-width: 80px;
  322. `;
  323. const StyledFeatureBadge = styled(FeatureBadge)`
  324. align-items: flex-start;
  325. `;