File tree Expand file tree Collapse file tree 4 files changed +58
-31
lines changed Expand file tree Collapse file tree 4 files changed +58
-31
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import cn from 'bem-cn-lite';
55import DataTable from '@yandex-cloud/react-data-table' ;
66import { RadioButton , Label } from '@yandex-cloud/uikit' ;
77
8- import StorageFilter from './StorageFilter /StorageFilter' ;
8+ import { StorageFilter } from './StorageFilter' ;
99import { AutoFetcher } from '../../utils/autofetcher' ;
1010import { TableSkeleton } from '../../components/TableSkeleton/TableSkeleton' ;
1111
@@ -234,6 +234,7 @@ class Storage extends React.Component {
234234
235235 renderControls ( ) {
236236 const {
237+ filter,
237238 setStorageFilter,
238239 visibleEntities,
239240 storageType,
@@ -243,8 +244,9 @@ class Storage extends React.Component {
243244 < div className = { b ( 'controls' ) } >
244245 < div className = { b ( 'search' ) } >
245246 < StorageFilter
246- changeReduxStorageFilter = { setStorageFilter }
247- storageType = { storageType }
247+ placeholder = { storageType === StorageTypes . groups ? 'Group ID, Pool name' : 'Node ID, FQDN' }
248+ onChange = { setStorageFilter }
249+ value = { filter }
248250 />
249251 </ div >
250252 < RadioButton value = { visibleEntities } onUpdate = { this . onGroupVisibilityChange } >
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ import { useEffect , useRef , useState } from 'react' ;
2+
3+ import { TextInput } from '@yandex-cloud/uikit' ;
4+
5+ interface StorageFilterProps {
6+ className ?: string ;
7+ value ?: string ;
8+ placeholder ?: string ;
9+ onChange ?: ( value : string ) => void ;
10+ debounce ?: number ;
11+ }
12+
13+ export const StorageFilter = ( props : StorageFilterProps ) => {
14+ const {
15+ className,
16+ value = '' ,
17+ placeholder,
18+ onChange,
19+ debounce = 200 ,
20+ } = props ;
21+ const [ filterValue , setFilterValue ] = useState ( value ) ;
22+ const timer = useRef < number > ( ) ;
23+
24+ useEffect ( ( ) => {
25+ setFilterValue ( ( prevValue ) => {
26+ if ( prevValue !== value ) {
27+ return value ;
28+ }
29+
30+ return prevValue ;
31+ } ) ;
32+ } , [ value ] ) ;
33+
34+ const changeFilter = ( newValue : string ) => {
35+ setFilterValue ( newValue ) ;
36+
37+ window . clearTimeout ( timer . current ) ;
38+ timer . current = window . setTimeout ( ( ) => {
39+ onChange ?.( newValue ) ;
40+ } , debounce ) ;
41+ } ;
42+
43+ return (
44+ < TextInput
45+ className = { className }
46+ placeholder = { placeholder }
47+ value = { filterValue }
48+ onUpdate = { changeFilter }
49+ hasClear
50+ />
51+ ) ;
52+ }
Original file line number Diff line number Diff line change 1+ export * from './StorageFilter' ;
You can’t perform that action at this time.
0 commit comments