perfTable.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import {useMemo, useRef} from 'react';
  2. import {
  3. AutoSizer,
  4. CellMeasurer,
  5. List as ReactVirtualizedList,
  6. ListRowProps,
  7. } from 'react-virtualized';
  8. import Placeholder from 'sentry/components/placeholder';
  9. import {useReplayContext} from 'sentry/components/replays/replayContext';
  10. import {t} from 'sentry/locale';
  11. import FilterLoadingIndicator from 'sentry/views/replays/detail/filterLoadingIndicator';
  12. import FluidHeight from 'sentry/views/replays/detail/layout/fluidHeight';
  13. import NoRowRenderer from 'sentry/views/replays/detail/noRowRenderer';
  14. import PerfFilters from 'sentry/views/replays/detail/perfTable/perfFilters';
  15. import PerfRow from 'sentry/views/replays/detail/perfTable/perfRow';
  16. import usePerfFilters from 'sentry/views/replays/detail/perfTable/usePerfFilters';
  17. import type useReplayPerfData from 'sentry/views/replays/detail/perfTable/useReplayPerfData';
  18. import TabItemContainer from 'sentry/views/replays/detail/tabItemContainer';
  19. import useVirtualizedList from 'sentry/views/replays/detail/useVirtualizedList';
  20. import useVirtualListDimentionChange from 'sentry/views/replays/detail/useVirtualListDimentionChange';
  21. interface Props {
  22. perfData: ReturnType<typeof useReplayPerfData>;
  23. }
  24. const cellMeasurer = {
  25. fixedWidth: true,
  26. minHeight: 24,
  27. };
  28. export default function PerfTable({perfData}: Props) {
  29. const {currentTime, currentHoverTime, replay} = useReplayContext();
  30. const startTimestampMs = replay?.getReplay().started_at.getTime() ?? 0;
  31. const traceRows = Array.from(perfData.data.values());
  32. const filterProps = usePerfFilters({traceRows: traceRows || []});
  33. const {items} = filterProps; // setSearchTerm
  34. const clearSearchTerm = () => {}; // setSearchTerm('');
  35. const listRef = useRef<ReactVirtualizedList>(null);
  36. const deps = useMemo(() => [items], [items]);
  37. const {cache, updateList} = useVirtualizedList({
  38. cellMeasurer,
  39. ref: listRef,
  40. deps,
  41. });
  42. const {handleDimensionChange} = useVirtualListDimentionChange({cache, listRef});
  43. const renderRow = ({index, key, style, parent}: ListRowProps) => {
  44. const traceRow = items[index];
  45. return (
  46. <CellMeasurer
  47. cache={cache}
  48. columnIndex={0}
  49. key={key}
  50. parent={parent}
  51. rowIndex={index}
  52. >
  53. <PerfRow
  54. currentHoverTime={currentHoverTime}
  55. currentTime={currentTime}
  56. index={index}
  57. onDimensionChange={handleDimensionChange}
  58. startTimestampMs={startTimestampMs}
  59. style={style}
  60. traceRow={traceRow}
  61. />
  62. </CellMeasurer>
  63. );
  64. };
  65. return (
  66. <FluidHeight>
  67. <FilterLoadingIndicator isLoading={perfData.isFetching}>
  68. <PerfFilters traceRows={traceRows} {...filterProps} />
  69. </FilterLoadingIndicator>
  70. <TabItemContainer>
  71. {traceRows ? (
  72. <AutoSizer onResize={updateList}>
  73. {({width, height}) => (
  74. <ReactVirtualizedList
  75. deferredMeasurementCache={cache}
  76. height={height}
  77. noRowsRenderer={() => (
  78. <NoRowRenderer
  79. unfilteredItems={traceRows}
  80. clearSearchTerm={clearSearchTerm}
  81. >
  82. {t('No events recorded')}
  83. </NoRowRenderer>
  84. )}
  85. overscanRowCount={5}
  86. ref={listRef}
  87. rowCount={items.length}
  88. rowHeight={cache.rowHeight}
  89. rowRenderer={renderRow}
  90. width={width}
  91. />
  92. )}
  93. </AutoSizer>
  94. ) : (
  95. <Placeholder height="100%" />
  96. )}
  97. </TabItemContainer>
  98. </FluidHeight>
  99. );
  100. }