@@ -30,6 +30,8 @@ import {
3030 TOP_QUERIES_SELECTED_COLUMNS_LS_KEY ,
3131} from './columns/constants' ;
3232import { DEFAULT_TIME_FILTER_VALUE , TIME_FRAME_OPTIONS } from './constants' ;
33+ import type { ReactList } from './hooks/useScrollToSelected' ;
34+ import { useScrollToSelected } from './hooks/useScrollToSelected' ;
3335import { useSetSelectedTopQueryRowFromParams } from './hooks/useSetSelectedTopQueryRowFromParams' ;
3436import { useTopQueriesSort } from './hooks/useTopQueriesSort' ;
3537import i18n from './i18n' ;
@@ -61,6 +63,9 @@ export const TopQueriesData = ({
6163 // null is reserved for not found state
6264 const [ selectedRow , setSelectedRow ] = React . useState < KeyValueRow | null | undefined > ( undefined ) ;
6365
66+ // Ref for react-list component to enable scrolling to selected row
67+ const reactListRef = React . useRef < ReactList > ( null ) ;
68+
6469 // Get columns for top queries
6570 const columns : Column < KeyValueRow > [ ] = React . useMemo ( ( ) => {
6671 return getTopQueriesColumns ( ) ;
@@ -89,6 +94,19 @@ export const TopQueriesData = ({
8994 const rows = currentData ?. resultSets ?. [ 0 ] ?. result ;
9095 useSetSelectedTopQueryRowFromParams ( setSelectedRow , rows ) ;
9196
97+ // Enhanced table settings with dynamicInnerRef for scrolling
98+ const tableSettings = React . useMemo (
99+ ( ) => ( {
100+ ...TOP_QUERIES_TABLE_SETTINGS ,
101+ dynamicInnerRef : reactListRef ,
102+ // Using 'uniform' type - react-list automatically calculates size from first item
103+ } ) ,
104+ [ ] ,
105+ ) ;
106+
107+ // Use custom hook to handle scrolling to selected row
108+ useScrollToSelected ( { selectedRow, rows, reactListRef} ) ;
109+
92110 const handleCloseDetails = React . useCallback ( ( ) => {
93111 setSelectedRow ( undefined ) ;
94112 } , [ setSelectedRow ] ) ;
@@ -182,7 +200,7 @@ export const TopQueriesData = ({
182200 columns = { columnsToShow }
183201 data = { rows || [ ] }
184202 loading = { isFetching && currentData === undefined }
185- settings = { TOP_QUERIES_TABLE_SETTINGS }
203+ settings = { tableSettings }
186204 onRowClick = { onRowClick }
187205 rowClassName = { ( row ) => b ( 'row' , { active : isEqual ( row , selectedRow ) } ) }
188206 sortOrder = { tableSort }
0 commit comments