eventDetails.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import {useLayoutEffect, useState} from 'react';
  2. import {useTheme} from '@emotion/react';
  3. import styled from '@emotion/styled';
  4. import ErrorBoundary from 'sentry/components/errorBoundary';
  5. import {t} from 'sentry/locale';
  6. import {space} from 'sentry/styles/space';
  7. import type {Event} from 'sentry/types/event';
  8. import type {Group} from 'sentry/types/group';
  9. import {useIsStuck} from 'sentry/utils/useIsStuck';
  10. import useMedia from 'sentry/utils/useMedia';
  11. import {
  12. EventDetailsContent,
  13. type EventDetailsContentProps,
  14. } from 'sentry/views/issueDetails/groupEventDetails/groupEventDetailsContent';
  15. import {
  16. EventDetailsContext,
  17. useEventDetails,
  18. useEventDetailsReducer,
  19. } from 'sentry/views/issueDetails/streamline/context';
  20. import {EventTitle} from 'sentry/views/issueDetails/streamline/eventTitle';
  21. export function EventDetails({
  22. group,
  23. event,
  24. project,
  25. }: Required<EventDetailsContentProps>) {
  26. const {eventDetails, dispatch} = useEventDetailsReducer();
  27. return (
  28. <EventDetailsContext.Provider value={{...eventDetails, dispatch}}>
  29. <PageErrorBoundary mini message={t('There was an error loading the event content')}>
  30. <GroupContent>
  31. <StickyEventNav event={event} group={group} />
  32. <ContentPadding>
  33. <EventDetailsContent group={group} event={event} project={project} />
  34. </ContentPadding>
  35. </GroupContent>
  36. </PageErrorBoundary>
  37. </EventDetailsContext.Provider>
  38. );
  39. }
  40. function StickyEventNav({event, group}: {event: Event; group: Group}) {
  41. const theme = useTheme();
  42. const [nav, setNav] = useState<HTMLDivElement | null>(null);
  43. const isStuck = useIsStuck(nav);
  44. const isScreenMedium = useMedia(`(max-width: ${theme.breakpoints.medium})`);
  45. const {dispatch} = useEventDetails();
  46. useLayoutEffect(() => {
  47. if (!nav) {
  48. return;
  49. }
  50. const navHeight = nav.offsetHeight ?? 0;
  51. const sidebarHeight = isScreenMedium ? theme.sidebar.mobileHeightNumber : 0;
  52. dispatch({
  53. type: 'UPDATE_DETAILS',
  54. state: {navScrollMargin: navHeight + sidebarHeight},
  55. });
  56. }, [nav, isScreenMedium, dispatch, theme.sidebar.mobileHeightNumber]);
  57. return (
  58. <FloatingEventNavigation
  59. event={event}
  60. group={group}
  61. ref={setNav}
  62. data-stuck={isStuck}
  63. />
  64. );
  65. }
  66. const FloatingEventNavigation = styled(EventTitle)`
  67. position: sticky;
  68. top: 0;
  69. @media (max-width: ${p => p.theme.breakpoints.medium}) {
  70. top: ${p => p.theme.sidebar.mobileHeight};
  71. }
  72. background: ${p => p.theme.background};
  73. z-index: ${p => p.theme.zIndex.header};
  74. border-radius: ${p => p.theme.borderRadiusTop};
  75. &[data-stuck='true'] {
  76. border-radius: 0;
  77. }
  78. `;
  79. const GroupContent = styled('div')`
  80. position: relative;
  81. border: 1px solid ${p => p.theme.translucentBorder};
  82. background: ${p => p.theme.background};
  83. border-radius: ${p => p.theme.borderRadius};
  84. `;
  85. const ContentPadding = styled('div')`
  86. padding: ${space(1)} ${space(1.5)};
  87. `;
  88. const PageErrorBoundary = styled(ErrorBoundary)`
  89. margin: 0;
  90. border: 1px solid ${p => p.theme.translucentBorder};
  91. `;