index.tsx 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. import {useCallback, useMemo, useRef, useState} from 'react';
  2. import type {GridCellProps} from 'react-virtualized';
  3. import {AutoSizer, CellMeasurer, MultiGrid} from 'react-virtualized';
  4. import Placeholder from 'sentry/components/placeholder';
  5. import JumpButtons from 'sentry/components/replays/jumpButtons';
  6. import {useReplayContext} from 'sentry/components/replays/replayContext';
  7. import useJumpButtons from 'sentry/components/replays/useJumpButtons';
  8. import {GridTable} from 'sentry/components/replays/virtualizedGrid/gridTable';
  9. import {OverflowHidden} from 'sentry/components/replays/virtualizedGrid/overflowHidden';
  10. import {SplitPanel} from 'sentry/components/replays/virtualizedGrid/splitPanel';
  11. import useDetailsSplit from 'sentry/components/replays/virtualizedGrid/useDetailsSplit';
  12. import {t} from 'sentry/locale';
  13. import {trackAnalytics} from 'sentry/utils/analytics';
  14. import useCrumbHandlers from 'sentry/utils/replays/hooks/useCrumbHandlers';
  15. import useCurrentHoverTime from 'sentry/utils/replays/playback/providers/useCurrentHoverTime';
  16. import {getFrameMethod, getFrameStatus} from 'sentry/utils/replays/resourceFrame';
  17. import useOrganization from 'sentry/utils/useOrganization';
  18. import FilterLoadingIndicator from 'sentry/views/replays/detail/filterLoadingIndicator';
  19. import FluidHeight from 'sentry/views/replays/detail/layout/fluidHeight';
  20. import NetworkDetails from 'sentry/views/replays/detail/network/details';
  21. import NetworkFilters from 'sentry/views/replays/detail/network/networkFilters';
  22. import NetworkHeaderCell, {
  23. COLUMN_COUNT,
  24. } from 'sentry/views/replays/detail/network/networkHeaderCell';
  25. import NetworkTableCell from 'sentry/views/replays/detail/network/networkTableCell';
  26. import useNetworkFilters from 'sentry/views/replays/detail/network/useNetworkFilters';
  27. import useSortNetwork from 'sentry/views/replays/detail/network/useSortNetwork';
  28. import NoRowRenderer from 'sentry/views/replays/detail/noRowRenderer';
  29. import useVirtualizedGrid from 'sentry/views/replays/detail/useVirtualizedGrid';
  30. const HEADER_HEIGHT = 25;
  31. const BODY_HEIGHT = 25;
  32. const RESIZEABLE_HANDLE_HEIGHT = 90;
  33. const cellMeasurer = {
  34. defaultHeight: BODY_HEIGHT,
  35. defaultWidth: 100,
  36. fixedHeight: true,
  37. };
  38. function NetworkList() {
  39. const organization = useOrganization();
  40. const {currentTime, replay} = useReplayContext();
  41. const [currentHoverTime] = useCurrentHoverTime();
  42. const {onMouseEnter, onMouseLeave, onClickTimestamp} = useCrumbHandlers();
  43. const isNetworkDetailsSetup = Boolean(replay?.isNetworkDetailsSetup());
  44. const isCaptureBodySetup = Boolean(replay?.isNetworkCaptureBodySetup());
  45. const networkFrames = replay?.getNetworkFrames();
  46. const projectId = replay?.getReplay()?.project_id;
  47. const startTimestampMs = replay?.getReplay()?.started_at?.getTime() || 0;
  48. const [scrollToRow, setScrollToRow] = useState<undefined | number>(undefined);
  49. const filterProps = useNetworkFilters({networkFrames: networkFrames || []});
  50. const {items: filteredItems, searchTerm, setSearchTerm} = filterProps;
  51. const clearSearchTerm = () => setSearchTerm('');
  52. const {handleSort, items, sortConfig} = useSortNetwork({items: filteredItems});
  53. const containerRef = useRef<HTMLDivElement>(null);
  54. const gridRef = useRef<MultiGrid>(null);
  55. const deps = useMemo(() => [items, searchTerm], [items, searchTerm]);
  56. const {cache, getColumnWidth, onScrollbarPresenceChange, onWrapperResize} =
  57. useVirtualizedGrid({
  58. cellMeasurer,
  59. gridRef,
  60. columnCount: COLUMN_COUNT,
  61. dynamicColumnIndex: 2,
  62. deps,
  63. });
  64. const {
  65. onClickCell,
  66. onCloseDetailsSplit,
  67. resizableDrawerProps,
  68. selectedIndex,
  69. splitSize,
  70. } = useDetailsSplit({
  71. containerRef,
  72. frames: networkFrames,
  73. handleHeight: RESIZEABLE_HANDLE_HEIGHT,
  74. urlParamName: 'n_detail_row',
  75. onShowDetails: useCallback(
  76. ({dataIndex, rowIndex}: any) => {
  77. setScrollToRow(rowIndex);
  78. const item = items[dataIndex];
  79. trackAnalytics('replay.details-network-panel-opened', {
  80. is_sdk_setup: isNetworkDetailsSetup,
  81. organization,
  82. resource_method: getFrameMethod(item!),
  83. resource_status: String(getFrameStatus(item!)),
  84. resource_type: item!.op,
  85. });
  86. },
  87. [organization, items, isNetworkDetailsSetup]
  88. ),
  89. onHideDetails: useCallback(() => {
  90. trackAnalytics('replay.details-network-panel-closed', {
  91. is_sdk_setup: isNetworkDetailsSetup,
  92. organization,
  93. });
  94. }, [organization, isNetworkDetailsSetup]),
  95. });
  96. const {
  97. handleClick: onClickToJump,
  98. onSectionRendered,
  99. showJumpDownButton,
  100. showJumpUpButton,
  101. } = useJumpButtons({
  102. currentTime,
  103. frames: filteredItems,
  104. isTable: true,
  105. setScrollToRow,
  106. });
  107. const cellRenderer = ({columnIndex, rowIndex, key, style, parent}: GridCellProps) => {
  108. const network = items[rowIndex - 1]!;
  109. return (
  110. <CellMeasurer
  111. cache={cache}
  112. columnIndex={columnIndex}
  113. key={key}
  114. parent={parent}
  115. rowIndex={rowIndex}
  116. >
  117. {({measure: _, registerChild}) =>
  118. rowIndex === 0 ? (
  119. <NetworkHeaderCell
  120. ref={e => e && registerChild?.(e)}
  121. handleSort={handleSort}
  122. index={columnIndex}
  123. sortConfig={sortConfig}
  124. style={{...style, height: HEADER_HEIGHT}}
  125. />
  126. ) : (
  127. <NetworkTableCell
  128. columnIndex={columnIndex}
  129. currentHoverTime={currentHoverTime}
  130. currentTime={currentTime}
  131. frame={network}
  132. onMouseEnter={onMouseEnter}
  133. onMouseLeave={onMouseLeave}
  134. onClickCell={onClickCell}
  135. onClickTimestamp={onClickTimestamp}
  136. ref={e => e && registerChild?.(e)}
  137. rowIndex={rowIndex}
  138. sortConfig={sortConfig}
  139. startTimestampMs={startTimestampMs}
  140. style={{...style, height: BODY_HEIGHT}}
  141. />
  142. )
  143. }
  144. </CellMeasurer>
  145. );
  146. };
  147. return (
  148. <FluidHeight>
  149. <FilterLoadingIndicator isLoading={!replay}>
  150. <NetworkFilters networkFrames={networkFrames} {...filterProps} />
  151. </FilterLoadingIndicator>
  152. <GridTable ref={containerRef} data-test-id="replay-details-network-tab">
  153. <SplitPanel
  154. style={{
  155. gridTemplateRows: splitSize !== undefined ? `1fr auto ${splitSize}px` : '1fr',
  156. }}
  157. >
  158. {networkFrames ? (
  159. <OverflowHidden>
  160. <AutoSizer onResize={onWrapperResize}>
  161. {({height, width}) => (
  162. <MultiGrid
  163. ref={gridRef}
  164. cellRenderer={cellRenderer}
  165. columnCount={COLUMN_COUNT}
  166. columnWidth={getColumnWidth(width)}
  167. deferredMeasurementCache={cache}
  168. estimatedColumnSize={100}
  169. estimatedRowSize={BODY_HEIGHT}
  170. fixedRowCount={1}
  171. height={height}
  172. noContentRenderer={() => (
  173. <NoRowRenderer
  174. unfilteredItems={networkFrames}
  175. clearSearchTerm={clearSearchTerm}
  176. >
  177. {t('No network requests recorded')}
  178. </NoRowRenderer>
  179. )}
  180. onScrollbarPresenceChange={onScrollbarPresenceChange}
  181. onScroll={() => {
  182. if (scrollToRow !== undefined) {
  183. setScrollToRow(undefined);
  184. }
  185. }}
  186. onSectionRendered={onSectionRendered}
  187. overscanColumnCount={COLUMN_COUNT}
  188. overscanRowCount={5}
  189. rowCount={items.length + 1}
  190. rowHeight={({index}) => (index === 0 ? HEADER_HEIGHT : BODY_HEIGHT)}
  191. scrollToRow={scrollToRow}
  192. width={width}
  193. />
  194. )}
  195. </AutoSizer>
  196. {sortConfig.by === 'startTimestamp' && items.length ? (
  197. <JumpButtons
  198. jump={showJumpUpButton ? 'up' : showJumpDownButton ? 'down' : undefined}
  199. onClick={onClickToJump}
  200. tableHeaderHeight={HEADER_HEIGHT}
  201. />
  202. ) : null}
  203. </OverflowHidden>
  204. ) : (
  205. <Placeholder height="100%" />
  206. )}
  207. <NetworkDetails
  208. {...resizableDrawerProps}
  209. isSetup={isNetworkDetailsSetup}
  210. isCaptureBodySetup={isCaptureBodySetup}
  211. // @ts-expect-error TS(7015): Element implicitly has an 'any' type because index... Remove this comment to see the full error message
  212. item={selectedIndex ? items[selectedIndex] : null}
  213. onClose={onCloseDetailsSplit}
  214. projectId={projectId}
  215. startTimestampMs={startTimestampMs}
  216. />
  217. </SplitPanel>
  218. </GridTable>
  219. </FluidHeight>
  220. );
  221. }
  222. export default NetworkList;