eventOrGroupHeader.tsx 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. import {Fragment} from 'react';
  2. import {withRouter, WithRouterProps} from 'react-router';
  3. import {css} from '@emotion/react';
  4. import styled from '@emotion/styled';
  5. import capitalize from 'lodash/capitalize';
  6. import ErrorBoundary from 'sentry/components/errorBoundary';
  7. import EventOrGroupTitle from 'sentry/components/eventOrGroupTitle';
  8. import GlobalSelectionLink from 'sentry/components/globalSelectionLink';
  9. import Tooltip from 'sentry/components/tooltip';
  10. import {IconMute, IconStar} from 'sentry/icons';
  11. import {tct} from 'sentry/locale';
  12. import space from 'sentry/styles/space';
  13. import {Group, GroupTombstone, Level, Organization} from 'sentry/types';
  14. import {Event} from 'sentry/types/event';
  15. import {getLocation, getMessage} from 'sentry/utils/events';
  16. import withOrganization from 'sentry/utils/withOrganization';
  17. import {TagAndMessageWrapper} from 'sentry/views/organizationGroupDetails/unhandledTag';
  18. import EventTitleError from './eventTitleError';
  19. type Size = 'small' | 'normal';
  20. type Props = WithRouterProps<{orgId: string}> & {
  21. data: Event | Group | GroupTombstone;
  22. organization: Organization;
  23. className?: string;
  24. /* is issue breakdown? */
  25. grouping?: boolean;
  26. hideIcons?: boolean;
  27. hideLevel?: boolean;
  28. includeLink?: boolean;
  29. index?: number;
  30. /** Group link clicked */
  31. onClick?: () => void;
  32. query?: string;
  33. size?: Size;
  34. };
  35. /**
  36. * Displays an event or group/issue title (i.e. in Stream)
  37. */
  38. function EventOrGroupHeader({
  39. data,
  40. index,
  41. organization,
  42. params,
  43. query,
  44. onClick,
  45. className,
  46. hideIcons,
  47. hideLevel,
  48. includeLink = true,
  49. size = 'normal',
  50. grouping = false,
  51. ...props
  52. }: Props) {
  53. const hasGroupingTreeUI = !!organization.features?.includes('grouping-tree-ui');
  54. function getTitleChildren() {
  55. const {level, status, isBookmarked, hasSeen} = data as Group;
  56. return (
  57. <Fragment>
  58. {!hideLevel && level && (
  59. <GroupLevel level={level}>
  60. <Tooltip title={tct('Error level: [level]', {level: capitalize(level)})}>
  61. <span />
  62. </Tooltip>
  63. </GroupLevel>
  64. )}
  65. {!hideIcons && status === 'ignored' && (
  66. <IconWrapper>
  67. <IconMute color="red300" />
  68. </IconWrapper>
  69. )}
  70. {!hideIcons && isBookmarked && (
  71. <IconWrapper>
  72. <IconStar isSolid color="yellow300" />
  73. </IconWrapper>
  74. )}
  75. <ErrorBoundary customComponent={<EventTitleError />} mini>
  76. <StyledEventOrGroupTitle
  77. data={data}
  78. organization={organization}
  79. hasSeen={hasGroupingTreeUI && hasSeen === undefined ? true : hasSeen}
  80. withStackTracePreview
  81. hasGuideAnchor={index === 0}
  82. grouping={grouping}
  83. />
  84. </ErrorBoundary>
  85. </Fragment>
  86. );
  87. }
  88. function getTitle() {
  89. const orgId = params?.orgId;
  90. const {id, status} = data as Group;
  91. const {eventID, groupID} = data as Event;
  92. const {location} = props;
  93. const commonEleProps = {
  94. 'data-test-id': status === 'resolved' ? 'resolved-issue' : null,
  95. style: status === 'resolved' ? {textDecoration: 'line-through'} : undefined,
  96. };
  97. if (includeLink) {
  98. return (
  99. <GlobalSelectionLink
  100. {...commonEleProps}
  101. to={{
  102. pathname: `/organizations/${orgId}/issues/${eventID ? groupID : id}/${
  103. eventID ? `events/${eventID}/` : ''
  104. }`,
  105. query: {
  106. query,
  107. // This adds sort to the query if one was selected from the
  108. // issues list page
  109. ...(location.query.sort !== undefined ? {sort: location.query.sort} : {}),
  110. // This appends _allp to the URL parameters if they have no
  111. // project selected ("all" projects included in results). This is
  112. // so that when we enter the issue details page and lock them to
  113. // a project, we can properly take them back to the issue list
  114. // page with no project selected (and not the locked project
  115. // selected)
  116. ...(location.query.project !== undefined ? {} : {_allp: 1}),
  117. },
  118. }}
  119. onClick={onClick}
  120. >
  121. {getTitleChildren()}
  122. </GlobalSelectionLink>
  123. );
  124. }
  125. return <span {...commonEleProps}>{getTitleChildren()}</span>;
  126. }
  127. const location = getLocation(data);
  128. const message = getMessage(data);
  129. return (
  130. <div className={className} data-test-id="event-issue-header">
  131. <Title size={size} hasGroupingTreeUI={hasGroupingTreeUI}>
  132. {getTitle()}
  133. </Title>
  134. {location && <Location size={size}>{location}</Location>}
  135. {message && (
  136. <StyledTagAndMessageWrapper size={size}>
  137. {message && <Message>{message}</Message>}
  138. </StyledTagAndMessageWrapper>
  139. )}
  140. </div>
  141. );
  142. }
  143. const truncateStyles = css`
  144. overflow: hidden;
  145. max-width: 100%;
  146. text-overflow: ellipsis;
  147. white-space: nowrap;
  148. `;
  149. const getMargin = ({size}: {size: Size}) => {
  150. if (size === 'small') {
  151. return 'margin: 0;';
  152. }
  153. return 'margin: 0 0 5px';
  154. };
  155. const Title = styled('div')<{hasGroupingTreeUI: boolean; size: Size}>`
  156. line-height: 1;
  157. margin-bottom: ${space(0.25)};
  158. & em {
  159. font-size: ${p => p.theme.fontSizeMedium};
  160. font-style: normal;
  161. font-weight: 300;
  162. color: ${p => p.theme.subText};
  163. }
  164. ${p =>
  165. !p.hasGroupingTreeUI
  166. ? css`
  167. ${truncateStyles}
  168. `
  169. : css`
  170. > a:first-child {
  171. display: flex;
  172. min-height: ${space(3)};
  173. }
  174. `}
  175. `;
  176. const LocationWrapper = styled('div')`
  177. ${truncateStyles};
  178. ${getMargin};
  179. direction: rtl;
  180. text-align: left;
  181. font-size: ${p => p.theme.fontSizeMedium};
  182. color: ${p => p.theme.subText};
  183. span {
  184. direction: ltr;
  185. }
  186. `;
  187. function Location(props) {
  188. const {children, ...rest} = props;
  189. return (
  190. <LocationWrapper {...rest}>
  191. {tct('in [location]', {
  192. location: <span>{children}</span>,
  193. })}
  194. </LocationWrapper>
  195. );
  196. }
  197. const StyledTagAndMessageWrapper = styled(TagAndMessageWrapper)`
  198. ${getMargin};
  199. line-height: 1.2;
  200. `;
  201. const Message = styled('div')`
  202. ${truncateStyles};
  203. font-size: ${p => p.theme.fontSizeMedium};
  204. `;
  205. const IconWrapper = styled('span')`
  206. position: relative;
  207. display: flex;
  208. margin-right: 5px;
  209. `;
  210. const GroupLevel = styled('div')<{level: Level}>`
  211. position: absolute;
  212. left: -1px;
  213. width: 9px;
  214. height: 15px;
  215. border-radius: 0 3px 3px 0;
  216. background-color: ${p => p.theme.level[p.level] ?? p.theme.level.default};
  217. & span {
  218. display: block;
  219. width: 9px;
  220. height: 15px;
  221. }
  222. `;
  223. export default withRouter(withOrganization(EventOrGroupHeader));
  224. const StyledEventOrGroupTitle = styled(EventOrGroupTitle)<{
  225. hasSeen: boolean;
  226. }>`
  227. font-weight: ${p => (p.hasSeen ? 400 : 600)};
  228. `;