header.tsx 12 KB

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