@@ -51,9 +51,11 @@ export abstract class ListWidget<
51
51
*/
52
52
protected firstActivate = true ;
53
53
54
+ protected readonly defaultSortComparator : ( left : T , right : T ) => number ;
55
+
54
56
constructor ( protected options : ListWidget . Options < T , S > ) {
55
57
super ( ) ;
56
- const { id, label, iconClass } = options ;
58
+ const { id, label, iconClass, itemDeprecated , itemLabel } = options ;
57
59
this . id = id ;
58
60
this . title . label = label ;
59
61
this . title . caption = label ;
@@ -63,12 +65,23 @@ export abstract class ListWidget<
63
65
this . node . tabIndex = 0 ; // To be able to set the focus on the widget.
64
66
this . scrollOptions = undefined ;
65
67
this . toDispose . push ( this . searchOptionsChangeEmitter ) ;
68
+
69
+ this . defaultSortComparator = ( left , right ) : number => {
70
+ // always put deprecated items at the bottom of the list
71
+ if ( itemDeprecated ( left ) ) {
72
+ return 1 ;
73
+ }
74
+
75
+ return itemLabel ( left ) . localeCompare ( itemLabel ( right ) ) ;
76
+ } ;
66
77
}
67
78
68
79
@postConstruct ( )
69
80
protected init ( ) : void {
70
81
this . toDispose . pushAll ( [
71
- this . notificationCenter . onIndexUpdateDidComplete ( ( ) => this . refresh ( undefined ) ) ,
82
+ this . notificationCenter . onIndexUpdateDidComplete ( ( ) =>
83
+ this . refresh ( undefined )
84
+ ) ,
72
85
this . notificationCenter . onDaemonDidStart ( ( ) => this . refresh ( undefined ) ) ,
73
86
this . notificationCenter . onDaemonDidStop ( ( ) => this . refresh ( undefined ) ) ,
74
87
] ) ;
@@ -128,6 +141,30 @@ export abstract class ListWidget<
128
141
return this . options . installable . uninstall ( { item, progressId } ) ;
129
142
}
130
143
144
+ protected filterableListSort = ( items : T [ ] ) : T [ ] => {
145
+ const isArduinoTypeComparator = ( left : T , right : T ) => {
146
+ const aIsArduinoType = left . types . includes ( 'Arduino' ) ;
147
+ const bIsArduinoType = right . types . includes ( 'Arduino' ) ;
148
+
149
+ if ( aIsArduinoType && ! bIsArduinoType && ! left . deprecated ) {
150
+ return - 1 ;
151
+ }
152
+
153
+ if ( ! aIsArduinoType && bIsArduinoType && ! right . deprecated ) {
154
+ return 1 ;
155
+ }
156
+
157
+ return 0 ;
158
+ } ;
159
+
160
+ return items . sort ( ( left , right ) => {
161
+ return (
162
+ isArduinoTypeComparator ( left , right ) ||
163
+ this . defaultSortComparator ( left , right )
164
+ ) ;
165
+ } ) ;
166
+ } ;
167
+
131
168
render ( ) : React . ReactNode {
132
169
return (
133
170
< FilterableListContainer < T , S >
@@ -145,6 +182,7 @@ export abstract class ListWidget<
145
182
messageService = { this . messageService }
146
183
commandService = { this . commandService }
147
184
responseService = { this . responseService }
185
+ sort = { this . filterableListSort }
148
186
/>
149
187
) ;
150
188
}
0 commit comments