From 9dd62e10400e427db861c234af05dbdcf0ea3172 Mon Sep 17 00:00:00 2001 From: Liza Katz Date: Sun, 1 Dec 2019 15:36:59 +0200 Subject: [PATCH 1/5] Merge --- .../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 +- .../public/discover/get_inner_angular.ts | 2 +- .../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} | 115 ++---------------- .../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 +- 49 files changed, 213 insertions(+), 245 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/data/public/index_patterns/index_patterns/index_pattern.tsx => plugins/data/public/index_patterns/index_patterns/index_pattern.ts} (79%) 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 946b3997a9712..c65ae3a0ec7b9 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 833d8c248f46a..bdfedbc2c81a8 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 496c4ba7b5b6f..74981165f3e47 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 3dcab22605c07..7a4c9f139c887 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 06c5caa04ba9a..0e12790d89fed 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 e341b7c4a5a86..bad006aa8c7d5 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 797583362a8f8..42ecc0fea5f07 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 dcd25033e9d15..7972c7603d311 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/discover/get_inner_angular.ts b/src/legacy/core_plugins/kibana/public/discover/get_inner_angular.ts index 3c1d41657a1d3..8e2d15ae48a1f 100644 --- a/src/legacy/core_plugins/kibana/public/discover/get_inner_angular.ts +++ b/src/legacy/core_plugins/kibana/public/discover/get_inner_angular.ts @@ -64,7 +64,7 @@ import { KbnUrlProvider, RedirectWhenMissingProvider } from 'ui/url'; // @ts-ignore import { createTopNavDirective, createTopNavHelper } from 'ui/kbn_top_nav/kbn_top_nav'; import { configureAppAngularModule } from 'ui/legacy_compat'; -import { IndexPatterns } from '../../../data/public/index_patterns/index_patterns'; +import { IndexPatterns } from '../../../../../plugins/data/public'; import { Storage } from '../../../../../plugins/kibana_utils/public'; import { NavigationStart } from '../../../navigation/public'; import { createDocTableDirective } from './angular/doc_table/doc_table'; 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 c9ea1e12c58fd..5f0994abc11e4 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 9ff09835e48da..6f3d39299f970 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 06001667c9e53..200276c1727fc 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 54977c7e66976..c9906fb136052 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 0edd219ca60f9..b2d92cf475a16 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 f9bbeb5f4b3f3..b334342a57ec6 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 0000000000000..7196c96989e97 --- /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 0000000000000..5f8d084ce5e88 --- /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 39d1296ddf8bc..379413c0d91c8 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 91964655f6f3e..ae17188de8625 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 108aacc8e07de..ff6706cec6c34 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 aedfc18db3ade..7492f9372e44a 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 a3653bb529fa3..eb6c69b414316 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 ee9f9b493ebf2..a0a884454a3f0 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.tsx b/src/plugins/data/public/index_patterns/index_patterns/index_pattern.ts similarity index 79% rename from src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.tsx rename to src/plugins/data/public/index_patterns/index_patterns/index_pattern.ts index a90db69b85a74..2c93c0aa9dc62 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.tsx +++ b/src/plugins/data/public/index_patterns/index_patterns/index_pattern.ts @@ -19,30 +19,20 @@ import _, { each, reject } from 'lodash'; import { i18n } from '@kbn/i18n'; -import { FormattedMessage } from '@kbn/i18n/react'; -import { EuiButton, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; -import React from 'react'; -import chrome from 'ui/chrome'; import { SavedObjectsClientContract } from 'src/core/public'; - import { DuplicateField, SavedObjectNotFound, expandShorthand, FieldMappingSpec, MappingObject, -} from '../../../../../../plugins/kibana_utils/public'; -import { toMountPoint } from '../../../../../../plugins/kibana_react/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'; @@ -52,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; @@ -67,7 +52,6 @@ export class IndexPattern implements IIndexPattern { public typeMeta: any; public fields: FieldListInterface; public timeFieldName: string | undefined; - public intervalName: string | undefined | null; public formatHit: any; public formatField: any; public flattenHit: any; @@ -177,7 +161,7 @@ export class IndexPattern implements IIndexPattern { this.initFields(); } - private async updateFromElasticSearch(response: any, forceFieldRefresh: boolean = false) { + private updateFromElasticSearch(response: any, forceFieldRefresh: boolean = false) { if (!response.found) { throw new SavedObjectNotFound(type, this.id, '#/management/kibana/index_pattern'); } @@ -197,48 +181,6 @@ export class IndexPattern implements IIndexPattern { this.title = this.id; } - if (this.isUnsupportedTimePattern()) { - const warningTitle = i18n.translate('data.indexPatterns.warningTitle', { - defaultMessage: 'Support for time interval index patterns removed', - }); - - const warningText = i18n.translate('data.indexPatterns.warningText', { - defaultMessage: - 'Currently querying all indices matching {index}. {title} should be migrated to a wildcard-based index pattern.', - values: { - title: this.title, - index: this.getIndex(), - }, - }); - - // kbnUrl was added to this service in #35262 before it was de-angularized, and merged in a PR - // directly against the 7.x branch. Index patterns were de-angularized in #39247, and in order - // to preserve the functionality from #35262 we need to get the injector here just for kbnUrl. - // This has all been removed as of 8.0. - const $injector = await chrome.dangerouslyGetActiveInjector(); - const kbnUrl = $injector.get('kbnUrl') as any; // `any` because KbnUrl interface doesn't have `getRouteHref` - const { toasts } = getNotifications(); - - toasts.addWarning({ - title: warningTitle, - text: toMountPoint( -
-

