index.tsx 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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 => {
  121. if (e) {
  122. registerChild(e);
  123. }
  124. }}
  125. handleSort={handleSort}
  126. index={columnIndex}
  127. sortConfig={sortConfig}
  128. style={{...style, height: HEADER_HEIGHT}}
  129. />
  130. ) : (
  131. <NetworkTableCell
  132. columnIndex={columnIndex}
  133. currentHoverTime={currentHoverTime}
  134. currentTime={currentTime}
  135. frame={network}
  136. onMouseEnter={onMouseEnter}
  137. onMouseLeave={onMouseLeave}
  138. onClickCell={onClickCell}
  139. onClickTimestamp={onClickTimestamp}
  140. ref={e => {
  141. if (e) {
  142. registerChild(e);
  143. }
  144. }}
  145. rowIndex={rowIndex}
  146. sortConfig={sortConfig}
  147. startTimestampMs={startTimestampMs}
  148. style={{...style, height: BODY_HEIGHT}}
  149. />
  150. )
  151. }
  152. </CellMeasurer>
  153. );
  154. };
  155. return (
  156. <FluidHeight>
  157. <FilterLoadingIndicator isLoading={!replay}>
  158. <NetworkFilters networkFrames={networkFrames} {...filterProps} />
  159. </FilterLoadingIndicator>
  160. <GridTable ref={containerRef} data-test-id="replay-details-network-tab">
  161. <SplitPanel
  162. style={{
  163. gridTemplateRows: splitSize === undefined ? '1fr' : `1fr auto ${splitSize}px`,
  164. }}
  165. >
  166. {networkFrames ? (
  167. <OverflowHidden>
  168. <AutoSizer onResize={onWrapperResize}>
  169. {({height, width}) => (
  170. <MultiGrid
  171. ref={gridRef}
  172. cellRenderer={cellRenderer}
  173. columnCount={COLUMN_COUNT}
  174. columnWidth={getColumnWidth(width)}
  175. deferredMeasurementCache={cache}
  176. estimatedColumnSize={100}
  177. estimatedRowSize={BODY_HEIGHT}
  178. fixedRowCount={1}
  179. height={height}
  180. noContentRenderer={() => (
  181. <NoRowRenderer
  182. unfilteredItems={networkFrames}
  183. clearSearchTerm={clearSearchTerm}
  184. >
  185. {t('No network requests recorded')}
  186. </NoRowRenderer>
  187. )}
  188. onScrollbarPresenceChange={onScrollbarPresenceChange}
  189. onScroll={() => {
  190. if (scrollToRow !== undefined) {
  191. setScrollToRow(undefined);
  192. }
  193. }}
  194. onSectionRendered={onSectionRendered}
  195. overscanColumnCount={COLUMN_COUNT}
  196. overscanRowCount={5}
  197. rowCount={items.length + 1}
  198. rowHeight={({index}) => (index === 0 ? HEADER_HEIGHT : BODY_HEIGHT)}
  199. scrollToRow={scrollToRow}
  200. width={width}
  201. />
  202. )}
  203. </AutoSizer>
  204. {sortConfig.by === 'startTimestamp' && items.length ? (
  205. <JumpButtons
  206. jump={showJumpUpButton ? 'up' : showJumpDownButton ? 'down' : undefined}
  207. onClick={onClickToJump}
  208. tableHeaderHeight={HEADER_HEIGHT}
  209. />
  210. ) : null}
  211. </OverflowHidden>
  212. ) : (
  213. <Placeholder height="100%" />
  214. )}
  215. <NetworkDetails
  216. {...resizableDrawerProps}
  217. isSetup={isNetworkDetailsSetup}
  218. isCaptureBodySetup={isCaptureBodySetup}
  219. // @ts-expect-error TS(7015): Element implicitly has an 'any' type because index... Remove this comment to see the full error message
  220. item={selectedIndex ? items[selectedIndex] : null}
  221. onClose={onCloseDetailsSplit}
  222. projectId={projectId}
  223. startTimestampMs={startTimestampMs}
  224. />
  225. </SplitPanel>
  226. </GridTable>
  227. </FluidHeight>
  228. );
  229. }
  230. export default NetworkList;