eventOrGroupHeader.tsx 6.3 KB

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