index.tsx 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. import {useCallback, useMemo, useRef, useState} from 'react';
  2. import {AutoSizer, CellMeasurer, GridCellProps, MultiGrid} from 'react-virtualized';
  3. import Placeholder from 'sentry/components/placeholder';
  4. import JumpButtons from 'sentry/components/replays/jumpButtons';
  5. import {useReplayContext} from 'sentry/components/replays/replayContext';
  6. import useJumpButtons from 'sentry/components/replays/useJumpButtons';
  7. import {GridTable} from 'sentry/components/replays/virtualizedGrid/gridTable';
  8. import {OverflowHidden} from 'sentry/components/replays/virtualizedGrid/overflowHidden';
  9. import {SplitPanel} from 'sentry/components/replays/virtualizedGrid/splitPanel';
  10. import useDetailsSplit from 'sentry/components/replays/virtualizedGrid/useDetailsSplit';
  11. import {t} from 'sentry/locale';
  12. import {trackAnalytics} from 'sentry/utils/analytics';
  13. import useCrumbHandlers from 'sentry/utils/replays/hooks/useCrumbHandlers';
  14. import {getFrameMethod, getFrameStatus} from 'sentry/utils/replays/resourceFrame';
  15. import useOrganization from 'sentry/utils/useOrganization';
  16. import FilterLoadingIndicator from 'sentry/views/replays/detail/filterLoadingIndicator';
  17. import FluidHeight from 'sentry/views/replays/detail/layout/fluidHeight';
  18. import NetworkDetails from 'sentry/views/replays/detail/network/details';
  19. import {ReqRespBodiesAlert} from 'sentry/views/replays/detail/network/details/onboarding';
  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. <ReqRespBodiesAlert isNetworkDetailsSetup={isNetworkDetailsSetup} />
  150. <GridTable ref={containerRef} data-test-id="replay-details-network-tab">
  151. <SplitPanel
  152. style={{
  153. gridTemplateRows: splitSize !== undefined ? `1fr auto ${splitSize}px` : '1fr',
  154. }}
  155. >
  156. {networkFrames ? (
  157. <OverflowHidden>
  158. <AutoSizer onResize={onWrapperResize}>
  159. {({height, width}) => (
  160. <MultiGrid
  161. ref={gridRef}
  162. cellRenderer={cellRenderer}
  163. columnCount={COLUMN_COUNT}
  164. columnWidth={getColumnWidth(width)}
  165. deferredMeasurementCache={cache}
  166. estimatedColumnSize={100}
  167. estimatedRowSize={BODY_HEIGHT}
  168. fixedRowCount={1}
  169. height={height}
  170. noContentRenderer={() => (
  171. <NoRowRenderer
  172. unfilteredItems={networkFrames}
  173. clearSearchTerm={clearSearchTerm}
  174. >
  175. {t('No network requests recorded')}
  176. </NoRowRenderer>
  177. )}
  178. onScrollbarPresenceChange={onScrollbarPresenceChange}
  179. onScroll={() => {
  180. if (scrollToRow !== undefined) {
  181. setScrollToRow(undefined);
  182. }
  183. }}
  184. onSectionRendered={onSectionRendered}
  185. overscanColumnCount={COLUMN_COUNT}
  186. overscanRowCount={5}
  187. rowCount={items.length + 1}
  188. rowHeight={({index}) => (index === 0 ? HEADER_HEIGHT : BODY_HEIGHT)}
  189. scrollToRow={scrollToRow}
  190. width={width}
  191. />
  192. )}
  193. </AutoSizer>
  194. {sortConfig.by === 'startTimestamp' && items.length ? (
  195. <JumpButtons
  196. jump={showJumpUpButton ? 'up' : showJumpDownButton ? 'down' : undefined}
  197. onClick={onClickToJump}
  198. tableHeaderHeight={HEADER_HEIGHT}
  199. />
  200. ) : null}
  201. </OverflowHidden>
  202. ) : (
  203. <Placeholder height="100%" />
  204. )}
  205. <NetworkDetails
  206. {...resizableDrawerProps}
  207. isSetup={isNetworkDetailsSetup}
  208. item={selectedIndex ? items[selectedIndex] : null}
  209. onClose={onCloseDetailsSplit}
  210. projectId={projectId}
  211. startTimestampMs={startTimestampMs}
  212. />
  213. </SplitPanel>
  214. </GridTable>
  215. </FluidHeight>
  216. );
  217. }
  218. export default NetworkList;