index.tsx 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. import {useCallback, useMemo, useRef, useState} 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 useA11yData from 'sentry/utils/replays/hooks/useA11yData';
  8. import useCrumbHandlers from 'sentry/utils/replays/hooks/useCrumbHandlers';
  9. import useMockA11yData from 'sentry/utils/replays/hooks/useMockA11yData';
  10. import {useResizableDrawer} from 'sentry/utils/useResizableDrawer';
  11. import useUrlParams from 'sentry/utils/useUrlParams';
  12. // import AccessibilityFilters from 'sentry/views/replays/detail/accessibility/accessibilityFilters';
  13. import AccessibilityHeaderCell, {
  14. COLUMN_COUNT,
  15. } from 'sentry/views/replays/detail/accessibility/accessibilityHeaderCell';
  16. import AccessibilityTableCell from 'sentry/views/replays/detail/accessibility/accessibilityTableCell';
  17. // import AccessibilityDetails from 'sentry/views/replays/detail/accessibility/details';
  18. // import useAccessibilityFilters from 'sentry/views/replays/detail/accessibility/useAccessibilityFilters';
  19. import useSortAccessibility from 'sentry/views/replays/detail/accessibility/useSortAccessibility';
  20. import FluidHeight from 'sentry/views/replays/detail/layout/fluidHeight';
  21. import NoRowRenderer from 'sentry/views/replays/detail/noRowRenderer';
  22. import useVirtualizedGrid from 'sentry/views/replays/detail/useVirtualizedGrid';
  23. const HEADER_HEIGHT = 25;
  24. const BODY_HEIGHT = 25;
  25. const RESIZEABLE_HANDLE_HEIGHT = 105;
  26. const cellMeasurer = {
  27. defaultHeight: BODY_HEIGHT,
  28. defaultWidth: 100,
  29. fixedHeight: true,
  30. };
  31. function AccessibilityList() {
  32. const {currentTime, currentHoverTime, replay} = useReplayContext();
  33. const {onMouseEnter, onMouseLeave, onClickTimestamp} = useCrumbHandlers();
  34. const accessibilityData = useMockA11yData();
  35. const startTimestampMs = replay?.getReplay()?.started_at?.getTime() || 0;
  36. const [scrollToRow, setScrollToRow] = useState<undefined | number>(undefined);
  37. const filteredItems = accessibilityData || [];
  38. const clearSearchTerm = () => {};
  39. const {handleSort, items, sortConfig} = useSortAccessibility({items: filteredItems});
  40. const containerRef = useRef<HTMLDivElement>(null);
  41. const gridRef = useRef<MultiGrid>(null);
  42. const deps = useMemo(() => [items], [items]);
  43. const {cache, getColumnWidth, onScrollbarPresenceChange, onWrapperResize} =
  44. useVirtualizedGrid({
  45. cellMeasurer,
  46. gridRef,
  47. columnCount: COLUMN_COUNT,
  48. dynamicColumnIndex: 2,
  49. deps,
  50. });
  51. // `initialSize` cannot depend on containerRef because the ref starts as
  52. // `undefined` which then gets set into the hook and doesn't update.
  53. const initialSize = Math.max(150, window.innerHeight * 0.4);
  54. const {size: containerSize} = useResizableDrawer({
  55. direction: 'up',
  56. initialSize,
  57. min: 0,
  58. onResize: () => {},
  59. });
  60. const {getParamValue: getDetailRow, setParamValue: setDetailRow} = useUrlParams(
  61. 'n_detail_row',
  62. ''
  63. );
  64. const detailDataIndex = getDetailRow();
  65. const maxContainerHeight =
  66. (containerRef.current?.clientHeight || window.innerHeight) - RESIZEABLE_HANDLE_HEIGHT;
  67. const splitSize =
  68. accessibilityData && detailDataIndex
  69. ? Math.min(maxContainerHeight, containerSize)
  70. : undefined;
  71. const onClickCell = useCallback(
  72. ({}: {dataIndex: number; rowIndex: number}) => {
  73. // eslint-disable-line
  74. // if (getDetailRow() === String(dataIndex)) {
  75. // setDetailRow('');
  76. // } else {
  77. // setDetailRow(String(dataIndex));
  78. // setScrollToRow(rowIndex);
  79. // }
  80. },
  81. // eslint-disable-next-line
  82. [getDetailRow, setDetailRow]
  83. );
  84. const cellRenderer = ({columnIndex, rowIndex, key, style, parent}: GridCellProps) => {
  85. const a11yIssue = items[rowIndex - 1];
  86. return (
  87. <CellMeasurer
  88. cache={cache}
  89. columnIndex={columnIndex}
  90. key={key}
  91. parent={parent}
  92. rowIndex={rowIndex}
  93. >
  94. {({
  95. measure: _,
  96. registerChild,
  97. }: {
  98. measure: () => void;
  99. registerChild?: (element?: Element) => void;
  100. }) =>
  101. rowIndex === 0 ? (
  102. <AccessibilityHeaderCell
  103. ref={e => e && registerChild?.(e)}
  104. handleSort={handleSort}
  105. index={columnIndex}
  106. sortConfig={sortConfig}
  107. style={{...style, height: HEADER_HEIGHT}}
  108. />
  109. ) : (
  110. <AccessibilityTableCell
  111. columnIndex={columnIndex}
  112. currentHoverTime={currentHoverTime}
  113. currentTime={currentTime}
  114. a11yIssue={a11yIssue}
  115. onMouseEnter={onMouseEnter}
  116. onMouseLeave={onMouseLeave}
  117. onClickCell={onClickCell}
  118. onClickTimestamp={onClickTimestamp}
  119. ref={e => e && registerChild?.(e)}
  120. rowIndex={rowIndex}
  121. sortConfig={sortConfig}
  122. startTimestampMs={startTimestampMs}
  123. style={{...style, height: BODY_HEIGHT}}
  124. />
  125. )
  126. }
  127. </CellMeasurer>
  128. );
  129. };
  130. return (
  131. <FluidHeight>
  132. {/* <AccessibilityFilters accessibilityData={accessibilityData} {...filterProps} /> */}
  133. <AccessibilityTable
  134. ref={containerRef}
  135. data-test-id="replay-details-accessibility-tab"
  136. >
  137. <SplitPanel
  138. style={{
  139. gridTemplateRows: splitSize !== undefined ? `1fr auto ${splitSize}px` : '1fr',
  140. }}
  141. >
  142. {accessibilityData ? (
  143. <OverflowHidden>
  144. <AutoSizer onResize={onWrapperResize}>
  145. {({height, width}) => (
  146. <MultiGrid
  147. ref={gridRef}
  148. cellRenderer={cellRenderer}
  149. columnCount={COLUMN_COUNT}
  150. columnWidth={getColumnWidth(width)}
  151. deferredMeasurementCache={cache}
  152. estimatedColumnSize={100}
  153. estimatedRowSize={BODY_HEIGHT}
  154. fixedRowCount={1}
  155. height={height}
  156. noContentRenderer={() => (
  157. <NoRowRenderer
  158. unfilteredItems={accessibilityData}
  159. clearSearchTerm={clearSearchTerm}
  160. >
  161. {t('No accessibility problems detected')}
  162. </NoRowRenderer>
  163. )}
  164. onScrollbarPresenceChange={onScrollbarPresenceChange}
  165. onScroll={() => {
  166. if (scrollToRow !== undefined) {
  167. setScrollToRow(undefined);
  168. }
  169. }}
  170. scrollToRow={scrollToRow}
  171. overscanColumnCount={COLUMN_COUNT}
  172. overscanRowCount={5}
  173. rowCount={items.length + 1}
  174. rowHeight={({index}) => (index === 0 ? HEADER_HEIGHT : BODY_HEIGHT)}
  175. width={width}
  176. />
  177. )}
  178. </AutoSizer>
  179. </OverflowHidden>
  180. ) : (
  181. <Placeholder height="100%" />
  182. )}
  183. {/* <AccessibilityDetails
  184. {...resizableDrawerProps}
  185. item={detailDataIndex ? items[detailDataIndex] : null}
  186. onClose={() => {
  187. setDetailRow('');
  188. }}
  189. projectId="1"
  190. startTimestampMs={startTimestampMs}
  191. /> */}
  192. </SplitPanel>
  193. </AccessibilityTable>
  194. </FluidHeight>
  195. );
  196. }
  197. const SplitPanel = styled('div')`
  198. width: 100%;
  199. height: 100%;
  200. position: relative;
  201. display: grid;
  202. overflow: auto;
  203. `;
  204. const OverflowHidden = styled('div')`
  205. position: relative;
  206. height: 100%;
  207. overflow: hidden;
  208. display: grid;
  209. `;
  210. const AccessibilityTable = styled(FluidHeight)`
  211. border: 1px solid ${p => p.theme.border};
  212. border-radius: ${p => p.theme.borderRadius};
  213. .beforeHoverTime + .afterHoverTime:before {
  214. border-top: 1px solid ${p => p.theme.purple200};
  215. content: '';
  216. left: 0;
  217. position: absolute;
  218. top: 0;
  219. width: 999999999%;
  220. }
  221. .beforeHoverTime:last-child:before {
  222. border-bottom: 1px solid ${p => p.theme.purple200};
  223. content: '';
  224. right: 0;
  225. position: absolute;
  226. bottom: 0;
  227. width: 999999999%;
  228. }
  229. .beforeCurrentTime + .afterCurrentTime:before {
  230. border-top: 1px solid ${p => p.theme.purple300};
  231. content: '';
  232. left: 0;
  233. position: absolute;
  234. top: 0;
  235. width: 999999999%;
  236. }
  237. .beforeCurrentTime:last-child:before {
  238. border-bottom: 1px solid ${p => p.theme.purple300};
  239. content: '';
  240. right: 0;
  241. position: absolute;
  242. bottom: 0;
  243. width: 999999999%;
  244. }
  245. `;
  246. export default AccessibilityList;