Skip to content

Commit

Permalink
fix #66185 (#66186)
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisljar committed Jun 8, 2020
1 parent 77ab709 commit de4eaf9
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Constructs a new instance of the `IndexPattern` class
<b>Signature:</b>

```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
Expand All @@ -20,5 +20,5 @@ constructor(id: string | undefined, getConfig: any, savedObjectsClient: SavedObj
| getConfig | <code>any</code> | |
| savedObjectsClient | <code>SavedObjectsClientContract</code> | |
| apiClient | <code>IIndexPatternsApiClient</code> | |
| patternCache | <code>any</code> | |
| patternCache | <code>PatternCache</code> | |

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 @@ -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';
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -117,6 +119,7 @@ export class IndexPattern implements IIndexPattern {
});

this.fields = this.createFieldList(this, [], this.shortDotsEnable);
this.apiClient = apiClient;
this.fieldsFetcher = createFieldsFetcher(
this,
apiClient,
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/data/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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 @@ -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 {
Expand All @@ -291,7 +292,7 @@ export async function resolveSavedObjects(
importedObjectCount++;
}
} catch (error) {
failedImports.push({ indexPatternDoc, error });
failedImports.push({ obj: indexPatternDoc as any, error });
}
});

Expand Down
1 change: 0 additions & 1 deletion test/functional/apps/management/_import_objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit de4eaf9

Please sign in to comment.