From de4eaf9ae70cc225db8bb92a43661b8cfbd4ab85 Mon Sep 17 00:00:00 2001 From: Peter Pisljar Date: Mon, 8 Jun 2020 15:31:14 +0200 Subject: [PATCH] fix #66185 (#66186) --- ...-data-public.indexpattern._constructor_.md | 4 ++-- .../index_patterns/_pattern_cache.ts | 2 +- .../index_patterns/index_pattern.test.ts | 3 +++ .../index_patterns/index_pattern.ts | 19 +++++++++++-------- src/plugins/data/public/public.api.md | 3 ++- .../public/lib/resolve_saved_objects.ts | 5 +++-- .../apps/management/_import_objects.js | 1 - 7 files changed, 22 insertions(+), 15 deletions(-) diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern._constructor_.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern._constructor_.md index 4159247bb7c32d..6256709e2ee368 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern._constructor_.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern._constructor_.md @@ -9,7 +9,7 @@ Constructs a new instance of the `IndexPattern` class Signature: ```typescript -constructor(id: string | undefined, getConfig: any, savedObjectsClient: SavedObjectsClientContract, apiClient: IIndexPatternsApiClient, patternCache: any); +constructor(id: string | undefined, getConfig: any, savedObjectsClient: SavedObjectsClientContract, apiClient: IIndexPatternsApiClient, patternCache: PatternCache); ``` ## Parameters @@ -20,5 +20,5 @@ constructor(id: string | undefined, getConfig: any, savedObjectsClient: SavedObj | getConfig | any | | | savedObjectsClient | SavedObjectsClientContract | | | apiClient | IIndexPatternsApiClient | | -| patternCache | any | | +| patternCache | PatternCache | | diff --git a/src/plugins/data/public/index_patterns/index_patterns/_pattern_cache.ts b/src/plugins/data/public/index_patterns/index_patterns/_pattern_cache.ts index eb6c69b4143160..a3653bb529fa38 100644 --- a/src/plugins/data/public/index_patterns/index_patterns/_pattern_cache.ts +++ b/src/plugins/data/public/index_patterns/index_patterns/_pattern_cache.ts @@ -19,7 +19,7 @@ import { IndexPattern } from './index_pattern'; -interface PatternCache { +export interface PatternCache { get: (id: string) => IndexPattern; set: (id: string, value: IndexPattern) => IndexPattern; clear: (id: string) => void; diff --git a/src/plugins/data/public/index_patterns/index_patterns/index_pattern.test.ts b/src/plugins/data/public/index_patterns/index_patterns/index_pattern.test.ts index e4058007e0a57e..84135bb5d1e2bd 100644 --- a/src/plugins/data/public/index_patterns/index_patterns/index_pattern.test.ts +++ b/src/plugins/data/public/index_patterns/index_patterns/index_pattern.test.ts @@ -85,6 +85,9 @@ const savedObjectsClient = { const patternCache = { clear: jest.fn(), + get: jest.fn(), + set: jest.fn(), + clearAll: jest.fn(), }; const config = { diff --git a/src/plugins/data/public/index_patterns/index_patterns/index_pattern.ts b/src/plugins/data/public/index_patterns/index_patterns/index_pattern.ts index 3d54009d0fdcab..84ea12a1f684fb 100644 --- a/src/plugins/data/public/index_patterns/index_patterns/index_pattern.ts +++ b/src/plugins/data/public/index_patterns/index_patterns/index_pattern.ts @@ -44,6 +44,7 @@ import { flattenHitWrapper } from './flatten_hit'; import { IIndexPatternsApiClient } from './index_patterns_api_client'; import { getNotifications, getFieldFormats } from '../../services'; import { TypeMeta } from './types'; +import { PatternCache } from './_pattern_cache'; const MAX_ATTEMPTS_TO_RESOLVE_CONFLICTS = 3; const type = 'index-pattern'; @@ -65,12 +66,13 @@ export class IndexPattern implements IIndexPattern { private version: string | undefined; private savedObjectsClient: SavedObjectsClientContract; - private patternCache: any; + private patternCache: PatternCache; private getConfig: any; private sourceFilters?: []; private originalBody: { [key: string]: any } = {}; public fieldsFetcher: any; // probably want to factor out any direct usage and change to private private shortDotsEnable: boolean = false; + private apiClient: IIndexPatternsApiClient; private mapping: MappingObject = expandShorthand({ title: ES_FIELD_TYPES.TEXT, @@ -99,7 +101,7 @@ export class IndexPattern implements IIndexPattern { getConfig: any, savedObjectsClient: SavedObjectsClientContract, apiClient: IIndexPatternsApiClient, - patternCache: any + patternCache: PatternCache ) { this.id = id; this.savedObjectsClient = savedObjectsClient; @@ -117,6 +119,7 @@ export class IndexPattern implements IIndexPattern { }); this.fields = this.createFieldList(this, [], this.shortDotsEnable); + this.apiClient = apiClient; this.fieldsFetcher = createFieldsFetcher( this, apiClient, @@ -396,8 +399,8 @@ export class IndexPattern implements IIndexPattern { duplicateId, this.getConfig, this.savedObjectsClient, - this.patternCache, - this.fieldsFetcher + this.apiClient, + this.patternCache ); await duplicatePattern.destroy(); } @@ -445,8 +448,8 @@ export class IndexPattern implements IIndexPattern { this.id, this.getConfig, this.savedObjectsClient, - this.patternCache, - this.fieldsFetcher + this.apiClient, + this.patternCache ); return samePattern.init().then(() => { // What keys changed from now and what the server returned @@ -489,7 +492,7 @@ export class IndexPattern implements IIndexPattern { this.version = samePattern.version; // Clear cache - this.patternCache.clear(this.id); + this.patternCache.clear(this.id!); // Try the save again return this.save(saveAttempts); @@ -545,8 +548,8 @@ export class IndexPattern implements IIndexPattern { } destroy() { - this.patternCache.clear(this.id); if (this.id) { + this.patternCache.clear(this.id); return this.savedObjectsClient.delete(type, this.id); } } diff --git a/src/plugins/data/public/public.api.md b/src/plugins/data/public/public.api.md index dcdb528ac8b7d5..e6f6ba0c1bd125 100644 --- a/src/plugins/data/public/public.api.md +++ b/src/plugins/data/public/public.api.md @@ -842,7 +842,8 @@ export type IMetricAggType = MetricAggType; // @public (undocumented) export class IndexPattern implements IIndexPattern { // Warning: (ae-forgotten-export) The symbol "IIndexPatternsApiClient" needs to be exported by the entry point index.d.ts - constructor(id: string | undefined, getConfig: any, savedObjectsClient: SavedObjectsClientContract, apiClient: IIndexPatternsApiClient, patternCache: any); + // Warning: (ae-forgotten-export) The symbol "PatternCache" needs to be exported by the entry point index.d.ts + constructor(id: string | undefined, getConfig: any, savedObjectsClient: SavedObjectsClientContract, apiClient: IIndexPatternsApiClient, patternCache: PatternCache); // (undocumented) [key: string]: any; // (undocumented) diff --git a/src/plugins/saved_objects_management/public/lib/resolve_saved_objects.ts b/src/plugins/saved_objects_management/public/lib/resolve_saved_objects.ts index 952e9628d2846b..79b8c33b84cfee 100644 --- a/src/plugins/saved_objects_management/public/lib/resolve_saved_objects.ts +++ b/src/plugins/saved_objects_management/public/lib/resolve_saved_objects.ts @@ -27,6 +27,7 @@ import { IIndexPattern, injectSearchSourceReferences, } from '../../../data/public'; +import { FailedImport } from './process_import_response'; type SavedObjectsRawDoc = Record; @@ -277,7 +278,7 @@ export async function resolveSavedObjects( // Keep track of how many we actually import because the user // can cancel an override let importedObjectCount = 0; - const failedImports: any[] = []; + const failedImports: FailedImport[] = []; // Start with the index patterns since everything is dependent on them await awaitEachItemInParallel(docTypes.indexPatterns, async (indexPatternDoc) => { try { @@ -291,7 +292,7 @@ export async function resolveSavedObjects( importedObjectCount++; } } catch (error) { - failedImports.push({ indexPatternDoc, error }); + failedImports.push({ obj: indexPatternDoc as any, error }); } }); diff --git a/test/functional/apps/management/_import_objects.js b/test/functional/apps/management/_import_objects.js index 6b40837808387e..6306d11eadb653 100644 --- a/test/functional/apps/management/_import_objects.js +++ b/test/functional/apps/management/_import_objects.js @@ -356,7 +356,6 @@ export default function ({ getService, getPageObjects }) { await PageObjects.settings.importFile( path.join(__dirname, 'exports', '_import_objects_with_index_patterns.json') ); - await PageObjects.settings.checkImportFailedWarning(); await PageObjects.settings.clickImportDone(); const objects = await PageObjects.settings.getSavedObjectsInTable();