header.tsx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  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 EventOrGroupTitle from 'sentry/components/eventOrGroupTitle';
  11. import ErrorLevel from 'sentry/components/events/errorLevel';
  12. import EventAnnotation from 'sentry/components/events/eventAnnotation';
  13. import EventMessage from 'sentry/components/events/eventMessage';
  14. import FeatureBadge from 'sentry/components/featureBadge';
  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>
  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. {group.issueCategory === IssueCategory.PERFORMANCE && (
  290. <FeatureBadge
  291. type="beta"
  292. title="Performance issues are available for early adopters and may change"
  293. />
  294. )}
  295. </ShortIdBreadrcumb>
  296. </GuideAnchor>
  297. );
  298. return (
  299. <Layout.Header>
  300. <div className={className}>
  301. <Breadcrumbs
  302. crumbs={[
  303. {
  304. label: 'Issues',
  305. to: `/organizations/${organization.slug}/issues/${location.search}`,
  306. },
  307. {label: shortIdBreadCrumb},
  308. ]}
  309. />
  310. <HeaderRow>
  311. <TitleWrapper>
  312. <TitleHeading>
  313. <h3>
  314. <StyledEventOrGroupTitle hasGuideAnchor data={group} />
  315. </h3>
  316. {group.inbox && <InboxReason inbox={group.inbox} fontSize="md" />}
  317. </TitleHeading>
  318. <StyledTagAndMessageWrapper>
  319. {group.level && <ErrorLevel level={group.level} size="11px" />}
  320. {group.isUnhandled && <UnhandledInboxTag />}
  321. <EventMessage
  322. message={message}
  323. annotations={
  324. group.logger && (
  325. <EventAnnotation>
  326. <Link
  327. to={{
  328. pathname: `/organizations/${organization.slug}/issues/`,
  329. query: {query: 'logger:' + group.logger},
  330. }}
  331. >
  332. {group.logger}
  333. </Link>
  334. </EventAnnotation>
  335. )
  336. }
  337. />
  338. </StyledTagAndMessageWrapper>
  339. </TitleWrapper>
  340. <StatsWrapper numItems={hasIssueDetailsOwners ? '2' : '3'}>
  341. <div className="count">
  342. <h6 className="nav-header">{t('Events')}</h6>
  343. <Link disabled={disableActions} to={eventRouteToObject}>
  344. <Count className="count" value={group.count} />
  345. </Link>
  346. </div>
  347. <div className="count">
  348. <h6 className="nav-header">{t('Users')}</h6>
  349. {userCount !== 0 ? (
  350. <Link
  351. disabled={disableActions}
  352. to={`${baseUrl}tags/user/${location.search}`}
  353. >
  354. <Count className="count" value={userCount} />
  355. </Link>
  356. ) : (
  357. <span>0</span>
  358. )}
  359. </div>
  360. {!hasIssueDetailsOwners && (
  361. <div data-test-id="assigned-to">
  362. <h6 className="nav-header">{t('Assignee')}</h6>
  363. <AssigneeSelector
  364. id={group.id}
  365. memberList={membersList}
  366. disabled={disableActions}
  367. onAssign={trackAssign}
  368. />
  369. </div>
  370. )}
  371. </StatsWrapper>
  372. </HeaderRow>
  373. <HeaderRow>
  374. <GroupActions
  375. group={group}
  376. project={project}
  377. disabled={disableActions}
  378. event={event}
  379. query={location.query}
  380. />
  381. <StyledSeenByList
  382. seenBy={group.seenBy}
  383. iconTooltip={t('People who have viewed this issue')}
  384. />
  385. </HeaderRow>
  386. {group.issueCategory === IssueCategory.PERFORMANCE
  387. ? performanceIssueTabs
  388. : errorIssueTabs}
  389. </div>
  390. </Layout.Header>
  391. );
  392. }
  393. export default GroupHeader;
  394. const ShortIdBreadrcumb = styled('div')`
  395. display: flex;
  396. gap: ${space(1)};
  397. align-items: center;
  398. `;
  399. const StyledShortId = styled(ShortId)`
  400. font-family: ${p => p.theme.text.family};
  401. font-size: ${p => p.theme.fontSizeMedium};
  402. `;
  403. const HeaderRow = styled('div')`
  404. display: flex;
  405. gap: ${space(2)};
  406. justify-content: space-between;
  407. margin-top: ${space(2)};
  408. @media (max-width: ${p => p.theme.breakpoints.small}) {
  409. flex-direction: column;
  410. }
  411. `;
  412. const TitleWrapper = styled('div')`
  413. @media (min-width: ${p => p.theme.breakpoints.small}) {
  414. max-width: 65%;
  415. }
  416. `;
  417. const TitleHeading = styled('div')`
  418. display: flex;
  419. line-height: 2;
  420. gap: ${space(1)};
  421. `;
  422. const StyledSeenByList = styled(SeenByList)`
  423. @media (max-width: ${p => p.theme.breakpoints.small}) {
  424. display: none;
  425. }
  426. `;
  427. const StyledEventOrGroupTitle = styled(EventOrGroupTitle)`
  428. font-size: inherit;
  429. `;
  430. const StatsWrapper = styled('div')<{numItems: '2' | '3'}>`
  431. display: grid;
  432. grid-template-columns: repeat(${p => p.numItems}, min-content);
  433. gap: calc(${space(3)} + ${space(3)});
  434. @media (min-width: ${p => p.theme.breakpoints.small}) {
  435. justify-content: flex-end;
  436. }
  437. `;
  438. const StyledTagAndMessageWrapper = styled(TagAndMessageWrapper)`
  439. display: flex;
  440. gap: ${space(1)};
  441. justify-content: flex-start;
  442. line-height: 1.2;
  443. `;
  444. const IconBadge = styled(Badge)`
  445. display: flex;
  446. align-items: center;
  447. gap: ${space(0.5)};
  448. `;
  449. const StyledTabList = styled(TabList)`
  450. margin-top: ${space(2)};
  451. `;