eventOrGroupHeader.tsx 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. <Tooltip
  61. skipWrapper
  62. disabled={level === 'unknown'}
  63. title={tct('Error level: [level]', {level: capitalize(level)})}
  64. >
  65. <GroupLevel level={level} />
  66. </Tooltip>
  67. )}
  68. {!hideIcons && status === 'ignored' && (
  69. <IconWrapper>
  70. <IconMute color="red300" />
  71. </IconWrapper>
  72. )}
  73. {!hideIcons && isBookmarked && (
  74. <IconWrapper>
  75. <IconStar isSolid color="yellow300" />
  76. </IconWrapper>
  77. )}
  78. <ErrorBoundary customComponent={<EventTitleError />} mini>
  79. <StyledEventOrGroupTitle
  80. data={data}
  81. organization={organization}
  82. hasSeen={hasGroupingTreeUI && hasSeen === undefined ? true : hasSeen}
  83. withStackTracePreview
  84. hasGuideAnchor={index === 0}
  85. grouping={grouping}
  86. />
  87. </ErrorBoundary>
  88. </Fragment>
  89. );
  90. }
  91. function getTitle() {
  92. const orgId = params?.orgId;
  93. const {id, status} = data as Group;
  94. const {eventID, groupID} = data as Event;
  95. const {location} = props;
  96. const commonEleProps = {
  97. 'data-test-id': status === 'resolved' ? 'resolved-issue' : null,
  98. style: status === 'resolved' ? {textDecoration: 'line-through'} : undefined,
  99. };
  100. if (includeLink) {
  101. return (
  102. <GlobalSelectionLink
  103. {...commonEleProps}
  104. to={{
  105. pathname: `/organizations/${orgId}/issues/${eventID ? groupID : id}/${
  106. eventID ? `events/${eventID}/` : ''
  107. }`,
  108. query: {
  109. query,
  110. // This adds sort to the query if one was selected from the
  111. // issues list page
  112. ...(location.query.sort !== undefined ? {sort: location.query.sort} : {}),
  113. // This appends _allp to the URL parameters if they have no
  114. // project selected ("all" projects included in results). This is
  115. // so that when we enter the issue details page and lock them to
  116. // a project, we can properly take them back to the issue list
  117. // page with no project selected (and not the locked project
  118. // selected)
  119. ...(location.query.project !== undefined ? {} : {_allp: 1}),
  120. },
  121. }}
  122. onClick={onClick}
  123. >
  124. {getTitleChildren()}
  125. </GlobalSelectionLink>
  126. );
  127. }
  128. return <span {...commonEleProps}>{getTitleChildren()}</span>;
  129. }
  130. const location = getLocation(data);
  131. const message = getMessage(data);
  132. return (
  133. <div className={className} data-test-id="event-issue-header">
  134. <Title size={size} hasGroupingTreeUI={hasGroupingTreeUI}>
  135. {getTitle()}
  136. </Title>
  137. {location && <Location size={size}>{location}</Location>}
  138. {message && (
  139. <StyledTagAndMessageWrapper size={size}>
  140. {message && <Message>{message}</Message>}
  141. </StyledTagAndMessageWrapper>
  142. )}
  143. </div>
  144. );
  145. }
  146. const truncateStyles = css`
  147. overflow: hidden;
  148. max-width: 100%;
  149. text-overflow: ellipsis;
  150. white-space: nowrap;
  151. `;
  152. const getMargin = ({size}: {size: Size}) => {
  153. if (size === 'small') {
  154. return 'margin: 0;';
  155. }
  156. return 'margin: 0 0 5px';
  157. };
  158. const Title = styled('div')<{hasGroupingTreeUI: boolean; size: Size}>`
  159. line-height: 1;
  160. margin-bottom: ${space(0.25)};
  161. & em {
  162. font-size: ${p => p.theme.fontSizeMedium};
  163. font-style: normal;
  164. font-weight: 300;
  165. color: ${p => p.theme.subText};
  166. }
  167. ${p =>
  168. !p.hasGroupingTreeUI
  169. ? css`
  170. ${truncateStyles}
  171. `
  172. : css`
  173. > a:first-child {
  174. display: inline-flex;
  175. min-height: ${space(3)};
  176. }
  177. `}
  178. `;
  179. const LocationWrapper = styled('div')`
  180. ${truncateStyles};
  181. ${getMargin};
  182. direction: rtl;
  183. text-align: left;
  184. font-size: ${p => p.theme.fontSizeMedium};
  185. color: ${p => p.theme.subText};
  186. span {
  187. direction: ltr;
  188. }
  189. `;
  190. function Location(props) {
  191. const {children, ...rest} = props;
  192. return (
  193. <LocationWrapper {...rest}>
  194. {tct('in [location]', {
  195. location: <span>{children}</span>,
  196. })}
  197. </LocationWrapper>
  198. );
  199. }
  200. const StyledTagAndMessageWrapper = styled(TagAndMessageWrapper)`
  201. ${getMargin};
  202. line-height: 1.2;
  203. `;
  204. const Message = styled('div')`
  205. ${truncateStyles};
  206. font-size: ${p => p.theme.fontSizeMedium};
  207. `;
  208. const IconWrapper = styled('span')`
  209. position: relative;
  210. display: flex;
  211. margin-right: 5px;
  212. `;
  213. const GroupLevel = styled('div')<{level: Level}>`
  214. position: absolute;
  215. left: -1px;
  216. width: 9px;
  217. height: 15px;
  218. border-radius: 0 3px 3px 0;
  219. background-color: ${p => p.theme.level[p.level] ?? p.theme.level.default};
  220. `;
  221. export default withRouter(withOrganization(EventOrGroupHeader));
  222. const StyledEventOrGroupTitle = styled(EventOrGroupTitle)<{
  223. hasSeen: boolean;
  224. }>`
  225. font-weight: ${p => (p.hasSeen ? 400 : 600)};
  226. `;