header.tsx 11 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} from './types';
  37. import type {ReprocessingStatus} from './utils';
  38. type Props = {
  39. baseUrl: string;
  40. event: Event | null;
  41. group: Group;
  42. groupReprocessingStatus: ReprocessingStatus;
  43. organization: Organization;
  44. project: Project;
  45. };
  46. interface GroupHeaderTabsProps extends Pick<Props, 'baseUrl' | 'group' | 'project'> {
  47. disabledTabs: Tab[];
  48. eventRoute: LocationDescriptor;
  49. }
  50. export function GroupHeaderTabs({
  51. baseUrl,
  52. disabledTabs,
  53. eventRoute,
  54. group,
  55. project,
  56. }: GroupHeaderTabsProps) {
  57. const organization = useOrganization();
  58. const location = useLocation();
  59. const {getReplayCountForIssue} = useReplayCountForIssues({
  60. statsPeriod: '90d',
  61. });
  62. const replaysCount = getReplayCountForIssue(group.id, group.issueCategory);
  63. // omit `sort` param from the URLs because it persists from the issues list,
  64. // which can cause the tab content rendering to break
  65. const queryParams = omit(location.query, ['sort']);
  66. const projectFeatures = new Set(project ? project.features : []);
  67. const organizationFeatures = new Set(organization ? organization.features : []);
  68. const hasSimilarView = projectFeatures.has('similarity-view');
  69. const hasEventAttachments = organizationFeatures.has('event-attachments');
  70. const hasReplaySupport =
  71. organizationFeatures.has('session-replay') &&
  72. projectCanLinkToReplay(organization, project);
  73. const issueTypeConfig = getConfigForIssueType(group, project);
  74. useRouteAnalyticsParams({
  75. group_has_replay: (replaysCount ?? 0) > 0,
  76. });
  77. useEffect(() => {
  78. if (group.issueType === IssueType.REPLAY_HYDRATION_ERROR) {
  79. trackAnalytics('replay.hydration-error.issue-details-opened', {organization});
  80. }
  81. }, [group.issueType, organization]);
  82. return (
  83. <StyledTabList hideBorder>
  84. <TabList.Item
  85. key={Tab.DETAILS}
  86. disabled={disabledTabs.includes(Tab.DETAILS)}
  87. to={`${baseUrl}${location.search}`}
  88. >
  89. {t('Details')}
  90. </TabList.Item>
  91. <TabList.Item
  92. key={Tab.ACTIVITY}
  93. textValue={t('Activity')}
  94. disabled={disabledTabs.includes(Tab.ACTIVITY)}
  95. to={{pathname: `${baseUrl}activity/`, query: queryParams}}
  96. >
  97. {t('Activity')}
  98. <IconBadge>
  99. {group.numComments}
  100. <IconChat size="xs" />
  101. </IconBadge>
  102. </TabList.Item>
  103. <TabList.Item
  104. key={Tab.USER_FEEDBACK}
  105. textValue={t('User Feedback')}
  106. hidden={!issueTypeConfig.userFeedback.enabled}
  107. disabled={disabledTabs.includes(Tab.USER_FEEDBACK)}
  108. to={{pathname: `${baseUrl}feedback/`, query: queryParams}}
  109. >
  110. {t('User Feedback')} <Badge text={group.userReportCount} />
  111. </TabList.Item>
  112. <TabList.Item
  113. key={Tab.ATTACHMENTS}
  114. hidden={!hasEventAttachments || !issueTypeConfig.attachments.enabled}
  115. disabled={disabledTabs.includes(Tab.ATTACHMENTS)}
  116. to={{pathname: `${baseUrl}attachments/`, query: queryParams}}
  117. >
  118. {t('Attachments')}
  119. </TabList.Item>
  120. <TabList.Item
  121. key={Tab.TAGS}
  122. hidden={!issueTypeConfig.tags.enabled}
  123. disabled={disabledTabs.includes(Tab.TAGS)}
  124. to={{pathname: `${baseUrl}tags/`, query: queryParams}}
  125. >
  126. {t('Tags')}
  127. </TabList.Item>
  128. <TabList.Item
  129. key={Tab.EVENTS}
  130. hidden={!issueTypeConfig.events.enabled}
  131. disabled={disabledTabs.includes(Tab.EVENTS)}
  132. to={eventRoute}
  133. >
  134. {group.issueCategory === IssueCategory.ERROR
  135. ? t('All Events')
  136. : t('Sampled Events')}
  137. </TabList.Item>
  138. <TabList.Item
  139. key={Tab.MERGED}
  140. hidden={!issueTypeConfig.mergedIssues.enabled}
  141. disabled={disabledTabs.includes(Tab.MERGED)}
  142. to={{pathname: `${baseUrl}merged/`, query: queryParams}}
  143. >
  144. {t('Merged Issues')}
  145. </TabList.Item>
  146. <TabList.Item
  147. key={Tab.SIMILAR_ISSUES}
  148. hidden={!hasSimilarView || !issueTypeConfig.similarIssues.enabled}
  149. disabled={disabledTabs.includes(Tab.SIMILAR_ISSUES)}
  150. to={{pathname: `${baseUrl}similar/`, query: queryParams}}
  151. >
  152. {t('Similar Issues')}
  153. </TabList.Item>
  154. <TabList.Item
  155. key={Tab.REPLAYS}
  156. textValue={t('Replays')}
  157. hidden={!hasReplaySupport || !issueTypeConfig.replays.enabled}
  158. to={{pathname: `${baseUrl}replays/`, query: queryParams}}
  159. >
  160. {t('Replays')}
  161. <ReplayCountBadge count={replaysCount} />
  162. </TabList.Item>
  163. </StyledTabList>
  164. );
  165. }
  166. function GroupHeader({
  167. baseUrl,
  168. group,
  169. groupReprocessingStatus,
  170. organization,
  171. event,
  172. project,
  173. }: Props) {
  174. const location = useLocation();
  175. const {
  176. disabledTabs,
  177. message,
  178. eventRoute,
  179. disableActions,
  180. shortIdBreadcrumb,
  181. className,
  182. } = useIssueDetailsHeader({
  183. group,
  184. groupReprocessingStatus,
  185. baseUrl,
  186. project,
  187. });
  188. const {userCount} = group;
  189. const issueTypeConfig = getConfigForIssueType(group, project);
  190. const NEW_ISSUE_TYPES = [IssueType.REPLAY_HYDRATION_ERROR]; // adds a "new" banner next to the title
  191. return (
  192. <Layout.Header>
  193. <div className={className}>
  194. <BreadcrumbActionWrapper>
  195. <Breadcrumbs
  196. crumbs={[
  197. {
  198. label: 'Issues',
  199. to: {
  200. pathname: `/organizations/${organization.slug}/issues/`,
  201. // Sanitize sort queries from query
  202. query: omit(location.query, 'sort'),
  203. },
  204. },
  205. {label: shortIdBreadcrumb},
  206. ]}
  207. />
  208. <GroupActions
  209. group={group}
  210. project={project}
  211. disabled={disableActions}
  212. event={event}
  213. query={location.query}
  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. `;