Skip to content

Commit

Permalink
create data views service and use in index pattern management (elasti…
Browse files Browse the repository at this point in the history
…c#110747) (elastic#110791)

Co-authored-by: Matthew Kime <[email protected]>
  • Loading branch information
kibanamachine and mattkime authored Sep 1, 2021
1 parent 9e6a282 commit d953c24
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 22 deletions.
8 changes: 7 additions & 1 deletion src/plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/data/public/index_patterns/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export {
IndexPatternsContract,
IndexPattern,
IndexPatternsApiClient,
DataViewsService,
DataViewsContract,
DataView,
} from './index_patterns';
export { UiSettingsPublicToCommon } from './ui_settings_wrapper';
export { SavedObjectsClientPublicToCommon } from './saved_objects_client_wrapper';
34 changes: 20 additions & 14 deletions src/plugins/data/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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']),
Expand All @@ -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(),
};
};
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export class DataPublicPlugin
autocomplete: this.autocomplete.start(),
fieldFormats,
indexPatterns,
dataViews: indexPatterns,
query,
search,
nowProvider: this.nowProvider,
Expand Down
12 changes: 9 additions & 3 deletions src/plugins/data/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -76,11 +76,17 @@ export interface DataPublicPluginStart {
* {@link AutocompleteStart}
*/
autocomplete: AutocompleteStart;
/**
* data views service
* {@link DataViewsContract}
*/
dataViews: DataViewsContract;
/**
* index patterns service
* {@link IndexPatternsContract}
* {@link DataViewsContract}
* @deprecated Use dataViews service instead. All index pattern interfaces were renamed.
*/
indexPatterns: IndexPatternsContract;
indexPatterns: DataViewsContract;
/**
* search service
* {@link ISearchStart}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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('');
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit d953c24

Please sign in to comment.