Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] fix #66185 (#66186) #68511

Merged
merged 1 commit into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -49,6 +49,7 @@ import { flattenHitWrapper } from './flatten_hit';
import { IIndexPatternsApiClient } from './index_patterns_api_client';
import { getNotifications, getFieldFormats, getHttp } from '../../services';
import { TypeMeta } from './types';
import { PatternCache } from './_pattern_cache';

const MAX_ATTEMPTS_TO_RESOLVE_CONFLICTS = 3;
const type = 'index-pattern';
Expand All @@ -71,12 +72,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 @@ -105,7 +107,7 @@ export class IndexPattern implements IIndexPattern {
getConfig: any,
savedObjectsClient: SavedObjectsClientContract,
apiClient: IIndexPatternsApiClient,
patternCache: any
patternCache: PatternCache
) {
this.id = id;
this.savedObjectsClient = savedObjectsClient;
Expand All @@ -123,6 +125,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 @@ -484,8 +487,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 @@ -533,8 +536,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 @@ -577,7 +580,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 @@ -633,8 +636,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 @@ -844,7 +844,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