{warningText}

- - - - - - - -
- ), - }); - } - return this.indexFields(forceFieldRefresh); } @@ -310,19 +252,6 @@ export class IndexPattern implements IIndexPattern { return this; } - migrate(newTitle: string) { - return this.savedObjectsClient - .update(type, this.id!, { - title: newTitle, - intervalName: null, - }) - .then(({ attributes: { title, intervalName } }) => { - this.title = title; - this.intervalName = intervalName; - }) - .then(() => this); - } - // Get the source filtering configuration for that index. getSourceFiltering() { return { @@ -358,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,29 +313,6 @@ export class IndexPattern implements IIndexPattern { return _.where(this.fields, { scripted: true }); } - getIndex() { - if (!this.isUnsupportedTimePattern()) { - return this.title; - } - - // Take a time-based interval index pattern title (like [foo-]YYYY.MM.DD[-bar]) and turn it - // into the actual index (like foo-*-bar) by replacing anything not inside square brackets - // with a *. - const regex = /\[[^\]]*]/g; // Matches text inside brackets - const splits = this.title.split(regex); // e.g. ['', 'YYYY.MM.DD', ''] from the above example - const matches = this.title.match(regex) || []; // e.g. ['[foo-]', '[-bar]'] from the above example - return splits - .map((split, i) => { - const match = i >= matches.length ? '' : matches[i].replace(/[\[\]]/g, ''); - return `${split.length ? '*' : ''}${match}`; - }) - .join(''); - } - - isUnsupportedTimePattern(): boolean { - return !!this.intervalName; - } - isTimeBased(): boolean { return !!this.timeFieldName && (!this.fields || !!this.getTimeField()); } @@ -469,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 06933dc409052..2d3e357e96819 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 87dd7a68e3061..961e519338ac4 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 db1ece78e7b4d..d38e9c76430eb 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 83738ffe5b747..40f833868847b 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 777a12c7e2884..320205f5139c9 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 3b87d91bb9fff..0f667e846af91 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 ecd898b28de63..a6844cb4c04e2 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 0000000000000..59e3075bf215d --- /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 0d0d5705a0ccc..8edb62f16bfeb 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 ceb57b4a3a564..19c21ab9934ef 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 35d8edc488467..c018efcad74e6 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 f41024ed16191..ad453c4e5d11d 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 e1cf1f9874fab..a1b463637b141 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 b1879ec92c131..9a13da65e976a 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, From e2e5ace9481749f88d84de65fd543ced66ab585f Mon Sep 17 00:00:00 2001 From: Liza K Date: Sun, 1 Dec 2019 23:48:52 +0200 Subject: [PATCH 2/5] Brought migration code back --- .../{index_pattern.ts => index_pattern.tsx} | 91 ++++++++++++++++++- 1 file changed, 90 insertions(+), 1 deletion(-) rename src/plugins/data/public/index_patterns/index_patterns/{index_pattern.ts => index_pattern.tsx} (81%) diff --git a/src/plugins/data/public/index_patterns/index_patterns/index_pattern.ts b/src/plugins/data/public/index_patterns/index_patterns/index_pattern.tsx similarity index 81% rename from src/plugins/data/public/index_patterns/index_patterns/index_pattern.ts rename to src/plugins/data/public/index_patterns/index_patterns/index_pattern.tsx index 2c93c0aa9dc62..fb3a8f598529a 100644 --- a/src/plugins/data/public/index_patterns/index_patterns/index_pattern.ts +++ b/src/plugins/data/public/index_patterns/index_patterns/index_pattern.tsx @@ -19,6 +19,10 @@ import _, { each, reject } from 'lodash'; import { i18n } from '@kbn/i18n'; +import { FormattedMessage } from '@kbn/i18n/react'; +import { EuiButton, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; +import React from 'react'; + import { SavedObjectsClientContract } from 'src/core/public'; import { DuplicateField, @@ -27,6 +31,7 @@ import { FieldMappingSpec, MappingObject, } from '../../../../kibana_utils/public'; +import { toMountPoint } from '../../../../kibana_react/public'; import { ES_FIELD_TYPES, KBN_FIELD_TYPES, IIndexPattern, IFieldType } from '../../../common'; @@ -52,6 +57,7 @@ export class IndexPattern implements IIndexPattern { public typeMeta: any; public fields: FieldListInterface; public timeFieldName: string | undefined; + public intervalName: string | undefined | null; public formatHit: any; public formatField: any; public flattenHit: any; @@ -161,7 +167,7 @@ export class IndexPattern implements IIndexPattern { this.initFields(); } - private updateFromElasticSearch(response: any, forceFieldRefresh: boolean = false) { + private async updateFromElasticSearch(response: any, forceFieldRefresh: boolean = false) { if (!response.found) { throw new SavedObjectNotFound(type, this.id, '#/management/kibana/index_pattern'); } @@ -181,6 +187,53 @@ export class IndexPattern implements IIndexPattern { this.title = this.id; } + if (this.isUnsupportedTimePattern()) { + const warningTitle = i18n.translate('data.indexPatterns.warningTitle', { + defaultMessage: 'Support for time interval index patterns removed', + }); + + const warningText = i18n.translate('data.indexPatterns.warningText', { + defaultMessage: + 'Currently querying all indices matching {index}. {title} should be migrated to a wildcard-based index pattern.', + values: { + title: this.title, + index: this.getIndex(), + }, + }); + + // kbnUrl was added to this service in #35262 before it was de-angularized, and merged in a PR + // directly against the 7.x branch. Index patterns were de-angularized in #39247, and in order + // to preserve the functionality from #35262 we need to get the injector here just for kbnUrl. + // This has all been removed as of 8.0. + + // 2019-12-01 The usage of kbnUrl had to be removed due to the transition to NP. + // It's now temporarily replaced by a simple replace of the single argument used by all URLs. + // Once kbnUrl is migrated to NP, this can be updated. + const editUrlTemplate = getRoutes().edit; + const editUrl = editUrlTemplate.replace('{{id}}', this.id!); + + const { toasts } = getNotifications(); + + toasts.addWarning({ + title: warningTitle, + text: toMountPoint( +
+

