fix where we slice for maxResults (#104661)

This commit is contained in:
Jean-Louis Leysens 2021-07-08 13:25:08 +02:00 committed by GitHub
parent ff327bee91
commit 170cb57827
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 15 deletions

View file

@ -164,18 +164,18 @@ describe('Package search provider', () => {
const packageSearchProvider = createPackageSearchProvider(setupMock);
expectObservable(
packageSearchProvider.find(
{ term: 'test' },
{ term: 'test1' },
{ aborted$: NEVER, maxResults: 1, preference: '' }
)
).toBe('--(a|)', {
a: [
{
id: 'test-test',
id: 'test1-test1',
score: 80,
title: 'test',
title: 'test1',
type: 'integration',
url: {
path: 'undefined#/detail/test-test/overview',
path: 'undefined#/detail/test1-test1/overview',
prependBasePath: false,
},
},

View file

@ -94,19 +94,19 @@ export const createPackageSearchProvider = (core: CoreSetup): GlobalSearchResult
coreStart: CoreStart,
packagesResponse: GetPackagesResponse['response']
): GlobalSearchProviderResult[] => {
const packages = packagesResponse.slice(0, maxResults);
return packagesResponse
.flatMap(
includeAllPackages
? (pkg) => toSearchResult(pkg, coreStart.application)
: (pkg) => {
if (!term || !pkg.title.toLowerCase().includes(term)) {
return [];
}
return packages.flatMap(
includeAllPackages
? (pkg) => toSearchResult(pkg, coreStart.application)
: (pkg) => {
if (!term || !pkg.title.toLowerCase().includes(term)) {
return [];
return toSearchResult(pkg, coreStart.application);
}
return toSearchResult(pkg, coreStart.application);
}
);
)
.slice(0, maxResults);
};
return combineLatest([coreStart$, getPackages$()]).pipe(