Skip to content

Commit

Permalink
fix where we slice for maxResults
Browse files Browse the repository at this point in the history
  • Loading branch information
jloleysens committed Jul 7, 2021
1 parent 2138c0e commit 2b743ad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions x-pack/plugins/fleet/public/search_provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: 'package',
url: {
path: 'undefined#/detail/test-test/overview',
path: 'undefined#/detail/test1-test1/overview',
prependBasePath: false,
},
},
Expand Down
24 changes: 12 additions & 12 deletions x-pack/plugins/fleet/public/search_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,19 @@ export const createPackageSearchProvider = (core: CoreSetup): GlobalSearchResult
coreStart: CoreStart,
packagesResponse: GetPackagesResponse['response']
): GlobalSearchProviderResult[] => {
const packages = packagesResponse.slice(0, maxResults);

return packages.flatMap(
includeAllPackages
? (pkg) => toSearchResult(pkg, coreStart.application)
: (pkg) => {
if (!term || !pkg.title.toLowerCase().includes(term)) {
return [];
return packagesResponse
.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(
Expand Down

0 comments on commit 2b743ad

Please sign in to comment.