eventTitle.tsx 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. import {type CSSProperties, forwardRef, Fragment} from 'react';
  2. import {css, type SerializedStyles, useTheme} from '@emotion/react';
  3. import styled from '@emotion/styled';
  4. import {Button, LinkButton} from 'sentry/components/button';
  5. import DropdownButton from 'sentry/components/dropdownButton';
  6. import {DropdownMenu} from 'sentry/components/dropdownMenu';
  7. import {useActionableItems} from 'sentry/components/events/interfaces/crashContent/exception/useActionableItems';
  8. import {ScrollCarousel} from 'sentry/components/scrollCarousel';
  9. import TimeSince from 'sentry/components/timeSince';
  10. import {Tooltip} from 'sentry/components/tooltip';
  11. import {IconWarning} from 'sentry/icons';
  12. import {t} from 'sentry/locale';
  13. import {space} from 'sentry/styles/space';
  14. import type {Event} from 'sentry/types/event';
  15. import type {Group} from 'sentry/types/group';
  16. import {trackAnalytics} from 'sentry/utils/analytics';
  17. import {
  18. getAnalyticsDataForEvent,
  19. getAnalyticsDataForGroup,
  20. getShortEventId,
  21. } from 'sentry/utils/events';
  22. import normalizeUrl from 'sentry/utils/url/normalizeUrl';
  23. import useCopyToClipboard from 'sentry/utils/useCopyToClipboard';
  24. import useOrganization from 'sentry/utils/useOrganization';
  25. import {useSyncedLocalStorageState} from 'sentry/utils/useSyncedLocalStorageState';
  26. import {Divider} from 'sentry/views/issueDetails/divider';
  27. import {
  28. type SectionConfig,
  29. SectionKey,
  30. useEventDetails,
  31. } from 'sentry/views/issueDetails/streamline/context';
  32. import {getFoldSectionKey} from 'sentry/views/issueDetails/streamline/foldSection';
  33. type EventNavigationProps = {
  34. event: Event;
  35. group: Group;
  36. className?: string;
  37. /**
  38. * Data property to help style the component when it's sticky
  39. */
  40. 'data-stuck'?: boolean;
  41. style?: CSSProperties;
  42. };
  43. const sectionLabels = {
  44. [SectionKey.HIGHLIGHTS]: t('Highlights'),
  45. [SectionKey.STACKTRACE]: t('Stack Trace'),
  46. [SectionKey.TRACE]: t('Trace'),
  47. [SectionKey.EXCEPTION]: t('Stack Trace'),
  48. [SectionKey.BREADCRUMBS]: t('Breadcrumbs'),
  49. [SectionKey.TAGS]: t('Tags'),
  50. [SectionKey.CONTEXTS]: t('Context'),
  51. [SectionKey.USER_FEEDBACK]: t('User Feedback'),
  52. [SectionKey.REPLAY]: t('Replay'),
  53. [SectionKey.FEATURE_FLAGS]: t('Flags'),
  54. };
  55. export const MIN_NAV_HEIGHT = 44;
  56. export const EventTitle = forwardRef<HTMLDivElement, EventNavigationProps>(
  57. function EventNavigation({event, group, ...props}, ref) {
  58. const organization = useOrganization();
  59. const theme = useTheme();
  60. const {sectionData} = useEventDetails();
  61. const eventSectionConfigs = Object.values(sectionData ?? {}).filter(
  62. config => sectionLabels[config.key]
  63. );
  64. const [_isEventErrorCollapsed, setEventErrorCollapsed] = useSyncedLocalStorageState(
  65. getFoldSectionKey(SectionKey.PROCESSING_ERROR),
  66. true
  67. );
  68. const {data: actionableItems} = useActionableItems({
  69. eventId: event.id,
  70. orgSlug: organization.slug,
  71. projectSlug: group.project.slug,
  72. });
  73. const hasEventError = actionableItems?.errors && actionableItems.errors.length > 0;
  74. const baseEventsPath = `/organizations/${organization.slug}/issues/${group.id}/events/`;
  75. const grayText = css`
  76. color: ${theme.subText};
  77. font-weight: ${theme.fontWeightNormal};
  78. `;
  79. const downloadJson = () => {
  80. const host = organization.links.regionUrl;
  81. const jsonUrl = `${host}/api/0/projects/${organization.slug}/${group.project.slug}/events/${event.id}/json/`;
  82. window.open(jsonUrl);
  83. trackAnalytics('issue_details.event_json_clicked', {
  84. organization,
  85. group_id: parseInt(`${event.groupID}`, 10),
  86. });
  87. };
  88. const {onClick: copyLink} = useCopyToClipboard({
  89. successMessage: t('Event URL copied to clipboard'),
  90. text: window.location.origin + normalizeUrl(`${baseEventsPath}${event.id}/`),
  91. onCopy: () =>
  92. trackAnalytics('issue_details.copy_event_link_clicked', {
  93. organization,
  94. ...getAnalyticsDataForGroup(group),
  95. ...getAnalyticsDataForEvent(event),
  96. }),
  97. });
  98. const {onClick: copyEventId} = useCopyToClipboard({
  99. successMessage: t('Event ID copied to clipboard'),
  100. text: event.id,
  101. });
  102. return (
  103. <div {...props} ref={ref}>
  104. <EventInfoJumpToWrapper>
  105. <EventInfo>
  106. <EventIdInfo>
  107. <DropdownMenu
  108. trigger={(triggerProps, isOpen) => (
  109. // Tooltip split from button to prevent re-opening w/ focus event on close
  110. <Tooltip
  111. title={event.id}
  112. delay={500}
  113. overlayStyle={{maxWidth: 'max-content'}}
  114. disabled={isOpen}
  115. >
  116. <DropdownButton
  117. {...triggerProps}
  118. aria-label={t('Event actions')}
  119. size="zero"
  120. borderless
  121. isOpen={isOpen}
  122. >
  123. {getShortEventId(event.id)}
  124. </DropdownButton>
  125. </Tooltip>
  126. )}
  127. position="bottom"
  128. size="xs"
  129. items={[
  130. {
  131. key: 'copy-event-id',
  132. label: t('Copy Event ID'),
  133. onAction: copyEventId,
  134. },
  135. {
  136. key: 'copy-event-link',
  137. label: t('Copy Event Link'),
  138. onAction: copyLink,
  139. },
  140. {
  141. key: 'view-json',
  142. label: t('View JSON'),
  143. onAction: downloadJson,
  144. },
  145. ]}
  146. />
  147. </EventIdInfo>
  148. <StyledTimeSince
  149. date={event.dateCreated ?? event.dateReceived}
  150. css={grayText}
  151. />
  152. {hasEventError && (
  153. <Fragment>
  154. <Divider />
  155. <ProcessingErrorButton
  156. title={t(
  157. 'Sentry has detected configuration issues with this event. Click for more info.'
  158. )}
  159. borderless
  160. size="zero"
  161. icon={<IconWarning color="red300" />}
  162. onClick={() => {
  163. document
  164. .getElementById(SectionKey.PROCESSING_ERROR)
  165. ?.scrollIntoView({block: 'start', behavior: 'smooth'});
  166. setEventErrorCollapsed(false);
  167. }}
  168. >
  169. {t('Processing Error')}
  170. </ProcessingErrorButton>
  171. </Fragment>
  172. )}
  173. </EventInfo>
  174. {eventSectionConfigs.length > 0 && (
  175. <JumpTo>
  176. <div>{t('Jump to:')}</div>
  177. <ScrollCarousel gap={0.25}>
  178. {eventSectionConfigs.map(config => (
  179. <EventNavigationLink
  180. key={config.key}
  181. config={config}
  182. propCss={grayText}
  183. />
  184. ))}
  185. </ScrollCarousel>
  186. </JumpTo>
  187. )}
  188. </EventInfoJumpToWrapper>
  189. </div>
  190. );
  191. }
  192. );
  193. function EventNavigationLink({
  194. config,
  195. propCss,
  196. }: {
  197. config: SectionConfig;
  198. propCss: SerializedStyles;
  199. }) {
  200. const [_isCollapsed, setIsCollapsed] = useSyncedLocalStorageState(
  201. getFoldSectionKey(config.key),
  202. config?.initialCollapse ?? false
  203. );
  204. return (
  205. <LinkButton
  206. to={{
  207. ...location,
  208. hash: `#${config.key}`,
  209. }}
  210. onClick={event => {
  211. event.preventDefault();
  212. setIsCollapsed(false);
  213. document
  214. .getElementById(config.key)
  215. ?.scrollIntoView({block: 'start', behavior: 'smooth'});
  216. }}
  217. borderless
  218. size="xs"
  219. css={propCss}
  220. >
  221. {sectionLabels[config.key]}
  222. </LinkButton>
  223. );
  224. }
  225. const StyledTimeSince = styled(TimeSince)`
  226. color: ${p => p.theme.subText};
  227. font-weight: ${p => p.theme.fontWeightNormal};
  228. white-space: nowrap;
  229. `;
  230. const EventInfoJumpToWrapper = styled('div')`
  231. display: flex;
  232. gap: ${space(1)};
  233. flex-direction: row;
  234. justify-content: space-between;
  235. align-items: center;
  236. padding: ${space(1)} ${space(2)};
  237. flex-wrap: wrap;
  238. min-height: ${MIN_NAV_HEIGHT}px;
  239. @media (min-width: ${p => p.theme.breakpoints.small}) {
  240. flex-wrap: nowrap;
  241. }
  242. box-shadow: ${p => p.theme.translucentBorder} 0 1px;
  243. `;
  244. const EventInfo = styled('div')`
  245. display: flex;
  246. gap: ${space(1)};
  247. flex-direction: row;
  248. align-items: center;
  249. line-height: 1.2;
  250. `;
  251. const JumpTo = styled('div')`
  252. display: flex;
  253. gap: ${space(1)};
  254. flex-direction: row;
  255. align-items: center;
  256. color: ${p => p.theme.subText};
  257. font-size: ${p => p.theme.fontSizeSmall};
  258. white-space: nowrap;
  259. max-width: 100%;
  260. @media (min-width: ${p => p.theme.breakpoints.small}) {
  261. max-width: 50%;
  262. }
  263. `;
  264. const EventIdInfo = styled('span')`
  265. display: flex;
  266. align-items: center;
  267. gap: ${space(0.25)};
  268. line-height: 1.2;
  269. `;
  270. const ProcessingErrorButton = styled(Button)`
  271. color: ${p => p.theme.red300};
  272. font-weight: ${p => p.theme.fontWeightNormal};
  273. font-size: ${p => p.theme.fontSizeSmall};
  274. :hover {
  275. color: ${p => p.theme.red300};
  276. }
  277. `;