@@ -2,9 +2,12 @@ import debounce from 'lodash.debounce';
22import type { Table , TreeTable } from '@deephaven/jsapi-types' ;
33import { TableUtils } from '@deephaven/jsapi-utils' ;
44import { useApi } from '@deephaven/jsapi-bootstrap' ;
5+ import Log from '@deephaven/log' ;
56import { useEffect , useMemo } from 'react' ;
67import { UseViewportDataResult } from './useViewportData' ;
78
9+ const log = Log . module ( 'useDebouncedViewportSearch' ) ;
10+
811export const DEBOUNCE_VIEWPORT_SEARCH_MS = 200 ;
912
1013/**
@@ -13,6 +16,7 @@ export const DEBOUNCE_VIEWPORT_SEARCH_MS = 200;
1316 * @param viewportData Table viewport to filter
1417 * @param columnName Column name to filter by
1518 * @param debounceMs Millisecond value to debounce
19+ * @returns A debounced search function
1620 */
1721export default function useDebouncedViewportSearch <
1822 I ,
@@ -24,34 +28,39 @@ export default function useDebouncedViewportSearch<
2428) : ( searchText : string ) => void {
2529 const dh = useApi ( ) ;
2630 const tableUtils = useMemo ( ( ) => new TableUtils ( dh ) , [ dh ] ) ;
31+ const { table, applyFiltersAndRefresh } = viewportData ;
32+
2733 const debouncedSearch = useMemo (
2834 ( ) =>
2935 debounce ( ( searchText : string ) => {
30- if ( viewportData . table == null ) {
36+ log . debug ( `Applying debounced searchText '${ searchText } '` ) ;
37+
38+ if ( table == null ) {
3139 return ;
3240 }
3341
3442 const searchTextTrimmed = searchText . trim ( ) ;
3543
3644 if ( searchTextTrimmed === '' ) {
37- viewportData . applyFiltersAndRefresh ( [ ] ) ;
45+ applyFiltersAndRefresh ( [ ] ) ;
3846 return ;
3947 }
4048
41- const column = viewportData . table . findColumn ( columnName ) ;
49+ const column = table . findColumn ( columnName ) ;
4250 const value = tableUtils . makeFilterValue (
4351 column . type ,
4452 searchTextTrimmed
4553 ) ;
4654 const filter = [ column . filter ( ) . contains ( value ) ] ;
4755
48- viewportData . applyFiltersAndRefresh ( filter ) ;
56+ applyFiltersAndRefresh ( filter ) ;
4957 } , debounceMs ) ,
50- [ columnName , debounceMs , tableUtils , viewportData ]
58+ [ applyFiltersAndRefresh , columnName , debounceMs , table , tableUtils ]
5159 ) ;
5260
5361 useEffect (
5462 ( ) => ( ) => {
63+ log . debug ( 'Cancelling debounced search function' ) ;
5564 debouncedSearch . cancel ( ) ;
5665 } ,
5766 [ debouncedSearch ]
0 commit comments