mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
IndexPatternService - remove getFields function (#77571)
* remove getFields fn
This commit is contained in:
parent
10b192b5b0
commit
5511f0f977
5 changed files with 11 additions and 23 deletions
|
@ -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 () => {
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue