8000 Layout improvements of the filter for boards and libs manager by francescospissu · Pull Request #1369 · arduino/arduino-ide · GitHub
[go: up one dir, main page]

Skip to content
8000

Layout improvements of the filter for boards and libs manager #1369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Generic type for the search options.
Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
  • Loading branch information
Akos Kitta committed Aug 27, 2022
commit 2b0d3976fa4743631d3abf86084360e522fc246f
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
postConstruct,
} from '@theia/core/shared/inversify';
import {
BoardSearch,
BoardsPackage,
BoardsService,
} from '../../common/protocol/boards-service';
Expand All @@ -12,7 +13,7 @@ import { ListItemRenderer } from '../widgets/component-list/list-item-renderer';
import { nls } from '@theia/core/lib/common';

@injectable()
export class BoardsListWidget extends ListWidget<BoardsPackage> {
export class BoardsListWidget extends ListWidget<BoardsPackage, BoardSearch> {
static WIDGET_ID = 'boards-list-widget';
static WIDGET_LABEL = nls.localize('arduino/boardsManager', 'Boards Manager');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { injectable } from '@theia/core/shared/inversify';
import { BoardsListWidget } from './boards-list-widget';
import { BoardsPackage } from '../../common/protocol/boards-service';
import type {
BoardSearch,
BoardsPackage,
} from '../../common/protocol/boards-service';
import { ListWidgetFrontendContribution } from '../widgets/component-list/list-widget-frontend-contribution';

@injectable()
export class BoardsListWidgetFrontendContribution extends ListWidgetFrontendContribution<BoardsPackage> {
export class BoardsListWidgetFrontendContribution extends ListWidgetFrontendContribution<
BoardsPackage,
BoardSearch
> {
constructor() {
super({
widgetId: BoardsListWidget.WIDGET_ID,
Expand Down
16 changes: 13 additions & 3 deletions arduino-ide-extension/src/browser/library/library-list-widget.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { injectable, postConstruct, inject } from '@theia/core/shared/inversify';
import {
injectable,
postConstruct,
inject,
} from '@theia/core/shared/inversify';
import { Message } from '@theia/core/shared/@phosphor/messaging';
import { addEventListener } from '@theia/core/lib/browser/widgets/widget';
import { DialogProps } from '@theia/core/lib/browser/dialogs';
import { AbstractDialog } from '../theia/dialogs/dialogs';
import {
LibraryPackage,
LibrarySearch,
LibraryService,
} from '../../common/protocol/library-service';
import { ListWidget } from '../widgets/component-list/list-widget';
Expand All @@ -13,7 +18,10 @@ import { ListItemRenderer } from '../widgets/component-list/list-item-renderer';
import { nls } from '@theia/core/lib/common';

@injectable()
export class LibraryListWidget extends ListWidget<LibraryPackage> {
export class LibraryListWidget extends ListWidget<
LibraryPackage,
LibrarySearch
> {
static WIDGET_ID = 'library-list-widget';
static WIDGET_LABEL = nls.localize(
'arduino/library/title',
Expand Down Expand Up @@ -41,7 +49,9 @@ export class LibraryListWidget extends ListWidget<LibraryPackage> {
protected override init(): void {
super.init();
this.toDispose.pushAll([
this.notificationCenter.onLibraryDidInstall(() => this.refresh(undefined)),
this.notificationCenter.onLibraryDidInstall(() =>
this.refresh(undefined)
),
this.notificationCenter.onLibraryDidUninstall(() =>
this.refresh(undefined)
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,24 @@ import { ResponseServiceClient } from '../../../common/protocol';
import { nls } from '@theia/core/lib/common';

export class FilterableListContainer<
T extends ArduinoComponent
T extends ArduinoComponent,
S extends Searchable.Options
> extends React.Component<
FilterableListContainer.Props<T>,
FilterableListContainer.State<T>
FilterableListContainer.Props<T, S>,
FilterableListContainer.State<T, S>
> {
constructor(props: Readonly<FilterableListContainer.Props<T>>) {
constructor(props: Readonly<FilterableListContainer.Props<T, S>>) {
super(props);
this.state = {
filterText: '',
searchOptions: { query: '' } as S,
items: [],
};
}

override componentDidMount(): void {
this.search = debounce(this.search, 500);
this.handleFilterTextChange('');
this.props.filterTextChangeEvent(this.handleFilterTextChange.bind(this));
this.handleQueryChange('');
this.props.filterTextChangeEvent(this.handleQueryChange.bind(this));
}

override componentDidUpdate(): void {
Expand All @@ -59,8 +60,8 @@ export class FilterableListContainer<
return (
<SearchBar
resolveFocus={this.props.resolveFocus}
filterText={this.state.filterText}
onFilterTextChanged={this.handleFilterTextChange}
filterText={this.state.searchOptions.query ?? ''}
onFilterTextChanged={this.handleQueryChange}
/>
);
}
Expand All @@ -79,17 +80,21 @@ export class FilterableListContainer<
);
}

protected handleFilterTextChange = (
filterText: string = this.state.filterText
protected handleQueryChange = (
query: string = this.state.searchOptions.query ?? ''
): void => {
this.setState({ filterText });
this.search(filterText);
const newSearchOptions = {
...this.state.searchOptions,
query,
};
this.setState({ searchOptions: newSearchOptions });
this.search(newSearchOptions);
};

protected search(query: string): void {
protected search(searchOptions: S): void {
const { searchable } = this.props;
searchable
.search({ query: query.trim() })
.search(searchOptions)
.then((items) => this.setState({ items: this.sort(items) }));
}

Expand Down Expand Up @@ -117,7 +122,7 @@ export class FilterableListContainer<
` ${item.name}:${version}`,
run: ({ progressId }) => install({ item, progressId, version }),
});
const items = await searchable.search({ query: this.state.filterText });
const items = await searchable.search(this.state.searchOptions);
this.setState({ items: this.sort(items) });
}

Expand Down Expand Up @@ -145,15 +150,18 @@ export class FilterableListContainer<
}`,
run: ({ progressId }) => uninstall({ item, progressId }),
});
const items = await searchable.search({ query: this.state.filterText });
const items = await searchable.search(this.state.searchOptions);
this.setState({ items: this.sort(items) });
}
}

export namespace FilterableListContainer {
export interface Props<T extends ArduinoComponent> {
readonly container: ListWidget<T>;
readonly searchable: Searchable<T>;
export interface Props<
T extends ArduinoComponent,
S extends Searchable.Options
> {
readonly container: ListWidget<T, S>;
readonly searchable: Searchable<T, S>;
readonly itemLabel: (item: T) => string;
readonly itemDeprecated: (item: T) => boolean;
readonly itemRenderer: ListItemRenderer<T>;
Expand Down Expand Up @@ -181,8 +189,8 @@ export namespace FilterableListContainer {
readonly commandService: CommandService;
}

export interface State<T> {
filterText: string;
export interface State<T, S extends Searchable.Options> {
searchOptions: S;
items: T[];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ import { FrontendApplicationContribution } from '@theia/core/lib/browser/fronten
import { AbstractViewContribution } from '@theia/core/lib/browser/shell/view-contribution';
import { ArduinoComponent } from '../../../common/protocol/arduino-component';
import { ListWidget } from './list-widget';
import { Searchable } from '../../../common/protocol';

@injectable()
export abstract class ListWidgetFrontendContribution<T extends ArduinoComponent>
extends AbstractViewContribution<ListWidget<T>>
export abstract class ListWidgetFrontendContribution<
T extends ArduinoComponent,
S extends Searchable.Options
>
extends AbstractViewContribution<ListWidget<T, S>>
implements FrontendApplicationContribution
{
async initializeLayout(): Promise<void> {}
async initializeLayout(): Promise<void> {
// TS requires at least one method from `FrontendApplicationContribution`.
// Expected to be empty.
}

override registerMenus(): void {
// NOOP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import { NotificationCenter } from '../../notification-center';

@injectable()
export abstract class ListWidget<
T extends ArduinoComponent
T extends ArduinoComponent,
S extends Searchable.Options
> extends ReactWidget {
@inject(MessageService)
protected readonly messageService: MessageService;
Expand Down Expand Up @@ -50,7 +51,7 @@ export abstract class ListWidget<
*/
protected firstActivate = true;

constructor(protected options: ListWidget.Options<T>) {
constructor(protected options: ListWidget.Options<T, S>) {
super();
const { id, label, iconClass } = options;
this.id = id;
Expand Down Expand Up @@ -129,7 +130,7 @@ export abstract class ListWidget<

render(): React.ReactNode {
return (
<FilterableListContainer<T>
<FilterableListContainer<T, S>
container={this}
resolveFocus={this.onFocusResolved}
searchable={this.options.searchable}
Expand Down Expand Up @@ -162,12 +163,15 @@ export abstract class ListWidget<
}

export namespace ListWidget {
export interface Options<T extends ArduinoComponent> {
export interface Options<
T extends ArduinoComponent,
S extends Searchable.Options
> {
readonly id: string;
readonly label: string;
readonly iconClass: string;
readonly installable: Installable<T>;
readonly searchable: Searchable<T>;
readonly searchable: Searchable<T, S>;
readonly itemLabel: (item: T) => string;
readonly itemDeprecated: (item: T) => boolean;
readonly itemRenderer: ListItemRenderer<T>;
Expand Down
18 changes: 17 additions & 1 deletion arduino-ide-extension/src/common/protocol/boards-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export const BoardsServicePath = '/services/boards-service';
export const BoardsService = Symbol('BoardsService');
export interface BoardsService
extends Installable<BoardsPackage>,
Searchable<BoardsPackage> {
Searchable<BoardsPackage, BoardSearch> {
getState(): Promise<AvailablePorts>;
getBoardDetails(options: { fqbn: string }): Promise<BoardDetails | undefined>;
getBoardPackage(options: { id: string }): Promise<BoardsPackage | undefined>;
Expand All @@ -145,6 +145,22 @@ export interface BoardsService
}): Promise<BoardUserField[]>;
}

export interface BoardSearch extends Searchable.Options {
readonly type?: BoardSearch.Type;
}
export namespace BoardSearch {
export const TypeLiterals = [
'All',
'Updatable',
'Arduino',
'Contributed',
'Arduino Certified',
'Partner',
'Arduino@Heart',
] as const;
export type Type = typeof TypeLiterals[number];
}

export interface Port {
readonly address: string;
readonly addressLabel: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const LibraryServicePath = '/services/library-service';
export const LibraryService = Symbol('LibraryService');
export interface LibraryService
extends Installable<LibraryPackage>,
Searchable<LibraryPackage> {
Searchable<LibraryPackage, LibrarySearch> {
list(options: LibraryService.List.Options): Promise<LibraryPackage[]>;
search(options: LibrarySearch): Promise<LibraryPackage[]>;
/**
Expand Down
4 changes: 2 additions & 2 deletions arduino-ide-extension/src/common/protocol/searchable.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface Searchable<T> {
search(options: Searchable.Options): Promise<T[]>;
export interface Searchable<T, O extends Searchable.Options> {
search(options: O): Promise<T[]>;
}
export namespace Searchable {
export interface Options {
Expand Down
0