header.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. import * as React from 'react';
  2. import {withRouter, WithRouterProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import omit from 'lodash/omit';
  5. import {fetchOrgMembers} from 'sentry/actionCreators/members';
  6. import {Client} from 'sentry/api';
  7. import AssigneeSelector from 'sentry/components/assigneeSelector';
  8. import GuideAnchor from 'sentry/components/assistant/guideAnchor';
  9. import Badge from 'sentry/components/badge';
  10. import Count from 'sentry/components/count';
  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 ExternalLink from 'sentry/components/links/externalLink';
  19. import Link from 'sentry/components/links/link';
  20. import ListLink from 'sentry/components/links/listLink';
  21. import NavTabs from 'sentry/components/navTabs';
  22. import SeenByList from 'sentry/components/seenByList';
  23. import ShortId from 'sentry/components/shortId';
  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 {Group, Organization, Project} from 'sentry/types';
  29. import {Event} from 'sentry/types/event';
  30. import {getMessage} from 'sentry/utils/events';
  31. import withApi from 'sentry/utils/withApi';
  32. import withOrganization from 'sentry/utils/withOrganization';
  33. import GroupActions from './actions';
  34. import {Tab} from './types';
  35. import {TagAndMessageWrapper} from './unhandledTag';
  36. import {ReprocessingStatus} from './utils';
  37. type Props = WithRouterProps & {
  38. currentTab: string;
  39. baseUrl: string;
  40. group: Group;
  41. groupReprocessingStatus: ReprocessingStatus;
  42. project: Project;
  43. api: Client;
  44. organization: Organization;
  45. event?: Event;
  46. };
  47. type MemberList = NonNullable<
  48. React.ComponentProps<typeof AssigneeSelector>['memberList']
  49. >;
  50. type State = {
  51. memberList?: MemberList;
  52. };
  53. class GroupHeader extends React.Component<Props, State> {
  54. state: State = {};
  55. componentDidMount() {
  56. const {group, api, organization} = this.props;
  57. const {project} = group;
  58. fetchOrgMembers(api, organization.slug, [project.id]).then(memberList => {
  59. const users = memberList.map(member => member.user);
  60. this.setState({memberList: users});
  61. });
  62. }
  63. getDisabledTabs() {
  64. const {organization} = this.props;
  65. const hasReprocessingV2Feature = organization.features.includes('reprocessing-v2');
  66. if (!hasReprocessingV2Feature) {
  67. return [];
  68. }
  69. const {groupReprocessingStatus} = this.props;
  70. if (groupReprocessingStatus === ReprocessingStatus.REPROCESSING) {
  71. return [
  72. Tab.ACTIVITY,
  73. Tab.USER_FEEDBACK,
  74. Tab.ATTACHMENTS,
  75. Tab.EVENTS,
  76. Tab.MERGED,
  77. Tab.GROUPING,
  78. Tab.SIMILAR_ISSUES,
  79. Tab.TAGS,
  80. ];
  81. }
  82. if (groupReprocessingStatus === ReprocessingStatus.REPROCESSED_AND_HASNT_EVENT) {
  83. return [
  84. Tab.DETAILS,
  85. Tab.ATTACHMENTS,
  86. Tab.EVENTS,
  87. Tab.MERGED,
  88. Tab.GROUPING,
  89. Tab.SIMILAR_ISSUES,
  90. Tab.TAGS,
  91. Tab.USER_FEEDBACK,
  92. ];
  93. }
  94. return [];
  95. }
  96. render() {
  97. const {project, group, currentTab, baseUrl, event, organization, location} =
  98. this.props;
  99. const projectFeatures = new Set(project ? project.features : []);
  100. const organizationFeatures = new Set(organization ? organization.features : []);
  101. const userCount = group.userCount;
  102. const hasGroupingTreeUI = organizationFeatures.has('grouping-tree-ui');
  103. const hasSimilarView = projectFeatures.has('similarity-view');
  104. const hasEventAttachments = organizationFeatures.has('event-attachments');
  105. let className = 'group-detail';
  106. if (group.hasSeen) {
  107. className += ' hasSeen';
  108. }
  109. if (group.status === 'resolved') {
  110. className += ' isResolved';
  111. }
  112. const {memberList} = this.state;
  113. const orgId = organization.slug;
  114. const message = getMessage(group);
  115. const searchTermWithoutQuery = omit(location.query, 'query');
  116. const eventRouteToObject = {
  117. pathname: `${baseUrl}events/`,
  118. query: searchTermWithoutQuery,
  119. };
  120. const disabledTabs = this.getDisabledTabs();
  121. const disableActions = !!disabledTabs.length;
  122. return (
  123. <div className={className}>
  124. <div className="row">
  125. <div className="col-sm-7">
  126. <TitleWrapper>
  127. <h3>
  128. <EventOrGroupTitle hasGuideAnchor data={group} />
  129. </h3>
  130. {group.inbox && (
  131. <InboxReasonWrapper>
  132. <InboxReason inbox={group.inbox} fontSize="md" />
  133. </InboxReasonWrapper>
  134. )}
  135. </TitleWrapper>
  136. <StyledTagAndMessageWrapper>
  137. {group.level && <ErrorLevel level={group.level} size="11px" />}
  138. {group.isUnhandled && <UnhandledInboxTag />}
  139. <EventMessage
  140. message={message}
  141. annotations={
  142. <React.Fragment>
  143. {group.logger && (
  144. <EventAnnotationWithSpace>
  145. <Link
  146. to={{
  147. pathname: `/organizations/${orgId}/issues/`,
  148. query: {query: 'logger:' + group.logger},
  149. }}
  150. >
  151. {group.logger}
  152. </Link>
  153. </EventAnnotationWithSpace>
  154. )}
  155. {group.annotations.map((annotation, i) => (
  156. <EventAnnotationWithSpace
  157. key={i}
  158. dangerouslySetInnerHTML={{__html: annotation}}
  159. />
  160. ))}
  161. </React.Fragment>
  162. }
  163. />
  164. </StyledTagAndMessageWrapper>
  165. </div>
  166. <div className="col-sm-5 stats">
  167. <div className="flex flex-justify-right">
  168. {group.shortId && (
  169. <GuideAnchor target="issue_number" position="bottom">
  170. <div className="short-id-box count align-right">
  171. <h6 className="nav-header">
  172. <Tooltip
  173. className="help-link"
  174. title={t(
  175. 'This identifier is unique across your organization, and can be used to reference an issue in various places, like commit messages.'
  176. )}
  177. position="bottom"
  178. >
  179. <ExternalLink href="https://docs.sentry.io/product/integrations/source-code-mgmt/github/#resolve-via-commit-or-pull-request">
  180. {t('Issue #')}
  181. </ExternalLink>
  182. </Tooltip>
  183. </h6>
  184. <ShortId
  185. shortId={group.shortId}
  186. avatar={
  187. <StyledProjectBadge project={project} avatarSize={20} hideName />
  188. }
  189. />
  190. </div>
  191. </GuideAnchor>
  192. )}
  193. <div className="count align-right m-l-1">
  194. <h6 className="nav-header">{t('Events')}</h6>
  195. {disableActions ? (
  196. <Count className="count" value={group.count} />
  197. ) : (
  198. <Link to={eventRouteToObject}>
  199. <Count className="count" value={group.count} />
  200. </Link>
  201. )}
  202. </div>
  203. <div className="count align-right m-l-1">
  204. <h6 className="nav-header">{t('Users')}</h6>
  205. {userCount !== 0 ? (
  206. disableActions ? (
  207. <Count className="count" value={userCount} />
  208. ) : (
  209. <Link to={`${baseUrl}tags/user/${location.search}`}>
  210. <Count className="count" value={userCount} />
  211. </Link>
  212. )
  213. ) : (
  214. <span>0</span>
  215. )}
  216. </div>
  217. <div className="assigned-to m-l-1">
  218. <h6 className="nav-header">{t('Assignee')}</h6>
  219. <AssigneeSelector
  220. id={group.id}
  221. memberList={memberList}
  222. disabled={disableActions}
  223. />
  224. </div>
  225. </div>
  226. </div>
  227. </div>
  228. <SeenByList
  229. seenBy={group.seenBy}
  230. iconTooltip={t('People who have viewed this issue')}
  231. />
  232. <GroupActions
  233. group={group}
  234. project={project}
  235. disabled={disableActions}
  236. event={event}
  237. />
  238. <NavTabs>
  239. <ListLink
  240. to={`${baseUrl}${location.search}`}
  241. isActive={() => currentTab === Tab.DETAILS}
  242. disabled={disabledTabs.includes(Tab.DETAILS)}
  243. >
  244. {t('Details')}
  245. </ListLink>
  246. <StyledListLink
  247. to={`${baseUrl}activity/${location.search}`}
  248. isActive={() => currentTab === Tab.ACTIVITY}
  249. disabled={disabledTabs.includes(Tab.ACTIVITY)}
  250. >
  251. {t('Activity')}
  252. <Badge>
  253. {group.numComments}
  254. <IconChat size="xs" />
  255. </Badge>
  256. </StyledListLink>
  257. <StyledListLink
  258. to={`${baseUrl}feedback/${location.search}`}
  259. isActive={() => currentTab === Tab.USER_FEEDBACK}
  260. disabled={disabledTabs.includes(Tab.USER_FEEDBACK)}
  261. >
  262. {t('User Feedback')} <Badge text={group.userReportCount} />
  263. </StyledListLink>
  264. {hasEventAttachments && (
  265. <ListLink
  266. to={`${baseUrl}attachments/${location.search}`}
  267. isActive={() => currentTab === Tab.ATTACHMENTS}
  268. disabled={disabledTabs.includes(Tab.ATTACHMENTS)}
  269. >
  270. {t('Attachments')}
  271. </ListLink>
  272. )}
  273. <ListLink
  274. to={`${baseUrl}tags/${location.search}`}
  275. isActive={() => currentTab === Tab.TAGS}
  276. disabled={disabledTabs.includes(Tab.TAGS)}
  277. >
  278. {t('Tags')}
  279. </ListLink>
  280. <ListLink
  281. to={eventRouteToObject}
  282. isActive={() => currentTab === Tab.EVENTS}
  283. disabled={disabledTabs.includes(Tab.EVENTS)}
  284. >
  285. {t('Events')}
  286. </ListLink>
  287. <ListLink
  288. to={`${baseUrl}merged/${location.search}`}
  289. isActive={() => currentTab === Tab.MERGED}
  290. disabled={disabledTabs.includes(Tab.MERGED)}
  291. >
  292. {t('Merged Issues')}
  293. </ListLink>
  294. {hasGroupingTreeUI && (
  295. <ListLink
  296. to={`${baseUrl}grouping/${location.search}`}
  297. isActive={() => currentTab === Tab.GROUPING}
  298. disabled={disabledTabs.includes(Tab.GROUPING)}
  299. >
  300. {t('Grouping')}
  301. </ListLink>
  302. )}
  303. {hasSimilarView && (
  304. <ListLink
  305. to={`${baseUrl}similar/${location.search}`}
  306. isActive={() => currentTab === Tab.SIMILAR_ISSUES}
  307. disabled={disabledTabs.includes(Tab.SIMILAR_ISSUES)}
  308. >
  309. {t('Similar Issues')}
  310. </ListLink>
  311. )}
  312. </NavTabs>
  313. </div>
  314. );
  315. }
  316. }
  317. export {GroupHeader};
  318. export default withApi(withRouter(withOrganization(GroupHeader)));
  319. const TitleWrapper = styled('div')`
  320. display: flex;
  321. line-height: 24px;
  322. `;
  323. const InboxReasonWrapper = styled('div')`
  324. margin-left: ${space(1)};
  325. `;
  326. const StyledTagAndMessageWrapper = styled(TagAndMessageWrapper)`
  327. display: grid;
  328. grid-auto-flow: column;
  329. gap: ${space(1)};
  330. justify-content: flex-start;
  331. line-height: 1.2;
  332. @media (max-width: ${p => p.theme.breakpoints[0]}) {
  333. margin-bottom: ${space(2)};
  334. }
  335. `;
  336. const StyledListLink = styled(ListLink)`
  337. svg {
  338. margin-left: ${space(0.5)};
  339. margin-bottom: ${space(0.25)};
  340. vertical-align: middle;
  341. }
  342. `;
  343. const StyledProjectBadge = styled(ProjectBadge)`
  344. flex-shrink: 0;
  345. `;
  346. const EventAnnotationWithSpace = styled(EventAnnotation)`
  347. margin-left: ${space(1)};
  348. `;