header.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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 Badge from 'sentry/components/badge';
  6. import {Breadcrumbs} from 'sentry/components/breadcrumbs';
  7. import Count from 'sentry/components/count';
  8. import EventOrGroupTitle from 'sentry/components/eventOrGroupTitle';
  9. import ErrorLevel from 'sentry/components/events/errorLevel';
  10. import EventMessage from 'sentry/components/events/eventMessage';
  11. import {GroupStatusBadge} from 'sentry/components/group/inboxBadges/statusBadge';
  12. import UnhandledInboxTag from 'sentry/components/group/inboxBadges/unhandledTag';
  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';
  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 GroupActions from './actions';
  31. import {ShortIdBreadrcumb} from './shortIdBreadcrumb';
  32. import {Tab} from './types';
  33. import {TagAndMessageWrapper} from './unhandledTag';
  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 {getReplayCountForIssue} = useReplayCountForIssues();
  56. const replaysCount = getReplayCountForIssue(group.id);
  57. const projectFeatures = new Set(project ? project.features : []);
  58. const organizationFeatures = new Set(organization ? organization.features : []);
  59. const hasSimilarView = projectFeatures.has('similarity-view');
  60. const hasEventAttachments = organizationFeatures.has('event-attachments');
  61. const hasReplaySupport =
  62. organizationFeatures.has('session-replay') && projectCanLinkToReplay(project);
  63. const issueTypeConfig = getConfigForIssueType(group, project);
  64. useRouteAnalyticsParams({
  65. group_has_replay: (replaysCount ?? 0) > 0,
  66. });
  67. return (
  68. <StyledTabList hideBorder>
  69. <TabList.Item
  70. key={Tab.DETAILS}
  71. disabled={disabledTabs.includes(Tab.DETAILS)}
  72. to={`${baseUrl}${location.search}`}
  73. >
  74. {t('Details')}
  75. </TabList.Item>
  76. <TabList.Item
  77. key={Tab.ACTIVITY}
  78. textValue={t('Activity')}
  79. disabled={disabledTabs.includes(Tab.ACTIVITY)}
  80. to={`${baseUrl}activity/${location.search}`}
  81. >
  82. {t('Activity')}
  83. <IconBadge>
  84. {group.numComments}
  85. <IconChat size="xs" />
  86. </IconBadge>
  87. </TabList.Item>
  88. <TabList.Item
  89. key={Tab.USER_FEEDBACK}
  90. textValue={t('User Feedback')}
  91. hidden={!issueTypeConfig.userFeedback.enabled}
  92. disabled={disabledTabs.includes(Tab.USER_FEEDBACK)}
  93. to={`${baseUrl}feedback/${location.search}`}
  94. >
  95. {t('User Feedback')} <Badge text={group.userReportCount} />
  96. </TabList.Item>
  97. <TabList.Item
  98. key={Tab.ATTACHMENTS}
  99. hidden={!hasEventAttachments || !issueTypeConfig.attachments.enabled}
  100. disabled={disabledTabs.includes(Tab.ATTACHMENTS)}
  101. to={`${baseUrl}attachments/${location.search}`}
  102. >
  103. {t('Attachments')}
  104. </TabList.Item>
  105. <TabList.Item
  106. key={Tab.TAGS}
  107. hidden={!issueTypeConfig.tags.enabled}
  108. disabled={disabledTabs.includes(Tab.TAGS)}
  109. to={`${baseUrl}tags/${location.search}`}
  110. >
  111. {t('Tags')}
  112. </TabList.Item>
  113. <TabList.Item
  114. key={Tab.EVENTS}
  115. hidden={!issueTypeConfig.events.enabled}
  116. disabled={disabledTabs.includes(Tab.EVENTS)}
  117. to={eventRoute}
  118. >
  119. {group.issueCategory === IssueCategory.ERROR
  120. ? t('All Events')
  121. : t('Sampled Events')}
  122. </TabList.Item>
  123. <TabList.Item
  124. key={Tab.MERGED}
  125. hidden={!issueTypeConfig.mergedIssues.enabled}
  126. disabled={disabledTabs.includes(Tab.MERGED)}
  127. to={`${baseUrl}merged/${location.search}`}
  128. >
  129. {t('Merged Issues')}
  130. </TabList.Item>
  131. <TabList.Item
  132. key={Tab.SIMILAR_ISSUES}
  133. hidden={!hasSimilarView || !issueTypeConfig.similarIssues.enabled}
  134. disabled={disabledTabs.includes(Tab.SIMILAR_ISSUES)}
  135. to={`${baseUrl}similar/${location.search}`}
  136. >
  137. {t('Similar Issues')}
  138. </TabList.Item>
  139. <TabList.Item
  140. key={Tab.REPLAYS}
  141. textValue={t('Replays')}
  142. hidden={!hasReplaySupport || !issueTypeConfig.replays.enabled}
  143. to={`${baseUrl}replays/${location.search}`}
  144. >
  145. {t('Replays')}
  146. <ReplayCountBadge count={replaysCount} />
  147. </TabList.Item>
  148. </StyledTabList>
  149. );
  150. }
  151. function GroupHeader({
  152. baseUrl,
  153. group,
  154. groupReprocessingStatus,
  155. organization,
  156. event,
  157. project,
  158. }: Props) {
  159. const location = useLocation();
  160. const disabledTabs = useMemo(() => {
  161. const hasReprocessingV2Feature = organization.features.includes('reprocessing-v2');
  162. if (!hasReprocessingV2Feature) {
  163. return [];
  164. }
  165. if (groupReprocessingStatus === ReprocessingStatus.REPROCESSING) {
  166. return [
  167. Tab.ACTIVITY,
  168. Tab.USER_FEEDBACK,
  169. Tab.ATTACHMENTS,
  170. Tab.EVENTS,
  171. Tab.MERGED,
  172. Tab.SIMILAR_ISSUES,
  173. Tab.TAGS,
  174. ];
  175. }
  176. if (groupReprocessingStatus === ReprocessingStatus.REPROCESSED_AND_HASNT_EVENT) {
  177. return [
  178. Tab.DETAILS,
  179. Tab.ATTACHMENTS,
  180. Tab.EVENTS,
  181. Tab.MERGED,
  182. Tab.SIMILAR_ISSUES,
  183. Tab.TAGS,
  184. Tab.USER_FEEDBACK,
  185. ];
  186. }
  187. return [];
  188. }, [organization, groupReprocessingStatus]);
  189. const eventRoute = useMemo(() => {
  190. const searchTermWithoutQuery = omit(location.query, 'query');
  191. return {
  192. pathname: `${baseUrl}events/`,
  193. query: searchTermWithoutQuery,
  194. };
  195. }, [location, baseUrl]);
  196. const {userCount} = group;
  197. let className = 'group-detail';
  198. if (group.hasSeen) {
  199. className += ' hasSeen';
  200. }
  201. if (group.status === 'resolved') {
  202. className += ' isResolved';
  203. }
  204. const message = getMessage(group);
  205. const disableActions = !!disabledTabs.length;
  206. const shortIdBreadcrumb = (
  207. <ShortIdBreadrcumb organization={organization} project={project} group={group} />
  208. );
  209. const issueTypeConfig = getConfigForIssueType(group, project);
  210. return (
  211. <Layout.Header>
  212. <div className={className}>
  213. <BreadcrumbActionWrapper>
  214. <Breadcrumbs
  215. crumbs={[
  216. {
  217. label: 'Issues',
  218. to: {
  219. pathname: `/organizations/${organization.slug}/issues/`,
  220. // Sanitize sort queries from query
  221. query: omit(location.query, 'sort'),
  222. },
  223. },
  224. {label: shortIdBreadcrumb},
  225. ]}
  226. />
  227. <GroupActions
  228. group={group}
  229. project={project}
  230. disabled={disableActions}
  231. event={event}
  232. query={location.query}
  233. />
  234. </BreadcrumbActionWrapper>
  235. <HeaderRow>
  236. <TitleWrapper>
  237. <TitleHeading>
  238. <h3>
  239. <StyledEventOrGroupTitle data={group} />
  240. </h3>
  241. <GroupStatusBadge
  242. status={group.status}
  243. substatus={group.substatus}
  244. fontSize="md"
  245. />
  246. </TitleHeading>
  247. <StyledTagAndMessageWrapper>
  248. {group.level && <ErrorLevel level={group.level} size="11px" />}
  249. {group.isUnhandled && <UnhandledInboxTag />}
  250. <EventMessage message={message} />
  251. </StyledTagAndMessageWrapper>
  252. </TitleWrapper>
  253. {issueTypeConfig.stats.enabled && (
  254. <StatsWrapper>
  255. <div className="count">
  256. <h6 className="nav-header">{t('Events')}</h6>
  257. <Link disabled={disableActions} to={eventRoute}>
  258. <Count className="count" value={group.count} />
  259. </Link>
  260. </div>
  261. <div className="count">
  262. <h6 className="nav-header">{t('Users')}</h6>
  263. {userCount !== 0 ? (
  264. <Link
  265. disabled={disableActions}
  266. to={`${baseUrl}tags/user/${location.search}`}
  267. >
  268. <Count className="count" value={userCount} />
  269. </Link>
  270. ) : (
  271. <span>0</span>
  272. )}
  273. </div>
  274. </StatsWrapper>
  275. )}
  276. </HeaderRow>
  277. {/* Environment picker for mobile */}
  278. <HeaderRow className="hidden-sm hidden-md hidden-lg">
  279. <EnvironmentPageFilter position="bottom-end" />
  280. </HeaderRow>
  281. <GroupHeaderTabs {...{baseUrl, disabledTabs, eventRoute, group, project}} />
  282. </div>
  283. </Layout.Header>
  284. );
  285. }
  286. export default GroupHeader;
  287. const BreadcrumbActionWrapper = styled('div')`
  288. display: flex;
  289. flex-direction: row;
  290. justify-content: space-between;
  291. gap: ${space(1)};
  292. align-items: center;
  293. `;
  294. const HeaderRow = styled('div')`
  295. display: flex;
  296. gap: ${space(2)};
  297. justify-content: space-between;
  298. margin-top: ${space(2)};
  299. @media (max-width: ${p => p.theme.breakpoints.small}) {
  300. flex-direction: column;
  301. }
  302. `;
  303. const TitleWrapper = styled('div')`
  304. @media (min-width: ${p => p.theme.breakpoints.small}) {
  305. max-width: 65%;
  306. }
  307. `;
  308. const TitleHeading = styled('div')`
  309. display: flex;
  310. line-height: 2;
  311. gap: ${space(1)};
  312. `;
  313. const StyledEventOrGroupTitle = styled(EventOrGroupTitle)`
  314. font-size: inherit;
  315. `;
  316. const StatsWrapper = styled('div')`
  317. display: grid;
  318. grid-template-columns: repeat(2, min-content);
  319. gap: calc(${space(3)} + ${space(3)});
  320. @media (min-width: ${p => p.theme.breakpoints.small}) {
  321. justify-content: flex-end;
  322. }
  323. `;
  324. const StyledTagAndMessageWrapper = styled(TagAndMessageWrapper)`
  325. display: flex;
  326. gap: ${space(1)};
  327. justify-content: flex-start;
  328. line-height: 1.2;
  329. `;
  330. const IconBadge = styled(Badge)`
  331. display: flex;
  332. align-items: center;
  333. gap: ${space(0.5)};
  334. `;
  335. const StyledTabList = styled(TabList)`
  336. margin-top: ${space(2)};
  337. `;