From 5a93fdb125fdddb8efb267f5aeeb5fc431b2be8f Mon Sep 17 00:00:00 2001 From: Liza Katz Date: Wed, 12 Feb 2020 10:48:05 +0200 Subject: [PATCH] Explicit index pattern namespace (#57194) (#57415) * Explicit index pattern namespace * typing of index patterns * fix ts error on master * export FieldList * Move isFilterable into indexPatterns namespace * Server index pattern cleanup * comment * isDefault * karma mock fix + discover fix Co-authored-by: Elastic Machine Co-authored-by: Elastic Machine --- .../public/search/aggs/param_types/field.ts | 12 +- .../param_types/filter/field_filters.test.ts | 8 +- .../aggs/param_types/filter/field_filters.ts | 6 +- .../public/test_utils/get_deps_mock.tsx | 5 +- .../query_parameters/action_add_filter.js | 6 - .../public/discover/get_inner_angular.ts | 8 +- .../angular/context/api/__tests__/anchor.js | 6 - .../context/api/__tests__/predecessors.js | 6 - .../components/field_chooser/field_chooser.js | 4 +- .../create_edit_field/create_edit_field.js | 9 +- .../public/components/agg_param_props.ts | 4 +- .../public/components/agg_params_helper.ts | 12 +- .../public/components/controls/field.test.tsx | 10 +- .../public/components/controls/field.tsx | 8 +- .../public/components/controls/top_field.tsx | 4 +- .../components/controls/top_sort_field.tsx | 4 +- .../timelion_expression_input_helpers.test.ts | 4 +- .../public/helpers/arg_value_suggestions.ts | 10 +- .../new_platform/new_platform.karma_mock.js | 28 ++++- src/plugins/data/public/index.ts | 103 ++++++++++++------ .../data/public/index_patterns/index.ts | 25 +---- .../index_patterns/index_pattern.tsx | 4 +- .../index_patterns/index_patterns.test.ts | 6 +- .../index_patterns/index_patterns.ts | 4 +- .../index_patterns_api_client.ts | 4 +- src/plugins/data/public/plugin.ts | 4 +- .../default_search_strategy.ts | 4 +- .../filter_editor/lib/filter_editor_utils.ts | 3 +- .../autocomplete/value_suggestions_route.ts | 10 +- src/plugins/data/server/index.ts | 54 +++++---- .../data/server/index_patterns/index.ts | 4 +- .../server/lib/get_fields.ts | 8 +- src/test_utils/public/stub_index_pattern.js | 9 +- .../services/persistence/deserialize.ts | 9 +- .../lens/public/indexpattern_plugin/loader.ts | 15 ++- .../operations/definitions/date_histogram.tsx | 4 +- .../lens/public/indexpattern_plugin/types.ts | 4 +- .../connected_components/gis_map/view.js | 4 +- .../layer_panel/join_editor/resources/join.js | 4 +- .../plugins/maps/public/index_pattern_util.js | 8 +- .../maps/public/layers/fields/es_doc_field.js | 4 +- .../update_source_editor.js | 6 +- .../es_pew_pew_source/es_pew_pew_source.js | 4 +- .../es_pew_pew_source/update_source_editor.js | 6 +- .../es_search_source/create_source_editor.js | 4 +- .../es_search_source/update_source_editor.js | 6 +- .../kql_query_suggestion/field.test.ts | 4 +- .../providers/kql_query_suggestion/field.tsx | 4 +- 48 files changed, 273 insertions(+), 209 deletions(-) diff --git a/src/legacy/core_plugins/data/public/search/aggs/param_types/field.ts b/src/legacy/core_plugins/data/public/search/aggs/param_types/field.ts index 9a204bb151e2d..40c30f6210a83 100644 --- a/src/legacy/core_plugins/data/public/search/aggs/param_types/field.ts +++ b/src/legacy/core_plugins/data/public/search/aggs/param_types/field.ts @@ -25,7 +25,11 @@ import { SavedObjectNotFound } from '../../../../../../../plugins/kibana_utils/p import { BaseParamType } from './base'; import { propFilter } from '../filter'; import { IMetricAggConfig } from '../metrics/metric_agg_type'; -import { Field, isNestedField, KBN_FIELD_TYPES } from '../../../../../../../plugins/data/public'; +import { + IndexPatternField, + indexPatterns, + KBN_FIELD_TYPES, +} from '../../../../../../../plugins/data/public'; const filterByType = propFilter('type'); @@ -72,7 +76,7 @@ export class FieldParamType extends BaseParamType { }; } - this.serialize = (field: Field) => { + this.serialize = (field: IndexPatternField) => { return field.name; }; @@ -112,11 +116,11 @@ export class FieldParamType extends BaseParamType { */ getAvailableFields = (aggConfig: IAggConfig) => { const fields = aggConfig.getIndexPattern().fields; - const filteredFields = fields.filter((field: Field) => { + const filteredFields = fields.filter((field: IndexPatternField) => { const { onlyAggregatable, scriptable, filterFieldTypes } = this; if ( - (onlyAggregatable && (!field.aggregatable || isNestedField(field))) || + (onlyAggregatable && (!field.aggregatable || indexPatterns.isNestedField(field))) || (!scriptable && field.scripted) ) { return false; diff --git a/src/legacy/core_plugins/data/public/search/aggs/param_types/filter/field_filters.test.ts b/src/legacy/core_plugins/data/public/search/aggs/param_types/filter/field_filters.test.ts index fb53e72b85c60..bc36bb46d3d16 100644 --- a/src/legacy/core_plugins/data/public/search/aggs/param_types/filter/field_filters.test.ts +++ b/src/legacy/core_plugins/data/public/search/aggs/param_types/filter/field_filters.test.ts @@ -20,7 +20,7 @@ import { IndexedArray } from 'ui/indexed_array'; import { AggTypeFieldFilters } from './field_filters'; import { AggConfig } from '../../agg_config'; -import { Field } from '../../../../../../../../plugins/data/public'; +import { IndexPatternField } from '../../../../../../../../plugins/data/public'; describe('AggTypeFieldFilters', () => { let registry: AggTypeFieldFilters; @@ -31,13 +31,13 @@ describe('AggTypeFieldFilters', () => { }); it('should filter nothing without registered filters', async () => { - const fields = [{ name: 'foo' }, { name: 'bar' }] as IndexedArray; + const fields = [{ name: 'foo' }, { name: 'bar' }] as IndexedArray; const filtered = registry.filter(fields, aggConfig); expect(filtered).toEqual(fields); }); it('should pass all fields to the registered filter', async () => { - const fields = [{ name: 'foo' }, { name: 'bar' }] as IndexedArray; + const fields = [{ name: 'foo' }, { name: 'bar' }] as IndexedArray; const filter = jest.fn(); registry.addFilter(filter); registry.filter(fields, aggConfig); @@ -46,7 +46,7 @@ describe('AggTypeFieldFilters', () => { }); it('should allow registered filters to filter out fields', async () => { - const fields = [{ name: 'foo' }, { name: 'bar' }] as IndexedArray; + const fields = [{ name: 'foo' }, { name: 'bar' }] as IndexedArray; let filtered = registry.filter(fields, aggConfig); expect(filtered).toEqual(fields); diff --git a/src/legacy/core_plugins/data/public/search/aggs/param_types/filter/field_filters.ts b/src/legacy/core_plugins/data/public/search/aggs/param_types/filter/field_filters.ts index 7d44bedafa7e1..7d1348ab5423b 100644 --- a/src/legacy/core_plugins/data/public/search/aggs/param_types/filter/field_filters.ts +++ b/src/legacy/core_plugins/data/public/search/aggs/param_types/filter/field_filters.ts @@ -16,10 +16,10 @@ * specific language governing permissions and limitations * under the License. */ -import { Field } from 'src/plugins/data/public'; +import { IndexPatternField } from 'src/plugins/data/public'; import { AggConfig } from '../../agg_config'; -type AggTypeFieldFilter = (field: Field, aggConfig: AggConfig) => boolean; +type AggTypeFieldFilter = (field: IndexPatternField, aggConfig: AggConfig) => boolean; /** * A registry to store {@link AggTypeFieldFilter} which are used to filter down @@ -45,7 +45,7 @@ class AggTypeFieldFilters { * @param aggConfig The aggConfig for which the returning list will be used. * @return A filtered list of the passed fields. */ - public filter(fields: Field[], aggConfig: AggConfig) { + public filter(fields: IndexPatternField[], aggConfig: AggConfig) { const allFilters = Array.from(this.filters); const allowedAggTypeFields = fields.filter(field => { const isAggTypeFieldAllowed = allFilters.every(filter => filter(field, aggConfig)); diff --git a/src/legacy/core_plugins/input_control_vis/public/test_utils/get_deps_mock.tsx b/src/legacy/core_plugins/input_control_vis/public/test_utils/get_deps_mock.tsx index 7b10eea3dde44..78a4ef3a5597a 100644 --- a/src/legacy/core_plugins/input_control_vis/public/test_utils/get_deps_mock.tsx +++ b/src/legacy/core_plugins/input_control_vis/public/test_utils/get_deps_mock.tsx @@ -18,13 +18,12 @@ */ import React from 'react'; -import { FieldList } from 'src/plugins/data/public'; import { InputControlVisDependencies } from '../plugin'; -const fields: FieldList = [] as any; +const fields = [] as any; fields.push({ name: 'myField' } as any); fields.getByName = (name: any) => { - return fields.find(({ name: n }) => n === name); + return fields.find(({ name: n }: { name: string }) => n === name); }; export const getDepsMock = (): InputControlVisDependencies => diff --git a/src/legacy/core_plugins/kibana/public/discover/__tests__/query_parameters/action_add_filter.js b/src/legacy/core_plugins/kibana/public/discover/__tests__/query_parameters/action_add_filter.js index f2acbf363d825..87eb283639c78 100644 --- a/src/legacy/core_plugins/kibana/public/discover/__tests__/query_parameters/action_add_filter.js +++ b/src/legacy/core_plugins/kibana/public/discover/__tests__/query_parameters/action_add_filter.js @@ -21,7 +21,6 @@ import expect from '@kbn/expect'; import ngMock from 'ng_mock'; import { createStateStub } from './_utils'; import { getQueryParameterActions } from '../../np_ready/angular/context/query_parameters/actions'; -import { createIndexPatternsStub } from '../../np_ready/angular/context/api/__tests__/_stubs'; import { pluginInstance } from 'plugins/kibana/discover/legacy'; import { npStart } from 'ui/new_platform'; @@ -29,11 +28,6 @@ describe('context app', function() { beforeEach(() => pluginInstance.initializeInnerAngular()); beforeEach(() => pluginInstance.initializeServices()); beforeEach(ngMock.module('app/discover')); - beforeEach( - ngMock.module(function createServiceStubs($provide) { - $provide.value('indexPatterns', createIndexPatternsStub()); - }) - ); describe('action addFilter', function() { let addFilter; 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 eb6d7e6467f2f..373395c86636c 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 @@ -39,7 +39,7 @@ import { StateManagementConfigProvider } from 'ui/state_management/config_provid import { KbnUrlProvider, RedirectWhenMissingProvider } from 'ui/url'; // @ts-ignore import { createTopNavDirective, createTopNavHelper } from 'ui/kbn_top_nav/kbn_top_nav'; -import { IndexPatterns, DataPublicPluginStart } from '../../../../../plugins/data/public'; +import { DataPublicPluginStart } from '../../../../../plugins/data/public'; import { Storage } from '../../../../../plugins/kibana_utils/public'; import { NavigationPublicPluginStart as NavigationStart } from '../../../../../plugins/navigation/public'; import { createDocTableDirective } from './np_ready/angular/doc_table/doc_table'; @@ -125,7 +125,6 @@ export function initializeInnerAngularModule( createLocalAppStateModule(); createLocalStorageModule(); createElasticSearchModule(data); - createIndexPatternsModule(); createPagerFactoryModule(); createDocTableModule(); initialized = true; @@ -164,7 +163,6 @@ export function initializeInnerAngularModule( 'discoverGlobalState', 'discoverAppState', 'discoverLocalStorageProvider', - 'discoverIndexPatterns', 'discoverEs', 'discoverDocTable', 'discoverPagerFactory', @@ -299,10 +297,6 @@ function createElasticSearchModule(data: DataPublicPluginStart) { }); } -function createIndexPatternsModule() { - angular.module('discoverIndexPatterns', []).value('indexPatterns', IndexPatterns); -} - function createPagerFactoryModule() { angular.module('discoverPagerFactory', []).factory('pagerFactory', createPagerFactory); } diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/__tests__/anchor.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/__tests__/anchor.js index debcccebbd11c..63834fb750e21 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/__tests__/anchor.js +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/__tests__/anchor.js @@ -33,12 +33,6 @@ describe('context app', function() { let fetchAnchor; let searchSourceStub; - beforeEach( - ngMock.module(function createServiceStubs($provide) { - $provide.value('indexPatterns', createIndexPatternsStub()); - }) - ); - beforeEach( ngMock.inject(function createPrivateStubs() { searchSourceStub = createSearchSourceStub([{ _id: 'hit1' }]); diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/__tests__/predecessors.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/__tests__/predecessors.js index c24b6ac6307ff..02d998e8f4529 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/__tests__/predecessors.js +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/context/api/__tests__/predecessors.js @@ -41,12 +41,6 @@ describe('context app', function() { let fetchPredecessors; let searchSourceStub; - beforeEach( - ngMock.module(function createServiceStubs($provide) { - $provide.value('indexPatterns', createIndexPatternsStub()); - }) - ); - beforeEach( ngMock.inject(function createPrivateStubs() { searchSourceStub = createContextSearchSourceStub([], '@timestamp', MS_PER_DAY * 8); diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/field_chooser.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/field_chooser.js index 47b3ec6b07e8e..a175a1aebebdf 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/field_chooser.js +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/field_chooser.js @@ -23,8 +23,8 @@ import { fieldCalculator } from './lib/field_calculator'; import './discover_field'; import './discover_field_search_directive'; import './discover_index_pattern_directive'; -import { FieldList } from '../../../../../../../../plugins/data/public'; import fieldChooserTemplate from './field_chooser.html'; +import { IndexPatternFieldList } from '../../../../../../../../plugins/data/public'; export function createFieldChooserDirective($location, config, $route) { return { @@ -281,7 +281,7 @@ export function createFieldChooserDirective($location, config, $route) { }); }); - const fields = new FieldList(indexPattern, fieldSpecs); + const fields = new IndexPatternFieldList(indexPattern, fieldSpecs); if (prevFields) { fields.forEach(function(field) { 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 b74ceda5a6df8..0dcf778a5a662 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,7 @@ * under the License. */ -import { Field } from '../../../../../../../../../plugins/data/public'; +import { IndexPatternField } from '../../../../../../../../../plugins/data/public'; import { RegistryFieldFormatEditorsProvider } from 'ui/registry/field_format_editors'; import { docTitle } from 'ui/doc_title'; import { KbnUrlProvider } from 'ui/url'; @@ -39,7 +39,7 @@ const renderFieldEditor = ( $scope, indexPattern, field, - { Field, getConfig, $http, fieldFormatEditors, redirectAway } + { getConfig, $http, fieldFormatEditors, redirectAway } ) => { $scope.$$postDigest(() => { const node = document.getElementById(REACT_FIELD_EDITOR_ID); @@ -53,7 +53,7 @@ const renderFieldEditor = ( indexPattern={indexPattern} field={field} helpers={{ - Field, + Field: IndexPatternField, getConfig, $http, fieldFormatEditors, @@ -135,7 +135,7 @@ uiRoutes return; } } else if (this.mode === 'create') { - this.field = new Field(this.indexPattern, { + this.field = new IndexPatternField(this.indexPattern, { scripted: true, type: 'number', }); @@ -158,7 +158,6 @@ uiRoutes docTitle.change([fieldName, this.indexPattern.title]); renderFieldEditor($scope, this.indexPattern, this.field, { - Field, getConfig, $http, fieldFormatEditors, diff --git a/src/legacy/core_plugins/vis_default_editor/public/components/agg_param_props.ts b/src/legacy/core_plugins/vis_default_editor/public/components/agg_param_props.ts index c858fb62045ca..843cfddc07010 100644 --- a/src/legacy/core_plugins/vis_default_editor/public/components/agg_param_props.ts +++ b/src/legacy/core_plugins/vis_default_editor/public/components/agg_param_props.ts @@ -17,7 +17,7 @@ * under the License. */ -import { Field } from 'src/plugins/data/public'; +import { IndexPatternField } from 'src/plugins/data/public'; import { VisState } from 'src/legacy/core_plugins/visualizations/public'; import { IAggConfig, AggParam } from '../legacy_imports'; import { ComboBoxGroupedOptions } from '../utils'; @@ -33,7 +33,7 @@ export interface AggParamCommonProps { disabled?: boolean; editorConfig: EditorConfig; formIsTouched: boolean; - indexedFields?: ComboBoxGroupedOptions; + indexedFields?: ComboBoxGroupedOptions; showValidation: boolean; state: VisState; value?: T; diff --git a/src/legacy/core_plugins/vis_default_editor/public/components/agg_params_helper.ts b/src/legacy/core_plugins/vis_default_editor/public/components/agg_params_helper.ts index 124c41a50c0df..0c0726ec67d50 100644 --- a/src/legacy/core_plugins/vis_default_editor/public/components/agg_params_helper.ts +++ b/src/legacy/core_plugins/vis_default_editor/public/components/agg_params_helper.ts @@ -19,7 +19,7 @@ import { get, isEmpty } from 'lodash'; -import { IndexPattern, Field } from 'src/plugins/data/public'; +import { IndexPattern, IndexPatternField } from 'src/plugins/data/public'; import { VisState } from 'src/legacy/core_plugins/visualizations/public'; import { groupAndSortBy, ComboBoxGroupedOptions } from '../utils'; import { AggTypeState, AggParamsState } from './agg_params_state'; @@ -45,7 +45,7 @@ interface ParamInstanceBase { export interface ParamInstance extends ParamInstanceBase { aggParam: AggParam; - indexedFields: ComboBoxGroupedOptions; + indexedFields: ComboBoxGroupedOptions; paramEditor: React.ComponentType>; value: unknown; } @@ -65,15 +65,17 @@ function getAggParamsToRender({ agg, editorConfig, metricAggs, state }: ParamIns // build collection of agg params components paramsToRender.forEach((param: AggParam, index: number) => { - let indexedFields: ComboBoxGroupedOptions = []; - let fields: Field[]; + let indexedFields: ComboBoxGroupedOptions = []; + let fields: IndexPatternField[]; if (agg.schema.hideCustomLabel && param.name === 'customLabel') { return; } // if field param exists, compute allowed fields if (param.type === 'field') { - const availableFields: Field[] = (param as IFieldParamType).getAvailableFields(agg); + const availableFields: IndexPatternField[] = (param as IFieldParamType).getAvailableFields( + agg + ); fields = aggTypeFieldFilters.filter(availableFields, agg); indexedFields = groupAndSortBy(fields, 'type', 'name'); diff --git a/src/legacy/core_plugins/vis_default_editor/public/components/controls/field.test.tsx b/src/legacy/core_plugins/vis_default_editor/public/components/controls/field.test.tsx index 636ef8f872d0e..89d39a0605b60 100644 --- a/src/legacy/core_plugins/vis_default_editor/public/components/controls/field.test.tsx +++ b/src/legacy/core_plugins/vis_default_editor/public/components/controls/field.test.tsx @@ -22,7 +22,7 @@ import { act } from 'react-dom/test-utils'; import { mount, shallow, ReactWrapper } from 'enzyme'; import { EuiComboBoxProps, EuiComboBox } from '@elastic/eui'; -import { Field } from 'src/plugins/data/public'; +import { IndexPatternField } from 'src/plugins/data/public'; import { VisState } from 'src/legacy/core_plugins/visualizations/public'; import { ComboBoxGroupedOptions } from '../../utils'; import { FieldParamEditor, FieldParamEditorProps } from './field'; @@ -41,11 +41,11 @@ describe('FieldParamEditor component', () => { let setTouched: jest.Mock; let onChange: jest.Mock; let defaultProps: FieldParamEditorProps; - let indexedFields: ComboBoxGroupedOptions; - let field: Field; + let indexedFields: ComboBoxGroupedOptions; + let field: IndexPatternField; let option: { label: string; - target: Field; + target: IndexPatternField; }; beforeEach(() => { @@ -54,7 +54,7 @@ describe('FieldParamEditor component', () => { setTouched = jest.fn(); onChange = jest.fn(); - field = { displayName: 'bytes' } as Field; + field = { displayName: 'bytes' } as IndexPatternField; option = { label: 'bytes', target: field }; indexedFields = [ { diff --git a/src/legacy/core_plugins/vis_default_editor/public/components/controls/field.tsx b/src/legacy/core_plugins/vis_default_editor/public/components/controls/field.tsx index f374353afabec..8bf7bc384b07a 100644 --- a/src/legacy/core_plugins/vis_default_editor/public/components/controls/field.tsx +++ b/src/legacy/core_plugins/vis_default_editor/public/components/controls/field.tsx @@ -23,7 +23,7 @@ import React, { useEffect } from 'react'; import { EuiComboBox, EuiComboBoxOptionProps, EuiFormRow } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; -import { Field } from 'src/plugins/data/public'; +import { IndexPatternField } from 'src/plugins/data/public'; import { AggParam, IAggConfig, IFieldParamType } from '../../legacy_imports'; import { formatListAsProse, parseCommaSeparatedList, useValidation } from './utils'; import { AggParamEditorProps } from '../agg_param_props'; @@ -33,7 +33,7 @@ const label = i18n.translate('visDefaultEditor.controls.field.fieldLabel', { defaultMessage: 'Field', }); -export interface FieldParamEditorProps extends AggParamEditorProps { +export interface FieldParamEditorProps extends AggParamEditorProps { customError?: string; customLabel?: string; } @@ -50,12 +50,12 @@ function FieldParamEditor({ setValidity, setValue, }: FieldParamEditorProps) { - const selectedOptions: ComboBoxGroupedOptions = value + const selectedOptions: ComboBoxGroupedOptions = value ? [{ label: value.displayName || value.name, target: value }] : []; const onChange = (options: EuiComboBoxOptionProps[]) => { - const selectedOption: Field = get(options, '0.target'); + const selectedOption: IndexPatternField = get(options, '0.target'); if (!(aggParam.required && !selectedOption)) { setValue(selectedOption); } diff --git a/src/legacy/core_plugins/vis_default_editor/public/components/controls/top_field.tsx b/src/legacy/core_plugins/vis_default_editor/public/components/controls/top_field.tsx index 6811f6b4c2034..f625fe3c75c8a 100644 --- a/src/legacy/core_plugins/vis_default_editor/public/components/controls/top_field.tsx +++ b/src/legacy/core_plugins/vis_default_editor/public/components/controls/top_field.tsx @@ -20,12 +20,12 @@ import React from 'react'; import { i18n } from '@kbn/i18n'; -import { Field } from 'src/plugins/data/public'; +import { IndexPatternField } from 'src/plugins/data/public'; import { FieldParamEditor } from './field'; import { getCompatibleAggs } from './top_aggregate'; import { AggParamEditorProps } from '../agg_param_props'; -function TopFieldParamEditor(props: AggParamEditorProps) { +function TopFieldParamEditor(props: AggParamEditorProps) { const compatibleAggs = getCompatibleAggs(props.agg); let customError; diff --git a/src/legacy/core_plugins/vis_default_editor/public/components/controls/top_sort_field.tsx b/src/legacy/core_plugins/vis_default_editor/public/components/controls/top_sort_field.tsx index 6ca030d05b604..1e5a4e187f19a 100644 --- a/src/legacy/core_plugins/vis_default_editor/public/components/controls/top_sort_field.tsx +++ b/src/legacy/core_plugins/vis_default_editor/public/components/controls/top_sort_field.tsx @@ -20,11 +20,11 @@ import React from 'react'; import { i18n } from '@kbn/i18n'; -import { Field } from 'src/plugins/data/public'; +import { IndexPatternField } from 'src/plugins/data/public'; import { FieldParamEditor } from './field'; import { AggParamEditorProps } from '../agg_param_props'; -function TopSortFieldParamEditor(props: AggParamEditorProps) { +function TopSortFieldParamEditor(props: AggParamEditorProps) { const customLabel = i18n.translate('visDefaultEditor.controls.sortOnLabel', { defaultMessage: 'Sort on', }); diff --git a/src/legacy/core_plugins/vis_type_timelion/public/components/timelion_expression_input_helpers.test.ts b/src/legacy/core_plugins/vis_type_timelion/public/components/timelion_expression_input_helpers.test.ts index cf40d2f791fc2..2f99256e2a192 100644 --- a/src/legacy/core_plugins/vis_type_timelion/public/components/timelion_expression_input_helpers.test.ts +++ b/src/legacy/core_plugins/vis_type_timelion/public/components/timelion_expression_input_helpers.test.ts @@ -20,12 +20,12 @@ import { SUGGESTION_TYPE, suggest } from './timelion_expression_input_helpers'; import { getArgValueSuggestions } from '../helpers/arg_value_suggestions'; import { setIndexPatterns, setSavedObjectsClient } from '../helpers/plugin_services'; -import { IndexPatterns } from 'src/plugins/data/public'; +import { IndexPatternsContract } from 'src/plugins/data/public'; import { SavedObjectsClient } from 'kibana/public'; import { ITimelionFunction } from '../../../../../plugins/timelion/common/types'; describe('Timelion expression suggestions', () => { - setIndexPatterns({} as IndexPatterns); + setIndexPatterns({} as IndexPatternsContract); setSavedObjectsClient({} as SavedObjectsClient); const argValueSuggestions = getArgValueSuggestions(); diff --git a/src/legacy/core_plugins/vis_type_timelion/public/helpers/arg_value_suggestions.ts b/src/legacy/core_plugins/vis_type_timelion/public/helpers/arg_value_suggestions.ts index 56562121397ce..95e01f9c8db5b 100644 --- a/src/legacy/core_plugins/vis_type_timelion/public/helpers/arg_value_suggestions.ts +++ b/src/legacy/core_plugins/vis_type_timelion/public/helpers/arg_value_suggestions.ts @@ -20,7 +20,7 @@ import { get } from 'lodash'; import { getIndexPatterns, getSavedObjectsClient } from './plugin_services'; import { TimelionFunctionArgs } from '../../../../../plugins/timelion/common/types'; -import { isNestedField } from '../../../../../plugins/data/public'; +import { indexPatterns as indexPatternsUtils } from '../../../../../plugins/data/public'; export interface Location { min: number; @@ -122,7 +122,7 @@ export function getArgValueSuggestions() { field.aggregatable && 'number' === field.type && containsFieldName(valueSplit[1], field) && - !isNestedField(field) + !indexPatternsUtils.isNestedField(field) ); }) .map(field => { @@ -141,7 +141,7 @@ export function getArgValueSuggestions() { field.aggregatable && ['number', 'boolean', 'date', 'ip', 'string'].includes(field.type) && containsFieldName(partial, field) && - !isNestedField(field) + !indexPatternsUtils.isNestedField(field) ); }) .map(field => { @@ -157,7 +157,9 @@ export function getArgValueSuggestions() { return indexPattern.fields .filter(field => { return ( - 'date' === field.type && containsFieldName(partial, field) && !isNestedField(field) + 'date' === field.type && + containsFieldName(partial, field) && + !indexPatternsUtils.isNestedField(field) ); }) .map(field => { diff --git a/src/legacy/ui/public/new_platform/new_platform.karma_mock.js b/src/legacy/ui/public/new_platform/new_platform.karma_mock.js index 47ef690c4f83e..4e52f6f6bafec 100644 --- a/src/legacy/ui/public/new_platform/new_platform.karma_mock.js +++ b/src/legacy/ui/public/new_platform/new_platform.karma_mock.js @@ -25,6 +25,11 @@ import { ComponentRegistry } from '../../../../../src/plugins/advanced_settings/ const mockObservable = () => { return { subscribe: () => {}, + pipe: () => { + return { + subscribe: () => {}, + }; + }, }; }; @@ -95,9 +100,17 @@ export const npSetup = { getProvider: sinon.fake(), }, query: { - filterManager: sinon.fake(), + filterManager: { + getGlobalFilters: sinon.fake(), + getUpdates$: mockObservable, + }, timefilter: { - timefilter: sinon.fake(), + timefilter: { + getTime: sinon.fake(), + getRefreshInterval: sinon.fake(), + getTimeUpdate$: mockObservable, + getRefreshIntervalUpdate$: mockObservable, + }, history: sinon.fake(), }, savedQueries: { @@ -226,7 +239,15 @@ export const npStart = { getProvider: sinon.fake(), }, getSuggestions: sinon.fake(), - indexPatterns: sinon.fake(), + indexPatterns: { + get: sinon.spy(indexPatternId => + Promise.resolve({ + id: indexPatternId, + isTimeNanosBased: () => false, + popularizeField: () => {}, + }) + ), + }, ui: { IndexPatternSelect: mockComponent, SearchBar: mockComponent, @@ -316,6 +337,7 @@ export const npStart = { }, home: { featureCatalogue: { + get: sinon.fake(), register: sinon.fake(), }, environment: { diff --git a/src/plugins/data/public/index.ts b/src/plugins/data/public/index.ts index 0a6b4e38babd0..14a5d8641bcb8 100644 --- a/src/plugins/data/public/index.ts +++ b/src/plugins/data/public/index.ts @@ -20,7 +20,7 @@ import { PluginInitializerContext } from '../../../core/public'; /* - * esQuery and esKuery helper namespaces: + * esQuery and esKuery: */ import { @@ -50,8 +50,10 @@ export const esQuery = { decorateQuery, }; +export { EsQueryConfig, KueryNode } from '../common'; + /* - * Field Formatters helper namespace: + * Field Formatters: */ import { @@ -104,39 +106,72 @@ export const fieldFormats = { TruncateFormat, }; -export function plugin(initializerContext: PluginInitializerContext) { - return new DataPublicPlugin(initializerContext); -} +export { + IFieldFormat, + IFieldFormatsRegistry, + FieldFormatsContentType, + FieldFormatsGetConfigFn, + FieldFormatConfig, + FieldFormatId, +} from '../common'; -/** - * Types to be shared externally - * @public +/* + * Index patterns: */ -export { IRequestTypesMap, IResponseTypesMap } from './search'; -export * from './types'; + +import { isNestedField, isFilterable } from '../common'; + +import { + ILLEGAL_CHARACTERS_KEY, + CONTAINS_SPACES_KEY, + ILLEGAL_CHARACTERS_VISIBLE, + ILLEGAL_CHARACTERS, + isDefault, + validateIndexPattern, + getFromSavedObject, + flattenHitWrapper, + getRoutes, + formatHitProvider, +} from './index_patterns'; + +export const indexPatterns = { + ILLEGAL_CHARACTERS_KEY, + CONTAINS_SPACES_KEY, + ILLEGAL_CHARACTERS_VISIBLE, + ILLEGAL_CHARACTERS, + isDefault, + isFilterable, + isNestedField, + validate: validateIndexPattern, + getFromSavedObject, + flattenHitWrapper, + // exported only in stub_index_pattern test. Move into data plugin and remove export. + getRoutes, + formatHitProvider, +}; + +export { + IndexPatternsContract, + IndexPattern, + Field as IndexPatternField, + TypeMeta as IndexPatternTypeMeta, + AggregationRestrictions as IndexPatternAggRestrictions, + // exported only in stub_index_pattern test. Move into data plugin and remove export. + FieldList as IndexPatternFieldList, +} from './index_patterns'; + export { - EsQueryConfig, - // index patterns IIndexPattern, IFieldType, IFieldSubType, - // kbn field types ES_FIELD_TYPES, KBN_FIELD_TYPES, - // query - Query, - // timefilter - RefreshInterval, - TimeRange, - // Field Formats - IFieldFormat, - IFieldFormatsRegistry, - FieldFormatsContentType, - FieldFormatsGetConfigFn, - FieldFormatConfig, - FieldFormatId, } from '../common'; +/* + * Autocomplete query suggestions: + */ + export { QuerySuggestion, QuerySuggestionTypes, @@ -146,8 +181,18 @@ export { QuerySuggestionField, } from './autocomplete'; -export * from './field_formats'; -export * from './index_patterns'; +export function plugin(initializerContext: PluginInitializerContext) { + return new DataPublicPlugin(initializerContext); +} + +/** + * Types to be shared externally + * @public + */ +export { IRequestTypesMap, IResponseTypesMap } from './search'; +export * from './types'; +export { Query, RefreshInterval, TimeRange } from '../common'; + export * from './search'; export * from './query'; export * from './ui'; @@ -155,16 +200,12 @@ export * from './field_formats'; export { // es query esFilters, - KueryNode, - // index patterns - isFilterable, // kbn field types castEsToKbnFieldTypeName, getKbnFieldType, getKbnTypeNames, // utils parseInterval, - isNestedField, } from '../common'; // Export plugin after all other imports diff --git a/src/plugins/data/public/index_patterns/index.ts b/src/plugins/data/public/index_patterns/index.ts index ecddd893d1a54..dcf799184b01c 100644 --- a/src/plugins/data/public/index_patterns/index.ts +++ b/src/plugins/data/public/index_patterns/index.ts @@ -17,40 +17,25 @@ * under the License. */ -import { +export { ILLEGAL_CHARACTERS_KEY, CONTAINS_SPACES_KEY, ILLEGAL_CHARACTERS_VISIBLE, ILLEGAL_CHARACTERS, - IndexPatternMissingIndices, validateIndexPattern, getFromSavedObject, isDefault, } from './lib'; -import { getRoutes } from './utils'; -import { flattenHitWrapper, formatHitProvider } from './index_patterns'; - -export const indexPatterns = { - ILLEGAL_CHARACTERS_KEY, - CONTAINS_SPACES_KEY, - ILLEGAL_CHARACTERS_VISIBLE, - ILLEGAL_CHARACTERS, - IndexPatternMissingIndices, - validate: validateIndexPattern, - getRoutes, - getFromSavedObject, - flattenHitWrapper, - formatHitProvider, - isDefault, -}; +export { getRoutes } from './utils'; +export { flattenHitWrapper, formatHitProvider } from './index_patterns'; export { Field, FieldList } from './fields'; // TODO: figure out how to replace IndexPatterns in get_inner_angular. export { - IndexPattern, - IndexPatterns, + IndexPatternsService, IndexPatternsContract, + IndexPattern, TypeMeta, AggregationRestrictions, } from './index_patterns'; 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 26ed35974b605..1bb76f395b3b5 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 @@ -36,7 +36,7 @@ import { toMountPoint } from '../../../../kibana_react/public'; import { ES_FIELD_TYPES, KBN_FIELD_TYPES, IIndexPattern, IFieldType } from '../../../common'; import { findByTitle, getRoutes } from '../utils'; -import { indexPatterns } from '../'; +import { IndexPatternMissingIndices } from '../lib'; import { Field, FieldList, IFieldList } from '../fields'; import { createFieldsFetcher } from './_fields_fetcher'; import { formatHitProvider } from './format_hit'; @@ -578,7 +578,7 @@ export class IndexPattern implements IIndexPattern { // so do not rethrow the error here const { toasts } = getNotifications(); - if (err instanceof indexPatterns.IndexPatternMissingIndices) { + if (err instanceof IndexPatternMissingIndices) { toasts.addDanger((err as any).message); return []; diff --git a/src/plugins/data/public/index_patterns/index_patterns/index_patterns.test.ts b/src/plugins/data/public/index_patterns/index_patterns/index_patterns.test.ts index f21a1610f29e2..c429431b632bd 100644 --- a/src/plugins/data/public/index_patterns/index_patterns/index_patterns.test.ts +++ b/src/plugins/data/public/index_patterns/index_patterns/index_patterns.test.ts @@ -18,7 +18,7 @@ */ // eslint-disable-next-line max-classes-per-file -import { IndexPatterns } from './index_patterns'; +import { IndexPatternsService } from './index_patterns'; import { SavedObjectsClientContract, IUiSettingsClient, @@ -49,7 +49,7 @@ jest.mock('./index_patterns_api_client', () => { }); describe('IndexPatterns', () => { - let indexPatterns: IndexPatterns; + let indexPatterns: IndexPatternsService; let savedObjectsClient: SavedObjectsClientContract; beforeEach(() => { @@ -64,7 +64,7 @@ describe('IndexPatterns', () => { const uiSettings = {} as IUiSettingsClient; const http = {} as HttpSetup; - indexPatterns = new IndexPatterns(uiSettings, savedObjectsClient, http); + indexPatterns = new IndexPatternsService(uiSettings, savedObjectsClient, http); }); test('does cache gets for the same id', async () => { diff --git a/src/plugins/data/public/index_patterns/index_patterns/index_patterns.ts b/src/plugins/data/public/index_patterns/index_patterns/index_patterns.ts index 2c93ed7fb79bf..5f95b101302ef 100644 --- a/src/plugins/data/public/index_patterns/index_patterns/index_patterns.ts +++ b/src/plugins/data/public/index_patterns/index_patterns/index_patterns.ts @@ -32,7 +32,7 @@ const indexPatternCache = createIndexPatternCache(); type IndexPatternCachedFieldType = 'id' | 'title'; -export class IndexPatterns { +export class IndexPatternsService { private config: IUiSettingsClient; private savedObjectsClient: SavedObjectsClientContract; private savedObjectsCache?: Array>> | null; @@ -150,4 +150,4 @@ export class IndexPatterns { }; } -export type IndexPatternsContract = PublicMethodsOf; +export type IndexPatternsContract = PublicMethodsOf; diff --git a/src/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 index 52d18170168d4..4d4e8d8827b48 100644 --- a/src/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 { HttpSetup } from 'src/core/public'; -import { indexPatterns } from '../'; +import { IndexPatternMissingIndices } from '../lib'; const API_BASE_URL: string = `/api/index_patterns/`; @@ -46,7 +46,7 @@ export class IndexPatternsApiClient { }) .catch((resp: any) => { if (resp.body.statusCode === 404 && resp.body.statuscode === 'no_matching_indices') { - throw new indexPatterns.IndexPatternMissingIndices(resp.body.message); + throw new IndexPatternMissingIndices(resp.body.message); } throw new Error(resp.body.message || resp.body.error || `${resp.body.statusCode} Response`); diff --git a/src/plugins/data/public/plugin.ts b/src/plugins/data/public/plugin.ts index 8a45d9fc2f23b..560f415eb082a 100644 --- a/src/plugins/data/public/plugin.ts +++ b/src/plugins/data/public/plugin.ts @@ -36,7 +36,7 @@ import { SearchService } from './search/search_service'; import { FieldFormatsService } from './field_formats'; import { QueryService } from './query'; import { createIndexPatternSelect } from './ui/index_pattern_select'; -import { IndexPatterns } from './index_patterns'; +import { IndexPatternsService } from './index_patterns'; import { setNotifications, setFieldFormats, @@ -90,7 +90,7 @@ export class DataPublicPlugin implements Plugin { - return indexPattern && indexPatterns.isDefault(indexPattern); + return indexPattern && isDefault(indexPattern); }, }; diff --git a/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_editor_utils.ts b/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_editor_utils.ts index 422ffb162125d..dbf84a6b546c9 100644 --- a/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_editor_utils.ts +++ b/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_editor_utils.ts @@ -20,7 +20,8 @@ import dateMath from '@elastic/datemath'; import { Ipv4Address } from '../../../../../../kibana_utils/public'; import { FILTER_OPERATORS, Operator } from './filter_operators'; -import { esFilters, IIndexPattern, IFieldType, isFilterable } from '../../../..'; +import { esFilters } from '../../../..'; +import { isFilterable, IIndexPattern, IFieldType } from '../../../../../common'; export function getFieldFromFilter(filter: esFilters.FieldFilter, indexPattern: IIndexPattern) { return indexPattern.fields.find(field => field.name === filter.meta.key); diff --git a/src/plugins/data/server/autocomplete/value_suggestions_route.ts b/src/plugins/data/server/autocomplete/value_suggestions_route.ts index b415e83becf93..c49b62f407da7 100644 --- a/src/plugins/data/server/autocomplete/value_suggestions_route.ts +++ b/src/plugins/data/server/autocomplete/value_suggestions_route.ts @@ -21,7 +21,8 @@ import { get, map } from 'lodash'; import { schema } from '@kbn/config-schema'; import { IRouter } from 'kibana/server'; -import { IFieldType, indexPatterns, esFilters } from '../index'; +import { IFieldType, esFilters } from '../index'; +import { findIndexPatternById, getFieldByName } from '../index_patterns'; export function registerValueSuggestionsRoute(router: IRouter) { router.post( @@ -55,12 +56,9 @@ export function registerValueSuggestionsRoute(router: IRouter) { terminate_after: await uiSettings.get('kibana.autocompleteTerminateAfter'), }; - const indexPattern = await indexPatterns.findIndexPatternById( - context.core.savedObjects.client, - index - ); + const indexPattern = await findIndexPatternById(context.core.savedObjects.client, index); - const field = indexPattern && indexPatterns.getFieldByName(fieldName, indexPattern); + const field = indexPattern && getFieldByName(fieldName, indexPattern); const body = await getBody(autocompleteSearchOptions, field || fieldName, query, boolFilter); try { diff --git a/src/plugins/data/server/index.ts b/src/plugins/data/server/index.ts index cadb56da395d0..02e69c610af43 100644 --- a/src/plugins/data/server/index.ts +++ b/src/plugins/data/server/index.ts @@ -21,7 +21,7 @@ import { PluginInitializerContext } from '../../../core/server'; import { DataServerPlugin, DataPluginSetup, DataPluginStart } from './plugin'; /* - * esQuery and esKuery helper namespaces: + * esQuery and esKuery: */ import { @@ -43,8 +43,10 @@ export const esQuery = { buildEsQuery, }; +export { EsQueryConfig, KueryNode } from '../common'; + /* - * Field Formatters helper namespace: + * Field Formats: */ import { @@ -87,6 +89,34 @@ export const fieldFormats = { StringFormat, TruncateFormat, }; + +export { IFieldFormatsRegistry, FieldFormatsGetConfigFn, FieldFormatConfig } from '../common'; + +/* + * Index patterns: + */ + +import { isNestedField, isFilterable } from '../common'; + +export const indexPatterns = { + isFilterable, + isNestedField, +}; + +export { + IndexPatternsFetcher, + FieldDescriptor as IndexPatternFieldDescriptor, + shouldReadFieldFromDocValues, // used only in logstash_fields fixture +} from './index_patterns'; + +export { + IIndexPattern, + IFieldType, + IFieldSubType, + ES_FIELD_TYPES, + KBN_FIELD_TYPES, +} from '../common'; + export function plugin(initializerContext: PluginInitializerContext) { return new DataServerPlugin(initializerContext); } @@ -98,22 +128,12 @@ export function plugin(initializerContext: PluginInitializerContext) { export { IRequestTypesMap, IResponseTypesMap } from './search'; export { - EsQueryConfig, // es query esFilters, - KueryNode, // kbn field types castEsToKbnFieldTypeName, getKbnFieldType, getKbnTypeNames, - // index patterns - IIndexPattern, - isFilterable, - IFieldType, - IFieldSubType, - // kbn field types - ES_FIELD_TYPES, - KBN_FIELD_TYPES, // query Query, // timefilter @@ -121,22 +141,12 @@ export { TimeRange, // utils parseInterval, - isNestedField, - IFieldFormatsRegistry, - FieldFormatsGetConfigFn, - FieldFormatConfig, } from '../common'; /** * Static code to be shared externally * @public */ -export { - IndexPatternsFetcher, - FieldDescriptor, - shouldReadFieldFromDocValues, - indexPatterns, -} from './index_patterns'; export * from './search'; diff --git a/src/plugins/data/server/index_patterns/index.ts b/src/plugins/data/server/index_patterns/index.ts index b303ae30ea810..33a37b28dedcf 100644 --- a/src/plugins/data/server/index_patterns/index.ts +++ b/src/plugins/data/server/index_patterns/index.ts @@ -16,8 +16,6 @@ * specific language governing permissions and limitations * under the License. */ -import * as indexPatterns from './utils'; - +export * from './utils'; export { IndexPatternsFetcher, FieldDescriptor, shouldReadFieldFromDocValues } from './fetcher'; export { IndexPatternsService } from './index_patterns_service'; -export { indexPatterns }; diff --git a/src/plugins/vis_type_timeseries/server/lib/get_fields.ts b/src/plugins/vis_type_timeseries/server/lib/get_fields.ts index 8eca30dae7773..33b88c9385ecb 100644 --- a/src/plugins/vis_type_timeseries/server/lib/get_fields.ts +++ b/src/plugins/vis_type_timeseries/server/lib/get_fields.ts @@ -22,9 +22,9 @@ import { KibanaRequest, RequestHandlerContext } from 'kibana/server'; // @ts-ignore import { getIndexPatternObject } from './vis_data/helpers/get_index_pattern'; -import { isNestedField } from '../../../data/server'; +import { indexPatterns } from '../../../data/server'; import { Framework } from '../plugin'; -import { FieldDescriptor, IndexPatternsFetcher } from '../../../data/server'; +import { IndexPatternFieldDescriptor, IndexPatternsFetcher } from '../../../data/server'; import { ReqFacade } from './search_strategies/strategies/abstract_search_strategy'; export async function getFields( @@ -83,7 +83,9 @@ export async function getFields( reqFacade, indexPatternString, capabilities - )) as FieldDescriptor[]).filter(field => field.aggregatable && !isNestedField(field)); + )) as IndexPatternFieldDescriptor[]).filter( + field => field.aggregatable && !indexPatterns.isNestedField(field) + ); return uniq(fields, field => field.name); } diff --git a/src/test_utils/public/stub_index_pattern.js b/src/test_utils/public/stub_index_pattern.js index 72255d9b0e3da..d3e803ad06bba 100644 --- a/src/test_utils/public/stub_index_pattern.js +++ b/src/test_utils/public/stub_index_pattern.js @@ -22,7 +22,12 @@ import sinon from 'sinon'; // 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 { FieldList, IndexPattern, indexPatterns, KBN_FIELD_TYPES } from '../../plugins/data/public'; +import { + IndexPatternFieldList, + IndexPattern, + indexPatterns, + KBN_FIELD_TYPES, +} from '../../plugins/data/public'; import { setFieldFormats } from '../../plugins/data/public/services'; @@ -63,7 +68,7 @@ export default function StubIndexPattern(pattern, getConfig, timeField, fields, this.formatField = this.formatHit.formatField; this._reindexFields = function() { - this.fields = new FieldList(this, this.fields || fields); + this.fields = new IndexPatternFieldList(this, this.fields || fields); }; this.stubSetFieldFormat = function(fieldName, id, params) { 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 0bef31e9fb7fe..947e56a6de6eb 100644 --- a/x-pack/legacy/plugins/graph/public/services/persistence/deserialize.ts +++ b/x-pack/legacy/plugins/graph/public/services/persistence/deserialize.ts @@ -24,7 +24,10 @@ import { colorChoices, iconChoicesByClass, } from '../../helpers/style_choices'; -import { IndexPattern, isNestedField } from '../../../../../../../src/plugins/data/public'; +import { + IndexPattern, + indexPatterns as indexPatternsUtils, +} from '../../../../../../../src/plugins/data/public'; const defaultAdvancedSettings: AdvancedSettings = { useSignificance: true, @@ -80,7 +83,9 @@ export function mapFields(indexPattern: IndexPattern): WorkspaceField[] { return indexPattern .getNonScriptedFields() - .filter(field => !blockedFieldNames.includes(field.name) && !isNestedField(field)) + .filter( + field => !blockedFieldNames.includes(field.name) && !indexPatternsUtils.isNestedField(field) + ) .map((field, index) => ({ name: field.name, hopSize: defaultHopSize, diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/loader.ts b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/loader.ts index e37c5db09ca74..3ec4b4f4df2ce 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/loader.ts +++ b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/loader.ts @@ -20,7 +20,11 @@ import { updateLayerIndexPattern } from './state_helpers'; import { DateRange, ExistingFields } from '../../../../../plugins/lens/common/types'; import { BASE_API_URL } from '../../../../../plugins/lens/common'; import { documentField } from './document_field'; -import { isNestedField, IFieldType, TypeMeta } from '../../../../../../src/plugins/data/public'; +import { + indexPatterns as indexPatternsUtils, + IFieldType, + IndexPatternTypeMeta, +} from '../../../../../../src/plugins/data/public'; interface SavedIndexPatternAttributes extends SavedObjectAttributes { title: string; @@ -267,9 +271,14 @@ function fromSavedObject( type, title: attributes.title, fields: (JSON.parse(attributes.fields) as IFieldType[]) - .filter(field => !isNestedField(field) && (!!field.aggregatable || !!field.scripted)) + .filter( + field => + !indexPatternsUtils.isNestedField(field) && (!!field.aggregatable || !!field.scripted) + ) .concat(documentField) as IndexPatternField[], - typeMeta: attributes.typeMeta ? (JSON.parse(attributes.typeMeta) as TypeMeta) : undefined, + typeMeta: attributes.typeMeta + ? (JSON.parse(attributes.typeMeta) as IndexPatternTypeMeta) + : undefined, fieldFormatMap: attributes.fieldFormatMap ? JSON.parse(attributes.fieldFormatMap) : undefined, }; diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/date_histogram.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/date_histogram.tsx index 4cfd7195d1fc0..ea848f4d3d166 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/date_histogram.tsx +++ b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/date_histogram.tsx @@ -27,7 +27,7 @@ import { updateColumnParam } from '../../state_helpers'; import { OperationDefinition } from '.'; import { FieldBasedIndexPatternColumn } from './column_types'; import { autoIntervalFromDateRange } from '../../auto_date'; -import { AggregationRestrictions } from '../../../../../../../../src/plugins/data/public'; +import { IndexPatternAggRestrictions } from '../../../../../../../../src/plugins/data/public'; const autoInterval = 'auto'; const calendarOnlyIntervals = new Set(['w', 'M', 'q', 'y']); @@ -322,7 +322,7 @@ function parseInterval(currentInterval: string) { }; } -function restrictedInterval(aggregationRestrictions?: Partial) { +function restrictedInterval(aggregationRestrictions?: Partial) { if (!aggregationRestrictions || !aggregationRestrictions.date_histogram) { return; } diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/types.ts b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/types.ts index 546d148be1e29..3820ff3b387bb 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/types.ts +++ b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/types.ts @@ -5,7 +5,7 @@ */ import { IndexPatternColumn } from './operations'; -import { AggregationRestrictions } from '../../../../../../src/plugins/data/public'; +import { IndexPatternAggRestrictions } from '../../../../../../src/plugins/data/public'; export interface IndexPattern { id: string; @@ -28,7 +28,7 @@ export interface IndexPatternField { aggregatable: boolean; scripted?: boolean; searchable: boolean; - aggregationRestrictions?: Partial; + aggregationRestrictions?: Partial; } export interface IndexPatternLayer { diff --git a/x-pack/legacy/plugins/maps/public/connected_components/gis_map/view.js b/x-pack/legacy/plugins/maps/public/connected_components/gis_map/view.js index 2430ca6503f84..97139103ab7c1 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/gis_map/view.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/gis_map/view.js @@ -15,7 +15,7 @@ import { EuiFlexGroup, EuiFlexItem, EuiCallOut } from '@elastic/eui'; import { ExitFullScreenButton } from 'ui/exit_full_screen'; import { getIndexPatternsFromIds } from '../../index_pattern_util'; import { ES_GEO_FIELD_TYPE } from '../../../common/constants'; -import { isNestedField } from '../../../../../../../src/plugins/data/public'; +import { indexPatterns as indexPatternsUtils } from '../../../../../../../src/plugins/data/public'; import { i18n } from '@kbn/i18n'; import uuid from 'uuid/v4'; @@ -81,7 +81,7 @@ export class GisMap extends Component { indexPatterns.forEach(indexPattern => { indexPattern.fields.forEach(field => { if ( - !isNestedField(field) && + !indexPatternsUtils.isNestedField(field) && (field.type === ES_GEO_FIELD_TYPE.GEO_POINT || field.type === ES_GEO_FIELD_TYPE.GEO_SHAPE) ) { diff --git a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join.js b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join.js index 554164bf0e8c4..8660fa6010f8a 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join.js @@ -13,7 +13,7 @@ import { MetricsExpression } from './metrics_expression'; import { WhereExpression } from './where_expression'; import { GlobalFilterCheckbox } from '../../../../components/global_filter_checkbox'; -import { isNestedField } from '../../../../../../../../../src/plugins/data/public'; +import { indexPatterns } from '../../../../../../../../../src/plugins/data/public'; import { indexPatternService } from '../../../../kibana_services'; const getIndexPatternId = props => { @@ -89,7 +89,7 @@ export class Join extends Component { } this.setState({ - rightFields: indexPattern.fields.filter(field => !isNestedField(field)), + rightFields: indexPattern.fields.filter(field => !indexPatterns.isNestedField(field)), indexPattern, }); } diff --git a/x-pack/legacy/plugins/maps/public/index_pattern_util.js b/x-pack/legacy/plugins/maps/public/index_pattern_util.js index 96d4a4b19fbfa..7aa87ab32cdf5 100644 --- a/x-pack/legacy/plugins/maps/public/index_pattern_util.js +++ b/x-pack/legacy/plugins/maps/public/index_pattern_util.js @@ -5,7 +5,7 @@ */ import { indexPatternService } from './kibana_services'; -import { isNestedField } from '../../../../../src/plugins/data/public'; +import { indexPatterns } from '../../../../../src/plugins/data/public'; import { ES_GEO_FIELD_TYPE } from '../common/constants'; export async function getIndexPatternsFromIds(indexPatternIds = []) { @@ -24,7 +24,7 @@ export function getTermsFields(fields) { return fields.filter(field => { return ( field.aggregatable && - !isNestedField(field) && + !indexPatterns.isNestedField(field) && ['number', 'boolean', 'date', 'ip', 'string'].includes(field.type) ); }); @@ -36,7 +36,7 @@ export function getAggregatableGeoFields(fields) { return fields.filter(field => { return ( field.aggregatable && - !isNestedField(field) && + !indexPatterns.isNestedField(field) && AGGREGATABLE_GEO_FIELD_TYPES.includes(field.type) ); }); @@ -47,6 +47,6 @@ export function getSourceFields(fields) { return fields.filter(field => { // Multi fields are not stored in _source and only exist in index. const isMultiField = field.subType && field.subType.multi; - return !isMultiField && !isNestedField(field); + return !isMultiField && !indexPatterns.isNestedField(field); }); } diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js b/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js index 76bcb8da552d1..0b90dbe47c6e9 100644 --- a/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js +++ b/x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js @@ -7,7 +7,7 @@ import { AbstractField } from './field'; import { ESTooltipProperty } from '../tooltips/es_tooltip_property'; import { COLOR_PALETTE_MAX_SIZE } from '../../../common/constants'; -import { isNestedField } from '../../../../../../../src/plugins/data/public'; +import { indexPatterns } from '../../../../../../../src/plugins/data/public'; export class ESDocField extends AbstractField { static type = 'ES_DOC'; @@ -15,7 +15,7 @@ export class ESDocField extends AbstractField { async _getField() { const indexPattern = await this._source.getIndexPattern(); const field = indexPattern.fields.getByName(this._fieldName); - return isNestedField(field) ? undefined : field; + return indexPatterns.isNestedField(field) ? undefined : field; } async createTooltipProperty(value) { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/update_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/update_source_editor.js index 0d9234acd9150..a7f31f1ee99f7 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/update_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/update_source_editor.js @@ -14,7 +14,7 @@ import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; import { EuiPanel, EuiSpacer, EuiTitle } from '@elastic/eui'; import { isMetricCountable } from '../../util/is_metric_countable'; -import { isNestedField } from '../../../../../../../../src/plugins/data/public'; +import { indexPatterns } from '../../../../../../../../src/plugins/data/public'; export class UpdateSourceEditor extends Component { state = { @@ -52,7 +52,9 @@ export class UpdateSourceEditor extends Component { return; } - this.setState({ fields: indexPattern.fields.filter(field => !isNestedField(field)) }); + this.setState({ + fields: indexPattern.fields.filter(field => !indexPatterns.isNestedField(field)), + }); } _onMetricsChange = metrics => { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js index 5d571967d53e8..176ab62baf98c 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/es_pew_pew_source.js @@ -24,7 +24,7 @@ import { AggConfigs, Schemas } from 'ui/agg_types'; import { AbstractESAggSource } from '../es_agg_source'; import { DynamicStyleProperty } from '../../styles/vector/properties/dynamic_style_property'; import { COLOR_GRADIENTS } from '../../styles/color_utils'; -import { isNestedField } from '../../../../../../../../src/plugins/data/public'; +import { indexPatterns } from '../../../../../../../../src/plugins/data/public'; const MAX_GEOTILE_LEVEL = 29; @@ -229,7 +229,7 @@ export class ESPewPewSource extends AbstractESAggSource { async _getGeoField() { const indexPattern = await this.getIndexPattern(); const field = indexPattern.fields.getByName(this._descriptor.destGeoField); - const geoField = isNestedField(field) ? undefined : field; + const geoField = indexPatterns.isNestedField(field) ? undefined : field; if (!geoField) { throw new Error( i18n.translate('xpack.maps.source.esSource.noGeoFieldErrorMessage', { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/update_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/update_source_editor.js index 6e2583bf85bb8..ff00f472e9edf 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/update_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/update_source_editor.js @@ -11,7 +11,7 @@ import { indexPatternService } from '../../../kibana_services'; import { i18n } from '@kbn/i18n'; import { EuiPanel, EuiTitle, EuiSpacer } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; -import { isNestedField } from '../../../../../../../../src/plugins/data/public'; +import { indexPatterns } from '../../../../../../../../src/plugins/data/public'; export class UpdateSourceEditor extends Component { state = { @@ -49,7 +49,9 @@ export class UpdateSourceEditor extends Component { return; } - this.setState({ fields: indexPattern.fields.filter(field => !isNestedField(field)) }); + this.setState({ + fields: indexPattern.fields.filter(field => !indexPatterns.isNestedField(field)), + }); } _onMetricsChange = metrics => { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/create_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/create_source_editor.js index da6248099c9c1..b7b63ce8082bc 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/create_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/create_source_editor.js @@ -21,7 +21,7 @@ import { DEFAULT_MAX_RESULT_WINDOW, } from '../../../../common/constants'; import { DEFAULT_FILTER_BY_MAP_BOUNDS } from './constants'; -import { isNestedField } from '../../../../../../../../src/plugins/data/public'; +import { indexPatterns } from '../../../../../../../../src/plugins/data/public'; import { npStart } from 'ui/new_platform'; const { IndexPatternSelect } = npStart.plugins.data.ui; @@ -29,7 +29,7 @@ const { IndexPatternSelect } = npStart.plugins.data.ui; function getGeoFields(fields) { return fields.filter(field => { return ( - !isNestedField(field) && + !indexPatterns.isNestedField(field) && [ES_GEO_FIELD_TYPE.GEO_POINT, ES_GEO_FIELD_TYPE.GEO_SHAPE].includes(field.type) ); }); diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js index fdebbe4c81911..52702c1f4ecc7 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js @@ -26,7 +26,7 @@ import { DEFAULT_MAX_INNER_RESULT_WINDOW, SORT_ORDER } from '../../../../common/ import { ESDocField } from '../../fields/es_doc_field'; import { FormattedMessage } from '@kbn/i18n/react'; import { loadIndexSettings } from './load_index_settings'; -import { isNestedField } from '../../../../../../../../src/plugins/data/public'; +import { indexPatterns } from '../../../../../../../../src/plugins/data/public'; export class UpdateSourceEditor extends Component { static propTypes = { @@ -104,7 +104,9 @@ export class UpdateSourceEditor extends Component { this.setState({ sourceFields: sourceFields, termFields: getTermsFields(indexPattern.fields), //todo change term fields to use fields - sortFields: indexPattern.fields.filter(field => field.sortable && !isNestedField(field)), //todo change sort fields to use fields + sortFields: indexPattern.fields.filter( + field => field.sortable && !indexPatterns.isNestedField(field) + ), //todo change sort fields to use fields }); } _onTooltipPropertiesChange = propertyNames => { diff --git a/x-pack/plugins/data_enhanced/public/autocomplete/providers/kql_query_suggestion/field.test.ts b/x-pack/plugins/data_enhanced/public/autocomplete/providers/kql_query_suggestion/field.test.ts index 09a2048e0b38b..2e12ae672f367 100644 --- a/x-pack/plugins/data_enhanced/public/autocomplete/providers/kql_query_suggestion/field.test.ts +++ b/x-pack/plugins/data_enhanced/public/autocomplete/providers/kql_query_suggestion/field.test.ts @@ -7,7 +7,7 @@ import indexPatternResponse from './__fixtures__/index_pattern_response.json'; import { setupGetFieldSuggestions } from './field'; import { - isFilterable, + indexPatterns as indexPatternsUtils, QuerySuggestionGetFnArgs, KueryNode, } from '../../../../../../../src/plugins/data/public'; @@ -38,7 +38,7 @@ describe('Kuery field suggestions', () => { querySuggestionsArgs, mockKueryNode({ prefix, suffix }) ); - const filterableFields = indexPatternResponse.fields.filter(isFilterable); + const filterableFields = indexPatternResponse.fields.filter(indexPatternsUtils.isFilterable); expect(suggestions.length).toBe(filterableFields.length); }); diff --git a/x-pack/plugins/data_enhanced/public/autocomplete/providers/kql_query_suggestion/field.tsx b/x-pack/plugins/data_enhanced/public/autocomplete/providers/kql_query_suggestion/field.tsx index 0dcbea893ace4..ca045c929f6a1 100644 --- a/x-pack/plugins/data_enhanced/public/autocomplete/providers/kql_query_suggestion/field.tsx +++ b/x-pack/plugins/data_enhanced/public/autocomplete/providers/kql_query_suggestion/field.tsx @@ -10,7 +10,7 @@ import { escapeKuery } from './lib/escape_kuery'; import { sortPrefixFirst } from './sort_prefix_first'; import { IFieldType, - isFilterable, + indexPatterns as indexPatternsUtils, QuerySuggestionField, QuerySuggestionTypes, } from '../../../../../../../src/plugins/data/public'; @@ -43,7 +43,7 @@ export const setupGetFieldSuggestions: KqlQuerySuggestionProvider { const allFields = flatten( indexPatterns.map(indexPattern => { - return indexPattern.fields.filter(isFilterable); + return indexPattern.fields.filter(indexPatternsUtils.isFilterable); }) ); const search = `${prefix}${suffix}`.trim().toLowerCase();