Skip to content

Commit

Permalink
factorize getSearchableTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Dec 9, 2020
1 parent c6fee45 commit 59cf6a1
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@

import { from, combineLatest, of } from 'rxjs';
import { map, takeUntil, first } from 'rxjs/operators';
import { SavedObjectsFindOptionsReference } from 'src/core/server';
import { SavedObjectsFindOptionsReference, ISavedObjectTypeRegistry } from 'src/core/server';
import { GlobalSearchResultProvider } from '../../../../global_search/server';
import { mapToResults } from './map_object_to_result';

const getSearchableTypes = (typeRegistry: ISavedObjectTypeRegistry, types?: string[]) =>
typeRegistry
.getVisibleTypes()
.filter(types ? (type) => includeIgnoreCase(types, type.name) : () => true)
.filter((type) => type.management?.defaultSearchField && type.management?.getInAppUrl);

export const createSavedObjectsResultProvider = (): GlobalSearchResultProvider => {
return {
id: 'savedObjects',
Expand All @@ -23,10 +29,7 @@ export const createSavedObjectsResultProvider = (): GlobalSearchResultProvider =
savedObjects: { client, typeRegistry },
} = core;

const searchableTypes = typeRegistry
.getVisibleTypes()
.filter(types ? (type) => includeIgnoreCase(types, type.name) : () => true)
.filter((type) => type.management?.defaultSearchField && type.management?.getInAppUrl);
const searchableTypes = getSearchableTypes(typeRegistry, types);

const searchFields = uniq(
searchableTypes.map((type) => type.management!.defaultSearchField!)
Expand Down Expand Up @@ -55,10 +58,7 @@ export const createSavedObjectsResultProvider = (): GlobalSearchResultProvider =
const {
savedObjects: { typeRegistry },
} = core;
return typeRegistry
.getVisibleTypes()
.filter((type) => type.management?.defaultSearchField && type.management?.getInAppUrl)
.map((type) => type.name);
return getSearchableTypes(typeRegistry).map((type) => type.name);
},
};
};
Expand Down

0 comments on commit 59cf6a1

Please sign in to comment.