1
1
import * as React from 'react' ;
2
+ import { Event } from '@theia/core/lib/common/event' ;
2
3
import { notEmpty } from '@theia/core/lib/common/objects' ;
4
+ import { MaybePromise } from '@theia/core/lib/common/types' ;
3
5
import { DisposableCollection } from '@theia/core/lib/common/disposable' ;
4
- import { Board , Port , AttachedBoardsChangeEvent } from '../../common/protocol/boards-service' ;
5
- import { BoardsServiceProvider } from './boards-service-provider' ;
6
+ import { Board , Port , AttachedBoardsChangeEvent , BoardWithPackage } from '../../common/protocol/boards-service' ;
6
7
import { NotificationCenter } from '../notification-center' ;
7
- import { MaybePromise } from '@theia/core ' ;
8
+ import { BoardsServiceProvider } from './boards-service-provider ' ;
8
9
9
10
export namespace BoardsConfig {
10
11
@@ -18,10 +19,11 @@ export namespace BoardsConfig {
18
19
readonly notificationCenter : NotificationCenter ;
19
20
readonly onConfigChange : ( config : Config ) => void ;
20
21
readonly onFocusNodeSet : ( element : HTMLElement | undefined ) => void ;
22
+ readonly onFilteredTextDidChangeEvent : Event < string > ;
21
23
}
22
24
23
25
export interface State extends Config {
24
- searchResults : Array < Board & { packageName : string } > ;
26
+ searchResults : Array < BoardWithPackage > ;
25
27
knownPorts : Port [ ] ;
26
28
showAllPorts : boolean ;
27
29
query : string ;
@@ -91,7 +93,8 @@ export class BoardsConfig extends React.Component<BoardsConfig.Props, BoardsConf
91
93
this . props . notificationCenter . onPlatformUninstalled ( ( ) => this . updateBoards ( this . state . query ) ) ,
92
94
this . props . notificationCenter . onIndexUpdated ( ( ) => this . updateBoards ( this . state . query ) ) ,
93
95
this . props . notificationCenter . onDaemonStarted ( ( ) => this . updateBoards ( this . state . query ) ) ,
94
- this . props . notificationCenter . onDaemonStopped ( ( ) => this . setState ( { searchResults : [ ] } ) )
96
+ this . props . notificationCenter . onDaemonStopped ( ( ) => this . setState ( { searchResults : [ ] } ) ) ,
97
+ this . props . onFilteredTextDidChangeEvent ( query => this . setState ( { query } , ( ) => this . updateBoards ( this . state . query ) ) )
95
98
] ) ;
96
99
}
97
100
@@ -105,10 +108,9 @@ export class BoardsConfig extends React.Component<BoardsConfig.Props, BoardsConf
105
108
}
106
109
107
110
protected updateBoards = ( eventOrQuery : React . ChangeEvent < HTMLInputElement > | string = '' ) => {
108
- const query = ( typeof eventOrQuery === 'string'
111
+ const query = typeof eventOrQuery === 'string'
109
112
? eventOrQuery
110
- : eventOrQuery . target . value . toLowerCase ( )
111
- ) . trim ( ) ;
113
+ : eventOrQuery . target . value . toLowerCase ( ) ;
112
114
this . setState ( { query } ) ;
113
115
this . queryBoards ( { query } ) . then ( searchResults => this . setState ( { searchResults } ) ) ;
114
116
}
@@ -124,7 +126,7 @@ export class BoardsConfig extends React.Component<BoardsConfig.Props, BoardsConf
124
126
} ) ;
125
127
}
126
128
127
- protected queryBoards = ( options : { query ?: string } = { } ) : Promise < Array < Board & { packageName : string } > > => {
129
+ protected queryBoards = ( options : { query ?: string } = { } ) : Promise < Array < BoardWithPackage > > => {
128
130
return this . props . boardsServiceProvider . searchBoards ( options ) ;
129
131
}
130
132
@@ -145,7 +147,7 @@ export class BoardsConfig extends React.Component<BoardsConfig.Props, BoardsConf
145
147
this . setState ( { selectedPort } , ( ) => this . fireConfigChanged ( ) ) ;
146
148
}
147
149
148
- protected selectBoard = ( selectedBoard : Board & { packageName : string } | undefined ) => {
150
+ protected selectBoard = ( selectedBoard : BoardWithPackage | undefined ) => {
149
151
this . setState ( { selectedBoard } , ( ) => this . fireConfigChanged ( ) ) ;
150
152
}
151
153
@@ -175,7 +177,7 @@ export class BoardsConfig extends React.Component<BoardsConfig.Props, BoardsConf
175
177
}
176
178
177
179
protected renderBoards ( ) : React . ReactNode {
178
- const { selectedBoard, searchResults } = this . state ;
180
+ const { selectedBoard, searchResults, query } = this . state ;
179
181
// Board names are not unique per core https://github.com/arduino/arduino-pro-ide/issues/262#issuecomment-661019560
180
182
// It is tricky when the core is not yet installed, no FQBNs are available.
181
183
const distinctBoards = new Map < string , Board . Detailed > ( ) ;
@@ -189,11 +191,18 @@ export class BoardsConfig extends React.Component<BoardsConfig.Props, BoardsConf
189
191
190
192
return < React . Fragment >
191
193
< div className = 'search' >
192
- < input type = 'search' className = 'theia-input' placeholder = 'SEARCH BOARD' onChange = { this . updateBoards } ref = { this . focusNodeSet } />
194
+ < input
195
+ type = 'search'
196
+ value = { query }
197
+ className = 'theia-input'
198
+ placeholder = 'SEARCH BOARD'
199
+ onChange = { this . updateBoards }
200
+ ref = { this . focusNodeSet }
201
+ />
193
202
< i className = 'fa fa-search' > </ i >
194
203
</ div >
195
204
< div className = 'boards list' >
196
- { Array . from ( distinctBoards . values ( ) ) . map ( board => < Item < Board & { packageName : string } >
205
+ { Array . from ( distinctBoards . values ( ) ) . map ( board => < Item < BoardWithPackage >
197
206
key = { `${ board . name } -${ board . packageName } ` }
198
207
item = { board }
199
208
label = { board . name }
0 commit comments