header.tsx 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. import {useCallback, useEffect, useMemo, useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import omit from 'lodash/omit';
  4. import {fetchOrgMembers} from 'sentry/actionCreators/members';
  5. import AssigneeSelector from 'sentry/components/assigneeSelector';
  6. import GuideAnchor from 'sentry/components/assistant/guideAnchor';
  7. import Badge from 'sentry/components/badge';
  8. import Breadcrumbs from 'sentry/components/breadcrumbs';
  9. import Count from 'sentry/components/count';
  10. import EnvironmentPageFilter from 'sentry/components/environmentPageFilter';
  11. import EventOrGroupTitle from 'sentry/components/eventOrGroupTitle';
  12. import ErrorLevel from 'sentry/components/events/errorLevel';
  13. import EventAnnotation from 'sentry/components/events/eventAnnotation';
  14. import EventMessage from 'sentry/components/events/eventMessage';
  15. import InboxReason from 'sentry/components/group/inboxBadges/inboxReason';
  16. import UnhandledInboxTag from 'sentry/components/group/inboxBadges/unhandledTag';
  17. import ProjectBadge from 'sentry/components/idBadge/projectBadge';
  18. import * as Layout from 'sentry/components/layouts/thirds';
  19. import Link from 'sentry/components/links/link';
  20. import ReplaysFeatureBadge from 'sentry/components/replays/replaysFeatureBadge';
  21. import SeenByList from 'sentry/components/seenByList';
  22. import ShortId from 'sentry/components/shortId';
  23. import {Item, TabList} from 'sentry/components/tabs';
  24. import Tooltip from 'sentry/components/tooltip';
  25. import {IconChat} from 'sentry/icons';
  26. import {t} from 'sentry/locale';
  27. import space from 'sentry/styles/space';
  28. import {Event, Group, IssueCategory, Organization, Project, User} from 'sentry/types';
  29. import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
  30. import {getUtcDateString} from 'sentry/utils/dates';
  31. import {getMessage} from 'sentry/utils/events';
  32. import projectSupportsReplay from 'sentry/utils/replays/projectSupportsReplay';
  33. import useApi from 'sentry/utils/useApi';
  34. import {useLocation} from 'sentry/utils/useLocation';
  35. import GroupActions from './actions';
  36. import {Tab} from './types';
  37. import {TagAndMessageWrapper} from './unhandledTag';
  38. import {ReprocessingStatus} from './utils';
  39. type Props = {
  40. baseUrl: string;
  41. group: Group;
  42. groupReprocessingStatus: ReprocessingStatus;
  43. organization: Organization;
  44. project: Project;
  45. replaysCount: number | undefined;
  46. event?: Event;
  47. };
  48. type UseMemberlistProps = {
  49. group: Group;
  50. organization: Organization;
  51. };
  52. function useMembersList({group, organization}: UseMemberlistProps) {
  53. const {project} = group;
  54. const api = useApi();
  55. const [membersList, setMembersList] = useState<User[]>();
  56. const hasIssueDetailsOwners = organization.features.includes('issue-details-owners');
  57. const loadMemberList = useCallback(async () => {
  58. if (hasIssueDetailsOwners) {
  59. return;
  60. }
  61. const members = await fetchOrgMembers(api, organization.slug, [project.id]);
  62. setMembersList(members.map(member => member.user));
  63. }, [api, organization.slug, project, hasIssueDetailsOwners]);
  64. useEffect(() => void loadMemberList(), [loadMemberList]);
  65. return membersList;
  66. }
  67. function GroupHeader({
  68. baseUrl,
  69. group,
  70. groupReprocessingStatus,
  71. organization,
  72. replaysCount,
  73. event,
  74. project,
  75. }: Props) {
  76. const location = useLocation();
  77. const trackAssign: React.ComponentProps<typeof AssigneeSelector>['onAssign'] =
  78. useCallback(
  79. (_, __, suggestedAssignee) => {
  80. const {alert_date, alert_rule_id, alert_type} = location.query;
  81. trackAdvancedAnalyticsEvent('issue_details.action_clicked', {
  82. organization,
  83. project_id: parseInt(project.id, 10),
  84. group_id: parseInt(group.id, 10),
  85. issue_category: group.issueCategory,
  86. action_type: 'assign',
  87. assigned_suggestion_reason: suggestedAssignee?.suggestedReason,
  88. // Alert properties track if the user came from email/slack alerts
  89. alert_date:
  90. typeof alert_date === 'string'
  91. ? getUtcDateString(Number(alert_date))
  92. : undefined,
  93. alert_rule_id: typeof alert_rule_id === 'string' ? alert_rule_id : undefined,
  94. alert_type: typeof alert_type === 'string' ? alert_type : undefined,
  95. });
  96. },
  97. [group.id, group.issueCategory, project.id, organization, location.query]
  98. );
  99. const disabledTabs = useMemo(() => {
  100. const hasReprocessingV2Feature = organization.features.includes('reprocessing-v2');
  101. if (!hasReprocessingV2Feature) {
  102. return [];
  103. }
  104. if (groupReprocessingStatus === ReprocessingStatus.REPROCESSING) {
  105. return [
  106. Tab.ACTIVITY,
  107. Tab.USER_FEEDBACK,
  108. Tab.ATTACHMENTS,
  109. Tab.EVENTS,
  110. Tab.MERGED,
  111. Tab.GROUPING,
  112. Tab.SIMILAR_ISSUES,
  113. Tab.TAGS,
  114. ];
  115. }
  116. if (groupReprocessingStatus === ReprocessingStatus.REPROCESSED_AND_HASNT_EVENT) {
  117. return [
  118. Tab.DETAILS,
  119. Tab.ATTACHMENTS,
  120. Tab.EVENTS,
  121. Tab.MERGED,
  122. Tab.GROUPING,
  123. Tab.SIMILAR_ISSUES,
  124. Tab.TAGS,
  125. Tab.USER_FEEDBACK,
  126. ];
  127. }
  128. return [];
  129. }, [organization, groupReprocessingStatus]);
  130. const eventRouteToObject = useMemo(() => {
  131. const searchTermWithoutQuery = omit(location.query, 'query');
  132. return {
  133. pathname: `${baseUrl}events/`,
  134. query: searchTermWithoutQuery,
  135. };
  136. }, [location, baseUrl]);
  137. const errorIssueTabs = useMemo(() => {
  138. const projectFeatures = new Set(project ? project.features : []);
  139. const organizationFeatures = new Set(organization ? organization.features : []);
  140. const hasGroupingTreeUI = organizationFeatures.has('grouping-tree-ui');
  141. const hasSimilarView = projectFeatures.has('similarity-view');
  142. const hasEventAttachments = organizationFeatures.has('event-attachments');
  143. const hasSessionReplay =
  144. organizationFeatures.has('session-replay-ui') && projectSupportsReplay(project);
  145. return (
  146. <StyledTabList hideBorder>
  147. <Item
  148. key={Tab.DETAILS}
  149. disabled={disabledTabs.includes(Tab.DETAILS)}
  150. to={`${baseUrl}${location.search}`}
  151. >
  152. {t('Details')}
  153. </Item>
  154. <Item
  155. key={Tab.ACTIVITY}
  156. textValue={t('Activity')}
  157. disabled={disabledTabs.includes(Tab.ACTIVITY)}
  158. to={`${baseUrl}activity/${location.search}`}
  159. >
  160. {t('Activity')}
  161. <IconBadge>
  162. {group.numComments}
  163. <IconChat size="xs" />
  164. </IconBadge>
  165. </Item>
  166. <Item
  167. key={Tab.USER_FEEDBACK}
  168. textValue={t('User Feedback')}
  169. disabled={disabledTabs.includes(Tab.USER_FEEDBACK)}
  170. to={`${baseUrl}feedback/${location.search}`}
  171. >
  172. {t('User Feedback')} <Badge text={group.userReportCount} />
  173. </Item>
  174. <Item
  175. key={Tab.ATTACHMENTS}
  176. hidden={!hasEventAttachments}
  177. disabled={disabledTabs.includes(Tab.ATTACHMENTS)}
  178. to={`${baseUrl}attachments/${location.search}`}
  179. >
  180. {t('Attachments')}
  181. </Item>
  182. <Item
  183. key={Tab.TAGS}
  184. disabled={disabledTabs.includes(Tab.TAGS)}
  185. to={`${baseUrl}tags/${location.search}`}
  186. >
  187. {t('Tags')}
  188. </Item>
  189. <Item
  190. key={Tab.EVENTS}
  191. disabled={disabledTabs.includes(Tab.EVENTS)}
  192. to={eventRouteToObject}
  193. >
  194. {t('All Events')}
  195. </Item>
  196. <Item
  197. key={Tab.MERGED}
  198. disabled={disabledTabs.includes(Tab.MERGED)}
  199. to={`${baseUrl}merged/${location.search}`}
  200. >
  201. {t('Merged Issues')}
  202. </Item>
  203. <Item
  204. key={Tab.GROUPING}
  205. hidden={!hasGroupingTreeUI}
  206. disabled={disabledTabs.includes(Tab.GROUPING)}
  207. to={`${baseUrl}grouping/${location.search}`}
  208. >
  209. {t('Grouping')}
  210. </Item>
  211. <Item
  212. key={Tab.SIMILAR_ISSUES}
  213. hidden={!hasSimilarView}
  214. disabled={disabledTabs.includes(Tab.SIMILAR_ISSUES)}
  215. to={`${baseUrl}similar/${location.search}`}
  216. >
  217. {t('Similar Issues')}
  218. </Item>
  219. <Item
  220. key={Tab.REPLAYS}
  221. textValue={t('Replays')}
  222. hidden={!hasSessionReplay}
  223. to={`${baseUrl}replays/${location.search}`}
  224. >
  225. {t('Replays')}{' '}
  226. {replaysCount !== undefined ? <Badge text={replaysCount} /> : null}
  227. <ReplaysFeatureBadge noTooltip />
  228. </Item>
  229. </StyledTabList>
  230. );
  231. }, [
  232. baseUrl,
  233. location,
  234. disabledTabs,
  235. group.numComments,
  236. group.userReportCount,
  237. organization,
  238. project,
  239. replaysCount,
  240. eventRouteToObject,
  241. ]);
  242. const performanceIssueTabs = useMemo(() => {
  243. return (
  244. <StyledTabList hideBorder>
  245. <Item
  246. key={Tab.DETAILS}
  247. disabled={disabledTabs.includes(Tab.DETAILS)}
  248. to={`${baseUrl}${location.search}`}
  249. >
  250. {t('Details')}
  251. </Item>
  252. <Item
  253. key={Tab.ACTIVITY}
  254. textValue={t('Activity')}
  255. disabled={disabledTabs.includes(Tab.ACTIVITY)}
  256. to={`${baseUrl}activity/${location.search}`}
  257. >
  258. {t('Activity')}
  259. <IconBadge>
  260. {group.numComments}
  261. <IconChat size="xs" />
  262. </IconBadge>
  263. </Item>
  264. <Item
  265. key={Tab.TAGS}
  266. disabled={disabledTabs.includes(Tab.TAGS)}
  267. to={`${baseUrl}tags/${location.search}`}
  268. >
  269. {t('Tags')}
  270. </Item>
  271. <Item
  272. key={Tab.EVENTS}
  273. disabled={disabledTabs.includes(Tab.EVENTS)}
  274. to={eventRouteToObject}
  275. >
  276. {t('Events')}
  277. </Item>
  278. </StyledTabList>
  279. );
  280. }, [disabledTabs, group.numComments, baseUrl, location, eventRouteToObject]);
  281. const membersList = useMembersList({group, organization});
  282. const hasIssueDetailsOwners = organization.features.includes('issue-details-owners');
  283. const {userCount} = group;
  284. let className = 'group-detail';
  285. if (group.hasSeen) {
  286. className += ' hasSeen';
  287. }
  288. if (group.status === 'resolved') {
  289. className += ' isResolved';
  290. }
  291. const message = getMessage(group);
  292. const disableActions = !!disabledTabs.length;
  293. const shortIdBreadCrumb = group.shortId && (
  294. <GuideAnchor target="issue_number" position="bottom">
  295. <ShortIdBreadrcumb>
  296. <ProjectBadge
  297. project={project}
  298. avatarSize={16}
  299. hideName
  300. avatarProps={{hasTooltip: true, tooltip: project.slug}}
  301. />
  302. <Tooltip
  303. className="help-link"
  304. title={t(
  305. 'This identifier is unique across your organization, and can be used to reference an issue in various places, like commit messages.'
  306. )}
  307. position="bottom"
  308. >
  309. <StyledShortId shortId={group.shortId} />
  310. </Tooltip>
  311. </ShortIdBreadrcumb>
  312. </GuideAnchor>
  313. );
  314. const hasIssueActionsV2 = organization.features.includes('issue-actions-v2');
  315. return (
  316. <Layout.Header>
  317. <div className={className}>
  318. <BreadcrumbActionWrapper>
  319. <Breadcrumbs
  320. crumbs={[
  321. {
  322. label: 'Issues',
  323. to: `/organizations/${organization.slug}/issues/${location.search}`,
  324. },
  325. {label: shortIdBreadCrumb},
  326. ]}
  327. />
  328. {hasIssueActionsV2 && (
  329. <GroupActions
  330. group={group}
  331. project={project}
  332. disabled={disableActions}
  333. event={event}
  334. query={location.query}
  335. />
  336. )}
  337. </BreadcrumbActionWrapper>
  338. <HeaderRow>
  339. <TitleWrapper>
  340. <TitleHeading>
  341. <h3>
  342. <StyledEventOrGroupTitle hasGuideAnchor data={group} />
  343. </h3>
  344. {group.inbox && <InboxReason inbox={group.inbox} fontSize="md" />}
  345. </TitleHeading>
  346. <StyledTagAndMessageWrapper>
  347. {group.level && <ErrorLevel level={group.level} size="11px" />}
  348. {group.isUnhandled && <UnhandledInboxTag />}
  349. <EventMessage
  350. message={message}
  351. annotations={
  352. group.logger && (
  353. <EventAnnotation>
  354. <Link
  355. to={{
  356. pathname: `/organizations/${organization.slug}/issues/`,
  357. query: {query: 'logger:' + group.logger},
  358. }}
  359. >
  360. {group.logger}
  361. </Link>
  362. </EventAnnotation>
  363. )
  364. }
  365. />
  366. </StyledTagAndMessageWrapper>
  367. </TitleWrapper>
  368. <StatsWrapper numItems={hasIssueDetailsOwners ? '2' : '3'}>
  369. <div className="count">
  370. <h6 className="nav-header">{t('Events')}</h6>
  371. <Link disabled={disableActions} to={eventRouteToObject}>
  372. <Count className="count" value={group.count} />
  373. </Link>
  374. </div>
  375. <div className="count">
  376. <h6 className="nav-header">{t('Users')}</h6>
  377. {userCount !== 0 ? (
  378. <Link
  379. disabled={disableActions}
  380. to={`${baseUrl}tags/user/${location.search}`}
  381. >
  382. <Count className="count" value={userCount} />
  383. </Link>
  384. ) : (
  385. <span>0</span>
  386. )}
  387. </div>
  388. {!hasIssueDetailsOwners && (
  389. <div data-test-id="assigned-to">
  390. <h6 className="nav-header">{t('Assignee')}</h6>
  391. <AssigneeSelector
  392. id={group.id}
  393. memberList={membersList}
  394. disabled={disableActions}
  395. onAssign={trackAssign}
  396. />
  397. </div>
  398. )}
  399. </StatsWrapper>
  400. </HeaderRow>
  401. {hasIssueActionsV2 ? (
  402. // Environment picker for mobile
  403. <HeaderRow className="hidden-sm hidden-md hidden-lg">
  404. <EnvironmentPageFilter alignDropdown="right" />
  405. </HeaderRow>
  406. ) : (
  407. <HeaderRow>
  408. <GroupActions
  409. group={group}
  410. project={project}
  411. disabled={disableActions}
  412. event={event}
  413. query={location.query}
  414. />
  415. <StyledSeenByList
  416. seenBy={group.seenBy}
  417. iconTooltip={t('People who have viewed this issue')}
  418. />
  419. </HeaderRow>
  420. )}
  421. {group.issueCategory === IssueCategory.PERFORMANCE
  422. ? performanceIssueTabs
  423. : errorIssueTabs}
  424. </div>
  425. </Layout.Header>
  426. );
  427. }
  428. export default GroupHeader;
  429. const BreadcrumbActionWrapper = styled('div')`
  430. display: flex;
  431. flex-direction: row;
  432. justify-content: space-between;
  433. gap: ${space(1)};
  434. align-items: center;
  435. `;
  436. const ShortIdBreadrcumb = styled('div')`
  437. display: flex;
  438. gap: ${space(1)};
  439. align-items: center;
  440. `;
  441. const StyledShortId = styled(ShortId)`
  442. font-family: ${p => p.theme.text.family};
  443. font-size: ${p => p.theme.fontSizeMedium};
  444. `;
  445. const HeaderRow = styled('div')`
  446. display: flex;
  447. gap: ${space(2)};
  448. justify-content: space-between;
  449. margin-top: ${space(2)};
  450. @media (max-width: ${p => p.theme.breakpoints.small}) {
  451. flex-direction: column;
  452. }
  453. `;
  454. const TitleWrapper = styled('div')`
  455. @media (min-width: ${p => p.theme.breakpoints.small}) {
  456. max-width: 65%;
  457. }
  458. `;
  459. const TitleHeading = styled('div')`
  460. display: flex;
  461. line-height: 2;
  462. gap: ${space(1)};
  463. `;
  464. const StyledSeenByList = styled(SeenByList)`
  465. @media (max-width: ${p => p.theme.breakpoints.small}) {
  466. display: none;
  467. }
  468. `;
  469. const StyledEventOrGroupTitle = styled(EventOrGroupTitle)`
  470. font-size: inherit;
  471. `;
  472. const StatsWrapper = styled('div')<{numItems: '2' | '3'}>`
  473. display: grid;
  474. grid-template-columns: repeat(${p => p.numItems}, min-content);
  475. gap: calc(${space(3)} + ${space(3)});
  476. @media (min-width: ${p => p.theme.breakpoints.small}) {
  477. justify-content: flex-end;
  478. }
  479. `;
  480. const StyledTagAndMessageWrapper = styled(TagAndMessageWrapper)`
  481. display: flex;
  482. gap: ${space(1)};
  483. justify-content: flex-start;
  484. line-height: 1.2;
  485. `;
  486. const IconBadge = styled(Badge)`
  487. display: flex;
  488. align-items: center;
  489. gap: ${space(0.5)};
  490. `;
  491. const StyledTabList = styled(TabList)`
  492. margin-top: ${space(2)};
  493. `;