Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: Su <[email protected]>
  • Loading branch information
zhongnansu committed Mar 16, 2023
1 parent c402636 commit 847ac7d
Showing 1 changed file with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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();
Expand Down Expand Up @@ -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<DataSourceAttributes>('data-source', id);
};

/**
* Get list of index pattern ids
* @param refresh Force refresh of index pattern list
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 847ac7d

Please sign in to comment.