header.tsx 11 KB

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