Skip to content

Commit e00fa2b

Browse files
author
Akos Kitta
committed
Can reset types from an action.
Signed-off-by: Akos Kitta <[email protected]>
1 parent ecef208 commit e00fa2b

File tree

5 files changed

+46
-29
lines changed

5 files changed

+46
-29
lines changed

arduino-ide-extension/src/browser/boards/boards-auto-installer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,10 @@ export class BoardsAutoInstaller implements FrontendApplicationContribution {
240240
this.boardsManagerFrontendContribution
241241
.openView({ reveal: true })
242242
.then((widget) =>
243-
widget.refresh(candidate.name.toLocaleLowerCase())
243+
widget.refresh({
244+
query: candidate.name.toLocaleLowerCase(),
245+
type: 'All',
246+
})
244247
);
245248
},
246249
},

arduino-ide-extension/src/browser/contributions/check-for-updates.ts

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -105,29 +105,37 @@ export class CheckForUpdates extends Contribution {
105105
}
106106

107107
private promptUpdateLibraries(items: LibraryPackage[]): void {
108-
this.prompt(
108+
this.prompt({
109109
items,
110-
this.libraryService,
111-
this.librariesContribution,
112-
UpdatesLibraries
113-
);
110+
installable: this.libraryService,
111+
viewContribution: this.librariesContribution,
112+
message: UpdatesLibraries,
113+
viewSearchOptions: { query: '', type: 'Updatable', topic: 'All' },
114+
});
114115
}
115116

116117
private promptUpdateBoards(items: BoardsPackage[]): void {
117-
this.prompt(
118+
this.prompt({
118119
items,
119-
this.boardsService,
120-
this.boardsContribution,
121-
UpdatesBoards
122-
);
120+
installable: this.boardsService,
121+
viewContribution: this.boardsContribution,
122+
message: UpdatesBoards,
123+
viewSearchOptions: { query: '', type: 'Updatable' },
124+
});
123125
}
124126

125-
private prompt<T extends ArduinoComponent, S extends Searchable.Options>(
126-
items: T[],
127-
installable: Installable<T>,
128-
viewContribution: AbstractViewContribution<ListWidget<T, S>>,
129-
message: string
130-
): void {
127+
private prompt<
128+
T extends ArduinoComponent,
129+
S extends Searchable.Options
130+
>(options: {
131+
items: T[];
132+
installable: Installable<T>;
133+
viewContribution: AbstractViewContribution<ListWidget<T, S>>;
134+
viewSearchOptions: S;
135+
message: string;
136+
}): void {
137+
const { items, installable, viewContribution, message, viewSearchOptions } =
138+
options;
131139
if (!items.length) {
132140
return;
133141
}
@@ -139,7 +147,7 @@ export class CheckForUpdates extends Contribution {
139147
} else if (answer === InstallManually) {
140148
viewContribution
141149
.openView({ reveal: true })
142-
.then((widget) => widget.refresh(candidate.name.toLocaleLowerCase()));
150+
.then((widget) => widget.refresh(viewSearchOptions));
143151
}
144152
});
145153
}

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ export class FilterableListContainer<
3434
override componentDidMount(): void {
3535
this.search = debounce(this.search, 500);
3636
this.search(this.state.searchOptions);
37-
this.props.filterTextChangeEvent(this.handlePropChange.bind(this));
37+
this.props.searchOptionsDidChange((newSearchOptions) => {
38+
const { searchOptions } = this.state;
39+
this.setSearchOptionsAndUpdate({ ...searchOptions, ...newSearchOptions });
40+
});
3841
}
3942

4043
override componentDidUpdate(): void {
@@ -95,9 +98,13 @@ export class FilterableListContainer<
9598
...this.state.searchOptions,
9699
[prop]: value,
97100
};
98-
this.setState({ searchOptions }, () => this.search(searchOptions));
101+
this.setSearchOptionsAndUpdate(searchOptions);
99102
};
100103

104+
private setSearchOptionsAndUpdate(searchOptions: S) {
105+
this.setState({ searchOptions }, () => this.search(searchOptions));
106+
}
107+
101108
protected search(searchOptions: S): void {
102109
const { searchable } = this.props;
103110
searchable
@@ -175,7 +182,7 @@ export namespace FilterableListContainer {
175182
readonly itemRenderer: ListItemRenderer<T>;
176183
readonly filterRenderer: FilterRenderer<S>;
177184
readonly resolveFocus: (element: HTMLElement | undefined) => void;
178-
readonly filterTextChangeEvent: Event<string | undefined>;
185+
readonly searchOptionsDidChange: Event<Partial<S> | undefined>;
179186
readonly messageService: MessageService;
180187
readonly responseService: ResponseServiceClient;
181188
readonly install: ({

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ export abstract class ListWidget<
4242
* Do not touch or use it. It is for setting the focus on the `input` after the widget activation.
4343
*/
4444
protected focusNode: HTMLElement | undefined;
45-
// protected readonly deferredContainer = new Deferred<HTMLElement>();
46-
protected readonly filterTextChangeEmitter = new Emitter<
47-
string | undefined
45+
protected readonly searchOptionsChangeEmitter = new Emitter<
46+
Partial<S> | undefined
4847
>();
4948
/**
5049
* Instead of running an `update` from the `postConstruct` `init` method,
@@ -63,7 +62,7 @@ export abstract class ListWidget<
6362
this.addClass('arduino-list-widget');
6463
this.node.tabIndex = 0; // To be able to set the focus on the widget.
6564
this.scrollOptions = undefined;
66-
this.toDispose.push(this.filterTextChangeEmitter);
65+
this.toDispose.push(this.searchOptionsChangeEmitter);
6766
}
6867

6968
@postConstruct()
@@ -142,7 +141,7 @@ export abstract class ListWidget<
142141
itemDeprecated={this.options.itemDeprecated}
143142
itemRenderer={this.options.itemRenderer}
144143
filterRenderer={this.options.filterRenderer}
145-
filterTextChangeEvent={this.filterTextChangeEmitter.event}
144+
searchOptionsDidChange={this.searchOptionsChangeEmitter.event}
146145
messageService={this.messageService}
147146
commandService={this.commandService}
148147
responseService={this.responseService}
@@ -154,8 +153,8 @@ export abstract class ListWidget<
154153
* If `filterText` is defined, sets the filter text to the argument.
155154
* If it is `undefined`, updates the view state by re-running the search with the current `filterText` term.
156155
*/
157-
refresh(filterText: string | undefined): void {
158-
this.filterTextChangeEmitter.fire(filterText);
156+
refresh(searchOptions: Partial<S> | undefined): void {
157+
this.searchOptionsChangeEmitter.fire(searchOptions);
159158
}
160159

161160
updateScrollBar(): void {

arduino-ide-extension/src/common/protocol/library-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export namespace LibrarySearch {
8787
'Signal Input/Output',
8888
'Timing',
8989
'Uncategorized',
90-
];
90+
] as const;
9191
export type Topic = typeof TopicLiterals[number];
9292
export const TopicLabels: Record<Topic, string> = {
9393
All: All,

0 commit comments

Comments
 (0)