index.tsx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. import {useMemo, useRef} from 'react';
  2. import {AutoSizer, CellMeasurer, GridCellProps, MultiGrid} from 'react-virtualized';
  3. import styled from '@emotion/styled';
  4. import Placeholder from 'sentry/components/placeholder';
  5. import {useReplayContext} from 'sentry/components/replays/replayContext';
  6. import {t} from 'sentry/locale';
  7. import useCrumbHandlers from 'sentry/utils/replays/hooks/useCrumbHandlers';
  8. import type {ErrorFrame} from 'sentry/utils/replays/types';
  9. import ErrorFilters from 'sentry/views/replays/detail/errorList/errorFilters';
  10. import ErrorHeaderCell, {
  11. COLUMN_COUNT,
  12. } from 'sentry/views/replays/detail/errorList/errorHeaderCell';
  13. import ErrorTableCell from 'sentry/views/replays/detail/errorList/errorTableCell';
  14. import useErrorFilters from 'sentry/views/replays/detail/errorList/useErrorFilters';
  15. import useSortErrors from 'sentry/views/replays/detail/errorList/useSortErrors';
  16. import FluidHeight from 'sentry/views/replays/detail/layout/fluidHeight';
  17. import NoRowRenderer from 'sentry/views/replays/detail/noRowRenderer';
  18. import useVirtualizedGrid from 'sentry/views/replays/detail/useVirtualizedGrid';
  19. const HEADER_HEIGHT = 25;
  20. const BODY_HEIGHT = 28;
  21. type Props = {
  22. errorFrames: undefined | ErrorFrame[];
  23. startTimestampMs: number;
  24. };
  25. const cellMeasurer = {
  26. defaultHeight: BODY_HEIGHT,
  27. defaultWidth: 100,
  28. fixedHeight: true,
  29. };
  30. function ErrorList({errorFrames, startTimestampMs}: Props) {
  31. const {currentTime, currentHoverTime} = useReplayContext();
  32. const {onMouseEnter, onMouseLeave, onClickTimestamp} = useCrumbHandlers();
  33. const filterProps = useErrorFilters({errorFrames: errorFrames || []});
  34. const {items: filteredItems, searchTerm, setSearchTerm} = filterProps;
  35. const clearSearchTerm = () => setSearchTerm('');
  36. const {handleSort, items, sortConfig} = useSortErrors({items: filteredItems});
  37. const gridRef = useRef<MultiGrid>(null);
  38. const deps = useMemo(() => [items, searchTerm], [items, searchTerm]);
  39. const {cache, getColumnWidth, onScrollbarPresenceChange, onWrapperResize} =
  40. useVirtualizedGrid({
  41. cellMeasurer,
  42. gridRef,
  43. columnCount: COLUMN_COUNT,
  44. dynamicColumnIndex: 1,
  45. deps,
  46. });
  47. const cellRenderer = ({columnIndex, rowIndex, key, style, parent}: GridCellProps) => {
  48. const error = items[rowIndex - 1];
  49. return (
  50. <CellMeasurer
  51. cache={cache}
  52. columnIndex={columnIndex}
  53. key={key}
  54. parent={parent}
  55. rowIndex={rowIndex}
  56. >
  57. {({
  58. measure: _,
  59. registerChild,
  60. }: {
  61. measure: () => void;
  62. registerChild?: (element?: Element) => void;
  63. }) =>
  64. rowIndex === 0 ? (
  65. <ErrorHeaderCell
  66. ref={e => e && registerChild?.(e)}
  67. handleSort={handleSort}
  68. index={columnIndex}
  69. sortConfig={sortConfig}
  70. style={{...style, height: HEADER_HEIGHT}}
  71. />
  72. ) : (
  73. <ErrorTableCell
  74. columnIndex={columnIndex}
  75. currentHoverTime={currentHoverTime}
  76. currentTime={currentTime}
  77. frame={error}
  78. onMouseEnter={onMouseEnter}
  79. onMouseLeave={onMouseLeave}
  80. onClickTimestamp={onClickTimestamp}
  81. ref={e => e && registerChild?.(e)}
  82. rowIndex={rowIndex}
  83. sortConfig={sortConfig}
  84. startTimestampMs={startTimestampMs}
  85. style={{...style, height: BODY_HEIGHT}}
  86. />
  87. )
  88. }
  89. </CellMeasurer>
  90. );
  91. };
  92. return (
  93. <FluidHeight>
  94. <ErrorFilters errorFrames={errorFrames} {...filterProps} />
  95. <ErrorTable data-test-id="replay-details-errors-tab">
  96. {errorFrames ? (
  97. <OverflowHidden>
  98. <AutoSizer onResize={onWrapperResize}>
  99. {({height, width}) => (
  100. <MultiGrid
  101. ref={gridRef}
  102. cellRenderer={cellRenderer}
  103. columnCount={COLUMN_COUNT}
  104. columnWidth={getColumnWidth(width)}
  105. deferredMeasurementCache={cache}
  106. estimatedColumnSize={100}
  107. estimatedRowSize={BODY_HEIGHT}
  108. fixedRowCount={1}
  109. height={height}
  110. noContentRenderer={() => (
  111. <NoRowRenderer
  112. unfilteredItems={errorFrames}
  113. clearSearchTerm={clearSearchTerm}
  114. >
  115. {t('No errors! Go make some.')}
  116. </NoRowRenderer>
  117. )}
  118. onScrollbarPresenceChange={onScrollbarPresenceChange}
  119. overscanColumnCount={COLUMN_COUNT}
  120. overscanRowCount={5}
  121. rowCount={items.length + 1}
  122. rowHeight={({index}) => (index === 0 ? HEADER_HEIGHT : BODY_HEIGHT)}
  123. width={width}
  124. />
  125. )}
  126. </AutoSizer>
  127. </OverflowHidden>
  128. ) : (
  129. <Placeholder height="100%" />
  130. )}
  131. </ErrorTable>
  132. </FluidHeight>
  133. );
  134. }
  135. const OverflowHidden = styled('div')`
  136. position: relative;
  137. height: 100%;
  138. overflow: hidden;
  139. `;
  140. const ErrorTable = styled(FluidHeight)`
  141. border: 1px solid ${p => p.theme.border};
  142. border-radius: ${p => p.theme.borderRadius};
  143. .beforeHoverTime + .afterHoverTime:before {
  144. border-top: 1px solid ${p => p.theme.purple200};
  145. content: '';
  146. left: 0;
  147. position: absolute;
  148. top: 0;
  149. width: 999999999%;
  150. }
  151. .beforeHoverTime:last-child:before {
  152. border-bottom: 1px solid ${p => p.theme.purple200};
  153. content: '';
  154. right: 0;
  155. position: absolute;
  156. bottom: 0;
  157. width: 999999999%;
  158. }
  159. .beforeCurrentTime + .afterCurrentTime:before {
  160. border-top: 1px solid ${p => p.theme.purple300};
  161. content: '';
  162. left: 0;
  163. position: absolute;
  164. top: 0;
  165. width: 999999999%;
  166. }
  167. .beforeCurrentTime:last-child:before {
  168. border-bottom: 1px solid ${p => p.theme.purple300};
  169. content: '';
  170. right: 0;
  171. position: absolute;
  172. bottom: 0;
  173. width: 999999999%;
  174. }
  175. `;
  176. export default ErrorList;