Skip to content

Commit e577de4

Browse files
Put Arduino libs and platforms on top of the Library/Boards Manager (#1541)
1 parent f3ef95c commit e577de4

File tree

2 files changed

+44
-17
lines changed

2 files changed

+44
-17
lines changed

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

+40-2
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,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

Comments
 (0)