@@ -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,6 +65,17 @@ 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
+ } ;
77
+
78
+ this . filterableListSort = this . filterableListSort . bind ( this ) ;
66
79
}
67
80
68
81
@postConstruct ( )
@@ -128,6 +141,10 @@ export abstract class ListWidget<
128
141
return this . options . installable . uninstall ( { item, progressId } ) ;
129
142
}
130
143
144
+ protected filterableListSort ( items : T [ ] ) : T [ ] {
145
+ return items . sort ( this . defaultSortComparator ) ;
146
+ }
147
+
131
148
render ( ) : React . ReactNode {
132
149
return (
133
150
< FilterableListContainer < T , S >
@@ -145,6 +162,7 @@ export abstract class ListWidget<
145
162
messageService = { this . messageService }
146
163
commandService = { this . commandService }
147
164
responseService = { this . responseService }
165
+ sort = { this . filterableListSort }
148
166
/>
149
167
) ;
150
168
}
0 commit comments