header.tsx 12 KB

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