eventOrGroupHeader.tsx 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. import {Fragment} from 'react';
  2. import {css} from '@emotion/react';
  3. import styled from '@emotion/styled';
  4. import capitalize from 'lodash/capitalize';
  5. import ErrorBoundary from 'sentry/components/errorBoundary';
  6. import EventOrGroupTitle from 'sentry/components/eventOrGroupTitle';
  7. import GlobalSelectionLink from 'sentry/components/globalSelectionLink';
  8. import {Tooltip} from 'sentry/components/tooltip';
  9. import {IconMute, IconStar} from 'sentry/icons';
  10. import {tct} from 'sentry/locale';
  11. import {space} from 'sentry/styles/space';
  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 {useLocation} from 'sentry/utils/useLocation';
  16. import withOrganization from 'sentry/utils/withOrganization';
  17. import {TagAndMessageWrapper} from 'sentry/views/issueDetails/unhandledTag';
  18. import EventTitleError from './eventTitleError';
  19. type Size = 'small' | 'normal';
  20. type Props = {
  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. source?: string;
  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. query,
  44. onClick,
  45. className,
  46. hideIcons,
  47. hideLevel,
  48. includeLink = true,
  49. size = 'normal',
  50. grouping = false,
  51. source,
  52. }: Props) {
  53. const location = useLocation();
  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 &&
  69. status === 'ignored' &&
  70. !organization.features.includes('escalating-issues-ui') && (
  71. <IconWrapper>
  72. <IconMute color="red400" />
  73. </IconWrapper>
  74. )}
  75. {!hideIcons && isBookmarked && (
  76. <IconWrapper>
  77. <IconStar isSolid color="yellow400" />
  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 = organization.slug;
  95. const {id, status} = data as Group;
  96. const {eventID, groupID} = data as Event;
  97. const commonEleProps = {
  98. 'data-test-id': status === 'resolved' ? 'resolved-issue' : null,
  99. style: status === 'resolved' ? {textDecoration: 'line-through'} : undefined,
  100. };
  101. if (includeLink) {
  102. return (
  103. <TitleWithLink
  104. {...commonEleProps}
  105. to={{
  106. pathname: `/organizations/${orgId}/issues/${eventID ? groupID : id}/${
  107. eventID ? `events/${eventID}/` : ''
  108. }`,
  109. query: {
  110. referrer: source || 'event-or-group-header',
  111. stream_index: index,
  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. </TitleWithLink>
  129. );
  130. }
  131. return <TitleWithoutLink {...commonEleProps}>{getTitleChildren()}</TitleWithoutLink>;
  132. }
  133. const eventLocation = 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. {eventLocation && <Location size={size}>{eventLocation}</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. `;
  171. const LocationWrapper = styled('div')`
  172. ${truncateStyles};
  173. ${getMargin};
  174. direction: rtl;
  175. text-align: left;
  176. font-size: ${p => p.theme.fontSizeMedium};
  177. color: ${p => p.theme.subText};
  178. span {
  179. direction: ltr;
  180. }
  181. `;
  182. function Location(props) {
  183. const {children, ...rest} = props;
  184. return (
  185. <LocationWrapper {...rest}>
  186. {tct('in [location]', {
  187. location: <span>{children}</span>,
  188. })}
  189. </LocationWrapper>
  190. );
  191. }
  192. const StyledTagAndMessageWrapper = styled(TagAndMessageWrapper)`
  193. ${getMargin};
  194. line-height: 1.2;
  195. `;
  196. const Message = styled('div')`
  197. ${truncateStyles};
  198. font-size: ${p => p.theme.fontSizeMedium};
  199. `;
  200. const IconWrapper = styled('span')`
  201. position: relative;
  202. margin-right: 5px;
  203. `;
  204. const GroupLevel = styled('div')<{level: Level}>`
  205. position: absolute;
  206. left: -1px;
  207. width: 9px;
  208. height: 15px;
  209. border-radius: 0 3px 3px 0;
  210. background-color: ${p => p.theme.level[p.level] ?? p.theme.level.default};
  211. `;
  212. const TitleWithLink = styled(GlobalSelectionLink)`
  213. display: flex;
  214. `;
  215. const TitleWithoutLink = styled('span')`
  216. display: flex;
  217. `;
  218. export default withOrganization(EventOrGroupHeader);
  219. const StyledEventOrGroupTitle = styled(EventOrGroupTitle)<{
  220. hasSeen: boolean;
  221. }>`
  222. font-weight: ${p => (p.hasSeen ? 400 : 600)};
  223. `;