index.tsx 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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 networkFrames = replay?.getNetworkFrames();
  45. const projectId = replay?.getReplay()?.project_id;
  46. const startTimestampMs = replay?.getReplay()?.started_at?.getTime() || 0;
  47. const [scrollToRow, setScrollToRow] = useState<undefined | number>(undefined);
  48. const filterProps = useNetworkFilters({networkFrames: networkFrames || []});
  49. const {items: filteredItems, searchTerm, setSearchTerm} = filterProps;
  50. const clearSearchTerm = () => setSearchTerm('');
  51. const {handleSort, items, sortConfig} = useSortNetwork({items: filteredItems});
  52. const containerRef = useRef<HTMLDivElement>(null);
  53. const gridRef = useRef<MultiGrid>(null);
  54. const deps = useMemo(() => [items, searchTerm], [items, searchTerm]);
  55. const {cache, getColumnWidth, onScrollbarPresenceChange, onWrapperResize} =
  56. useVirtualizedGrid({
  57. cellMeasurer,
  58. gridRef,
  59. columnCount: COLUMN_COUNT,
  60. dynamicColumnIndex: 2,
  61. deps,
  62. });
  63. const {
  64. onClickCell,
  65. onCloseDetailsSplit,
  66. resizableDrawerProps,
  67. selectedIndex,
  68. splitSize,
  69. } = useDetailsSplit({
  70. containerRef,
  71. frames: networkFrames,
  72. handleHeight: RESIZEABLE_HANDLE_HEIGHT,
  73. urlParamName: 'n_detail_row',
  74. onShowDetails: useCallback(
  75. ({dataIndex, rowIndex}) => {
  76. setScrollToRow(rowIndex);
  77. const item = items[dataIndex];
  78. trackAnalytics('replay.details-network-panel-opened', {
  79. is_sdk_setup: isNetworkDetailsSetup,
  80. organization,
  81. resource_method: getFrameMethod(item),
  82. resource_status: String(getFrameStatus(item)),
  83. resource_type: item.op,
  84. });
  85. },
  86. [organization, items, isNetworkDetailsSetup]
  87. ),
  88. onHideDetails: useCallback(() => {
  89. trackAnalytics('replay.details-network-panel-closed', {
  90. is_sdk_setup: isNetworkDetailsSetup,
  91. organization,
  92. });
  93. }, [organization, isNetworkDetailsSetup]),
  94. });
  95. const {
  96. handleClick: onClickToJump,
  97. onSectionRendered,
  98. showJumpDownButton,
  99. showJumpUpButton,
  100. } = useJumpButtons({
  101. currentTime,
  102. frames: filteredItems,
  103. isTable: true,
  104. setScrollToRow,
  105. });
  106. const cellRenderer = ({columnIndex, rowIndex, key, style, parent}: GridCellProps) => {
  107. const network = items[rowIndex - 1];
  108. return (
  109. <CellMeasurer
  110. cache={cache}
  111. columnIndex={columnIndex}
  112. key={key}
  113. parent={parent}
  114. rowIndex={rowIndex}
  115. >
  116. {({measure: _, registerChild}) =>
  117. rowIndex === 0 ? (
  118. <NetworkHeaderCell
  119. ref={e => e && registerChild?.(e)}
  120. handleSort={handleSort}
  121. index={columnIndex}
  122. sortConfig={sortConfig}
  123. style={{...style, height: HEADER_HEIGHT}}
  124. />
  125. ) : (
  126. <NetworkTableCell
  127. columnIndex={columnIndex}
  128. currentHoverTime={currentHoverTime}
  129. currentTime={currentTime}
  130. frame={network}
  131. onMouseEnter={onMouseEnter}
  132. onMouseLeave={onMouseLeave}
  133. onClickCell={onClickCell}
  134. onClickTimestamp={onClickTimestamp}
  135. ref={e => e && registerChild?.(e)}
  136. rowIndex={rowIndex}
  137. sortConfig={sortConfig}
  138. startTimestampMs={startTimestampMs}
  139. style={{...style, height: BODY_HEIGHT}}
  140. />
  141. )
  142. }
  143. </CellMeasurer>
  144. );
  145. };
  146. return (
  147. <FluidHeight>
  148. <FilterLoadingIndicator isLoading={!replay}>
  149. <NetworkFilters networkFrames={networkFrames} {...filterProps} />
  150. </FilterLoadingIndicator>
  151. <GridTable ref={containerRef} data-test-id="replay-details-network-tab">
  152. <SplitPanel
  153. style={{
  154. gridTemplateRows: splitSize !== undefined ? `1fr auto ${splitSize}px` : '1fr',
  155. }}
  156. >
  157. {networkFrames ? (
  158. <OverflowHidden>
  159. <AutoSizer onResize={onWrapperResize}>
  160. {({height, width}) => (
  161. <MultiGrid
  162. ref={gridRef}
  163. cellRenderer={cellRenderer}
  164. columnCount={COLUMN_COUNT}
  165. columnWidth={getColumnWidth(width)}
  166. deferredMeasurementCache={cache}
  167. estimatedColumnSize={100}
  168. estimatedRowSize={BODY_HEIGHT}
  169. fixedRowCount={1}
  170. height={height}
  171. noContentRenderer={() => (
  172. <NoRowRenderer
  173. unfilteredItems={networkFrames}
  174. clearSearchTerm={clearSearchTerm}
  175. >
  176. {t('No network requests recorded')}
  177. </NoRowRenderer>
  178. )}
  179. onScrollbarPresenceChange={onScrollbarPresenceChange}
  180. onScroll={() => {
  181. if (scrollToRow !== undefined) {
  182. setScrollToRow(undefined);
  183. }
  184. }}
  185. onSectionRendered={onSectionRendered}
  186. overscanColumnCount={COLUMN_COUNT}
  187. overscanRowCount={5}
  188. rowCount={items.length + 1}
  189. rowHeight={({index}) => (index === 0 ? HEADER_HEIGHT : BODY_HEIGHT)}
  190. scrollToRow={scrollToRow}
  191. width={width}
  192. />
  193. )}
  194. </AutoSizer>
  195. {sortConfig.by === 'startTimestamp' && items.length ? (
  196. <JumpButtons
  197. jump={showJumpUpButton ? 'up' : showJumpDownButton ? 'down' : undefined}
  198. onClick={onClickToJump}
  199. tableHeaderHeight={HEADER_HEIGHT}
  200. />
  201. ) : null}
  202. </OverflowHidden>
  203. ) : (
  204. <Placeholder height="100%" />
  205. )}
  206. <NetworkDetails
  207. {...resizableDrawerProps}
  208. isSetup={isNetworkDetailsSetup}
  209. item={selectedIndex ? items[selectedIndex] : null}
  210. onClose={onCloseDetailsSplit}
  211. projectId={projectId}
  212. startTimestampMs={startTimestampMs}
  213. />
  214. </SplitPanel>
  215. </GridTable>
  216. </FluidHeight>
  217. );
  218. }
  219. export default NetworkList;