eventTitle.tsx 9.3 KB

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