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 bd5bc48bba7c..688605821097 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 @@ -29,6 +29,7 @@ */ import { i18n } from '@osd/i18n'; +import { DataSourceAttributes } from 'src/plugins/data_source/common/data_sources'; import { SavedObjectsClientCommon } from '../..'; import { createIndexPatternCache } from '.'; import { IndexPattern } from './index_pattern'; @@ -53,7 +54,7 @@ import { FieldFormatsStartCommon } from '../../field_formats'; import { UI_SETTINGS, SavedObject } from '../../../common'; import { SavedObjectNotFound } from '../../../../opensearch_dashboards_utils/common'; import { IndexPatternMissingIndices } from '../lib'; -import { findByTitle } from '../utils'; +import { findByTitle, getIndexPatternTitle } from '../utils'; import { DuplicateIndexPatternError } from '../errors'; const indexPatternCache = createIndexPatternCache(); @@ -118,8 +119,28 @@ export class IndexPatternsService { fields: ['title'], perPage: 10000, }); + + this.savedObjectsCache = await Promise.all( + this.savedObjectsCache.map(async (obj) => { + if (obj.type === 'index-pattern') { + const result = { ...obj }; + result.attributes.title = await getIndexPatternTitle( + obj.attributes.title, + obj.references, + this.getDataSource + ); + return result; + } else { + return obj; + } + }) + ); } + getDataSource = async (id: string) => { + return await this.savedObjectsClient.get('data-source', id); + }; + /** * Get list of index pattern ids * @param refresh Force refresh of index pattern list @@ -557,7 +578,11 @@ export class IndexPatternsService { */ async createSavedObject(indexPattern: IndexPattern, override = false) { - const dupe = await findByTitle(this.savedObjectsClient, indexPattern.title); + const dupe = await findByTitle( + this.savedObjectsClient, + indexPattern.title, + indexPattern.dataSourceRef?.id + ); if (dupe) { if (override) { await this.delete(dupe.id);