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 {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 {ReqRespBodiesAlert} from 'sentry/views/replays/detail/network/details/onboarding';
  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, currentHoverTime, replay} = useReplayContext();
  41. const {onMouseEnter, onMouseLeave, onClickTimestamp} = useCrumbHandlers();
  42. const isNetworkDetailsSetup = Boolean(replay?.isNetworkDetailsSetup());
  43. const networkFrames = replay?.getNetworkFrames();
  44. const projectId = replay?.getReplay()?.project_id;
  45. const startTimestampMs = replay?.getReplay()?.started_at?.getTime() || 0;
  46. const [scrollToRow, setScrollToRow] = useState<undefined | number>(undefined);
  47. const filterProps = useNetworkFilters({networkFrames: networkFrames || []});
  48. const {items: filteredItems, searchTerm, setSearchTerm} = filterProps;
  49. const clearSearchTerm = () => setSearchTerm('');
  50. const {handleSort, items, sortConfig} = useSortNetwork({items: filteredItems});
  51. const containerRef = useRef<HTMLDivElement>(null);
  52. const gridRef = useRef<MultiGrid>(null);
  53. const deps = useMemo(() => [items, searchTerm], [items, searchTerm]);
  54. const {cache, getColumnWidth, onScrollbarPresenceChange, onWrapperResize} =
  55. useVirtualizedGrid({
  56. cellMeasurer,
  57. gridRef,
  58. columnCount: COLUMN_COUNT,
  59. dynamicColumnIndex: 2,
  60. deps,
  61. });
  62. const {
  63. onClickCell,
  64. onCloseDetailsSplit,
  65. resizableDrawerProps,
  66. selectedIndex,
  67. splitSize,
  68. } = useDetailsSplit({
  69. containerRef,
  70. frames: networkFrames,
  71. handleHeight: RESIZEABLE_HANDLE_HEIGHT,
  72. urlParamName: 'n_detail_row',
  73. onShowDetails: useCallback(
  74. ({dataIndex, rowIndex}) => {
  75. setScrollToRow(rowIndex);
  76. const item = items[dataIndex];
  77. trackAnalytics('replay.details-network-panel-opened', {
  78. is_sdk_setup: isNetworkDetailsSetup,
  79. organization,
  80. resource_method: getFrameMethod(item),
  81. resource_status: String(getFrameStatus(item)),
  82. resource_type: item.op,
  83. });
  84. },
  85. [organization, items, isNetworkDetailsSetup]
  86. ),
  87. onHideDetails: useCallback(() => {
  88. trackAnalytics('replay.details-network-panel-closed', {
  89. is_sdk_setup: isNetworkDetailsSetup,
  90. organization,
  91. });
  92. }, [organization, isNetworkDetailsSetup]),
  93. });
  94. const {
  95. handleClick: onClickToJump,
  96. onSectionRendered,
  97. showJumpDownButton,
  98. showJumpUpButton,
  99. } = useJumpButtons({
  100. currentTime,
  101. frames: filteredItems,
  102. isTable: true,
  103. setScrollToRow,
  104. });
  105. const cellRenderer = ({columnIndex, rowIndex, key, style, parent}: GridCellProps) => {
  106. const network = items[rowIndex - 1];
  107. return (
  108. <CellMeasurer
  109. cache={cache}
  110. columnIndex={columnIndex}
  111. key={key}
  112. parent={parent}
  113. rowIndex={rowIndex}
  114. >
  115. {({measure: _, registerChild}) =>
  116. rowIndex === 0 ? (
  117. <NetworkHeaderCell
  118. ref={e => e && registerChild?.(e)}
  119. handleSort={handleSort}
  120. index={columnIndex}
  121. sortConfig={sortConfig}
  122. style={{...style, height: HEADER_HEIGHT}}
  123. />
  124. ) : (
  125. <NetworkTableCell
  126. columnIndex={columnIndex}
  127. currentHoverTime={currentHoverTime}
  128. currentTime={currentTime}
  129. frame={network}
  130. onMouseEnter={onMouseEnter}
  131. onMouseLeave={onMouseLeave}
  132. onClickCell={onClickCell}
  133. onClickTimestamp={onClickTimestamp}
  134. ref={e => e && registerChild?.(e)}
  135. rowIndex={rowIndex}
  136. sortConfig={sortConfig}
  137. startTimestampMs={startTimestampMs}
  138. style={{...style, height: BODY_HEIGHT}}
  139. />
  140. )
  141. }
  142. </CellMeasurer>
  143. );
  144. };
  145. return (
  146. <FluidHeight>
  147. <FilterLoadingIndicator isLoading={!replay}>
  148. <NetworkFilters networkFrames={networkFrames} {...filterProps} />
  149. </FilterLoadingIndicator>
  150. <ReqRespBodiesAlert isNetworkDetailsSetup={isNetworkDetailsSetup} />
  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;