create data views service and use in index pattern management (#110747)
This commit is contained in:
parent
3a434d710e
commit
b77ca9392b
|
@ -62,7 +62,13 @@ export const indexPatterns = {
|
|||
flattenHitWrapper,
|
||||
};
|
||||
|
||||
export { IndexPatternsContract, IndexPattern, IndexPatternField, TypeMeta } from './index_patterns';
|
||||
export {
|
||||
IndexPatternsContract,
|
||||
DataViewsContract,
|
||||
IndexPattern,
|
||||
IndexPatternField,
|
||||
TypeMeta,
|
||||
} from './index_patterns';
|
||||
|
||||
export {
|
||||
IIndexPattern,
|
||||
|
|
|
@ -23,6 +23,9 @@ export {
|
|||
IndexPatternsContract,
|
||||
IndexPattern,
|
||||
IndexPatternsApiClient,
|
||||
DataViewsService,
|
||||
DataViewsContract,
|
||||
DataView,
|
||||
} from './index_patterns';
|
||||
export { UiSettingsPublicToCommon } from './ui_settings_wrapper';
|
||||
export { SavedObjectsClientPublicToCommon } from './saved_objects_client_wrapper';
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { DataPlugin, IndexPatternsContract } from '.';
|
||||
import { DataPlugin, DataViewsContract } from '.';
|
||||
import { fieldFormatsServiceMock } from '../../field_formats/public/mocks';
|
||||
import { searchServiceMock } from './search/mocks';
|
||||
import { queryServiceMock } from './query/mocks';
|
||||
|
@ -38,6 +38,20 @@ const createSetupContract = (): Setup => {
|
|||
|
||||
const createStartContract = (): Start => {
|
||||
const queryStartMock = queryServiceMock.createStartContract();
|
||||
const dataViews = ({
|
||||
find: jest.fn((search) => [{ id: search, title: search }]),
|
||||
createField: jest.fn(() => {}),
|
||||
createFieldList: jest.fn(() => []),
|
||||
ensureDefaultIndexPattern: jest.fn(),
|
||||
make: () => ({
|
||||
fieldsFetcher: {
|
||||
fetchForWildcard: jest.fn(),
|
||||
},
|
||||
}),
|
||||
get: jest.fn().mockReturnValue(Promise.resolve({})),
|
||||
clearCache: jest.fn(),
|
||||
} as unknown) as DataViewsContract;
|
||||
|
||||
return {
|
||||
actions: {
|
||||
createFiltersFromValueClickAction: jest.fn().mockResolvedValue(['yes']),
|
||||
|
@ -51,19 +65,11 @@ const createStartContract = (): Start => {
|
|||
IndexPatternSelect: jest.fn(),
|
||||
SearchBar: jest.fn().mockReturnValue(null),
|
||||
},
|
||||
indexPatterns: ({
|
||||
find: jest.fn((search) => [{ id: search, title: search }]),
|
||||
createField: jest.fn(() => {}),
|
||||
createFieldList: jest.fn(() => []),
|
||||
ensureDefaultIndexPattern: jest.fn(),
|
||||
make: () => ({
|
||||
fieldsFetcher: {
|
||||
fetchForWildcard: jest.fn(),
|
||||
},
|
||||
}),
|
||||
get: jest.fn().mockReturnValue(Promise.resolve({})),
|
||||
clearCache: jest.fn(),
|
||||
} as unknown) as IndexPatternsContract,
|
||||
dataViews,
|
||||
/**
|
||||
* @deprecated Use dataViews service instead. All index pattern interfaces were renamed.
|
||||
*/
|
||||
indexPatterns: dataViews,
|
||||
nowProvider: createNowProviderMock(),
|
||||
};
|
||||
};
|
||||
|
|
|
@ -197,6 +197,7 @@ export class DataPublicPlugin
|
|||
autocomplete: this.autocomplete.start(),
|
||||
fieldFormats,
|
||||
indexPatterns,
|
||||
dataViews: indexPatterns,
|
||||
query,
|
||||
search,
|
||||
nowProvider: this.nowProvider,
|
||||
|
|
|
@ -17,7 +17,7 @@ import { AutocompleteSetup, AutocompleteStart } from './autocomplete';
|
|||
import { createFiltersFromRangeSelectAction, createFiltersFromValueClickAction } from './actions';
|
||||
import { ISearchSetup, ISearchStart } from './search';
|
||||
import { QuerySetup, QueryStart } from './query';
|
||||
import { IndexPatternsContract } from './index_patterns';
|
||||
import { DataViewsContract } from './index_patterns';
|
||||
import { IndexPatternSelectProps, StatefulSearchBarProps } from './ui';
|
||||
import { UsageCollectionSetup, UsageCollectionStart } from '../../usage_collection/public';
|
||||
import { Setup as InspectorSetup } from '../../inspector/public';
|
||||
|
@ -77,10 +77,16 @@ export interface DataPublicPluginStart {
|
|||
*/
|
||||
autocomplete: AutocompleteStart;
|
||||
/**
|
||||
* index patterns service
|
||||
* {@link IndexPatternsContract}
|
||||
* data views service
|
||||
* {@link DataViewsContract}
|
||||
*/
|
||||
indexPatterns: IndexPatternsContract;
|
||||
dataViews: DataViewsContract;
|
||||
/**
|
||||
* index patterns service
|
||||
* {@link DataViewsContract}
|
||||
* @deprecated Use dataViews service instead. All index pattern interfaces were renamed.
|
||||
*/
|
||||
indexPatterns: DataViewsContract;
|
||||
/**
|
||||
* search service
|
||||
* {@link ISearchStart}
|
||||
|
|
|
@ -88,7 +88,7 @@ export const EditIndexPattern = withRouter(
|
|||
const removePattern = () => {
|
||||
async function doRemove() {
|
||||
if (indexPattern.id === defaultIndex) {
|
||||
const indexPatterns = await data.indexPatterns.getIdsWithTitle();
|
||||
const indexPatterns = await data.dataViews.getIdsWithTitle();
|
||||
uiSettings.remove('defaultIndex');
|
||||
const otherPatterns = filter(indexPatterns, (pattern) => {
|
||||
return pattern.id !== indexPattern.id;
|
||||
|
@ -99,7 +99,7 @@ export const EditIndexPattern = withRouter(
|
|||
}
|
||||
}
|
||||
if (indexPattern.id) {
|
||||
Promise.resolve(data.indexPatterns.delete(indexPattern.id)).then(function () {
|
||||
Promise.resolve(data.dataViews.delete(indexPattern.id)).then(function () {
|
||||
history.push('');
|
||||
});
|
||||
}
|
||||
|
|
|
@ -77,13 +77,13 @@ export const IndexPatternTable = ({
|
|||
(async function () {
|
||||
const gettedIndexPatterns: IndexPatternTableItem[] = await getIndexPatterns(
|
||||
uiSettings.get('defaultIndex'),
|
||||
data.indexPatterns
|
||||
data.dataViews
|
||||
);
|
||||
setIndexPatterns(gettedIndexPatterns);
|
||||
setIsLoadingIndexPatterns(false);
|
||||
if (
|
||||
gettedIndexPatterns.length === 0 ||
|
||||
!(await data.indexPatterns.hasUserIndexPattern().catch(() => false))
|
||||
!(await data.dataViews.hasUserIndexPattern().catch(() => false))
|
||||
) {
|
||||
setShowCreateDialog(true);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue