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