index.tsx 4.6 KB

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