|
18 | 18 | */ |
19 | 19 |
|
20 | 20 | import { VisSavedObject } from '../types'; |
21 | | -import { |
22 | | - indexPatterns, |
23 | | - IIndexPattern, |
24 | | - IndexPatternAttributes, |
25 | | -} from '../../../../plugins/data/public'; |
26 | | -import { getUISettings, getSavedObjects } from '../services'; |
| 21 | +import type { IndexPattern } from '../../../../plugins/data/public'; |
| 22 | +import { getIndexPatterns } from '../services'; |
27 | 23 |
|
28 | 24 | export async function getIndexPattern( |
29 | 25 | savedVis: VisSavedObject |
30 | | -): Promise<IIndexPattern | undefined> { |
| 26 | +): Promise<IndexPattern | undefined | null> { |
31 | 27 | if (savedVis.visState.type !== 'metrics') { |
32 | 28 | return savedVis.searchSource!.getField('index'); |
33 | 29 | } |
34 | 30 |
|
35 | | - const savedObjectsClient = getSavedObjects().client; |
36 | | - const defaultIndex = getUISettings().get('defaultIndex'); |
| 31 | + const indexPatternsClient = getIndexPatterns(); |
37 | 32 |
|
38 | | - if (savedVis.visState.params.index_pattern) { |
39 | | - const indexPatternObjects = await savedObjectsClient.find<IndexPatternAttributes>({ |
40 | | - type: 'index-pattern', |
41 | | - fields: ['title', 'fields'], |
42 | | - search: `"${savedVis.visState.params.index_pattern}"`, |
43 | | - searchFields: ['title'], |
44 | | - }); |
45 | | - const [indexPattern] = indexPatternObjects.savedObjects.map(indexPatterns.getFromSavedObject); |
46 | | - return indexPattern; |
47 | | - } |
48 | | - |
49 | | - const savedObject = await savedObjectsClient.get<IndexPatternAttributes>( |
50 | | - 'index-pattern', |
51 | | - defaultIndex |
52 | | - ); |
53 | | - return indexPatterns.getFromSavedObject(savedObject); |
| 33 | + return savedVis.visState.params.index_pattern |
| 34 | + ? (await indexPatternsClient.find(`"${savedVis.visState.params.index_pattern}"`))[0] |
| 35 | + : await indexPatternsClient.getDefault(); |
54 | 36 | } |
0 commit comments