1
1
import * as React from 'react' ;
2
2
import { WindowService } from '@theia/core/lib/browser/window/window-service' ;
3
- import { ComponentList } from './component-list' ;
4
3
import { SearchBar } from './search-bar' ;
4
+ import { ComponentList } from './component-list' ;
5
+ import { LibraryService } from '../../../common/protocol/library-service' ;
5
6
import { ArduinoComponent } from '../../../common/protocol/arduino-component' ;
6
7
import { InstallationProgressDialog } from '../installation-progress-dialog' ;
7
8
@@ -21,21 +22,37 @@ export class FilterableListContainer extends React.Component<FilterableListConta
21
22
}
22
23
23
24
render ( ) : React . ReactNode {
24
- return < div className = { FilterableListContainer . Styles . FILTERABLE_LIST_CONTAINER_CLASS } >
25
- < SearchBar
26
- filterText = { this . state . filterText }
27
- onFilterTextChanged = { this . handleFilterTextChange }
28
- />
29
- < ComponentList
30
- items = { this . state . items }
31
- install = { this . install . bind ( this ) }
32
- windowService = { this . props . windowService }
33
- />
25
+ return < div className = { 'filterable-list-container' } >
26
+ { this . renderSearchFilter ( ) }
27
+ { this . renderSearchBar ( ) }
28
+ { this . renderComponentList ( ) }
34
29
</ div >
35
30
}
36
31
32
+ protected renderSearchFilter ( ) : React . ReactNode {
33
+ return undefined ;
34
+ }
35
+
36
+ protected renderSearchBar ( ) : React . ReactNode {
37
+ return < SearchBar
38
+ resolveFocus = { this . props . resolveFocus }
39
+ filterText = { this . state . filterText }
40
+ onFilterTextChanged = { this . handleFilterTextChange }
41
+ />
42
+ }
43
+
44
+ protected renderComponentList ( ) : React . ReactNode {
45
+ return < ComponentList
46
+ items = { this . state . items }
47
+ install = { this . install . bind ( this ) }
48
+ windowService = { this . props . windowService }
49
+ resolveContainer = { this . props . resolveContainer }
50
+ />
51
+ }
52
+
37
53
private handleFilterTextChange ( filterText : string ) : void {
38
- this . props . service . search ( { query : filterText } ) . then ( result => {
54
+ const { props } = this . state ;
55
+ this . props . service . search ( { query : filterText , props } ) . then ( result => {
39
56
const { items } = result ;
40
57
this . setState ( {
41
58
filterText,
@@ -45,23 +62,16 @@ export class FilterableListContainer extends React.Component<FilterableListConta
45
62
}
46
63
47
64
protected sort ( items : ArduinoComponent [ ] ) : ArduinoComponent [ ] {
48
- return items . sort ( ( a , b ) => {
49
- if ( a . name < b . name ) {
50
- return - 1 ;
51
- } else if ( a . name === b . name ) {
52
- return 0 ;
53
- } else {
54
- return 1 ;
55
- }
56
- } ) ;
65
+ return items . sort ( ( left , right ) => left . name . localeCompare ( right . name ) ) ;
57
66
}
58
67
59
68
protected async install ( comp : ArduinoComponent ) : Promise < void > {
60
69
const dialog = new InstallationProgressDialog ( comp . name ) ;
61
70
dialog . open ( ) ;
62
71
try {
63
72
await this . props . service . install ( comp ) ;
64
- const { items } = await this . props . service . search ( { query : this . state . filterText } ) ;
73
+ const { props } = this . state ;
74
+ const { items } = await this . props . service . search ( { query : this . state . filterText , props } ) ;
65
75
this . setState ( { items : this . sort ( items ) } ) ;
66
76
} finally {
67
77
dialog . close ( ) ;
@@ -75,19 +85,18 @@ export namespace FilterableListContainer {
75
85
export interface Props {
76
86
readonly service : ComponentSource ;
77
87
readonly windowService : WindowService ;
88
+ readonly resolveContainer ?: ( element : HTMLElement ) => void ;
89
+ readonly resolveFocus ?: ( element : HTMLElement | undefined ) => void ;
78
90
}
79
91
80
92
export interface State {
81
93
filterText : string ;
82
94
items : ArduinoComponent [ ] ;
83
- }
84
-
85
- export namespace Styles {
86
- export const FILTERABLE_LIST_CONTAINER_CLASS = 'filterable-list-container' ;
95
+ props ?: LibraryService . Search . Props ;
87
96
}
88
97
89
98
export interface ComponentSource {
90
- search ( req : { query : string } ) : Promise < { items : ArduinoComponent [ ] } >
99
+ search ( req : { query : string , props ?: LibraryService . Search . Props } ) : Promise < { items : ArduinoComponent [ ] } >
91
100
install ( board : ArduinoComponent ) : Promise < void > ;
92
101
}
93
102
0 commit comments