index.tsx 7.0 KB

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