header.tsx 12 KB

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