index.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import {useRef} from 'react';
  2. import styled from '@emotion/styled';
  3. import ErrorBoundary from 'sentry/components/errorBoundary';
  4. import ReplayController from 'sentry/components/replays/replayController';
  5. import ReplayView from 'sentry/components/replays/replayView';
  6. import {space} from 'sentry/styles/space';
  7. import useReplayLayout, {LayoutKey} from 'sentry/utils/replays/hooks/useReplayLayout';
  8. import {useDimensions} from 'sentry/utils/useDimensions';
  9. import useFullscreen from 'sentry/utils/window/useFullscreen';
  10. import FluidHeight from 'sentry/views/replays/detail/layout/fluidHeight';
  11. import FluidPanel from 'sentry/views/replays/detail/layout/fluidPanel';
  12. import FocusArea from 'sentry/views/replays/detail/layout/focusArea';
  13. import FocusTabs from 'sentry/views/replays/detail/layout/focusTabs';
  14. import SplitPanel from 'sentry/views/replays/detail/layout/splitPanel';
  15. const MIN_CONTENT_WIDTH = 340;
  16. const MIN_SIDEBAR_WIDTH = 325;
  17. const MIN_VIDEO_HEIGHT = 200;
  18. const MIN_CONTENT_HEIGHT = 180;
  19. const DIVIDER_SIZE = 16;
  20. function ReplayLayout() {
  21. const {getLayout} = useReplayLayout();
  22. const layout = getLayout() ?? LayoutKey.TOPBAR;
  23. const fullscreenRef = useRef(null);
  24. const {toggle: toggleFullscreen} = useFullscreen({
  25. elementRef: fullscreenRef,
  26. });
  27. const measureRef = useRef<HTMLDivElement>(null);
  28. const {width, height} = useDimensions({elementRef: measureRef});
  29. const video = (
  30. <VideoSection ref={fullscreenRef}>
  31. <ErrorBoundary mini>
  32. <ReplayView toggleFullscreen={toggleFullscreen} />
  33. </ErrorBoundary>
  34. </VideoSection>
  35. );
  36. const controller = (
  37. <ErrorBoundary mini>
  38. <ReplayController toggleFullscreen={toggleFullscreen} />
  39. </ErrorBoundary>
  40. );
  41. if (layout === LayoutKey.VIDEO_ONLY) {
  42. return (
  43. <BodyContent>
  44. {video}
  45. {controller}
  46. </BodyContent>
  47. );
  48. }
  49. const focusArea = (
  50. <FluidPanel title={<SmallMarginFocusTabs />}>
  51. <ErrorBoundary mini>
  52. <FocusArea />
  53. </ErrorBoundary>
  54. </FluidPanel>
  55. );
  56. const hasSize = width + height > 0;
  57. if (layout === LayoutKey.NO_VIDEO) {
  58. return (
  59. <BodyContent>
  60. <FluidHeight ref={measureRef}>
  61. {hasSize ? <PanelContainer key={layout}>{focusArea}</PanelContainer> : null}
  62. </FluidHeight>
  63. </BodyContent>
  64. );
  65. }
  66. if (layout === LayoutKey.SIDEBAR_LEFT) {
  67. return (
  68. <BodyContent>
  69. <FluidHeight ref={measureRef}>
  70. {hasSize ? (
  71. <SplitPanel
  72. key={layout}
  73. availableSize={width}
  74. left={{
  75. content: <PanelContainer key={layout}>{video}</PanelContainer>,
  76. default: width * 0.5,
  77. min: MIN_SIDEBAR_WIDTH,
  78. max: width - MIN_CONTENT_WIDTH,
  79. }}
  80. right={focusArea}
  81. />
  82. ) : null}
  83. </FluidHeight>
  84. {controller}
  85. </BodyContent>
  86. );
  87. }
  88. // layout === 'topbar'
  89. return (
  90. <BodyContent>
  91. <FluidHeight ref={measureRef}>
  92. {hasSize ? (
  93. <SplitPanel
  94. key={layout}
  95. availableSize={height}
  96. top={{
  97. content: <PanelContainer>{video}</PanelContainer>,
  98. default: (height - DIVIDER_SIZE) * 0.5,
  99. min: MIN_VIDEO_HEIGHT,
  100. max: height - DIVIDER_SIZE - MIN_CONTENT_HEIGHT,
  101. }}
  102. bottom={focusArea}
  103. />
  104. ) : null}
  105. </FluidHeight>
  106. {controller}
  107. </BodyContent>
  108. );
  109. }
  110. const BodyContent = styled('main')`
  111. background: ${p => p.theme.background};
  112. width: 100%;
  113. height: 100%;
  114. display: grid;
  115. grid-template-rows: 1fr auto;
  116. gap: ${space(2)};
  117. overflow: hidden;
  118. padding: ${space(2)};
  119. `;
  120. const SmallMarginFocusTabs = styled(FocusTabs)`
  121. margin-bottom: ${space(1)};
  122. `;
  123. const VideoSection = styled(FluidHeight)`
  124. background: ${p => p.theme.background};
  125. gap: ${space(1)};
  126. :fullscreen {
  127. padding: ${space(1)};
  128. }
  129. `;
  130. const PanelContainer = styled('div')`
  131. width: 100%;
  132. height: 100%;
  133. position: relative;
  134. display: grid;
  135. overflow: auto;
  136. &.disable-iframe-pointer iframe {
  137. pointer-events: none !important;
  138. }
  139. `;
  140. export default ReplayLayout;