eventOrGroupHeader.tsx 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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 && status === 'ignored' && (
  69. <IconWrapper>
  70. <IconMute color="red400" />
  71. </IconWrapper>
  72. )}
  73. {!hideIcons && isBookmarked && (
  74. <IconWrapper>
  75. <IconStar isSolid color="yellow400" />
  76. </IconWrapper>
  77. )}
  78. <ErrorBoundary customComponent={<EventTitleError />} mini>
  79. <StyledEventOrGroupTitle
  80. data={data}
  81. organization={organization}
  82. hasSeen={hasGroupingTreeUI && hasSeen === undefined ? true : hasSeen}
  83. withStackTracePreview
  84. hasGuideAnchor={index === 0}
  85. grouping={grouping}
  86. />
  87. </ErrorBoundary>
  88. </Fragment>
  89. );
  90. }
  91. function getTitle() {
  92. const orgId = organization.slug;
  93. const {id, status} = data as Group;
  94. const {eventID, groupID} = data as Event;
  95. const commonEleProps = {
  96. 'data-test-id': status === 'resolved' ? 'resolved-issue' : null,
  97. style: status === 'resolved' ? {textDecoration: 'line-through'} : undefined,
  98. };
  99. if (includeLink) {
  100. return (
  101. <TitleWithLink
  102. {...commonEleProps}
  103. to={{
  104. pathname: `/organizations/${orgId}/issues/${eventID ? groupID : id}/${
  105. eventID ? `events/${eventID}/` : ''
  106. }`,
  107. query: {
  108. referrer: source || 'event-or-group-header',
  109. stream_index: index,
  110. query,
  111. // This adds sort to the query if one was selected from the
  112. // issues list page
  113. ...(location.query.sort !== undefined ? {sort: location.query.sort} : {}),
  114. // This appends _allp to the URL parameters if they have no
  115. // project selected ("all" projects included in results). This is
  116. // so that when we enter the issue details page and lock them to
  117. // a project, we can properly take them back to the issue list
  118. // page with no project selected (and not the locked project
  119. // selected)
  120. ...(location.query.project !== undefined ? {} : {_allp: 1}),
  121. },
  122. }}
  123. onClick={onClick}
  124. >
  125. {getTitleChildren()}
  126. </TitleWithLink>
  127. );
  128. }
  129. return <TitleWithoutLink {...commonEleProps}>{getTitleChildren()}</TitleWithoutLink>;
  130. }
  131. const eventLocation = getLocation(data);
  132. const message = getMessage(data);
  133. return (
  134. <div className={className} data-test-id="event-issue-header">
  135. <Title size={size} hasGroupingTreeUI={hasGroupingTreeUI}>
  136. {getTitle()}
  137. </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')<{hasGroupingTreeUI: boolean; size: Size}>`
  160. line-height: 1;
  161. margin-bottom: ${space(0.25)};
  162. & em {
  163. font-size: ${p => p.theme.fontSizeMedium};
  164. font-style: normal;
  165. font-weight: 300;
  166. color: ${p => p.theme.subText};
  167. }
  168. `;
  169. const LocationWrapper = styled('div')`
  170. ${truncateStyles};
  171. ${getMargin};
  172. direction: rtl;
  173. text-align: left;
  174. font-size: ${p => p.theme.fontSizeMedium};
  175. color: ${p => p.theme.subText};
  176. span {
  177. direction: ltr;
  178. }
  179. `;
  180. function Location(props) {
  181. const {children, ...rest} = props;
  182. return (
  183. <LocationWrapper {...rest}>
  184. {tct('in [location]', {
  185. location: <span>{children}</span>,
  186. })}
  187. </LocationWrapper>
  188. );
  189. }
  190. const StyledTagAndMessageWrapper = styled(TagAndMessageWrapper)`
  191. ${getMargin};
  192. line-height: 1.2;
  193. `;
  194. const Message = styled('div')`
  195. ${truncateStyles};
  196. font-size: ${p => p.theme.fontSizeMedium};
  197. `;
  198. const IconWrapper = styled('span')`
  199. position: relative;
  200. margin-right: 5px;
  201. `;
  202. const GroupLevel = styled('div')<{level: Level}>`
  203. position: absolute;
  204. left: -1px;
  205. width: 9px;
  206. height: 15px;
  207. border-radius: 0 3px 3px 0;
  208. background-color: ${p => p.theme.level[p.level] ?? p.theme.level.default};
  209. `;
  210. const TitleWithLink = styled(GlobalSelectionLink)`
  211. display: flex;
  212. `;
  213. const TitleWithoutLink = styled('span')`
  214. display: flex;
  215. `;
  216. export default withOrganization(EventOrGroupHeader);
  217. const StyledEventOrGroupTitle = styled(EventOrGroupTitle)<{
  218. hasSeen: boolean;
  219. }>`
  220. font-weight: ${p => (p.hasSeen ? 400 : 600)};
  221. `;