eventOrGroupHeader.tsx 6.6 KB

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