diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_patterns.test.ts b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.test.ts index 9bc286d5b9a91..72819681eedde 100644 --- a/src/plugins/data/common/index_patterns/index_patterns/index_patterns.test.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.test.ts @@ -114,15 +114,13 @@ describe('IndexPatterns', () => { test('caches saved objects', async () => { await indexPatterns.getIds(); await indexPatterns.getTitles(); - await indexPatterns.getFields(['id', 'title']); expect(savedObjectsClient.find).toHaveBeenCalledTimes(1); }); test('can refresh the saved objects caches', async () => { await indexPatterns.getIds(); await indexPatterns.getTitles(true); - await indexPatterns.getFields(['id', 'title'], true); - expect(savedObjectsClient.find).toHaveBeenCalledTimes(3); + expect(savedObjectsClient.find).toHaveBeenCalledTimes(2); }); test('deletes the index pattern', async () => { diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts index 9f813ec9a8fb3..ba5efdc6487a9 100644 --- a/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts @@ -42,8 +42,6 @@ const indexPatternCache = createIndexPatternCache(); const MAX_ATTEMPTS_TO_RESOLVE_CONFLICTS = 3; const savedObjectType = 'index-pattern'; -type IndexPatternCachedFieldType = 'id' | 'title'; - export interface IndexPatternSavedObjectAttrs { title: string; } @@ -121,22 +119,6 @@ export class IndexPatternsService { return this.savedObjectsCache.map((obj) => obj?.attributes?.title); }; - getFields = async (fields: IndexPatternCachedFieldType[], refresh: boolean = false) => { - if (!this.savedObjectsCache || refresh) { - await this.refreshSavedObjectsCache(); - } - if (!this.savedObjectsCache) { - return []; - } - return this.savedObjectsCache.map((obj: Record) => { - const result: Partial> = {}; - fields.forEach( - (f: IndexPatternCachedFieldType) => (result[f] = obj[f] || obj?.attributes?.[f]) - ); - return result; - }); - }; - getFieldsForTimePattern = (options: GetFieldsOptions = {}) => { return this.apiClient.getFieldsForTimePattern(options); }; diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/flyout.test.tsx.snap b/src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/flyout.test.tsx.snap index 0a330d074fd42..3a03c5c01b3c2 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/flyout.test.tsx.snap +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/flyout.test.tsx.snap @@ -222,9 +222,11 @@ exports[`Flyout conflicts should allow conflict resolution 2`] = ` "indexPatterns": Array [ Object { "id": "1", + "title": undefined, }, Object { "id": "2", + "title": undefined, }, ], "isLegacyFile": false, diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/components/flyout.test.tsx b/src/plugins/saved_objects_management/public/management_section/objects_table/components/flyout.test.tsx index cc9d2ed160241..72ed69cdca816 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/components/flyout.test.tsx +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/components/flyout.test.tsx @@ -64,7 +64,10 @@ describe('Flyout', () => { done: jest.fn(), newIndexPatternUrl: '', indexPatterns: { - getFields: jest.fn().mockImplementation(() => [{ id: '1' }, { id: '2' }]), + getCache: jest.fn().mockImplementation(() => [ + { id: '1', attributes: {} }, + { id: '2', attributes: {} }, + ]), } as any, overlays, http, diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/components/flyout.tsx b/src/plugins/saved_objects_management/public/management_section/objects_table/components/flyout.tsx index 47d82077294cc..3165ea4ca0794 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/components/flyout.tsx +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/components/flyout.tsx @@ -132,7 +132,10 @@ export class Flyout extends Component { } fetchIndexPatterns = async () => { - const indexPatterns = await this.props.indexPatterns.getFields(['id', 'title']); + const indexPatterns = (await this.props.indexPatterns.getCache())?.map((savedObject) => ({ + id: savedObject.id, + title: savedObject.attributes.title, + })); this.setState({ indexPatterns } as any); };