IndexPatternService - remove getFields function (#77571)

* remove getFields fn
This commit is contained in:
Matthew Kime 2020-09-16 09:23:59 -05:00 committed by GitHub
parent 10b192b5b0
commit 5511f0f977
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 23 deletions

View file

@ -113,15 +113,13 @@ describe('IndexPatterns', () => {
test('caches saved objects', async () => {
await indexPatterns.getIds();
await indexPatterns.getTitles();
await indexPatterns.getFields(['id', 'title']);
expect(savedObjectsClient.find).toHaveBeenCalledTimes(1);
});
test('can refresh the saved objects caches', async () => {
await indexPatterns.getIds();
await indexPatterns.getTitles(true);
await indexPatterns.getFields(['id', 'title'], true);
expect(savedObjectsClient.find).toHaveBeenCalledTimes(3);
expect(savedObjectsClient.find).toHaveBeenCalledTimes(2);
});
test('deletes the index pattern', async () => {

View file

@ -41,8 +41,6 @@ const indexPatternCache = createIndexPatternCache();
const MAX_ATTEMPTS_TO_RESOLVE_CONFLICTS = 3;
const savedObjectType = 'index-pattern';
type IndexPatternCachedFieldType = 'id' | 'title';
export interface IndexPatternSavedObjectAttrs {
title: string;
}
@ -116,22 +114,6 @@ export class IndexPatternsService {
return this.savedObjectsCache.map((obj) => obj?.attributes?.title);
};
getFields = async (fields: IndexPatternCachedFieldType[], refresh: boolean = false) => {
if (!this.savedObjectsCache || refresh) {
await this.refreshSavedObjectsCache();
}
if (!this.savedObjectsCache) {
return [];
}
return this.savedObjectsCache.map((obj: Record<string, any>) => {
const result: Partial<Record<IndexPatternCachedFieldType, string>> = {};
fields.forEach(
(f: IndexPatternCachedFieldType) => (result[f] = obj[f] || obj?.attributes?.[f])
);
return result;
});
};
getFieldsForTimePattern = (options: GetFieldsOptions = {}) => {
return this.apiClient.getFieldsForTimePattern(options);
};

View file

@ -222,9 +222,11 @@ exports[`Flyout conflicts should allow conflict resolution 2`] = `
"indexPatterns": Array [
Object {
"id": "1",
"title": undefined,
},
Object {
"id": "2",
"title": undefined,
},
],
"isLegacyFile": false,

View file

@ -64,7 +64,10 @@ describe('Flyout', () => {
done: jest.fn(),
newIndexPatternUrl: '',
indexPatterns: {
getFields: jest.fn().mockImplementation(() => [{ id: '1' }, { id: '2' }]),
getCache: jest.fn().mockImplementation(() => [
{ id: '1', attributes: {} },
{ id: '2', attributes: {} },
]),
} as any,
overlays,
http,

View file

@ -132,7 +132,10 @@ export class Flyout extends Component<FlyoutProps, FlyoutState> {
}
fetchIndexPatterns = async () => {
const indexPatterns = await this.props.indexPatterns.getFields(['id', 'title']);
const indexPatterns = (await this.props.indexPatterns.getCache())?.map((savedObject) => ({
id: savedObject.id,
title: savedObject.attributes.title,
}));
this.setState({ indexPatterns } as any);
};