header.tsx 16 KB

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