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 c65ae3a0ec7b9..946b3997a9712 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,9 +32,8 @@ 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 { @@ -75,7 +74,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 bdfedbc2c81a8..833d8c248f46a 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, flattenHitWrapper } from './index_patterns'; +export { getFromSavedObject, getRoutes } from './index_patterns'; diff --git a/src/plugins/data/public/index_patterns/fields/field.ts b/src/legacy/core_plugins/data/public/index_patterns/fields/field.ts similarity index 94% rename from src/plugins/data/public/index_patterns/fields/field.ts rename to src/legacy/core_plugins/data/public/index_patterns/fields/field.ts index ae17188de8625..91964655f6f3e 100644 --- a/src/plugins/data/public/index_patterns/fields/field.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/fields/field.ts @@ -20,19 +20,26 @@ 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 { - IFieldType, + FieldFormat, getKbnFieldType, + IFieldType, IFieldSubType, - FieldFormat, - shortenDottedString, -} from '../../../common'; +} from '../../../../../../plugins/data/public'; export type FieldSpec = Record; -export class Field implements IFieldType { +/** @deprecated + * Please use IFieldType instead + * */ +export type FieldType = IFieldType; + +export class Field implements FieldType { name: string; type: string; script?: string; diff --git a/src/plugins/data/public/index_patterns/fields/field_list.ts b/src/legacy/core_plugins/data/public/index_patterns/fields/field_list.ts similarity index 91% rename from src/plugins/data/public/index_patterns/fields/field_list.ts rename to src/legacy/core_plugins/data/public/index_patterns/fields/field_list.ts index ff6706cec6c34..108aacc8e07de 100644 --- a/src/plugins/data/public/index_patterns/fields/field_list.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/fields/field_list.ts @@ -19,8 +19,7 @@ import { findIndex } from 'lodash'; import { IndexPattern } from '../index_patterns'; -import { IFieldType } from '../../../common'; -import { Field, FieldSpec } from './field'; +import { Field, FieldType, FieldSpec } from './field'; type FieldMap = Map; @@ -28,7 +27,7 @@ export interface FieldListInterface extends Array { getByName(name: Field['name']): Field | undefined; getByType(type: Field['type']): Field[]; add(field: FieldSpec): void; - remove(field: IFieldType): void; + remove(field: FieldType): void; } export class FieldList extends Array implements FieldListInterface { @@ -43,7 +42,7 @@ export class FieldList extends Array implements FieldListInterface { } this.groups.get(field.type)!.set(field.name, field); }; - private removeByGroup = (field: IFieldType) => this.groups.get(field.type)!.delete(field.name); + private removeByGroup = (field: FieldType) => this.groups.get(field.type)!.delete(field.name); constructor(indexPattern: IndexPattern, specs: FieldSpec[] = [], shortDotsEnable = false) { super(); @@ -62,7 +61,7 @@ export class FieldList extends Array implements FieldListInterface { this.setByGroup(newField); }; - remove = (field: IFieldType) => { + remove = (field: FieldType) => { this.removeByGroup(field); this.byName.delete(field.name); diff --git a/src/plugins/data/public/index_patterns/fields/index.ts b/src/legacy/core_plugins/data/public/index_patterns/fields/index.ts similarity index 100% rename from src/plugins/data/public/index_patterns/fields/index.ts rename to src/legacy/core_plugins/data/public/index_patterns/fields/index.ts diff --git a/src/plugins/data/public/index_patterns/fields/obj_define.js b/src/legacy/core_plugins/data/public/index_patterns/fields/obj_define.js similarity index 100% rename from src/plugins/data/public/index_patterns/fields/obj_define.js rename to src/legacy/core_plugins/data/public/index_patterns/fields/obj_define.js diff --git a/src/plugins/data/public/index_patterns/fields/obj_define.test.js b/src/legacy/core_plugins/data/public/index_patterns/fields/obj_define.test.js similarity index 100% rename from src/plugins/data/public/index_patterns/fields/obj_define.test.js rename to src/legacy/core_plugins/data/public/index_patterns/fields/obj_define.test.js 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 74981165f3e47..496c4ba7b5b6f 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index.ts @@ -17,21 +17,4 @@ * under the License. */ -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'; +export * from './index_patterns_service'; diff --git a/src/plugins/data/public/index_patterns/index_patterns/_fields_fetcher.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/_fields_fetcher.ts similarity index 100% rename from src/plugins/data/public/index_patterns/index_patterns/_fields_fetcher.ts rename to src/legacy/core_plugins/data/public/index_patterns/index_patterns/_fields_fetcher.ts diff --git a/src/plugins/data/public/index_patterns/index_patterns/_pattern_cache.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/_pattern_cache.ts similarity index 97% rename from src/plugins/data/public/index_patterns/index_patterns/_pattern_cache.ts rename to src/legacy/core_plugins/data/public/index_patterns/index_patterns/_pattern_cache.ts index eb6c69b414316..a3653bb529fa3 100644 --- a/src/plugins/data/public/index_patterns/index_patterns/_pattern_cache.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/_pattern_cache.ts @@ -19,7 +19,7 @@ import { IndexPattern } from './index_pattern'; -interface PatternCache { +export interface PatternCache { get: (id: string) => IndexPattern; set: (id: string, value: IndexPattern) => IndexPattern; clear: (id: string) => void; diff --git a/src/plugins/data/public/index_patterns/index_patterns/flatten_hit.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/flatten_hit.ts similarity index 100% rename from src/plugins/data/public/index_patterns/index_patterns/flatten_hit.ts rename to src/legacy/core_plugins/data/public/index_patterns/index_patterns/flatten_hit.ts diff --git a/src/plugins/data/public/index_patterns/index_patterns/format_hit.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/format_hit.ts similarity index 100% rename from src/plugins/data/public/index_patterns/index_patterns/format_hit.ts rename to src/legacy/core_plugins/data/public/index_patterns/index_patterns/format_hit.ts diff --git a/src/plugins/data/public/index_patterns/index_patterns/index.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index.ts similarity index 100% rename from src/plugins/data/public/index_patterns/index_patterns/index.ts rename to src/legacy/core_plugins/data/public/index_patterns/index_patterns/index.ts diff --git a/src/plugins/data/public/index_patterns/index_patterns/index_pattern.test.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.test.ts similarity index 95% rename from src/plugins/data/public/index_patterns/index_patterns/index_pattern.test.ts rename to src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.test.ts index a0a884454a3f0..ee9f9b493ebf2 100644 --- a/src/plugins/data/public/index_patterns/index_patterns/index_pattern.test.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.test.ts @@ -20,23 +20,24 @@ import { defaults, pluck, last, get } from 'lodash'; import { IndexPattern } from './index_pattern'; -import { DuplicateField } from '../../../../kibana_utils/public'; +import { DuplicateField } from '../../../../../../plugins/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 '../fields'; + +import { stubbedSavedObjectIndexPattern } from '../../../../../../fixtures/stubbed_saved_object_index_pattern'; +import { Field } from '../index_patterns_service'; 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 '../../field_formats_provider'; +import { notificationServiceMock } from '../../../../../../core/public/notifications/notifications_service.mock'; +import { FieldFormatRegisty } from '../../../../../../plugins/data/public'; jest.mock('ui/new_platform'); -jest.mock('../../../../kibana_utils/public', () => { - const originalModule = jest.requireActual('../../../../kibana_utils/public'); +jest.mock('../../../../../../plugins/kibana_utils/public', () => { + const originalModule = jest.requireActual('../../../../../../plugins/kibana_utils/public'); return { ...originalModule, diff --git a/src/plugins/data/public/index_patterns/index_patterns/index_pattern.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.ts similarity index 96% rename from src/plugins/data/public/index_patterns/index_patterns/index_pattern.ts rename to src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.ts index 2c93c0aa9dc62..de364b6c217dd 100644 --- a/src/plugins/data/public/index_patterns/index_patterns/index_pattern.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.ts @@ -26,13 +26,17 @@ import { expandShorthand, FieldMappingSpec, MappingObject, -} from '../../../../kibana_utils/public'; +} from '../../../../../../plugins/kibana_utils/public'; -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 { + 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 { createFieldsFetcher } from './_fields_fetcher'; import { formatHitProvider } from './format_hit'; import { flattenHitWrapper } from './flatten_hit'; @@ -42,6 +46,11 @@ 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; @@ -287,7 +296,7 @@ export class IndexPattern implements IIndexPattern { await this.save(); } - removeScriptedField(field: IFieldType) { + removeScriptedField(field: FieldType) { this.fields.remove(field); return this.save(); } @@ -375,7 +384,10 @@ export class IndexPattern implements IIndexPattern { return response.id; }; - const potentialDuplicateByTitle = await findByTitle(this.savedObjectsClient, this.title); + const potentialDuplicateByTitle = await findIndexPatternByTitle( + this.savedObjectsClient, + this.title + ); // If there is potentially duplicate title, just create it if (!potentialDuplicateByTitle) { return await _create(); diff --git a/src/plugins/data/public/index_patterns/index_patterns/index_patterns.test.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.test.ts similarity index 100% rename from src/plugins/data/public/index_patterns/index_patterns/index_patterns.test.ts rename to src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.test.ts diff --git a/src/plugins/data/public/index_patterns/index_patterns/index_patterns.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.ts similarity index 100% rename from src/plugins/data/public/index_patterns/index_patterns/index_patterns.ts rename to src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.ts diff --git a/src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.mock.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.mock.ts similarity index 92% rename from src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.mock.ts rename to src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.mock.ts index 2d3e357e96819..06933dc409052 100644 --- a/src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.mock.ts +++ b/src/legacy/core_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/http_test_setup'; +import { setup } from '../../../../../../test_utils/public/http_test_setup'; export const { http } = setup(injectedMetadata => { injectedMetadata.getBasePath.mockReturnValue('/hola/daro/'); diff --git a/src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.ts similarity index 100% rename from src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.ts rename to src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.ts diff --git a/src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.ts similarity index 97% rename from src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.ts rename to src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.ts index 961e519338ac4..87dd7a68e3061 100644 --- a/src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.ts +++ b/src/legacy/core_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 '../'; +import { indexPatterns } from '../../../../../../plugins/data/public'; const API_BASE_URL: string = `/api/index_patterns/`; diff --git a/src/plugins/data/public/index_patterns/index_patterns_service.mock.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.mock.ts similarity index 87% rename from src/plugins/data/public/index_patterns/index_patterns_service.mock.ts rename to src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.mock.ts index d38e9c76430eb..db1ece78e7b4d 100644 --- a/src/plugins/data/public/index_patterns/index_patterns_service.mock.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.mock.ts @@ -17,9 +17,8 @@ * under the License. */ -import { IndexPatternsService } from './index_patterns_service'; +import { IndexPatternsService, IndexPatternsSetup } from '.'; import { flattenHitWrapper } from './index_patterns'; -import { IndexPatternsSetup } from './types'; type IndexPatternsServiceClientContract = PublicMethodsOf; @@ -34,7 +33,11 @@ const createSetupContractMock = () => { flattenHitWrapper: jest.fn().mockImplementation(flattenHitWrapper), formatHitProvider: jest.fn(), indexPatterns: jest.fn() as any, - IndexPatternSelect: jest.fn(), + __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(), + }, }; return setupContract; diff --git a/src/plugins/data/public/index_patterns/index_patterns_service.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts similarity index 60% rename from src/plugins/data/public/index_patterns/index_patterns_service.ts rename to src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts index 40f833868847b..83738ffe5b747 100644 --- a/src/plugins/data/public/index_patterns/index_patterns_service.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts @@ -23,11 +23,19 @@ import { HttpServiceBase, NotificationsStart, } from 'src/core/public'; -import { FieldFormatsStart } from '../field_formats_provider'; +import { FieldFormatsStart } from '../../../../../plugins/data/public'; +import { Field, FieldList, FieldListInterface, FieldType } from './fields'; import { setNotifications, setFieldFormats } from './services'; -import { IndexPatterns } from './index_patterns'; -interface IndexPatternDependencies { +import { + createFlattenHitWrapper, + formatHitProvider, + IndexPattern, + IndexPatterns, + StaticIndexPattern, +} from './index_patterns'; + +export interface IndexPatternDependencies { uiSettings: IUiSettingsClient; savedObjectsClient: SavedObjectsClientContract; http: HttpServiceBase; @@ -44,8 +52,16 @@ export class IndexPatternsService { private setupApi: any; public setup() { - this.setupApi = {}; - + 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, + }, + }; return this.setupApi; } @@ -60,6 +76,7 @@ export class IndexPatternsService { setFieldFormats(fieldFormats); return { + ...this.setupApi, indexPatterns: new IndexPatterns(uiSettings, savedObjectsClient, http), }; } @@ -68,3 +85,20 @@ 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/services.ts b/src/legacy/core_plugins/data/public/index_patterns/services.ts similarity index 87% rename from src/plugins/data/public/index_patterns/services.ts rename to src/legacy/core_plugins/data/public/index_patterns/services.ts index a6844cb4c04e2..ecd898b28de63 100644 --- a/src/plugins/data/public/index_patterns/services.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/services.ts @@ -18,8 +18,8 @@ */ import { NotificationsStart } from 'src/core/public'; -import { createGetterSetter } from '../../../kibana_utils/public'; -import { FieldFormatsStart } from '../field_formats_provider'; +import { createGetterSetter } from '../../../../../plugins/kibana_utils/public'; +import { FieldFormatsStart } from '../../../../../plugins/data/public'; export const [getNotifications, setNotifications] = createGetterSetter( 'Notifications' diff --git a/src/plugins/data/public/index_patterns/utils.ts b/src/legacy/core_plugins/data/public/index_patterns/utils.ts similarity index 93% rename from src/plugins/data/public/index_patterns/utils.ts rename to src/legacy/core_plugins/data/public/index_patterns/utils.ts index 8edb62f16bfeb..0d0d5705a0ccc 100644 --- a/src/plugins/data/public/index_patterns/utils.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/utils.ts @@ -18,7 +18,8 @@ */ import { find, get } from 'lodash'; -import { SavedObjectsClientContract, SimpleSavedObject } from 'src/core/public'; + +import { SavedObjectsClientContract, SimpleSavedObject } from '../../../../../core/public'; /** * Returns an object matching a given title @@ -27,7 +28,7 @@ import { SavedObjectsClientContract, SimpleSavedObject } from 'src/core/public'; * @param title {string} * @returns {Promise} */ -export async function findByTitle( +export async function findIndexPatternByTitle( client: SavedObjectsClientContract, title: string ): Promise | void> { diff --git a/src/plugins/data/common/utils/shorten_dotted_string.ts b/src/legacy/core_plugins/data/public/mocks.ts similarity index 68% rename from src/plugins/data/common/utils/shorten_dotted_string.ts rename to src/legacy/core_plugins/data/public/mocks.ts index 379413c0d91c8..39d1296ddf8bc 100644 --- a/src/plugins/data/common/utils/shorten_dotted_string.ts +++ b/src/legacy/core_plugins/data/public/mocks.ts @@ -17,14 +17,19 @@ * under the License. */ -const DOT_PREFIX_RE = /(.).+?\./g; +import { indexPatternsServiceMock } from './index_patterns/index_patterns_service.mock'; -/** - * 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.'); +function createDataSetupMock() { + return { + indexPatterns: indexPatternsServiceMock.createSetupContract(), + }; } + +function createDataStartMock() { + return {}; +} + +export const dataPluginMock = { + createSetup: createDataSetupMock, + createStart: createDataStartMock, +}; 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 7a4c9f139c887..3dcab22605c07 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 '../../../'; +import { getFromSavedObject } from '../../../index_patterns'; 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 0e12790d89fed..06c5caa04ba9a 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 '../'; +import { IndexPatterns } from '../index_patterns/index_patterns'; /** @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 bad006aa8c7d5..e341b7c4a5a86 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/'; +import { flattenHitWrapper } from '../../../../data/public/index_patterns/index_patterns/flatten_hit'; 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 42ecc0fea5f07..797583362a8f8 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, IndexPatterns } from '../../../data/public'; +import { DataStart } 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: IndexPatterns; + indexPatterns: DataStart['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 7972c7603d311..dcd25033e9d15 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, IndexPatterns } from '../../../../../plugins/data/public'; +import { Query, SavedQuery } from '../../../../../plugins/data/public'; import './dashboard_empty_screen_directive'; @@ -78,7 +78,9 @@ export interface DashboardAppControllerDependencies extends RenderDeps { $routeParams: any; getAppState: any; globalState: State; - indexPatterns: IndexPatterns; + indexPatterns: { + getDefault: () => Promise; + }; dashboardConfig: any; kbnUrl: KbnUrl; AppStateClass: TAppStateClass; @@ -169,7 +171,7 @@ export class DashboardAppController { } else { indexPatterns.getDefault().then(defaultIndexPattern => { $scope.$evalAsync(() => { - $scope.indexPatterns = [defaultIndexPattern as IndexPattern]; + $scope.indexPatterns = [defaultIndexPattern]; }); }); } 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 5f0994abc11e4..c9ea1e12c58fd 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,7 +17,9 @@ * under the License. */ -import { Field } from '../../../../../../../../../plugins/data/public'; +import { setup as data } from '../../../../../../../data/public/legacy'; +const { FieldImpl: Field } = data.indexPatterns.__LEGACY; + 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 6f3d39299f970..9ff09835e48da 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. */ -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { dataPluginMock } from '../../../../../plugins/data/public/mocks'; -import { indexPatterns as npIndexPatterns } from '../../../../../plugins/data/public'; +import { dataPluginMock } from '../../../../core_plugins/data/public/mocks'; -const dataSetup = dataPluginMock.createSetupContract(); +const dataSetup = dataPluginMock.createSetup(); // mocks for stateful code -export const { indexPatterns } = dataSetup.indexPatterns!; - -export const flattenHitWrapper = npIndexPatterns.flattenHitWrapper; -export const formatHitProvider = npIndexPatterns.formatHitProvider; +export const { FieldImpl } = dataSetup.indexPatterns!.__LEGACY; +export const { + FieldList, + flattenHitWrapper, + formatHitProvider, + indexPatterns, +} = dataSetup.indexPatterns!; // 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 200276c1727fc..06001667c9e53 100644 --- a/src/legacy/ui/public/index_patterns/index.ts +++ b/src/legacy/ui/public/index_patterns/index.ts @@ -24,6 +24,14 @@ * 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 @@ -34,8 +42,6 @@ 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 { @@ -46,5 +52,3 @@ 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 c9906fb136052..54977c7e66976 100644 --- a/src/plugins/data/common/field_formats/converters/source.ts +++ b/src/plugins/data/common/field_formats/converters/source.ts @@ -20,7 +20,8 @@ import { template, escape, keys } from 'lodash'; // @ts-ignore import { noWhiteSpace } from '../../../../../legacy/core_plugins/kibana/common/utils/no_white_space'; -import { shortenDottedString } from '../../utils'; +// @ts-ignore +import { shortenDottedString } from '../../../../../legacy/core_plugins/kibana/common/utils/shorten_dotted_string'; 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 b2d92cf475a16..0edd219ca60f9 100644 --- a/src/plugins/data/common/field_formats/converters/string.ts +++ b/src/plugins/data/common/field_formats/converters/string.ts @@ -22,7 +22,8 @@ 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'; -import { shortenDottedString } from '../../utils'; +// @ts-ignore +import { shortenDottedString } from '../../../../../legacy/core_plugins/kibana/common/utils/shorten_dotted_string'; const TRANSFORM_OPTIONS = [ { diff --git a/src/plugins/data/common/index.ts b/src/plugins/data/common/index.ts index b334342a57ec6..f9bbeb5f4b3f3 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 deleted file mode 100644 index 7196c96989e97..0000000000000 --- a/src/plugins/data/common/utils/index.ts +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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 deleted file mode 100644 index 5f8d084ce5e88..0000000000000 --- a/src/plugins/data/common/utils/shorten_dotted_string.test.ts +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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/plugins/data/public/index_patterns/index.ts b/src/plugins/data/public/index_patterns/index.ts index 7492f9372e44a..aedfc18db3ade 100644 --- a/src/plugins/data/public/index_patterns/index.ts +++ b/src/plugins/data/public/index_patterns/index.ts @@ -25,8 +25,6 @@ import { ILLEGAL_CHARACTERS, validateIndexPattern, } from './lib'; -import { getRoutes, getFromSavedObject } from './utils'; -import { flattenHitWrapper, formatHitProvider } from './index_patterns'; export const indexPatterns = { ILLEGAL_CHARACTERS_KEY, @@ -35,13 +33,4 @@ 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/plugins/data/public/index_patterns/lib/get_title.ts b/src/plugins/data/public/index_patterns/lib/get_index_pattern_title.ts similarity index 96% rename from src/plugins/data/public/index_patterns/lib/get_title.ts rename to src/plugins/data/public/index_patterns/lib/get_index_pattern_title.ts index 320205f5139c9..777a12c7e2884 100644 --- a/src/plugins/data/public/index_patterns/lib/get_title.ts +++ b/src/plugins/data/public/index_patterns/lib/get_index_pattern_title.ts @@ -19,7 +19,7 @@ import { SavedObjectsClientContract, SimpleSavedObject } from '../../../../../core/public'; -export async function getTitle( +export async function getIndexPatternTitle( 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 0f667e846af91..3b87d91bb9fff 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 { getTitle } from './get_title'; +export { getIndexPatternTitle } from './get_index_pattern_title'; export * from './types'; export { validateIndexPattern } from './validate_index_pattern'; diff --git a/src/plugins/data/public/index_patterns/types.ts b/src/plugins/data/public/index_patterns/types.ts deleted file mode 100644 index 59e3075bf215d..0000000000000 --- a/src/plugins/data/public/index_patterns/types.ts +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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/plugins/data/public/mocks.ts b/src/plugins/data/public/mocks.ts index 19c21ab9934ef..ceb57b4a3a564 100644 --- a/src/plugins/data/public/mocks.ts +++ b/src/plugins/data/public/mocks.ts @@ -19,7 +19,6 @@ 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>; @@ -54,7 +53,6 @@ const createSetupContract = (): Setup => { search: searchSetupMock, fieldFormats: fieldFormatsMock as FieldFormatsSetup, query: querySetupMock, - indexPatterns: indexPatternsServiceMock.createSetupContract(), }; return setupContract; @@ -71,7 +69,6 @@ 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 c018efcad74e6..35d8edc488467 100644 --- a/src/plugins/data/public/plugin.ts +++ b/src/plugins/data/public/plugin.ts @@ -26,10 +26,8 @@ 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; @@ -56,30 +54,19 @@ 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 ad453c4e5d11d..f41024ed16191 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 { getTitle } from '../../index_patterns/lib'; +import { getIndexPatternTitle } 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 getTitle(this.props.savedObjectsClient, indexPatternId); + indexPatternTitle = await getIndexPatternTitle(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 b76da4b4eca3e..b41ebe3e61861 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/'; +import { IndexPattern } from '../../legacy/core_plugins/data/public/index_patterns/index_patterns'; 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 9a13da65e976a..b1879ec92c131 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/'; +import { IndexPattern } from 'src/legacy/core_plugins/data/public/index_patterns/index_patterns'; import { SerializedNode, UrlTemplate,