{warningText}

+ + + + + + + +
+ ), + }); + } + return this.indexFields(forceFieldRefresh); } @@ -252,6 +305,19 @@ export class IndexPattern implements IIndexPattern { return this; } + migrate(newTitle: string) { + return this.savedObjectsClient + .update(type, this.id!, { + title: newTitle, + intervalName: null, + }) + .then(({ attributes: { title, intervalName } }) => { + this.title = title; + this.intervalName = intervalName; + }) + .then(() => this); + } + // Get the source filtering configuration for that index. getSourceFiltering() { return { @@ -313,6 +379,29 @@ export class IndexPattern implements IIndexPattern { return _.where(this.fields, { scripted: true }); } + getIndex() { + if (!this.isUnsupportedTimePattern()) { + return this.title; + } + + // Take a time-based interval index pattern title (like [foo-]YYYY.MM.DD[-bar]) and turn it + // into the actual index (like foo-*-bar) by replacing anything not inside square brackets + // with a *. + const regex = /\[[^\]]*]/g; // Matches text inside brackets + const splits = this.title.split(regex); // e.g. ['', 'YYYY.MM.DD', ''] from the above example + const matches = this.title.match(regex) || []; // e.g. ['[foo-]', '[-bar]'] from the above example + return splits + .map((split, i) => { + const match = i >= matches.length ? '' : matches[i].replace(/[\[\]]/g, ''); + return `${split.length ? '*' : ''}${match}`; + }) + .join(''); + } + + isUnsupportedTimePattern(): boolean { + return !!this.intervalName; + } + isTimeBased(): boolean { return !!this.timeFieldName && (!this.fields || !!this.getTimeField()); } From 032d7230a00ae552015efaf6f56907989ab8ab63 Mon Sep 17 00:00:00 2001 From: Liza K Date: Mon, 2 Dec 2019 15:15:43 +0200 Subject: [PATCH 3/5] Add base path --- .../data/public/index_patterns/index_patterns/index_pattern.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/data/public/index_patterns/index_patterns/index_pattern.tsx b/src/plugins/data/public/index_patterns/index_patterns/index_pattern.tsx index fb3a8f598529a..0e05b11293e58 100644 --- a/src/plugins/data/public/index_patterns/index_patterns/index_pattern.tsx +++ b/src/plugins/data/public/index_patterns/index_patterns/index_pattern.tsx @@ -221,7 +221,7 @@ export class IndexPattern implements IIndexPattern {

