Skip to content

Commit

Permalink
fixing error on index patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisljar committed May 14, 2020
1 parent 31be22b commit 4d59a6c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ const savedObjectsClient = {

const patternCache = {
clear: jest.fn(),
get: jest.fn(),
set: jest.fn(),
clearAll: jest.fn(),
};

const config = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,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';
Expand All @@ -60,7 +61,7 @@ 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 } = {};
Expand Down Expand Up @@ -95,7 +96,7 @@ export class IndexPattern implements IIndexPattern {
getConfig: any,
savedObjectsClient: SavedObjectsClientContract,
apiClient: IIndexPatternsApiClient,
patternCache: any
patternCache: PatternCache
) {
this.id = id;
this.savedObjectsClient = savedObjectsClient;
Expand Down Expand Up @@ -423,8 +424,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
Expand Down Expand Up @@ -467,7 +468,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);
Expand Down Expand Up @@ -523,8 +524,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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
IIndexPattern,
injectSearchSourceReferences,
} from '../../../data/public';
import { FailedImport } from './process_import_response';

type SavedObjectsRawDoc = Record<string, any>;

Expand Down Expand Up @@ -265,11 +266,6 @@ export async function resolveSavedSearches(
return importCount;
}

interface FailedDoc {
obj: Record<string, any>;
error: Error;
}

export async function resolveSavedObjects(
savedObjects: SavedObjectsRawDoc[],
overwriteAll: boolean,
Expand All @@ -282,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: FailedDoc[] = [];
const failedImports: FailedImport[] = [];
// Start with the index patterns since everything is dependent on them
await awaitEachItemInParallel(docTypes.indexPatterns, async indexPatternDoc => {
try {
Expand All @@ -296,7 +292,7 @@ export async function resolveSavedObjects(
importedObjectCount++;
}
} catch (error) {
failedImports.push({ obj: indexPatternDoc, error });
failedImports.push({ obj: indexPatternDoc as any, error });
}
});

Expand Down

0 comments on commit 4d59a6c

Please sign in to comment.