Skip to content

Commit

Permalink
fix some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwizp committed Nov 27, 2020
1 parent 7b25522 commit f2ca98a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,16 @@ export class IndexPatternsService {
* @param title {string}
* @returns {Promise<SavedObject|undefined>}
*/
findByTitle = async (title: string) => {
const savedObject = await findByTitle(this.savedObjectsClient, title);
findByTitle = async (title: string, refresh: boolean = false) => {
if (!this.savedObjectsCache || refresh) {
await this.refreshSavedObjectsCache();
}
if (this.savedObjectsCache) {
const so = this.savedObjectsCache.find((obj) => obj.attributes.title === title);

if (savedObject?.id) {
return this.get(savedObject?.id);
if (so?.id) {
return this.get(so.id);
}
}
};

Expand Down
11 changes: 4 additions & 7 deletions src/plugins/data/common/index_patterns/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* under the License.
*/

import { find } from 'lodash';
import { SavedObjectsClientCommon, SavedObject } from '..';
import type { IndexPatternSavedObjectAttrs } from './index_patterns';
import type { SavedObjectsClientCommon } from '../types';

/**
* Returns an object matching a given title
Expand All @@ -29,17 +29,14 @@ import { SavedObjectsClientCommon, SavedObject } from '..';
*/
export async function findByTitle(client: SavedObjectsClientCommon, title: string) {
if (title) {
const savedObjects = await client.find({
const savedObjects = await client.find<IndexPatternSavedObjectAttrs>({
type: 'index-pattern',
perPage: 10,
search: `"${title}"`,
searchFields: ['title'],
fields: ['title'],
});

return find(
savedObjects,
(obj: SavedObject<any>) => obj.attributes.title.toLowerCase() === title.toLowerCase()
);
return savedObjects.find((obj) => obj.attributes.title.toLowerCase() === title.toLowerCase());
}
}

0 comments on commit f2ca98a

Please sign in to comment.