eventTitle.tsx 10 KB

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