header.tsx 14 KB

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