@@ -2,20 +2,19 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
22import {
33 ItemKey ,
44 NormalizedItem ,
5- NormalizedItemData ,
65 NormalizedSection ,
7- NormalizedSectionData ,
86 usePickerItemScale ,
97} from '@deephaven/components' ;
10- import { dh as DhType } from '@deephaven/jsapi-types ' ;
8+ import { TableUtils } from '@deephaven/jsapi-utils ' ;
119import Log from '@deephaven/log' ;
10+ import { usePromiseFactory } from '@deephaven/react-hooks' ;
1211import { PICKER_TOP_OFFSET } from '@deephaven/utils' ;
1312import useFormatter from '../../useFormatter' ;
1413import type { PickerWithTableProps } from '../PickerProps' ;
15- import { getItemKeyColumn } from './itemUtils' ;
16- import useItemRowDeserializer from './useItemRowDeserializer' ;
17- import useGetItemIndexByValue from '../../useGetItemIndexByValue' ;
18- import useViewportData from '../../useViewportData ' ;
14+ import { getItemKeyColumn , getItemLabelColumn } from './itemUtils' ;
15+ import { useItemRowDeserializer } from './useItemRowDeserializer' ;
16+ import { useGetItemIndexByValue } from '../../useGetItemIndexByValue' ;
17+ import useSearchableViewportData from '../../useSearchableViewportData ' ;
1918
2019const log = Log . module ( 'jsapi-components.usePickerProps' ) ;
2120
@@ -26,6 +25,7 @@ export type UsePickerDerivedProps = {
2625 getInitialScrollPosition : ( ) => Promise < number | null > ;
2726 onChange : ( key : ItemKey | null ) => void ;
2827 onScroll : ( event : Event ) => void ;
28+ onSearchTextChange : ( searchText : string ) => void ;
2929} ;
3030
3131/**
@@ -49,7 +49,7 @@ export type UsePickerProps<TProps> = UsePickerDerivedProps &
4949 UsePickerPassthroughProps < TProps > ;
5050
5151export function usePickerProps < TProps > ( {
52- table,
52+ table : tableSource ,
5353 keyColumn : keyColumnName ,
5454 labelColumn : labelColumnName ,
5555 iconColumn : iconColumnName ,
@@ -69,22 +69,44 @@ export function usePickerProps<TProps>({
6969 ItemKey | null | undefined
7070 > ( props . defaultSelectedKey ) ;
7171
72+ // Copy table so we can apply filters without affecting the original table.
73+ // (Note that this call is not actually applying any filters. Filter will be
74+ // applied in `useSearchableViewportData`.)
75+ const { data : tableCopy } = usePromiseFactory (
76+ TableUtils . copyTableAndApplyFilters ,
77+ [ tableSource ]
78+ ) ;
79+
7280 const keyColumn = useMemo (
73- ( ) => getItemKeyColumn ( table , keyColumnName ) ,
74- [ keyColumnName , table ]
81+ ( ) =>
82+ tableCopy == null ? null : getItemKeyColumn ( tableCopy , keyColumnName ) ,
83+ [ keyColumnName , tableCopy ]
84+ ) ;
85+
86+ const labelColumn = useMemo (
87+ ( ) =>
88+ tableCopy == null || keyColumn == null
89+ ? null
90+ : getItemLabelColumn ( tableCopy , keyColumn , labelColumnName ) ,
91+ [ keyColumn , labelColumnName , tableCopy ]
92+ ) ;
93+
94+ const searchColumnNames = useMemo (
95+ ( ) => ( labelColumn == null ? [ ] : [ labelColumn . name ] ) ,
96+ [ labelColumn ]
7597 ) ;
7698
7799 const deserializeRow = useItemRowDeserializer ( {
78- table,
100+ table : tableCopy ,
79101 iconColumnName,
80102 keyColumnName,
81103 labelColumnName,
82104 formatValue,
83105 } ) ;
84106
85107 const getItemIndexByValue = useGetItemIndexByValue ( {
86- table,
87- columnName : keyColumn . name ,
108+ table : tableCopy ,
109+ columnName : keyColumn ? .name ?? null ,
88110 value : isUncontrolled ? uncontrolledSelectedKey : props . selectedKey ,
89111 } ) ;
90112
@@ -98,15 +120,14 @@ export function usePickerProps<TProps>({
98120 return index * itemHeight + PICKER_TOP_OFFSET ;
99121 } , [ getItemIndexByValue , itemHeight ] ) ;
100122
101- const { viewportData, onScroll, setViewport } = useViewportData <
102- NormalizedItemData | NormalizedSectionData ,
103- DhType . Table
104- > ( {
105- reuseItemsOnTableResize : true ,
106- table,
107- itemHeight,
108- deserializeRow,
109- } ) ;
123+ const { onScroll, onSearchTextChange, setViewport, viewportData } =
124+ useSearchableViewportData ( {
125+ reuseItemsOnTableResize : true ,
126+ table : tableCopy ,
127+ itemHeight,
128+ deserializeRow,
129+ searchColumnNames,
130+ } ) ;
110131
111132 const normalizedItems = viewportData . items as (
112133 | NormalizedItem
@@ -158,6 +179,7 @@ export function usePickerProps<TProps>({
158179 getInitialScrollPosition,
159180 onChange : onSelectionChangeInternal ,
160181 onScroll,
182+ onSearchTextChange,
161183 } ;
162184}
163185
0 commit comments