index.tsx 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. import {useCallback, useEffect, 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 {GridTable} from 'sentry/components/replays/virtualizedGrid/gridTable';
  10. import {OverflowHidden} from 'sentry/components/replays/virtualizedGrid/overflowHidden';
  11. import {SplitPanel} from 'sentry/components/replays/virtualizedGrid/splitPanel';
  12. import useDetailsSplit from 'sentry/components/replays/virtualizedGrid/useDetailsSplit';
  13. import {t} from 'sentry/locale';
  14. import {trackAnalytics} from 'sentry/utils/analytics';
  15. import useA11yData from 'sentry/utils/replays/hooks/useA11yData';
  16. import useCrumbHandlers from 'sentry/utils/replays/hooks/useCrumbHandlers';
  17. import useCurrentHoverTime from 'sentry/utils/replays/playback/providers/useCurrentHoverTime';
  18. import useOrganization from 'sentry/utils/useOrganization';
  19. import AccessibilityFilters from 'sentry/views/replays/detail/accessibility/accessibilityFilters';
  20. import AccessibilityHeaderCell, {
  21. COLUMN_COUNT,
  22. } from 'sentry/views/replays/detail/accessibility/accessibilityHeaderCell';
  23. import AccessibilityRefetchBanner from 'sentry/views/replays/detail/accessibility/accessibilityRefetchBanner';
  24. import AccessibilityTableCell from 'sentry/views/replays/detail/accessibility/accessibilityTableCell';
  25. import AccessibilityDetails from 'sentry/views/replays/detail/accessibility/details';
  26. import useAccessibilityFilters from 'sentry/views/replays/detail/accessibility/useAccessibilityFilters';
  27. import useSortAccessibility from 'sentry/views/replays/detail/accessibility/useSortAccessibility';
  28. import FilterLoadingIndicator from 'sentry/views/replays/detail/filterLoadingIndicator';
  29. import FluidHeight from 'sentry/views/replays/detail/layout/fluidHeight';
  30. import NoRowRenderer from 'sentry/views/replays/detail/noRowRenderer';
  31. import useVirtualizedGrid from 'sentry/views/replays/detail/useVirtualizedGrid';
  32. const HEADER_HEIGHT = 25;
  33. const BODY_HEIGHT = 25;
  34. const RESIZEABLE_HANDLE_HEIGHT = 105;
  35. const cellMeasurer = {
  36. defaultHeight: BODY_HEIGHT,
  37. defaultWidth: 100,
  38. fixedHeight: true,
  39. };
  40. function AccessibilityList() {
  41. const organization = useOrganization();
  42. const {currentTime} = useReplayContext();
  43. const [currentHoverTime] = useCurrentHoverTime();
  44. const {onMouseEnter, onMouseLeave, onClickTimestamp} = useCrumbHandlers();
  45. const {
  46. dataOffsetMs,
  47. data: accessibilityData,
  48. isLoading,
  49. isRefetching,
  50. refetch,
  51. } = useA11yData();
  52. const [scrollToRow, setScrollToRow] = useState<undefined | number>(undefined);
  53. const filterProps = useAccessibilityFilters({
  54. accessibilityData: accessibilityData || [],
  55. });
  56. const {items: filteredItems, searchTerm, setSearchTerm} = filterProps;
  57. const clearSearchTerm = () => setSearchTerm('');
  58. const {handleSort, items, sortConfig} = useSortAccessibility({items: filteredItems});
  59. const containerRef = useRef<HTMLDivElement>(null);
  60. const gridRef = useRef<MultiGrid>(null);
  61. const deps = useMemo(() => [items, searchTerm], [items, searchTerm]);
  62. const {cache, getColumnWidth, onScrollbarPresenceChange, onWrapperResize} =
  63. useVirtualizedGrid({
  64. cellMeasurer,
  65. gridRef,
  66. columnCount: COLUMN_COUNT,
  67. dynamicColumnIndex: 2,
  68. deps,
  69. });
  70. const {
  71. onClickCell,
  72. onCloseDetailsSplit,
  73. resizableDrawerProps,
  74. selectedIndex,
  75. splitSize,
  76. } = useDetailsSplit({
  77. containerRef,
  78. handleHeight: RESIZEABLE_HANDLE_HEIGHT,
  79. frames: accessibilityData,
  80. urlParamName: 'a_detail_row',
  81. onShowDetails: useCallback(
  82. ({dataIndex, rowIndex}) => {
  83. setScrollToRow(rowIndex);
  84. const item = items[dataIndex];
  85. trackAnalytics('replay.accessibility-issue-clicked', {
  86. organization,
  87. issue_description: item.description,
  88. issue_impact: item.impact,
  89. });
  90. },
  91. [items, organization]
  92. ),
  93. });
  94. useEffect(() => {
  95. if (isRefetching) {
  96. onCloseDetailsSplit();
  97. }
  98. }, [isRefetching, onCloseDetailsSplit]);
  99. const {
  100. handleClick: onClickToJump,
  101. onSectionRendered,
  102. showJumpDownButton,
  103. showJumpUpButton,
  104. } = useJumpButtons({
  105. currentTime,
  106. frames: filteredItems,
  107. isTable: true,
  108. setScrollToRow,
  109. });
  110. const cellRenderer = ({columnIndex, rowIndex, key, style, parent}: GridCellProps) => {
  111. const a11yIssue = items[rowIndex - 1];
  112. return (
  113. <CellMeasurer
  114. cache={cache}
  115. columnIndex={columnIndex}
  116. key={key}
  117. parent={parent}
  118. rowIndex={rowIndex}
  119. >
  120. {({measure: _, registerChild}) =>
  121. rowIndex === 0 ? (
  122. <AccessibilityHeaderCell
  123. ref={e => e && registerChild?.(e)}
  124. handleSort={handleSort}
  125. index={columnIndex}
  126. sortConfig={sortConfig}
  127. style={{...style, height: HEADER_HEIGHT}}
  128. />
  129. ) : (
  130. <AccessibilityTableCell
  131. columnIndex={columnIndex}
  132. currentHoverTime={currentHoverTime}
  133. currentTime={currentTime}
  134. a11yIssue={a11yIssue}
  135. onMouseEnter={onMouseEnter}
  136. onMouseLeave={onMouseLeave}
  137. onClickCell={onClickCell}
  138. onClickTimestamp={onClickTimestamp}
  139. ref={e => e && registerChild?.(e)}
  140. rowIndex={rowIndex}
  141. sortConfig={sortConfig}
  142. style={{...style, height: BODY_HEIGHT}}
  143. />
  144. )
  145. }
  146. </CellMeasurer>
  147. );
  148. };
  149. return (
  150. <FluidHeight>
  151. <FilterLoadingIndicator isLoading={isLoading || isRefetching}>
  152. <AccessibilityFilters accessibilityData={accessibilityData} {...filterProps} />
  153. </FilterLoadingIndicator>
  154. <AccessibilityRefetchBanner initialOffsetMs={dataOffsetMs} refetch={refetch} />
  155. <StyledGridTable ref={containerRef} data-test-id="replay-details-accessibility-tab">
  156. <SplitPanel
  157. style={{
  158. gridTemplateRows: splitSize !== undefined ? `1fr auto ${splitSize}px` : '1fr',
  159. }}
  160. >
  161. {accessibilityData && !isRefetching ? (
  162. <OverflowHidden>
  163. <AutoSizer onResize={onWrapperResize}>
  164. {({height, width}) => (
  165. <MultiGrid
  166. ref={gridRef}
  167. cellRenderer={cellRenderer}
  168. columnCount={COLUMN_COUNT}
  169. columnWidth={getColumnWidth(width)}
  170. deferredMeasurementCache={cache}
  171. estimatedColumnSize={100}
  172. estimatedRowSize={BODY_HEIGHT}
  173. fixedRowCount={1}
  174. height={height}
  175. noContentRenderer={() => (
  176. <NoRowRenderer
  177. unfilteredItems={accessibilityData}
  178. clearSearchTerm={clearSearchTerm}
  179. >
  180. {t('No accessibility problems detected')}
  181. </NoRowRenderer>
  182. )}
  183. onScrollbarPresenceChange={onScrollbarPresenceChange}
  184. onScroll={() => {
  185. if (scrollToRow !== undefined) {
  186. setScrollToRow(undefined);
  187. }
  188. }}
  189. onSectionRendered={onSectionRendered}
  190. overscanColumnCount={COLUMN_COUNT}
  191. overscanRowCount={5}
  192. rowCount={items.length + 1}
  193. rowHeight={({index}) => (index === 0 ? HEADER_HEIGHT : BODY_HEIGHT)}
  194. scrollToRow={scrollToRow}
  195. width={width}
  196. />
  197. )}
  198. </AutoSizer>
  199. {sortConfig.by === 'timestamp' && items.length ? (
  200. <JumpButtons
  201. jump={showJumpUpButton ? 'up' : showJumpDownButton ? 'down' : undefined}
  202. onClick={onClickToJump}
  203. tableHeaderHeight={HEADER_HEIGHT}
  204. />
  205. ) : null}
  206. </OverflowHidden>
  207. ) : (
  208. <Placeholder height="100%" />
  209. )}
  210. <AccessibilityDetails
  211. {...resizableDrawerProps}
  212. item={selectedIndex ? items[selectedIndex] : null}
  213. onClose={onCloseDetailsSplit}
  214. />
  215. </SplitPanel>
  216. </StyledGridTable>
  217. </FluidHeight>
  218. );
  219. }
  220. const StyledGridTable = styled(GridTable)`
  221. border-radius: ${p => p.theme.borderRadiusBottom};
  222. border-top: none;
  223. `;
  224. export default AccessibilityList;