eventOrGroupHeader.tsx 6.8 KB

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