index.tsx 6.0 KB

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