@@ -51,9 +51,11 @@ export abstract class ListWidget<
5151 */
5252 protected firstActivate = true ;
5353
54+ protected readonly defaultSortComparator : ( left : T , right : T ) => number ;
55+
5456 constructor ( protected options : ListWidget . Options < T , S > ) {
5557 super ( ) ;
56- const { id, label, iconClass } = options ;
58+ const { id, label, iconClass, itemDeprecated , itemLabel } = options ;
5759 this . id = id ;
5860 this . title . label = label ;
5961 this . title . caption = label ;
@@ -63,12 +65,23 @@ export abstract class ListWidget<
6365 this . node . tabIndex = 0 ; // To be able to set the focus on the widget.
6466 this . scrollOptions = undefined ;
6567 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+ } ;
6677 }
6778
6879 @postConstruct ( )
6980 protected init ( ) : void {
7081 this . toDispose . pushAll ( [
71- this . notificationCenter . onIndexUpdateDidComplete ( ( ) => this . refresh ( undefined ) ) ,
82+ this . notificationCenter . onIndexUpdateDidComplete ( ( ) =>
83+ this . refresh ( undefined )
84+ ) ,
7285 this . notificationCenter . onDaemonDidStart ( ( ) => this . refresh ( undefined ) ) ,
7386 this . notificationCenter . onDaemonDidStop ( ( ) => this . refresh ( undefined ) ) ,
7487 ] ) ;
@@ -128,6 +141,30 @@ export abstract class ListWidget<
128141 return this . options . installable . uninstall ( { item, progressId } ) ;
129142 }
130143
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+
131168 render ( ) : React . ReactNode {
132169 return (
133170 < FilterableListContainer < T , S >
@@ -145,6 +182,7 @@ export abstract class ListWidget<
145182 messageService = { this . messageService }
146183 commandService = { this . commandService }
147184 responseService = { this . responseService }
185+ sort = { this . filterableListSort }
148186 />
149187 ) ;
150188 }
0 commit comments