eventOrGroupHeader.tsx 6.8 KB

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