From 3a0d5f4bf54f91129e70a82d7aeac6fa6ee2511a Mon Sep 17 00:00:00 2001 From: Artyom Gospodarsky Date: Sat, 30 Nov 2019 15:58:20 +0300 Subject: [PATCH] [NP] Move IndexPatterns into the NP (#51199) * Make a copy of index_patterns module inside NP * Sync changes of index patterns * Remove UI component from service * Remove redundant exports from index_patterns * Sync old index_patters changes * Make common namespace of IndexPattern * Make re-exports of old IndexPatter dependencies * Remove utils and error of the old indexPattern * Plug InterPatternService in data plugin * Make shortenDotString in new data plugin * Remove field folder * Fix wrong merge * Remove index_pattern folder * Remove _LEGACY from service * Remove static code from service * Fix start contract * Remove services from the old plugin * Remove index_patterns_service * Fix filter.meta.index type * Fix reviews * Fix type error --- .../filter/action/apply_filter_action.ts | 5 ++- src/legacy/core_plugins/data/public/index.ts | 2 +- .../data/public/index_patterns/index.ts | 19 +++++++- .../components/fetch_index_patterns.ts | 2 +- .../data/public/shim/legacy_module.ts | 2 +- .../public/views/table/table.test.tsx | 2 +- .../kibana/public/dashboard/application.ts | 4 +- .../dashboard/dashboard_app_controller.tsx | 8 ++-- .../create_edit_field/create_edit_field.js | 4 +- .../public/index_patterns/__mocks__/index.ts | 18 ++++---- src/legacy/ui/public/index_patterns/index.ts | 12 ++--- .../common/field_formats/converters/source.ts | 3 +- .../common/field_formats/converters/string.ts | 3 +- src/plugins/data/common/index.ts | 2 +- src/plugins/data/common/utils/index.ts | 20 +++++++++ .../utils/shorten_dotted_string.test.ts | 34 ++++++++++++++ .../common/utils/shorten_dotted_string.ts} | 23 ++++------ .../public/index_patterns/fields/field.ts | 17 +++---- .../index_patterns/fields/field_list.ts | 9 ++-- .../public/index_patterns/fields/index.ts | 0 .../index_patterns/fields/obj_define.js | 0 .../index_patterns/fields/obj_define.test.js | 0 .../data/public/index_patterns/index.ts | 11 +++++ .../index_patterns/_fields_fetcher.ts | 0 .../index_patterns/_pattern_cache.ts | 2 +- .../index_patterns/flatten_hit.ts | 0 .../index_patterns/format_hit.ts | 0 .../index_patterns/index_patterns/index.ts | 0 .../index_patterns/index_pattern.test.ts | 17 ++++--- .../index_patterns/index_pattern.ts | 28 ++++-------- .../index_patterns/index_patterns.test.ts | 0 .../index_patterns/index_patterns.ts | 0 .../index_patterns_api_client.test.mock.ts | 2 +- .../index_patterns_api_client.test.ts | 0 .../index_patterns_api_client.ts | 2 +- .../index_patterns_service.mock.ts | 9 ++-- .../index_patterns/index_patterns_service.ts | 44 +++---------------- ...et_index_pattern_title.ts => get_title.ts} | 2 +- .../data/public/index_patterns/lib/index.ts | 2 +- .../data/public/index_patterns/services.ts | 4 +- .../data/public/index_patterns/types.ts | 23 ++++++++++ .../data/public/index_patterns/utils.ts | 5 +-- src/plugins/data/public/mocks.ts | 3 ++ src/plugins/data/public/plugin.ts | 15 ++++++- src/plugins/data/public/types.ts | 3 ++ .../index_pattern_select.tsx | 4 +- src/test_utils/public/stub_index_pattern.js | 2 +- .../services/persistence/deserialize.ts | 2 +- 48 files changed, 211 insertions(+), 158 deletions(-) create mode 100644 src/plugins/data/common/utils/index.ts create mode 100644 src/plugins/data/common/utils/shorten_dotted_string.test.ts rename src/{legacy/core_plugins/data/public/mocks.ts => plugins/data/common/utils/shorten_dotted_string.ts} (68%) rename src/{legacy/core_plugins => plugins}/data/public/index_patterns/fields/field.ts (94%) rename src/{legacy/core_plugins => plugins}/data/public/index_patterns/fields/field_list.ts (91%) rename src/{legacy/core_plugins => plugins}/data/public/index_patterns/fields/index.ts (100%) rename src/{legacy/core_plugins => plugins}/data/public/index_patterns/fields/obj_define.js (100%) rename src/{legacy/core_plugins => plugins}/data/public/index_patterns/fields/obj_define.test.js (100%) rename src/{legacy/core_plugins => plugins}/data/public/index_patterns/index_patterns/_fields_fetcher.ts (100%) rename src/{legacy/core_plugins => plugins}/data/public/index_patterns/index_patterns/_pattern_cache.ts (97%) rename src/{legacy/core_plugins => plugins}/data/public/index_patterns/index_patterns/flatten_hit.ts (100%) rename src/{legacy/core_plugins => plugins}/data/public/index_patterns/index_patterns/format_hit.ts (100%) rename src/{legacy/core_plugins => plugins}/data/public/index_patterns/index_patterns/index.ts (100%) rename src/{legacy/core_plugins => plugins}/data/public/index_patterns/index_patterns/index_pattern.test.ts (95%) rename src/{legacy/core_plugins => plugins}/data/public/index_patterns/index_patterns/index_pattern.ts (96%) rename src/{legacy/core_plugins => plugins}/data/public/index_patterns/index_patterns/index_patterns.test.ts (100%) rename src/{legacy/core_plugins => plugins}/data/public/index_patterns/index_patterns/index_patterns.ts (100%) rename src/{legacy/core_plugins => plugins}/data/public/index_patterns/index_patterns/index_patterns_api_client.test.mock.ts (92%) rename src/{legacy/core_plugins => plugins}/data/public/index_patterns/index_patterns/index_patterns_api_client.test.ts (100%) rename src/{legacy/core_plugins => plugins}/data/public/index_patterns/index_patterns/index_patterns_api_client.ts (97%) rename src/{legacy/core_plugins => plugins}/data/public/index_patterns/index_patterns_service.mock.ts (87%) rename src/{legacy/core_plugins => plugins}/data/public/index_patterns/index_patterns_service.ts (60%) rename src/plugins/data/public/index_patterns/lib/{get_index_pattern_title.ts => get_title.ts} (96%) rename src/{legacy/core_plugins => plugins}/data/public/index_patterns/services.ts (87%) create mode 100644 src/plugins/data/public/index_patterns/types.ts rename src/{legacy/core_plugins => plugins}/data/public/index_patterns/utils.ts (93%) diff --git a/src/legacy/core_plugins/data/public/filter/action/apply_filter_action.ts b/src/legacy/core_plugins/data/public/filter/action/apply_filter_action.ts index 946b3997a97129..c65ae3a0ec7b93 100644 --- a/src/legacy/core_plugins/data/public/filter/action/apply_filter_action.ts +++ b/src/legacy/core_plugins/data/public/filter/action/apply_filter_action.ts @@ -32,8 +32,9 @@ import { applyFiltersPopover, changeTimeFilter, extractTimeFilter, + IndexPatternsStart, } from '../../../../../../plugins/data/public'; -import { IndexPatternsStart } from '../../index_patterns'; + export const GLOBAL_APPLY_FILTER_ACTION = 'GLOBAL_APPLY_FILTER_ACTION'; interface ActionContext { @@ -74,7 +75,7 @@ export function createFilterAction( if (selectedFilters.length > 1) { const indexPatterns = await Promise.all( filters.map(filter => { - return indexPatternsService.indexPatterns.get(filter.meta.index); + return indexPatternsService.indexPatterns.get(filter.meta.index!); }) ); diff --git a/src/legacy/core_plugins/data/public/index.ts b/src/legacy/core_plugins/data/public/index.ts index 833d8c248f46aa..bdfedbc2c81a85 100644 --- a/src/legacy/core_plugins/data/public/index.ts +++ b/src/legacy/core_plugins/data/public/index.ts @@ -48,4 +48,4 @@ export { /** @public static code */ export * from '../common'; export { FilterStateManager } from './filter/filter_manager'; -export { getFromSavedObject, getRoutes } from './index_patterns'; +export { getFromSavedObject, getRoutes, flattenHitWrapper } from './index_patterns'; diff --git a/src/legacy/core_plugins/data/public/index_patterns/index.ts b/src/legacy/core_plugins/data/public/index_patterns/index.ts index 496c4ba7b5b6f1..74981165f3e474 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index.ts @@ -17,4 +17,21 @@ * under the License. */ -export * from './index_patterns_service'; +import { IFieldType, IIndexPattern, indexPatterns } from '../../../../../plugins/data/public'; + +const getFromSavedObject = indexPatterns.getFromSavedObject; +const getRoutes = indexPatterns.getRoutes; +const flattenHitWrapper = indexPatterns.flattenHitWrapper; + +export { getFromSavedObject, getRoutes, flattenHitWrapper }; +export { IFieldType as FieldType }; +export { IIndexPattern as StaticIndexPattern }; +export { + Field, + FieldListInterface, + IndexPattern, + IndexPatterns, + IndexPatternsStart, + IndexPatternsSetup, + IndexPatternsService, +} from '../../../../../plugins/data/public'; diff --git a/src/legacy/core_plugins/data/public/query/query_bar/components/fetch_index_patterns.ts b/src/legacy/core_plugins/data/public/query/query_bar/components/fetch_index_patterns.ts index 3dcab22605c07e..7a4c9f139c8873 100644 --- a/src/legacy/core_plugins/data/public/query/query_bar/components/fetch_index_patterns.ts +++ b/src/legacy/core_plugins/data/public/query/query_bar/components/fetch_index_patterns.ts @@ -18,7 +18,7 @@ */ import { isEmpty } from 'lodash'; import { IUiSettingsClient, SavedObjectsClientContract } from 'src/core/public'; -import { getFromSavedObject } from '../../../index_patterns'; +import { getFromSavedObject } from '../../../'; export async function fetchIndexPatterns( savedObjectsClient: SavedObjectsClientContract, diff --git a/src/legacy/core_plugins/data/public/shim/legacy_module.ts b/src/legacy/core_plugins/data/public/shim/legacy_module.ts index 06c5caa04ba9ac..0e12790d89fed7 100644 --- a/src/legacy/core_plugins/data/public/shim/legacy_module.ts +++ b/src/legacy/core_plugins/data/public/shim/legacy_module.ts @@ -21,7 +21,7 @@ import { once } from 'lodash'; // @ts-ignore import { uiModules } from 'ui/modules'; -import { IndexPatterns } from '../index_patterns/index_patterns'; +import { IndexPatterns } from '../'; /** @internal */ export const initLegacyModule = once((indexPatterns: IndexPatterns): void => { diff --git a/src/legacy/core_plugins/kbn_doc_views/public/views/table/table.test.tsx b/src/legacy/core_plugins/kbn_doc_views/public/views/table/table.test.tsx index e341b7c4a5a866..bad006aa8c7d5a 100644 --- a/src/legacy/core_plugins/kbn_doc_views/public/views/table/table.test.tsx +++ b/src/legacy/core_plugins/kbn_doc_views/public/views/table/table.test.tsx @@ -21,7 +21,7 @@ import { mount } from 'enzyme'; import { IndexPattern } from 'ui/index_patterns'; // @ts-ignore import { findTestSubject } from '@elastic/eui/lib/test'; -import { flattenHitWrapper } from '../../../../data/public/index_patterns/index_patterns/flatten_hit'; +import { flattenHitWrapper } from '../../../../data/public/'; import { DocViewTable } from './table'; // @ts-ignore diff --git a/src/legacy/core_plugins/kibana/public/dashboard/application.ts b/src/legacy/core_plugins/kibana/public/dashboard/application.ts index 797583362a8f88..42ecc0fea5f073 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/application.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/application.ts @@ -47,7 +47,7 @@ import { // @ts-ignore import { initDashboardApp } from './legacy_app'; -import { DataStart } from '../../../data/public'; +import { DataStart, IndexPatterns } from '../../../data/public'; import { IEmbeddableStart } from '../../../../../plugins/embeddable/public'; import { NavigationStart } from '../../../navigation/public'; import { DataPublicPluginStart as NpDataStart } from '../../../../../plugins/data/public'; @@ -55,7 +55,7 @@ import { SharePluginStart } from '../../../../../plugins/share/public'; export interface RenderDeps { core: LegacyCoreStart; - indexPatterns: DataStart['indexPatterns']['indexPatterns']; + indexPatterns: IndexPatterns; dataStart: DataStart; npDataStart: NpDataStart; navigation: NavigationStart; diff --git a/src/legacy/core_plugins/kibana/public/dashboard/dashboard_app_controller.tsx b/src/legacy/core_plugins/kibana/public/dashboard/dashboard_app_controller.tsx index dcd25033e9d151..7972c7603d3111 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/dashboard_app_controller.tsx +++ b/src/legacy/core_plugins/kibana/public/dashboard/dashboard_app_controller.tsx @@ -39,7 +39,7 @@ import { unhashUrl, } from './legacy_imports'; import { FilterStateManager, IndexPattern } from '../../../data/public'; -import { Query, SavedQuery } from '../../../../../plugins/data/public'; +import { Query, SavedQuery, IndexPatterns } from '../../../../../plugins/data/public'; import './dashboard_empty_screen_directive'; @@ -78,9 +78,7 @@ export interface DashboardAppControllerDependencies extends RenderDeps { $routeParams: any; getAppState: any; globalState: State; - indexPatterns: { - getDefault: () => Promise; - }; + indexPatterns: IndexPatterns; dashboardConfig: any; kbnUrl: KbnUrl; AppStateClass: TAppStateClass; @@ -171,7 +169,7 @@ export class DashboardAppController { } else { indexPatterns.getDefault().then(defaultIndexPattern => { $scope.$evalAsync(() => { - $scope.indexPatterns = [defaultIndexPattern]; + $scope.indexPatterns = [defaultIndexPattern as IndexPattern]; }); }); } diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/create_edit_field/create_edit_field.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/create_edit_field/create_edit_field.js index c9ea1e12c58fdc..5f0994abc11e48 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/create_edit_field/create_edit_field.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/create_edit_field/create_edit_field.js @@ -17,9 +17,7 @@ * under the License. */ -import { setup as data } from '../../../../../../../data/public/legacy'; -const { FieldImpl: Field } = data.indexPatterns.__LEGACY; - +import { Field } from '../../../../../../../../../plugins/data/public'; import { RegistryFieldFormatEditorsProvider } from 'ui/registry/field_format_editors'; import { docTitle } from 'ui/doc_title'; import { KbnUrlProvider } from 'ui/url'; diff --git a/src/legacy/ui/public/index_patterns/__mocks__/index.ts b/src/legacy/ui/public/index_patterns/__mocks__/index.ts index 9ff09835e48da2..6f3d39299f9707 100644 --- a/src/legacy/ui/public/index_patterns/__mocks__/index.ts +++ b/src/legacy/ui/public/index_patterns/__mocks__/index.ts @@ -17,18 +17,18 @@ * under the License. */ -import { dataPluginMock } from '../../../../core_plugins/data/public/mocks'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { dataPluginMock } from '../../../../../plugins/data/public/mocks'; +import { indexPatterns as npIndexPatterns } from '../../../../../plugins/data/public'; -const dataSetup = dataPluginMock.createSetup(); +const dataSetup = dataPluginMock.createSetupContract(); // mocks for stateful code -export const { FieldImpl } = dataSetup.indexPatterns!.__LEGACY; -export const { - FieldList, - flattenHitWrapper, - formatHitProvider, - indexPatterns, -} = dataSetup.indexPatterns!; +export const { indexPatterns } = dataSetup.indexPatterns!; + +export const flattenHitWrapper = npIndexPatterns.flattenHitWrapper; +export const formatHitProvider = npIndexPatterns.formatHitProvider; // static code export { getFromSavedObject, getRoutes } from '../../../../core_plugins/data/public'; +export { FieldList } from '../../../../../plugins/data/public'; diff --git a/src/legacy/ui/public/index_patterns/index.ts b/src/legacy/ui/public/index_patterns/index.ts index 06001667c9e53a..200276c1727fcf 100644 --- a/src/legacy/ui/public/index_patterns/index.ts +++ b/src/legacy/ui/public/index_patterns/index.ts @@ -24,14 +24,6 @@ * from ui/index_patterns for backwards compatibility. */ -import { start as data } from '../../../core_plugins/data/public/legacy'; - -export const { - FieldList, // only used in Discover and StubIndexPattern - flattenHitWrapper, - formatHitProvider, -} = data.indexPatterns; - import { indexPatterns } from '../../../../plugins/data/public'; // static code @@ -42,6 +34,8 @@ export const INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE = indexPatterns.ILLEGAL_CH export const ILLEGAL_CHARACTERS = indexPatterns.ILLEGAL_CHARACTERS_KEY; export const CONTAINS_SPACES = indexPatterns.CONTAINS_SPACES_KEY; export const validateIndexPattern = indexPatterns.validate; +export const flattenHitWrapper = indexPatterns.flattenHitWrapper; +export const formatHitProvider = indexPatterns.formatHitProvider; // types export { @@ -52,3 +46,5 @@ export { IndexPatterns, StaticIndexPattern, } from '../../../core_plugins/data/public'; + +export { FieldList } from '../../../../plugins/data/public'; diff --git a/src/plugins/data/common/field_formats/converters/source.ts b/src/plugins/data/common/field_formats/converters/source.ts index 54977c7e669761..c9906fb1360524 100644 --- a/src/plugins/data/common/field_formats/converters/source.ts +++ b/src/plugins/data/common/field_formats/converters/source.ts @@ -20,8 +20,7 @@ import { template, escape, keys } from 'lodash'; // @ts-ignore import { noWhiteSpace } from '../../../../../legacy/core_plugins/kibana/common/utils/no_white_space'; -// @ts-ignore -import { shortenDottedString } from '../../../../../legacy/core_plugins/kibana/common/utils/shorten_dotted_string'; +import { shortenDottedString } from '../../utils'; import { KBN_FIELD_TYPES } from '../../kbn_field_types/types'; import { FieldFormat } from '../field_format'; import { TextContextTypeConvert, HtmlContextTypeConvert, FIELD_FORMAT_IDS } from '../types'; diff --git a/src/plugins/data/common/field_formats/converters/string.ts b/src/plugins/data/common/field_formats/converters/string.ts index 0edd219ca60f94..b2d92cf475a161 100644 --- a/src/plugins/data/common/field_formats/converters/string.ts +++ b/src/plugins/data/common/field_formats/converters/string.ts @@ -22,8 +22,7 @@ import { asPrettyString } from '../index'; import { KBN_FIELD_TYPES } from '../../kbn_field_types/types'; import { FieldFormat } from '../field_format'; import { TextContextTypeConvert, FIELD_FORMAT_IDS } from '../types'; -// @ts-ignore -import { shortenDottedString } from '../../../../../legacy/core_plugins/kibana/common/utils/shorten_dotted_string'; +import { shortenDottedString } from '../../utils'; const TRANSFORM_OPTIONS = [ { diff --git a/src/plugins/data/common/index.ts b/src/plugins/data/common/index.ts index f9bbeb5f4b3f39..b334342a57ec6b 100644 --- a/src/plugins/data/common/index.ts +++ b/src/plugins/data/common/index.ts @@ -22,5 +22,5 @@ export * from './field_formats'; export * from './kbn_field_types'; export * from './index_patterns'; export * from './es_query'; - +export * from './utils'; export * from './types'; diff --git a/src/plugins/data/common/utils/index.ts b/src/plugins/data/common/utils/index.ts new file mode 100644 index 00000000000000..7196c96989e97d --- /dev/null +++ b/src/plugins/data/common/utils/index.ts @@ -0,0 +1,20 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export { shortenDottedString } from './shorten_dotted_string'; diff --git a/src/plugins/data/common/utils/shorten_dotted_string.test.ts b/src/plugins/data/common/utils/shorten_dotted_string.test.ts new file mode 100644 index 00000000000000..5f8d084ce5e88c --- /dev/null +++ b/src/plugins/data/common/utils/shorten_dotted_string.test.ts @@ -0,0 +1,34 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { shortenDottedString } from './shorten_dotted_string'; + +describe('shortenDottedString', () => { + test('should convert a dot.notated.string into a short string', () => { + expect(shortenDottedString('dot.notated.string')).toBe('d.n.string'); + }); + + test('should ignore non-string values', () => { + const obj = { key: 'val' }; + + expect(shortenDottedString(true)).toBe(true); + expect(shortenDottedString(123)).toBe(123); + expect(shortenDottedString(obj)).toBe(obj); + }); +}); diff --git a/src/legacy/core_plugins/data/public/mocks.ts b/src/plugins/data/common/utils/shorten_dotted_string.ts similarity index 68% rename from src/legacy/core_plugins/data/public/mocks.ts rename to src/plugins/data/common/utils/shorten_dotted_string.ts index 39d1296ddf8bc4..379413c0d91c8f 100644 --- a/src/legacy/core_plugins/data/public/mocks.ts +++ b/src/plugins/data/common/utils/shorten_dotted_string.ts @@ -17,19 +17,14 @@ * under the License. */ -import { indexPatternsServiceMock } from './index_patterns/index_patterns_service.mock'; +const DOT_PREFIX_RE = /(.).+?\./g; -function createDataSetupMock() { - return { - indexPatterns: indexPatternsServiceMock.createSetupContract(), - }; -} - -function createDataStartMock() { - return {}; +/** + * Convert a dot.notated.string into a short + * version (d.n.string) + * + * @return {any} + */ +export function shortenDottedString(input: any) { + return typeof input !== 'string' ? input : input.replace(DOT_PREFIX_RE, '$1.'); } - -export const dataPluginMock = { - createSetup: createDataSetupMock, - createStart: createDataStartMock, -}; diff --git a/src/legacy/core_plugins/data/public/index_patterns/fields/field.ts b/src/plugins/data/public/index_patterns/fields/field.ts similarity index 94% rename from src/legacy/core_plugins/data/public/index_patterns/fields/field.ts rename to src/plugins/data/public/index_patterns/fields/field.ts index 91964655f6f3e7..ae17188de8625f 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/fields/field.ts +++ b/src/plugins/data/public/index_patterns/fields/field.ts @@ -20,26 +20,19 @@ import { i18n } from '@kbn/i18n'; // @ts-ignore import { ObjDefine } from './obj_define'; -// @ts-ignore -import { shortenDottedString } from '../../../../../core_plugins/kibana/common/utils/shorten_dotted_string'; import { IndexPattern } from '../index_patterns'; import { getNotifications, getFieldFormats } from '../services'; - import { - FieldFormat, - getKbnFieldType, IFieldType, + getKbnFieldType, IFieldSubType, -} from '../../../../../../plugins/data/public'; + FieldFormat, + shortenDottedString, +} from '../../../common'; export type FieldSpec = Record; -/** @deprecated - * Please use IFieldType instead - * */ -export type FieldType = IFieldType; - -export class Field implements FieldType { +export class Field implements IFieldType { name: string; type: string; script?: string; diff --git a/src/legacy/core_plugins/data/public/index_patterns/fields/field_list.ts b/src/plugins/data/public/index_patterns/fields/field_list.ts similarity index 91% rename from src/legacy/core_plugins/data/public/index_patterns/fields/field_list.ts rename to src/plugins/data/public/index_patterns/fields/field_list.ts index 108aacc8e07def..ff6706cec6c344 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/fields/field_list.ts +++ b/src/plugins/data/public/index_patterns/fields/field_list.ts @@ -19,7 +19,8 @@ import { findIndex } from 'lodash'; import { IndexPattern } from '../index_patterns'; -import { Field, FieldType, FieldSpec } from './field'; +import { IFieldType } from '../../../common'; +import { Field, FieldSpec } from './field'; type FieldMap = Map; @@ -27,7 +28,7 @@ export interface FieldListInterface extends Array { getByName(name: Field['name']): Field | undefined; getByType(type: Field['type']): Field[]; add(field: FieldSpec): void; - remove(field: FieldType): void; + remove(field: IFieldType): void; } export class FieldList extends Array implements FieldListInterface { @@ -42,7 +43,7 @@ export class FieldList extends Array implements FieldListInterface { } this.groups.get(field.type)!.set(field.name, field); }; - private removeByGroup = (field: FieldType) => this.groups.get(field.type)!.delete(field.name); + private removeByGroup = (field: IFieldType) => this.groups.get(field.type)!.delete(field.name); constructor(indexPattern: IndexPattern, specs: FieldSpec[] = [], shortDotsEnable = false) { super(); @@ -61,7 +62,7 @@ export class FieldList extends Array implements FieldListInterface { this.setByGroup(newField); }; - remove = (field: FieldType) => { + remove = (field: IFieldType) => { this.removeByGroup(field); this.byName.delete(field.name); diff --git a/src/legacy/core_plugins/data/public/index_patterns/fields/index.ts b/src/plugins/data/public/index_patterns/fields/index.ts similarity index 100% rename from src/legacy/core_plugins/data/public/index_patterns/fields/index.ts rename to src/plugins/data/public/index_patterns/fields/index.ts diff --git a/src/legacy/core_plugins/data/public/index_patterns/fields/obj_define.js b/src/plugins/data/public/index_patterns/fields/obj_define.js similarity index 100% rename from src/legacy/core_plugins/data/public/index_patterns/fields/obj_define.js rename to src/plugins/data/public/index_patterns/fields/obj_define.js diff --git a/src/legacy/core_plugins/data/public/index_patterns/fields/obj_define.test.js b/src/plugins/data/public/index_patterns/fields/obj_define.test.js similarity index 100% rename from src/legacy/core_plugins/data/public/index_patterns/fields/obj_define.test.js rename to src/plugins/data/public/index_patterns/fields/obj_define.test.js diff --git a/src/plugins/data/public/index_patterns/index.ts b/src/plugins/data/public/index_patterns/index.ts index aedfc18db3ade3..7492f9372e44a6 100644 --- a/src/plugins/data/public/index_patterns/index.ts +++ b/src/plugins/data/public/index_patterns/index.ts @@ -25,6 +25,8 @@ import { ILLEGAL_CHARACTERS, validateIndexPattern, } from './lib'; +import { getRoutes, getFromSavedObject } from './utils'; +import { flattenHitWrapper, formatHitProvider } from './index_patterns'; export const indexPatterns = { ILLEGAL_CHARACTERS_KEY, @@ -33,4 +35,13 @@ export const indexPatterns = { ILLEGAL_CHARACTERS, IndexPatternMissingIndices, validate: validateIndexPattern, + getRoutes, + getFromSavedObject, + flattenHitWrapper, + formatHitProvider, }; + +export { IndexPatternsService } from './index_patterns_service'; +export { Field, FieldList, FieldListInterface } from './fields'; +export { IndexPattern, IndexPatterns } from './index_patterns'; +export { IndexPatternsStart, IndexPatternsSetup } from './types'; diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/_fields_fetcher.ts b/src/plugins/data/public/index_patterns/index_patterns/_fields_fetcher.ts similarity index 100% rename from src/legacy/core_plugins/data/public/index_patterns/index_patterns/_fields_fetcher.ts rename to src/plugins/data/public/index_patterns/index_patterns/_fields_fetcher.ts diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/_pattern_cache.ts b/src/plugins/data/public/index_patterns/index_patterns/_pattern_cache.ts similarity index 97% rename from src/legacy/core_plugins/data/public/index_patterns/index_patterns/_pattern_cache.ts rename to src/plugins/data/public/index_patterns/index_patterns/_pattern_cache.ts index a3653bb529fa38..eb6c69b4143160 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/_pattern_cache.ts +++ b/src/plugins/data/public/index_patterns/index_patterns/_pattern_cache.ts @@ -19,7 +19,7 @@ import { IndexPattern } from './index_pattern'; -export interface PatternCache { +interface PatternCache { get: (id: string) => IndexPattern; set: (id: string, value: IndexPattern) => IndexPattern; clear: (id: string) => void; diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/flatten_hit.ts b/src/plugins/data/public/index_patterns/index_patterns/flatten_hit.ts similarity index 100% rename from src/legacy/core_plugins/data/public/index_patterns/index_patterns/flatten_hit.ts rename to src/plugins/data/public/index_patterns/index_patterns/flatten_hit.ts diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/format_hit.ts b/src/plugins/data/public/index_patterns/index_patterns/format_hit.ts similarity index 100% rename from src/legacy/core_plugins/data/public/index_patterns/index_patterns/format_hit.ts rename to src/plugins/data/public/index_patterns/index_patterns/format_hit.ts diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index.ts b/src/plugins/data/public/index_patterns/index_patterns/index.ts similarity index 100% rename from src/legacy/core_plugins/data/public/index_patterns/index_patterns/index.ts rename to src/plugins/data/public/index_patterns/index_patterns/index.ts diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.test.ts b/src/plugins/data/public/index_patterns/index_patterns/index_pattern.test.ts similarity index 95% rename from src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.test.ts rename to src/plugins/data/public/index_patterns/index_patterns/index_pattern.test.ts index ee9f9b493ebf25..a0a884454a3f00 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.test.ts +++ b/src/plugins/data/public/index_patterns/index_patterns/index_pattern.test.ts @@ -20,24 +20,23 @@ import { defaults, pluck, last, get } from 'lodash'; import { IndexPattern } from './index_pattern'; -import { DuplicateField } from '../../../../../../plugins/kibana_utils/public'; +import { DuplicateField } from '../../../../kibana_utils/public'; // @ts-ignore -import mockLogStashFields from '../../../../../../fixtures/logstash_fields'; +import mockLogStashFields from '../../../../../fixtures/logstash_fields'; // @ts-ignore - -import { stubbedSavedObjectIndexPattern } from '../../../../../../fixtures/stubbed_saved_object_index_pattern'; -import { Field } from '../index_patterns_service'; +import { stubbedSavedObjectIndexPattern } from '../../../../../fixtures/stubbed_saved_object_index_pattern'; +import { Field } from '../fields'; import { setNotifications, setFieldFormats } from '../services'; // Temporary disable eslint, will be removed after moving to new platform folder // eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { notificationServiceMock } from '../../../../../../core/public/notifications/notifications_service.mock'; -import { FieldFormatRegisty } from '../../../../../../plugins/data/public'; +import { notificationServiceMock } from '../../../../../core/public/notifications/notifications_service.mock'; +import { FieldFormatRegisty } from '../../field_formats_provider'; jest.mock('ui/new_platform'); -jest.mock('../../../../../../plugins/kibana_utils/public', () => { - const originalModule = jest.requireActual('../../../../../../plugins/kibana_utils/public'); +jest.mock('../../../../kibana_utils/public', () => { + const originalModule = jest.requireActual('../../../../kibana_utils/public'); return { ...originalModule, diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.ts b/src/plugins/data/public/index_patterns/index_patterns/index_pattern.ts similarity index 96% rename from src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.ts rename to src/plugins/data/public/index_patterns/index_patterns/index_pattern.ts index de364b6c217dd7..2c93c0aa9dc620 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.ts +++ b/src/plugins/data/public/index_patterns/index_patterns/index_pattern.ts @@ -26,17 +26,13 @@ import { expandShorthand, FieldMappingSpec, MappingObject, -} from '../../../../../../plugins/kibana_utils/public'; +} from '../../../../kibana_utils/public'; -import { - ES_FIELD_TYPES, - KBN_FIELD_TYPES, - IIndexPattern, - indexPatterns, -} from '../../../../../../plugins/data/public'; - -import { findIndexPatternByTitle, getRoutes } from '../utils'; -import { Field, FieldList, FieldListInterface, FieldType } from '../fields'; +import { ES_FIELD_TYPES, KBN_FIELD_TYPES, IIndexPattern, IFieldType } from '../../../common'; + +import { findByTitle, getRoutes } from '../utils'; +import { indexPatterns } from '../'; +import { Field, FieldList, FieldListInterface } from '../fields'; import { createFieldsFetcher } from './_fields_fetcher'; import { formatHitProvider } from './format_hit'; import { flattenHitWrapper } from './flatten_hit'; @@ -46,11 +42,6 @@ import { getNotifications, getFieldFormats } from '../services'; const MAX_ATTEMPTS_TO_RESOLVE_CONFLICTS = 3; const type = 'index-pattern'; -/** @deprecated - * Please use IIndexPattern instead - * */ -export type StaticIndexPattern = IIndexPattern; - export class IndexPattern implements IIndexPattern { [key: string]: any; @@ -296,7 +287,7 @@ export class IndexPattern implements IIndexPattern { await this.save(); } - removeScriptedField(field: FieldType) { + removeScriptedField(field: IFieldType) { this.fields.remove(field); return this.save(); } @@ -384,10 +375,7 @@ export class IndexPattern implements IIndexPattern { return response.id; }; - const potentialDuplicateByTitle = await findIndexPatternByTitle( - this.savedObjectsClient, - this.title - ); + const potentialDuplicateByTitle = await findByTitle(this.savedObjectsClient, this.title); // If there is potentially duplicate title, just create it if (!potentialDuplicateByTitle) { return await _create(); diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.test.ts b/src/plugins/data/public/index_patterns/index_patterns/index_patterns.test.ts similarity index 100% rename from src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.test.ts rename to src/plugins/data/public/index_patterns/index_patterns/index_patterns.test.ts diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.ts b/src/plugins/data/public/index_patterns/index_patterns/index_patterns.ts similarity index 100% rename from src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.ts rename to src/plugins/data/public/index_patterns/index_patterns/index_patterns.ts diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.mock.ts b/src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.mock.ts similarity index 92% rename from src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.mock.ts rename to src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.mock.ts index 06933dc4090528..2d3e357e968199 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.mock.ts +++ b/src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.mock.ts @@ -17,7 +17,7 @@ * under the License. */ -import { setup } from '../../../../../../test_utils/public/http_test_setup'; +import { setup } from 'test_utils/http_test_setup'; export const { http } = setup(injectedMetadata => { injectedMetadata.getBasePath.mockReturnValue('/hola/daro/'); diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.ts b/src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.ts similarity index 100% rename from src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.ts rename to src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.ts diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.ts b/src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.ts similarity index 97% rename from src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.ts rename to src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.ts index 87dd7a68e30614..961e519338ac4d 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.ts +++ b/src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.ts @@ -18,7 +18,7 @@ */ import { HttpServiceBase } from 'src/core/public'; -import { indexPatterns } from '../../../../../../plugins/data/public'; +import { indexPatterns } from '../'; const API_BASE_URL: string = `/api/index_patterns/`; diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.mock.ts b/src/plugins/data/public/index_patterns/index_patterns_service.mock.ts similarity index 87% rename from src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.mock.ts rename to src/plugins/data/public/index_patterns/index_patterns_service.mock.ts index db1ece78e7b4d1..d38e9c76430eb7 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.mock.ts +++ b/src/plugins/data/public/index_patterns/index_patterns_service.mock.ts @@ -17,8 +17,9 @@ * under the License. */ -import { IndexPatternsService, IndexPatternsSetup } from '.'; +import { IndexPatternsService } from './index_patterns_service'; import { flattenHitWrapper } from './index_patterns'; +import { IndexPatternsSetup } from './types'; type IndexPatternsServiceClientContract = PublicMethodsOf; @@ -33,11 +34,7 @@ const createSetupContractMock = () => { flattenHitWrapper: jest.fn().mockImplementation(flattenHitWrapper), formatHitProvider: jest.fn(), indexPatterns: jest.fn() as any, - __LEGACY: { - // For BWC we must temporarily export the class implementation of Field, - // which is only used externally by the Index Pattern UI. - FieldImpl: jest.fn(), - }, + IndexPatternSelect: jest.fn(), }; return setupContract; diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts b/src/plugins/data/public/index_patterns/index_patterns_service.ts similarity index 60% rename from src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts rename to src/plugins/data/public/index_patterns/index_patterns_service.ts index 83738ffe5b747c..40f833868847b7 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts +++ b/src/plugins/data/public/index_patterns/index_patterns_service.ts @@ -23,19 +23,11 @@ import { HttpServiceBase, NotificationsStart, } from 'src/core/public'; -import { FieldFormatsStart } from '../../../../../plugins/data/public'; -import { Field, FieldList, FieldListInterface, FieldType } from './fields'; +import { FieldFormatsStart } from '../field_formats_provider'; import { setNotifications, setFieldFormats } from './services'; +import { IndexPatterns } from './index_patterns'; -import { - createFlattenHitWrapper, - formatHitProvider, - IndexPattern, - IndexPatterns, - StaticIndexPattern, -} from './index_patterns'; - -export interface IndexPatternDependencies { +interface IndexPatternDependencies { uiSettings: IUiSettingsClient; savedObjectsClient: SavedObjectsClientContract; http: HttpServiceBase; @@ -52,16 +44,8 @@ export class IndexPatternsService { private setupApi: any; public setup() { - this.setupApi = { - FieldList, - flattenHitWrapper: createFlattenHitWrapper(), - formatHitProvider, - __LEGACY: { - // For BWC we must temporarily export the class implementation of Field, - // which is only used externally by the Index Pattern UI. - FieldImpl: Field, - }, - }; + this.setupApi = {}; + return this.setupApi; } @@ -76,7 +60,6 @@ export class IndexPatternsService { setFieldFormats(fieldFormats); return { - ...this.setupApi, indexPatterns: new IndexPatterns(uiSettings, savedObjectsClient, http), }; } @@ -85,20 +68,3 @@ export class IndexPatternsService { // nothing to do here yet } } - -// static code - -/** @public */ -export { getFromSavedObject, getRoutes } from './utils'; - -// types - -/** @internal */ -export type IndexPatternsSetup = ReturnType; -export type IndexPatternsStart = ReturnType; - -/** @public */ -export { IndexPattern, IndexPatterns, StaticIndexPattern, Field, FieldType, FieldListInterface }; - -/** @public */ -export { findIndexPatternByTitle } from './utils'; diff --git a/src/plugins/data/public/index_patterns/lib/get_index_pattern_title.ts b/src/plugins/data/public/index_patterns/lib/get_title.ts similarity index 96% rename from src/plugins/data/public/index_patterns/lib/get_index_pattern_title.ts rename to src/plugins/data/public/index_patterns/lib/get_title.ts index 777a12c7e2884a..320205f5139c98 100644 --- a/src/plugins/data/public/index_patterns/lib/get_index_pattern_title.ts +++ b/src/plugins/data/public/index_patterns/lib/get_title.ts @@ -19,7 +19,7 @@ import { SavedObjectsClientContract, SimpleSavedObject } from '../../../../../core/public'; -export async function getIndexPatternTitle( +export async function getTitle( client: SavedObjectsClientContract, indexPatternId: string ): Promise> { diff --git a/src/plugins/data/public/index_patterns/lib/index.ts b/src/plugins/data/public/index_patterns/lib/index.ts index 3b87d91bb9fffb..0f667e846af91d 100644 --- a/src/plugins/data/public/index_patterns/lib/index.ts +++ b/src/plugins/data/public/index_patterns/lib/index.ts @@ -17,6 +17,6 @@ * under the License. */ -export { getIndexPatternTitle } from './get_index_pattern_title'; +export { getTitle } from './get_title'; export * from './types'; export { validateIndexPattern } from './validate_index_pattern'; diff --git a/src/legacy/core_plugins/data/public/index_patterns/services.ts b/src/plugins/data/public/index_patterns/services.ts similarity index 87% rename from src/legacy/core_plugins/data/public/index_patterns/services.ts rename to src/plugins/data/public/index_patterns/services.ts index ecd898b28de636..a6844cb4c04e2f 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/services.ts +++ b/src/plugins/data/public/index_patterns/services.ts @@ -18,8 +18,8 @@ */ import { NotificationsStart } from 'src/core/public'; -import { createGetterSetter } from '../../../../../plugins/kibana_utils/public'; -import { FieldFormatsStart } from '../../../../../plugins/data/public'; +import { createGetterSetter } from '../../../kibana_utils/public'; +import { FieldFormatsStart } from '../field_formats_provider'; export const [getNotifications, setNotifications] = createGetterSetter( 'Notifications' diff --git a/src/plugins/data/public/index_patterns/types.ts b/src/plugins/data/public/index_patterns/types.ts new file mode 100644 index 00000000000000..59e3075bf215d1 --- /dev/null +++ b/src/plugins/data/public/index_patterns/types.ts @@ -0,0 +1,23 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { IndexPatternsService } from './index_patterns_service'; + +export type IndexPatternsSetup = ReturnType; +export type IndexPatternsStart = ReturnType; diff --git a/src/legacy/core_plugins/data/public/index_patterns/utils.ts b/src/plugins/data/public/index_patterns/utils.ts similarity index 93% rename from src/legacy/core_plugins/data/public/index_patterns/utils.ts rename to src/plugins/data/public/index_patterns/utils.ts index 0d0d5705a0cccd..8edb62f16bfeb6 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/utils.ts +++ b/src/plugins/data/public/index_patterns/utils.ts @@ -18,8 +18,7 @@ */ import { find, get } from 'lodash'; - -import { SavedObjectsClientContract, SimpleSavedObject } from '../../../../../core/public'; +import { SavedObjectsClientContract, SimpleSavedObject } from 'src/core/public'; /** * Returns an object matching a given title @@ -28,7 +27,7 @@ import { SavedObjectsClientContract, SimpleSavedObject } from '../../../../../co * @param title {string} * @returns {Promise} */ -export async function findIndexPatternByTitle( +export async function findByTitle( client: SavedObjectsClientContract, title: string ): Promise | void> { diff --git a/src/plugins/data/public/mocks.ts b/src/plugins/data/public/mocks.ts index ceb57b4a3a564d..19c21ab9934ef1 100644 --- a/src/plugins/data/public/mocks.ts +++ b/src/plugins/data/public/mocks.ts @@ -19,6 +19,7 @@ import { FieldFormatRegisty, Plugin, FieldFormatsStart, FieldFormatsSetup } from '.'; import { searchSetupMock } from './search/mocks'; import { queryServiceMock } from './query/mocks'; +import { indexPatternsServiceMock } from './index_patterns/index_patterns_service.mock'; export type Setup = jest.Mocked>; export type Start = jest.Mocked>; @@ -53,6 +54,7 @@ const createSetupContract = (): Setup => { search: searchSetupMock, fieldFormats: fieldFormatsMock as FieldFormatsSetup, query: querySetupMock, + indexPatterns: indexPatternsServiceMock.createSetupContract(), }; return setupContract; @@ -69,6 +71,7 @@ const createStartContract = (): Start => { ui: { IndexPatternSelect: jest.fn(), }, + indexPatterns: indexPatternsServiceMock.createStartContract(), }; return startContract; }; diff --git a/src/plugins/data/public/plugin.ts b/src/plugins/data/public/plugin.ts index 35d8edc4884671..c018efcad74e65 100644 --- a/src/plugins/data/public/plugin.ts +++ b/src/plugins/data/public/plugin.ts @@ -26,8 +26,10 @@ import { SearchService } from './search/search_service'; import { FieldFormatsService } from './field_formats_provider'; import { QueryService } from './query'; import { createIndexPatternSelect } from './ui/index_pattern_select'; +import { IndexPatternsService } from './index_patterns'; export class DataPublicPlugin implements Plugin { + private readonly indexPatterns: IndexPatternsService = new IndexPatternsService(); private readonly autocomplete = new AutocompleteProviderRegister(); private readonly searchService: SearchService; private readonly fieldFormatsService: FieldFormatsService; @@ -54,19 +56,30 @@ export class DataPublicPlugin implements Plugin; }; + indexPatterns: IndexPatternsStart; } export * from './autocomplete_provider/types'; diff --git a/src/plugins/data/public/ui/index_pattern_select/index_pattern_select.tsx b/src/plugins/data/public/ui/index_pattern_select/index_pattern_select.tsx index f41024ed16191c..ad453c4e5d11d2 100644 --- a/src/plugins/data/public/ui/index_pattern_select/index_pattern_select.tsx +++ b/src/plugins/data/public/ui/index_pattern_select/index_pattern_select.tsx @@ -22,7 +22,7 @@ import React, { Component } from 'react'; import { EuiComboBox } from '@elastic/eui'; import { SavedObjectsClientContract, SimpleSavedObject } from '../../../../../core/public'; -import { getIndexPatternTitle } from '../../index_patterns/lib'; +import { getTitle } from '../../index_patterns/lib'; export interface IndexPatternSelectProps { onChange: (opt: any) => void; @@ -104,7 +104,7 @@ export class IndexPatternSelect extends Component { let indexPatternTitle; try { - indexPatternTitle = await getIndexPatternTitle(this.props.savedObjectsClient, indexPatternId); + indexPatternTitle = await getTitle(this.props.savedObjectsClient, indexPatternId); } catch (err) { // index pattern no longer exists return; diff --git a/src/test_utils/public/stub_index_pattern.js b/src/test_utils/public/stub_index_pattern.js index b41ebe3e618615..b76da4b4eca3ef 100644 --- a/src/test_utils/public/stub_index_pattern.js +++ b/src/test_utils/public/stub_index_pattern.js @@ -21,7 +21,7 @@ import sinon from 'sinon'; // TODO: We should not be importing from the data plugin directly here; this is only necessary // because it is one of the few places that we need to access the IndexPattern class itself, rather // than just the type. Doing this as a temporary measure; it will be left behind when migrating to NP. -import { IndexPattern } from '../../legacy/core_plugins/data/public/index_patterns/index_patterns'; +import { IndexPattern } from '../../legacy/core_plugins/data/public/'; import { FieldList, getRoutes, diff --git a/x-pack/legacy/plugins/graph/public/services/persistence/deserialize.ts b/x-pack/legacy/plugins/graph/public/services/persistence/deserialize.ts index b1879ec92c131d..9a13da65e976ae 100644 --- a/x-pack/legacy/plugins/graph/public/services/persistence/deserialize.ts +++ b/x-pack/legacy/plugins/graph/public/services/persistence/deserialize.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { IndexPattern } from 'src/legacy/core_plugins/data/public/index_patterns/index_patterns'; +import { IndexPattern } from 'src/legacy/core_plugins/data/public/'; import { SerializedNode, UrlTemplate,