eventOrGroupHeader.tsx 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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>{getTitle()}</Title>
  138. {eventLocation && <Location size={size}>{eventLocation}</Location>}
  139. {message && (
  140. <StyledTagAndMessageWrapper size={size}>
  141. {message && <Message>{message}</Message>}
  142. </StyledTagAndMessageWrapper>
  143. )}
  144. </div>
  145. );
  146. }
  147. const truncateStyles = css`
  148. overflow: hidden;
  149. max-width: 100%;
  150. text-overflow: ellipsis;
  151. white-space: nowrap;
  152. `;
  153. const getMargin = ({size}: {size: Size}) => {
  154. if (size === 'small') {
  155. return 'margin: 0;';
  156. }
  157. return 'margin: 0 0 5px';
  158. };
  159. const Title = styled('div')`
  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. `;
  168. const LocationWrapper = styled('div')`
  169. ${truncateStyles};
  170. ${getMargin};
  171. direction: rtl;
  172. text-align: left;
  173. font-size: ${p => p.theme.fontSizeMedium};
  174. color: ${p => p.theme.subText};
  175. span {
  176. direction: ltr;
  177. }
  178. `;
  179. function Location(props) {
  180. const {children, ...rest} = props;
  181. return (
  182. <LocationWrapper {...rest}>
  183. {tct('in [location]', {
  184. location: <span>{children}</span>,
  185. })}
  186. </LocationWrapper>
  187. );
  188. }
  189. const StyledTagAndMessageWrapper = styled(TagAndMessageWrapper)`
  190. ${getMargin};
  191. line-height: 1.2;
  192. `;
  193. const Message = styled('div')`
  194. ${truncateStyles};
  195. font-size: ${p => p.theme.fontSizeMedium};
  196. `;
  197. const IconWrapper = styled('span')`
  198. position: relative;
  199. margin-right: 5px;
  200. `;
  201. const GroupLevel = styled('div')<{level: Level}>`
  202. position: absolute;
  203. left: -1px;
  204. width: 9px;
  205. height: 15px;
  206. border-radius: 0 3px 3px 0;
  207. background-color: ${p => p.theme.level[p.level] ?? p.theme.level.default};
  208. `;
  209. const TitleWithLink = styled(GlobalSelectionLink)`
  210. display: flex;
  211. `;
  212. const TitleWithoutLink = styled('span')`
  213. display: flex;
  214. `;
  215. export default withOrganization(EventOrGroupHeader);
  216. const StyledEventOrGroupTitle = styled(EventOrGroupTitle)<{
  217. hasSeen: boolean;
  218. }>`
  219. font-weight: ${p => (p.hasSeen ? 400 : 600)};
  220. `;