index.tsx 8.5 KB

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