header.tsx 17 KB

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