header.tsx 18 KB

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