Skip to content

Commit b980215

Browse files
put arduino libs at the top of the lib manager
1 parent 61a11a0 commit b980215

File tree

5 files changed

+51
-16
lines changed

5 files changed

+51
-16
lines changed

arduino-ide-extension/src/browser/library/library-list-widget.ts

+26
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,32 @@ export class LibraryListWidget extends ListWidget<
189189
{ timeout: 3000 }
190190
);
191191
}
192+
193+
protected override filterableListSort(
194+
items: LibraryPackage[]
195+
): LibraryPackage[] {
196+
const isArduinoMaintainedComparator = (
197+
left: LibraryPackage,
198+
right: LibraryPackage
199+
) => {
200+
if (left.isArduinoMaintained && !right.isArduinoMaintained) {
201+
return -1;
202+
}
203+
204+
if (!left.isArduinoMaintained && right.isArduinoMaintained) {
205+
return 1;
206+
}
207+
208+
return 0;
209+
};
210+
211+
return items.sort((left, right) => {
212+
return (
213+
isArduinoMaintainedComparator(left, right) ||
214+
this.defaultSortComparator(left, right)
215+
);
216+
});
217+
}
192218
}
193219

194220
class MessageBoxDialog extends AbstractDialog<MessageBoxDialog.Result> {

arduino-ide-extension/src/browser/widgets/component-list/filterable-list-container.tsx

+4-15
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,7 @@ export class FilterableListContainer<
111111
const { searchable } = this.props;
112112
searchable
113113
.search(searchOptions)
114-
.then((items) => this.setState({ items: this.sort(items) }));
115-
}
116-
117-
protected sort(items: T[]): T[] {
118-
const { itemLabel, itemDeprecated } = this.props;
119-
return items.sort((left, right) => {
120-
// always put deprecated items at the bottom of the list
121-
if (itemDeprecated(left)) {
122-
return 1;
123-
}
124-
125-
return itemLabel(left).localeCompare(itemLabel(right));
126-
});
114+
.then((items) => this.setState({ items: this.props.sort(items) }));
127115
}
128116

129117
protected async install(
@@ -139,7 +127,7 @@ export class FilterableListContainer<
139127
run: ({ progressId }) => install({ item, progressId, version }),
140128
});
141129
const items = await searchable.search(this.state.searchOptions);
142-
this.setState({ items: this.sort(items) });
130+
this.setState({ items: this.props.sort(items) });
143131
}
144132

145133
protected async uninstall(item: T): Promise<void> {
@@ -167,7 +155,7 @@ export class FilterableListContainer<
167155
run: ({ progressId }) => uninstall({ item, progressId }),
168156
});
169157
const items = await searchable.search(this.state.searchOptions);
170-
this.setState({ items: this.sort(items) });
158+
this.setState({ items: this.props.sort(items) });
171159
}
172160
}
173161

@@ -204,6 +192,7 @@ export namespace FilterableListContainer {
204192
progressId: string;
205193
}) => Promise<void>;
206194
readonly commandService: CommandService;
195+
readonly sort: (items: T[]) => T[];
207196
}
208197

209198
export interface State<T, S extends Searchable.Options> {

arduino-ide-extension/src/browser/widgets/component-list/list-widget.tsx

+19-1
Original file line numberDiff line numberDiff line change
@@ -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,6 +65,17 @@ 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+
};
77+
78+
this.filterableListSort = this.filterableListSort.bind(this);
6679
}
6780

6881
@postConstruct()
@@ -128,6 +141,10 @@ export abstract class ListWidget<
128141
return this.options.installable.uninstall({ item, progressId });
129142
}
130143

144+
protected filterableListSort(items: T[]): T[] {
145+
return items.sort(this.defaultSortComparator);
146+
}
147+
131148
render(): React.ReactNode {
132149
return (
133150
<FilterableListContainer<T, S>
@@ -145,6 +162,7 @@ export abstract class ListWidget<
145162
messageService={this.messageService}
146163
commandService={this.commandService}
147164
responseService={this.responseService}
165+
sort={this.filterableListSort}
148166
/>
149167
);
150168
}

arduino-ide-extension/src/common/protocol/arduino-component.ts

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface ArduinoComponent {
1010
readonly availableVersions: Installable.Version[];
1111
readonly installable: boolean;
1212
readonly installedVersion?: Installable.Version;
13+
readonly isArduinoMaintained?: boolean;
1314
/**
1415
* This is the `Type` in IDE (1.x) UI.
1516
*/

arduino-ide-extension/src/node/library-service-impl.ts

+1
Original file line numberDiff line numberDiff line change
@@ -456,5 +456,6 @@ function toLibrary(
456456
summary: lib.getParagraph(),
457457
category: lib.getCategory(),
458458
types: lib.getTypesList(),
459+
isArduinoMaintained: lib.getAuthor() === 'Arduino', // TODO check if .getMaintainer is more appropriate
459460
};
460461
}

0 commit comments

Comments
 (0)