{warningText}

- + Date: Mon, 2 Dec 2019 17:31:24 +0200 Subject: [PATCH 4/5] getHTTP --- .../public/index_patterns/index_patterns/index_pattern.tsx | 7 ++++--- .../data/public/index_patterns/index_patterns_service.ts | 3 ++- src/plugins/data/public/index_patterns/services.ts | 4 +++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/plugins/data/public/index_patterns/index_patterns/index_pattern.tsx b/src/plugins/data/public/index_patterns/index_patterns/index_pattern.tsx index 0e05b11293e58..68edb964c3f76 100644 --- a/src/plugins/data/public/index_patterns/index_patterns/index_pattern.tsx +++ b/src/plugins/data/public/index_patterns/index_patterns/index_pattern.tsx @@ -42,7 +42,7 @@ import { createFieldsFetcher } from './_fields_fetcher'; import { formatHitProvider } from './format_hit'; import { flattenHitWrapper } from './flatten_hit'; import { IIndexPatternsApiClient } from './index_patterns_api_client'; -import { getNotifications, getFieldFormats } from '../services'; +import { getNotifications, getFieldFormats, getHttp } from '../services'; const MAX_ATTEMPTS_TO_RESOLVE_CONFLICTS = 3; const type = 'index-pattern'; @@ -210,7 +210,7 @@ export class IndexPattern implements IIndexPattern { // It's now temporarily replaced by a simple replace of the single argument used by all URLs. // Once kbnUrl is migrated to NP, this can be updated. const editUrlTemplate = getRoutes().edit; - const editUrl = editUrlTemplate.replace('{{id}}', this.id!); + const editUrl = '/app/kibana#' + editUrlTemplate.replace('{{id}}', this.id!); const { toasts } = getNotifications(); @@ -221,7 +221,7 @@ export class IndexPattern implements IIndexPattern {

{warningText}

- + ( 'FieldFormats' ); + +export const [getHttp, setHttp] = createGetterSetter('Http'); From bd8b7d49a6f0b09118ec55296e0893145f15b695 Mon Sep 17 00:00:00 2001 From: Liza K Date: Mon, 2 Dec 2019 17:45:26 +0200 Subject: [PATCH 5/5] Removed return true --- .../data/public/index_patterns/index_patterns/index_pattern.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/plugins/data/public/index_patterns/index_patterns/index_pattern.tsx b/src/plugins/data/public/index_patterns/index_patterns/index_pattern.tsx index 68edb964c3f76..d45e2a5d3516e 100644 --- a/src/plugins/data/public/index_patterns/index_patterns/index_pattern.tsx +++ b/src/plugins/data/public/index_patterns/index_patterns/index_pattern.tsx @@ -399,7 +399,6 @@ export class IndexPattern implements IIndexPattern { } isUnsupportedTimePattern(): boolean { - return true; return !!this.intervalName; }