@@ -16,23 +16,24 @@ import { ResponseServiceClient } from '../../../common/protocol';
16
16
import { nls } from '@theia/core/lib/common' ;
17
17
18
18
export class FilterableListContainer <
19
- T extends ArduinoComponent
19
+ T extends ArduinoComponent ,
20
+ S extends Searchable . Options
20
21
> extends React . Component <
21
- FilterableListContainer . Props < T > ,
22
- FilterableListContainer . State < T >
22
+ FilterableListContainer . Props < T , S > ,
23
+ FilterableListContainer . State < T , S >
23
24
> {
24
- constructor ( props : Readonly < FilterableListContainer . Props < T > > ) {
25
+ constructor ( props : Readonly < FilterableListContainer . Props < T , S > > ) {
25
26
super ( props ) ;
26
27
this . state = {
27
- filterText : '' ,
28
+ searchOptions : { query : '' } as S ,
28
29
items : [ ] ,
29
30
} ;
30
31
}
31
32
32
33
override componentDidMount ( ) : void {
33
34
this . search = debounce ( this . search , 500 ) ;
34
- this . handleFilterTextChange ( '' ) ;
35
- this . props . filterTextChangeEvent ( this . handleFilterTextChange . bind ( this ) ) ;
35
+ this . handleQueryChange ( '' ) ;
36
+ this . props . filterTextChangeEvent ( this . handleQueryChange . bind ( this ) ) ;
36
37
}
37
38
38
39
override componentDidUpdate ( ) : void {
@@ -59,8 +60,8 @@ export class FilterableListContainer<
59
60
return (
60
61
< SearchBar
61
62
resolveFocus = { this . props . resolveFocus }
62
- filterText = { this . state . filterText }
63
- onFilterTextChanged = { this . handleFilterTextChange }
63
+ filterText = { this . state . searchOptions . query ?? '' }
64
+ onFilterTextChanged = { this . handleQueryChange }
64
65
/>
65
66
) ;
66
67
}
@@ -79,17 +80,21 @@ export class FilterableListContainer<
79
80
) ;
80
81
}
81
82
82
- protected handleFilterTextChange = (
83
- filterText : string = this . state . filterText
83
+ protected handleQueryChange = (
84
+ query : string = this . state . searchOptions . query ?? ''
84
85
) : void => {
85
- this . setState ( { filterText } ) ;
86
- this . search ( filterText ) ;
86
+ const newSearchOptions = {
87
+ ...this . state . searchOptions ,
88
+ query,
89
+ } ;
90
+ this . setState ( { searchOptions : newSearchOptions } ) ;
91
+ this . search ( newSearchOptions ) ;
87
92
} ;
88
93
89
- protected search ( query : string ) : void {
94
+ protected search ( searchOptions : S ) : void {
90
95
const { searchable } = this . props ;
91
96
searchable
92
- . search ( { query : query . trim ( ) } )
97
+ . search ( searchOptions )
93
98
. then ( ( items ) => this . setState ( { items : this . sort ( items ) } ) ) ;
94
99
}
95
100
@@ -117,7 +122,7 @@ export class FilterableListContainer<
117
122
` ${ item . name } :${ version } ` ,
118
123
run : ( { progressId } ) => install ( { item, progressId, version } ) ,
119
124
} ) ;
120
- const items = await searchable . search ( { query : this . state . filterText } ) ;
125
+ const items = await searchable . search ( this . state . searchOptions ) ;
121
126
this . setState ( { items : this . sort ( items ) } ) ;
122
127
}
123
128
@@ -145,15 +150,18 @@ export class FilterableListContainer<
145
150
} `,
146
151
run : ( { progressId } ) => uninstall ( { item, progressId } ) ,
147
152
} ) ;
148
- const items = await searchable . search ( { query : this . state . filterText } ) ;
153
+ const items = await searchable . search ( this . state . searchOptions ) ;
149
154
this . setState ( { items : this . sort ( items ) } ) ;
150
155
}
151
156
}
152
157
153
158
export namespace FilterableListContainer {
154
- export interface Props < T extends ArduinoComponent > {
155
- readonly container : ListWidget < T > ;
156
- readonly searchable : Searchable < T > ;
159
+ export interface Props <
160
+ T extends ArduinoComponent ,
161
+ S extends Searchable . Options
162
+ > {
163
+ readonly container : ListWidget < T , S > ;
164
+ readonly searchable : Searchable < T , S > ;
157
165
readonly itemLabel : ( item : T ) => string ;
158
166
readonly itemDeprecated : ( item : T ) => boolean ;
159
167
readonly itemRenderer : ListItemRenderer < T > ;
@@ -181,8 +189,8 @@ export namespace FilterableListContainer {
181
189
readonly commandService : CommandService ;
182
190
}
183
191
184
- export interface State < T > {
185
- filterText : string ;
192
+ export interface State < T , S extends Searchable . Options > {
193
+ searchOptions : S ;
186
194
items : T [ ] ;
187
195
}
188
196
}
0 commit comments