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

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
Basic filter.
Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
  • Loading branch information
Akos Kitta committed Aug 28, 2022
commit a0463a0ff005227774b3ca224c881446b1bf05d0
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,11 @@ export class ComponentList<T extends ArduinoComponent> extends React.Component<

private clear(index: number): void {
this.cache.clear(index, 0);
if (this.list) {
this.list.recomputeRowHeights(index);
this.list?.recomputeRowHeights(index);
// Update the last item if the if the one before was updated
if (index === this.props.items.length - 2) {
this.cache.clear(index + 1, 0);
this.list?.recomputeRowHeights(index + 1);
}
}

Expand Down
2 changes: 2 additions & 0 deletions arduino-ide-extension/src/common/protocol/library-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ export interface LibraryPackage extends ArduinoComponent {
readonly exampleUris: string[];
readonly location: LibraryLocation;
readonly installDirUri?: string;
readonly category?: string;
readonly maintainer?: string;
}
export namespace LibraryPackage {
export function is(arg: any): arg is LibraryPackage {
Expand Down
60 changes: 58 additions & 2 deletions arduino-ide-extension/src/node/library-service-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
LibraryDependency,
LibraryLocation,
LibraryPackage,
LibrarySearch,
LibraryService,
} from '../common/protocol/library-service';
import { CoreClientAware } from './core-client-provider';
Expand Down Expand Up @@ -46,7 +47,7 @@ export class LibraryServiceImpl
protected readonly notificationServer: NotificationServiceServer;

@duration()
async search(options: { query?: string }): Promise<LibraryPackage[]> {
async search(options: LibrarySearch): Promise<LibraryPackage[]> {
const coreClient = await this.coreClient;
const { client, instance } = coreClient;

Expand Down Expand Up @@ -104,7 +105,60 @@ export class LibraryServiceImpl
);
});

return items;
const typePredicate = this.typePredicate(options);
const topicPredicate = this.topicPredicate(options);
return items.filter((item) => typePredicate(item) && topicPredicate(item));
}

private typePredicate(
options: LibrarySearch
): (item: LibraryPackage) => boolean {
if (!options.type) {
return () => true;
}
switch (options.type) {
case 'All':
return () => true;
case 'Arduino':
return ({ maintainer }: LibraryPackage) =>
maintainer === 'Arduino <info@arduino.cc>';
case 'Installed':
return ({ installedVersion }: LibraryPackage) => !!installedVersion;
case 'Retired':
return ({ deprecated }: LibraryPackage) => deprecated;
case 'Updatable':
return (item: LibraryPackage) => {
const { installedVersion } = item;
if (!installedVersion) {
return false;
}
const latestVersion = item.availableVersions[0];
if (!latestVersion) {
console.warn(
`Installed version ${installedVersion} is available for ${item.name}, but available versions are mission. Skipping.`
);
return false;
}
const result = Installable.Version.COMPARATOR(
latestVersion,
installedVersion
);
return result > 0;
};
default: {
console.error('unhandled type: ' + options.type);
return () => true;
}
}
}

private topicPredicate(
options: LibrarySearch
): (item: LibraryPackage) => boolean {
if (!options.topic || options.topic === 'All') {
return () => true;
}
return (item: LibraryPackage) => item.category === options.topic;
}

async list({
Expand Down Expand Up @@ -409,5 +463,7 @@ function toLibrary(
description: lib.getSentence(),
moreInfoLink: lib.getWebsite(),
summary: lib.getParagraph(),
category: lib.getCategory(),
maintainer: lib.getMaintainer(),
};
}
0