From 3d2f8cdcabbe73eec20ba8c03857098b905eb093 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Thu, 23 Jul 2020 22:18:45 -0500 Subject: [PATCH 01/13] first pass at new field class --- .../common/index_patterns/fields/field.ts | 176 ---------------- .../index_patterns/fields/field_list.ts | 159 ++++++++------- .../common/index_patterns/fields/index.ts | 2 +- ...ld.test.ts => index_pattern_field.test.ts} | 105 ++-------- .../fields/index_pattern_field.ts | 190 ++++++++++++++++++ .../index_patterns/fields/obj_define.js | 158 --------------- .../index_patterns/fields/obj_define.test.js | 149 -------------- .../index_patterns/index_pattern.test.ts | 18 +- .../index_patterns/index_pattern.ts | 109 +++++----- .../index_patterns/index_patterns.ts | 28 +-- .../data/common/index_patterns/types.ts | 15 +- .../kbn_field_types/kbn_field_types.test.ts | 4 +- .../common/kbn_field_types/kbn_field_types.ts | 6 +- .../kbn_field_types_factory.ts | 8 +- src/plugins/data/public/index.ts | 4 +- .../data/public/index_patterns/index.ts | 6 +- .../public/search/aggs/agg_configs.test.ts | 2 +- .../public/search/aggs/param_types/field.ts | 2 +- .../sidebar/discover_field.test.tsx | 30 +-- .../components/sidebar/discover_sidebar.tsx | 11 +- .../lib/get_index_pattern_field_list.ts | 12 +- .../components/sidebar/lib/group_fields.tsx | 4 +- .../create_edit_field/create_edit_field.tsx | 31 ++- .../indexed_fields_table.tsx | 2 +- .../components/field_editor/field_editor.tsx | 164 +++++++-------- 25 files changed, 523 insertions(+), 872 deletions(-) delete mode 100644 src/plugins/data/common/index_patterns/fields/field.ts rename src/plugins/data/common/index_patterns/fields/{field.test.ts => index_pattern_field.test.ts} (64%) create mode 100644 src/plugins/data/common/index_patterns/fields/index_pattern_field.ts delete mode 100644 src/plugins/data/common/index_patterns/fields/obj_define.js delete mode 100644 src/plugins/data/common/index_patterns/fields/obj_define.test.js diff --git a/src/plugins/data/common/index_patterns/fields/field.ts b/src/plugins/data/common/index_patterns/fields/field.ts deleted file mode 100644 index 81c7aff8a0faaa..00000000000000 --- a/src/plugins/data/common/index_patterns/fields/field.ts +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import { i18n } from '@kbn/i18n'; -// @ts-ignore -import { ObjDefine } from './obj_define'; -import { IIndexPattern } from '../../types'; -import { - IFieldType, - getKbnFieldType, - IFieldSubType, - FieldFormat, - shortenDottedString, -} from '../../../common'; -import { - OnNotification, - FieldSpec, - FieldSpecConflictDescriptions, - FieldSpecExportFmt, -} from '../types'; -import { FieldFormatsStartCommon } from '../../field_formats'; - -interface FieldDependencies { - fieldFormats: FieldFormatsStartCommon; - onNotification: OnNotification; -} - -export class Field implements IFieldType { - name: string; - type: string; - script?: string; - lang?: string; - count?: number; - // esTypes might be undefined on old index patterns that have not been refreshed since we added - // this prop. It is also undefined on scripted fields. - esTypes?: string[]; - aggregatable?: boolean; - filterable?: boolean; - searchable?: boolean; - sortable?: boolean; - visualizable?: boolean; - scripted?: boolean; - subType?: IFieldSubType; - displayName?: string; - indexPattern?: IIndexPattern; - readFromDocValues?: boolean; - format: any; - $$spec: FieldSpec; - conflictDescriptions?: FieldSpecConflictDescriptions; - - constructor( - indexPattern: IIndexPattern, - spec: FieldSpecExportFmt | FieldSpec | Field, - shortDotsEnable: boolean, - { fieldFormats, onNotification }: FieldDependencies - ) { - // unwrap old instances of Field - if (spec instanceof Field) spec = spec.$$spec; - - // construct this object using ObjDefine class, which - // extends the Field.prototype but gets it's properties - // defined using the logic below - const obj = new ObjDefine(spec, Field.prototype); - - if (spec.name === '_source') { - spec.type = '_source'; - } - - // find the type for this field, fallback to unknown type - let type = getKbnFieldType(spec.type); - if (spec.type && !type) { - const title = i18n.translate('data.indexPatterns.unknownFieldHeader', { - values: { type: spec.type }, - defaultMessage: 'Unknown field type {type}', - }); - const text = i18n.translate('data.indexPatterns.unknownFieldErrorMessage', { - values: { name: spec.name, title: indexPattern.title }, - defaultMessage: 'Field {name} in indexPattern {title} is using an unknown field type.', - }); - onNotification({ title, text, color: 'danger', iconType: 'alert' }); - } - - if (!type) type = getKbnFieldType('unknown'); - - let format: any = spec.format; - - if (!FieldFormat.isInstanceOfFieldFormat(format)) { - format = - (indexPattern.fieldFormatMap && indexPattern.fieldFormatMap[spec.name]) || - fieldFormats.getDefaultInstance(spec.type, spec.esTypes); - } - - const indexed = !!spec.indexed; - const scripted = !!spec.scripted; - const searchable = !!spec.searchable || scripted; - const aggregatable = !!spec.aggregatable || scripted; - const readFromDocValues = !!spec.readFromDocValues && !scripted; - const sortable = spec.name === '_score' || ((indexed || aggregatable) && type && type.sortable); - const filterable = - spec.name === '_id' || scripted || ((indexed || searchable) && type && type.filterable); - const visualizable = aggregatable; - - this.name = ''; - obj.fact('name'); - this.type = ''; - obj.fact('type'); - obj.fact('esTypes'); - obj.writ('count', spec.count || 0); - - // scripted objs - obj.fact('scripted', scripted); - obj.writ('script', scripted ? spec.script : null); - obj.writ('lang', scripted ? spec.lang || 'painless' : null); - - // stats - obj.fact('searchable', searchable); - obj.fact('aggregatable', aggregatable); - obj.fact('readFromDocValues', readFromDocValues); - - // usage flags, read-only and won't be saved - obj.comp('format', format); - obj.comp('sortable', sortable); - obj.comp('filterable', filterable); - obj.comp('visualizable', visualizable); - - // computed values - obj.comp('indexPattern', indexPattern); - obj.comp('displayName', shortDotsEnable ? shortenDottedString(spec.name) : spec.name); - this.$$spec = spec; - obj.comp('$$spec', spec); - - // conflict info - obj.writ('conflictDescriptions'); - - // multi info - obj.fact('subType'); - - const newObj = obj.create(); - newObj.toSpec = function () { - return { - count: this.count, - script: this.script, - lang: this.lang, - conflictDescriptions: this.conflictDescriptions, - name: this.name, - type: this.type, - esTypes: this.esTypes, - scripted: this.scripted, - searchable: this.searchable, - aggregatable: this.aggregatable, - readFromDocValues: this.readFromDocValues, - subType: this.subType, - format: this.indexPattern?.fieldFormatMap[this.name]?.toJSON() || undefined, - }; - }; - return newObj; - } - // only providing type info as constructor returns new object instead of `this` - toSpec = () => (({} as unknown) as FieldSpecExportFmt); -} diff --git a/src/plugins/data/common/index_patterns/fields/field_list.ts b/src/plugins/data/common/index_patterns/fields/field_list.ts index c1ca5341328ce1..d0deae28c10010 100644 --- a/src/plugins/data/common/index_patterns/fields/field_list.ts +++ b/src/plugins/data/common/index_patterns/fields/field_list.ts @@ -18,95 +18,110 @@ */ import { findIndex } from 'lodash'; -import { IIndexPattern } from '../../types'; -import { IFieldType } from '../../../common'; -import { Field } from './field'; +import { IFieldType, shortenDottedString } from '../../../common'; +import { IndexPatternField } from './index_pattern_field'; import { OnNotification, FieldSpec } from '../types'; -import { FieldFormatsStartCommon } from '../../field_formats'; +import { IndexPattern } from '../index_patterns'; -type FieldMap = Map; +type FieldMap = Map; -interface FieldListDependencies { - fieldFormats: FieldFormatsStartCommon; - onNotification: OnNotification; -} - -export interface IIndexPatternFieldList extends Array { - getByName(name: Field['name']): Field | undefined; - getByType(type: Field['type']): Field[]; +export interface IIndexPatternFieldList extends Array { add(field: FieldSpec): void; + getByName(name: IndexPatternField['name']): IndexPatternField | undefined; + getByType(type: IndexPatternField['type']): IndexPatternField[]; remove(field: IFieldType): void; + removeAll(): void; + replaceAll(specs: FieldSpec[]): void; update(field: FieldSpec): void; } export type CreateIndexPatternFieldList = ( - indexPattern: IIndexPattern, + indexPattern: IndexPattern, specs?: FieldSpec[], - shortDotsEnable?: boolean + shortDotsEnable?: boolean, + onNotification?: OnNotification ) => IIndexPatternFieldList; -export const getIndexPatternFieldListCreator = ({ - fieldFormats, - onNotification, -}: FieldListDependencies): CreateIndexPatternFieldList => (...fieldListParams) => { - class FieldList extends Array implements IIndexPatternFieldList { - private byName: FieldMap = new Map(); - private groups: Map = new Map(); - private indexPattern: IIndexPattern; - private shortDotsEnable: boolean; - private setByName = (field: Field) => this.byName.set(field.name, field); - private setByGroup = (field: Field) => { - if (typeof this.groups.get(field.type) === 'undefined') { - this.groups.set(field.type, new Map()); - } - this.groups.get(field.type)!.set(field.name, field); - }; - private removeByGroup = (field: IFieldType) => this.groups.get(field.type)!.delete(field.name); +export class FieldList extends Array implements IIndexPatternFieldList { + private byName: FieldMap = new Map(); + private groups: Map = new Map(); + private indexPattern: IndexPattern; + private shortDotsEnable: boolean; + private onNotification: OnNotification; + private setByName = (field: IndexPatternField) => this.byName.set(field.name, field); + private setByGroup = (field: IndexPatternField) => { + if (typeof this.groups.get(field.type) === 'undefined') { + this.groups.set(field.type, new Map()); + } + this.groups.get(field.type)!.set(field.name, field); + }; + private removeByGroup = (field: IFieldType) => this.groups.get(field.type)!.delete(field.name); + private calcDisplayName = (name: string) => + this.shortDotsEnable ? shortenDottedString(name) : name; + constructor( + indexPattern: IndexPattern, + specs: FieldSpec[] = [], + shortDotsEnable = false, + onNotification = () => {} + ) { + super(); + this.indexPattern = indexPattern; + this.shortDotsEnable = shortDotsEnable; + this.onNotification = onNotification; - constructor(indexPattern: IIndexPattern, specs: FieldSpec[] = [], shortDotsEnable = false) { - super(); - this.indexPattern = indexPattern; - this.shortDotsEnable = shortDotsEnable; + specs.map((field) => this.add(field)); + } - specs.map((field) => this.add(field)); - } + getByName = (name: IndexPatternField['name']) => this.byName.get(name); + getByType = (type: IndexPatternField['type']) => [ + ...(this.groups.get(type) || new Map()).values(), + ]; + add = (field: FieldSpec) => { + const newField = new IndexPatternField( + this.indexPattern, + field, + this.calcDisplayName(field.name), + this.onNotification + ); + this.push(newField); + this.setByName(newField); + this.setByGroup(newField); + }; - getByName = (name: Field['name']) => this.byName.get(name); - getByType = (type: Field['type']) => [...(this.groups.get(type) || new Map()).values()]; - add = (field: FieldSpec) => { - const newField = new Field(this.indexPattern, field, this.shortDotsEnable, { - fieldFormats, - onNotification, - }); - this.push(newField); - this.setByName(newField); - this.setByGroup(newField); - }; + remove = (field: IFieldType) => { + this.removeByGroup(field); + this.byName.delete(field.name); - remove = (field: IFieldType) => { - this.removeByGroup(field); - this.byName.delete(field.name); + const fieldIndex = findIndex(this, { name: field.name }); + this.splice(fieldIndex, 1); + }; - const fieldIndex = findIndex(this, { name: field.name }); - this.splice(fieldIndex, 1); - }; + update = (field: FieldSpec) => { + const newField = new IndexPatternField( + this.indexPattern, + field, + this.calcDisplayName(field.name), + this.onNotification + ); + const index = this.findIndex((f) => f.name === newField.name); + this.splice(index, 1, newField); + this.setByName(newField); + this.removeByGroup(newField); + this.setByGroup(newField); + }; - update = (field: FieldSpec) => { - const newField = new Field(this.indexPattern, field, this.shortDotsEnable, { - fieldFormats, - onNotification, - }); - const index = this.findIndex((f) => f.name === newField.name); - this.splice(index, 1, newField); - this.setByName(newField); - this.removeByGroup(newField); - this.setByGroup(newField); - }; + removeAll = () => { + this.length = 0; + this.byName.clear(); + this.groups.clear(); + }; - toSpec = () => { - return [...this.map((field) => field.toSpec())]; - }; - } + replaceAll = (specs: FieldSpec[]) => { + this.removeAll(); + specs.forEach(this.add); + }; - return new FieldList(...fieldListParams); -}; + toSpec = () => { + return [...this.map((field) => field.toSpec())]; + }; +} diff --git a/src/plugins/data/common/index_patterns/fields/index.ts b/src/plugins/data/common/index_patterns/fields/index.ts index 1b7c87d556f592..0c3b43181c5b4e 100644 --- a/src/plugins/data/common/index_patterns/fields/index.ts +++ b/src/plugins/data/common/index_patterns/fields/index.ts @@ -20,4 +20,4 @@ export * from './types'; export { isFilterable, isNestedField } from './utils'; export * from './field_list'; -export * from './field'; +export * from './index_pattern_field'; diff --git a/src/plugins/data/common/index_patterns/fields/field.test.ts b/src/plugins/data/common/index_patterns/fields/index_pattern_field.test.ts similarity index 64% rename from src/plugins/data/common/index_patterns/fields/field.test.ts rename to src/plugins/data/common/index_patterns/fields/index_pattern_field.test.ts index 910f22088f43a8..0cd0fe8324809c 100644 --- a/src/plugins/data/common/index_patterns/fields/field.test.ts +++ b/src/plugins/data/common/index_patterns/fields/index_pattern_field.test.ts @@ -17,10 +17,10 @@ * under the License. */ -import { Field } from './field'; +import { IndexPatternField } from './index_pattern_field'; import { IndexPattern } from '../index_patterns'; -import { FieldFormatsStartCommon } from '../..'; -import { KBN_FIELD_TYPES, FieldSpec, FieldSpecExportFmt } from '../../../common'; +import { KBN_FIELD_TYPES } from '../../../common'; +import { FieldSpec } from '../types'; describe('Field', function () { function flatten(obj: Record) { @@ -28,14 +28,11 @@ describe('Field', function () { } function getField(values = {}) { - return new Field( + return new IndexPatternField( fieldValues.indexPattern as IndexPattern, { ...fieldValues, ...values }, - false, - { - fieldFormats: {} as FieldFormatsStartCommon, - onNotification: () => {}, - } + 'displayName', + () => {} ); } @@ -50,6 +47,7 @@ describe('Field', function () { filterable: true, searchable: true, sortable: true, + indexed: true, readFromDocValues: false, visualizable: true, scripted: true, @@ -58,11 +56,9 @@ describe('Field', function () { indexPattern: ({ fieldFormatMap: { name: {}, _source: {}, _score: {}, _id: {} }, } as unknown) as IndexPattern, - format: { name: 'formatName' }, $$spec: ({} as unknown) as FieldSpec, conflictDescriptions: { a: ['b', 'c'], d: ['e'] }, - toSpec: () => (({} as unknown) as FieldSpecExportFmt), - } as Field; + }; it('the correct properties are writable', () => { const field = getField(); @@ -84,72 +80,6 @@ describe('Field', function () { expect(field.conflictDescriptions).toEqual({}); }); - it('the correct properties are not writable', () => { - const field = getField(); - - expect(field.name).toEqual(fieldValues.name); - field.name = 'newName'; - expect(field.name).toEqual(fieldValues.name); - - expect(field.type).toEqual(fieldValues.type); - field.type = 'newType'; - expect(field.type).toEqual(fieldValues.type); - - expect(field.esTypes).toEqual(fieldValues.esTypes); - field.esTypes = ['newType']; - expect(field.esTypes).toEqual(fieldValues.esTypes); - - expect(field.scripted).toEqual(fieldValues.scripted); - field.scripted = false; - expect(field.scripted).toEqual(fieldValues.scripted); - - expect(field.searchable).toEqual(fieldValues.searchable); - field.searchable = false; - expect(field.searchable).toEqual(fieldValues.searchable); - - expect(field.aggregatable).toEqual(fieldValues.aggregatable); - field.aggregatable = false; - expect(field.aggregatable).toEqual(fieldValues.aggregatable); - - expect(field.readFromDocValues).toEqual(fieldValues.readFromDocValues); - field.readFromDocValues = true; - expect(field.readFromDocValues).toEqual(fieldValues.readFromDocValues); - - expect(field.subType).toEqual(fieldValues.subType); - field.subType = {}; - expect(field.subType).toEqual(fieldValues.subType); - - // not writable, not serialized - expect(() => { - field.indexPattern = {} as IndexPattern; - }).toThrow(); - - // computed fields - expect(() => { - field.format = { name: 'newFormatName' }; - }).toThrow(); - - expect(() => { - field.sortable = false; - }).toThrow(); - - expect(() => { - field.filterable = false; - }).toThrow(); - - expect(() => { - field.visualizable = false; - }).toThrow(); - - expect(() => { - field.displayName = 'newDisplayName'; - }).toThrow(); - - expect(() => { - field.$$spec = ({ a: 'b' } as unknown) as FieldSpec; - }).toThrow(); - }); - it('sets type field when _source field', () => { const field = getField({ name: '_source' }); expect(field.type).toEqual('_source'); @@ -214,26 +144,25 @@ describe('Field', function () { }); it('exports the property to JSON', () => { - const field = new Field({ fieldFormatMap: { name: {} } } as IndexPattern, fieldValues, false, { - fieldFormats: {} as FieldFormatsStartCommon, - onNotification: () => {}, - }); + const field = new IndexPatternField( + { fieldFormatMap: { name: {} } } as IndexPattern, + fieldValues, + 'displayName', + () => {} + ); expect(flatten(field)).toMatchSnapshot(); }); it('spec snapshot', () => { - const field = new Field( + const field = new IndexPatternField( { fieldFormatMap: { name: { toJSON: () => ({ id: 'number', params: { pattern: '$0,0.[00]' } }) }, }, } as IndexPattern, fieldValues, - false, - { - fieldFormats: {} as FieldFormatsStartCommon, - onNotification: () => {}, - } + 'displayName', + () => {} ); expect(field.toSpec()).toMatchSnapshot(); }); diff --git a/src/plugins/data/common/index_patterns/fields/index_pattern_field.ts b/src/plugins/data/common/index_patterns/fields/index_pattern_field.ts new file mode 100644 index 00000000000000..8d1e45c26cc6af --- /dev/null +++ b/src/plugins/data/common/index_patterns/fields/index_pattern_field.ts @@ -0,0 +1,190 @@ +/* + * 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 { i18n } from '@kbn/i18n'; +import { + IFieldType, + KbnFieldType, + getKbnFieldType, + KBN_FIELD_TYPES, + FieldFormat, +} from '../../../common'; +import { OnNotification, FieldSpec } from '../types'; + +import { IndexPattern } from '../index_patterns'; + +export class IndexPatternField implements IFieldType { + readonly spec: FieldSpec; + // not writable or serialized + readonly indexPattern: IndexPattern; + readonly displayName: string; + private readonly kbnFieldType: KbnFieldType; + + constructor( + indexPattern: IndexPattern, + spec: FieldSpec, + displayName: string, + onNotification: OnNotification + ) { + this.indexPattern = indexPattern; + this.spec = { ...spec, type: spec.name === '_source' ? '_source' : spec.type }; + this.displayName = displayName; + + // todo + // try to refactor this code so it can provide a return value which can be handled. + this.kbnFieldType = getKbnFieldType(spec.type); + if (spec.type && this.kbnFieldType?.name === KBN_FIELD_TYPES.UNKNOWN) { + const title = i18n.translate('data.indexPatterns.unknownFieldHeader', { + values: { type: spec.type }, + defaultMessage: 'Unknown field type {type}', + }); + const text = i18n.translate('data.indexPatterns.unknownFieldErrorMessage', { + values: { name: spec.name, title: indexPattern.title }, + defaultMessage: 'Field {name} in indexPattern {title} is using an unknown field type.', + }); + onNotification({ title, text, color: 'danger', iconType: 'alert' }); + } + } + + // writable attrs + public get count() { + return this.spec.count; + } + + public set count(count) { + this.spec.count = count; + } + + public get script() { + return this.spec.script; + } + + public set script(script) { + this.spec.script = script; + } + + public get lang() { + return this.spec.lang; + } + + public set lang(lang) { + this.spec.lang = lang; + } + + public get conflictDescriptions() { + return this.spec.conflictDescriptions; + } + + public set conflictDescriptions(conflictDescriptions) { + this.spec.conflictDescriptions = conflictDescriptions; + } + + // read only attrs + public get name() { + return this.spec.name; + } + + public get type() { + return this.spec.type; + } + + public get esTypes() { + return this.spec.esTypes; + } + + public get scripted() { + return this.spec.scripted; + } + + public get searchable() { + return this.spec.searchable || this.scripted; + } + + public get aggregatable() { + return this.spec.aggregatable || this.scripted; + } + + public get readFromDocValues() { + return this.spec.readFromDocValues && !this.scripted; + } + + public get subType() { + return this.spec.subType; + } + + // not writable, not serialized + public get sortable() { + return ( + this.name === '_score' || + ((this.spec.indexed || this.aggregatable) && this.kbnFieldType.sortable) + ); + } + + public get filterable() { + return ( + this.name === '_id' || + this.scripted || + ((this.spec.indexed || this.searchable) && this.kbnFieldType.filterable) + ); + } + + public get visualizable() { + return this.aggregatable; + } + + public get format(): FieldFormat { + return this.indexPattern.getFormatterForField(this); + } + + public toJSON() { + return { + count: this.count, + script: this.script, + lang: this.lang, + conflictDescriptions: this.conflictDescriptions, + + name: this.name, + type: this.type, + esTypes: this.esTypes, + scripted: this.scripted, + searchable: this.searchable, + aggregatable: this.aggregatable, + readFromDocValues: this.readFromDocValues, + subType: this.subType, + }; + } + + public toSpec() { + return { + count: this.count, + script: this.script, + lang: this.lang, + conflictDescriptions: this.conflictDescriptions, + name: this.name, + type: this.type, + esTypes: this.esTypes, + scripted: this.scripted, + searchable: this.searchable, + aggregatable: this.aggregatable, + readFromDocValues: this.readFromDocValues, + subType: this.subType, + format: this.indexPattern?.fieldFormatMap[this.name]?.toJSON() || undefined, + }; + } +} diff --git a/src/plugins/data/common/index_patterns/fields/obj_define.js b/src/plugins/data/common/index_patterns/fields/obj_define.js deleted file mode 100644 index 9c9e5c8f3d55fa..00000000000000 --- a/src/plugins/data/common/index_patterns/fields/obj_define.js +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import _ from 'lodash'; - -export function ObjDefine(defaults, prototype) { - this.obj; // created by this.create() - - this.descs = {}; - this.defaults = defaults || {}; - this.prototype = prototype || Object.prototype; -} - -ObjDefine.REDEFINE_SUPPORTED = (function () { - const a = Object.create(Object.prototype, { - prop: { - configurable: true, - value: 1, - }, - }); - - Object.defineProperty(a, 'prop', { - configurable: true, - value: 2, - }); - - return a.prop === 2; -})(); - -/** - * normal value, writable and exported in JSON - * - * @param {any} v - value - * @return {object} - property descriptor - */ -ObjDefine.prototype.writ = function (name, val) { - this._define(name, val, true, true); -}; - -/** - * known value, exported in JSON, not changeable - * - * @param {any} v - value - * @return {object} - property descriptor - */ -ObjDefine.prototype.fact = function (name, val) { - this._define(name, val, true); -}; - -/** - * computed fact, not exported or changeable - * - * @param {any} v - value - * @return {object} - property descriptor - */ -ObjDefine.prototype.comp = function (name, val) { - this._define(name, val); -}; - -/** - * Creates an object, decorated by the property descriptors - * created by other ObjDefine methods and inheriting form the - * prototype - * - * # note: - * If a value is writable, but the value is undefined, the property will - * be created by not exported to JSON unless the property is written to - * - * @return {object} - created object - */ -ObjDefine.prototype.create = function () { - const self = this; - self.obj = Object.create(this.prototype, self.descs); - - if (!ObjDefine.REDEFINE_SUPPORTED && !self.prototype.toJSON) { - // since we can't redefine properties as enumerable we will - // clone the object on serialization and choose which properties - // to include or trim manually. This is currently only in use in PhantomJS - // due to https://github.com/ariya/phantomjs/issues/11856 - // TODO: remove this: https://github.com/elastic/kibana/issues/27136 - self.obj.toJSON = function () { - return _.transform( - self.obj, - function (json, val, key) { - const desc = self.descs[key]; - if (desc && desc.enumerable && val == null) return; - json[key] = val; - }, - {} - ); - }; - } - - return self.obj; -}; - -/** - * Private APIS - */ - -ObjDefine.prototype._define = function (name, val, exported, changeable) { - val = val != null ? val : this.defaults[name]; - this.descs[name] = this._describe(name, val, !!exported, !!changeable); -}; - -ObjDefine.prototype._describe = function (name, val, exported, changeable) { - const self = this; - const exists = val != null; - - if (exported && ObjDefine.REDEFINE_SUPPORTED) { - return { - enumerable: exists, - configurable: true, - get: _.constant(val), - set: function (update) { - if (!changeable) return false; - - // change the descriptor, since the value now exists. - self.descs[name] = self._describe(name, update, exported, changeable); - - // apply the updated descriptor - Object.defineProperty(self.obj, name, self.descs[name]); - }, - }; - } - - if (exported && !ObjDefine.REDEFINE_SUPPORTED) { - return { - enumerable: true, - configurable: true, - writable: changeable, - value: val, - }; - } - - return { - enumerable: false, - writable: changeable, - configurable: true, - value: val, - }; -}; diff --git a/src/plugins/data/common/index_patterns/fields/obj_define.test.js b/src/plugins/data/common/index_patterns/fields/obj_define.test.js deleted file mode 100644 index ec9a0222536218..00000000000000 --- a/src/plugins/data/common/index_patterns/fields/obj_define.test.js +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import expect from '@kbn/expect'; -import { ObjDefine } from './obj_define'; - -describe('ObjDefine Utility', function () { - function flatten(obj) { - return JSON.parse(JSON.stringify(obj)); - } - - describe('#writ', function () { - it('creates writeable properties', function () { - const def = new ObjDefine(); - def.writ('name', 'foo'); - - const obj = def.create(); - expect(obj).to.have.property('name', 'foo'); - - obj.name = 'bar'; - expect(obj).to.have.property('name', 'bar'); - }); - - it('exports the property to JSON', function () { - const def = new ObjDefine(); - def.writ('name', 'foo'); - expect(flatten(def.create())).to.have.property('name', 'foo'); - }); - - it("does not export property to JSON it it's undefined or null", function () { - const def = new ObjDefine(); - def.writ('name'); - expect(flatten(def.create())).to.not.have.property('name'); - - def.writ('name', null); - expect(flatten(def.create())).to.not.have.property('name'); - }); - - it('switched to exporting if a value is written', function () { - const def = new ObjDefine(); - def.writ('name'); - - const obj = def.create(); - expect(flatten(obj)).to.not.have.property('name'); - - obj.name = null; - expect(flatten(obj)).to.not.have.property('name'); - - obj.name = 'foo'; - expect(flatten(obj)).to.have.property('name', 'foo'); - }); - - it('setting a writ value to null prevents it from exporting', function () { - const def = new ObjDefine(); - def.writ('name', 'foo'); - - const obj = def.create(); - expect(flatten(obj)).to.have.property('name', 'foo'); - - obj.name = null; - expect(flatten(obj)).to.not.have.property('name'); - }); - }); - - describe('#fact', function () { - it('creates an immutable field', function () { - const def = new ObjDefine(); - const val = 'foo'; - const notval = 'bar'; - def.fact('name', val); - const obj = def.create(); - - obj.name = notval; // UPDATE SHOULD BE IGNORED - expect(obj).to.have.property('name', val); - }); - - it('exports the fact to JSON', function () { - const def = new ObjDefine(); - def.fact('name', 'foo'); - expect(flatten(def.create())).to.have.property('name', 'foo'); - }); - }); - - describe('#comp', function () { - it('creates an immutable field', function () { - const def = new ObjDefine(); - const val = 'foo'; - const notval = 'bar'; - def.comp('name', val); - const obj = def.create(); - - expect(function () { - 'use strict'; // eslint-disable-line strict - - obj.name = notval; - }).to.throwException(); - }); - - it('does not export the computed value to JSON', function () { - const def = new ObjDefine(); - def.comp('name', 'foo'); - expect(flatten(def.create())).to.not.have.property('name'); - }); - }); - - describe('#create', function () { - it('creates object that inherits from the prototype', function () { - function SomeClass() {} - - const def = new ObjDefine(null, SomeClass.prototype); - const obj = def.create(); - - expect(obj).to.be.a(SomeClass); - }); - - it('uses the defaults for property values', function () { - const def = new ObjDefine({ name: 'bar' }); - def.fact('name'); - - const obj = def.create(); - - expect(obj).to.have.property('name', 'bar'); - }); - - it('ignores default values that are not defined properties', function () { - const def = new ObjDefine({ name: 'foo', name2: 'bar' }); - const obj = def.create(); - - expect(obj).to.not.have.property('name'); - expect(obj).to.not.have.property('name2'); - }); - }); -}); diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_pattern.test.ts b/src/plugins/data/common/index_patterns/index_patterns/index_pattern.test.ts index ebf873b14c379d..97e7b6fde08308 100644 --- a/src/plugins/data/common/index_patterns/index_patterns/index_pattern.test.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index_pattern.test.ts @@ -26,7 +26,7 @@ import { DuplicateField } from '../../../../kibana_utils/common'; import mockLogStashFields from '../../../../../fixtures/logstash_fields'; // @ts-ignore import { stubbedSavedObjectIndexPattern } from '../../../../../fixtures/stubbed_saved_object_index_pattern'; -import { Field } from '../fields'; +import { IndexPatternField } from '../fields'; import { fieldFormatsMock } from '../../field_formats/mocks'; @@ -170,8 +170,8 @@ describe('IndexPattern', () => { describe('getScriptedFields', () => { test('should return all scripted fields', () => { const scriptedNames = mockLogStashFields() - .filter((item: Field) => item.scripted === true) - .map((item: Field) => item.name); + .filter((item: IndexPatternField) => item.scripted === true) + .map((item: IndexPatternField) => item.name); const respNames = map(indexPattern.getScriptedFields(), 'name'); expect(respNames).toEqual(scriptedNames); @@ -214,8 +214,8 @@ describe('IndexPattern', () => { describe('getNonScriptedFields', () => { test('should return all non-scripted fields', () => { const notScriptedNames = mockLogStashFields() - .filter((item: Field) => item.scripted === false) - .map((item: Field) => item.name); + .filter((item: IndexPatternField) => item.scripted === false) + .map((item: IndexPatternField) => item.name); const respNames = map(indexPattern.getNonScriptedFields(), 'name'); expect(respNames).toEqual(notScriptedNames); @@ -235,7 +235,7 @@ describe('IndexPattern', () => { const newFields = indexPattern.getNonScriptedFields(); expect(newFields).toHaveLength(2); - expect(newFields.map((f) => f.name)).toEqual(['foo', 'bar']); + expect([...newFields.map((f) => f.name)]).toEqual(['foo', 'bar']); }); test('should preserve the scripted fields', async () => { @@ -249,8 +249,8 @@ describe('IndexPattern', () => { // sinon.assert.calledOnce(indexPattern.getScriptedFields); expect(indexPattern.getScriptedFields().map((f) => f.name)).toEqual( mockLogStashFields() - .filter((f: Field) => f.scripted) - .map((f: Field) => f.name) + .filter((f: IndexPatternField) => f.scripted) + .map((f: IndexPatternField) => f.name) ); }); }); @@ -278,7 +278,7 @@ describe('IndexPattern', () => { const scriptedFields = indexPattern.getScriptedFields(); // expect(saveSpy.callCount).to.equal(1); expect(scriptedFields).toHaveLength(oldCount + 1); - expect((indexPattern.fields.getByName(scriptedField.name) as Field).name).toEqual( + expect((indexPattern.fields.getByName(scriptedField.name) as IndexPatternField).name).toEqual( scriptedField.name ); }); diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts b/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts index 2acb9d5f767ad7..927655c9309450 100644 --- a/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts @@ -22,10 +22,10 @@ import { i18n } from '@kbn/i18n'; import { SavedObjectsClientCommon } from '../..'; import { DuplicateField, SavedObjectNotFound } from '../../../../kibana_utils/common'; -import { ES_FIELD_TYPES, KBN_FIELD_TYPES, IIndexPattern, IFieldType } from '../../../common'; +import { ES_FIELD_TYPES, KBN_FIELD_TYPES, IIndexPattern } from '../../../common'; import { findByTitle } from '../utils'; import { IndexPatternMissingIndices } from '../lib'; -import { Field, IIndexPatternFieldList, getIndexPatternFieldListCreator } from '../fields'; +import { IndexPatternField, IIndexPatternFieldList, FieldList } from '../fields'; import { createFieldsFetcher } from './_fields_fetcher'; import { formatHitProvider } from './format_hit'; import { flattenHitWrapper } from './flatten_hit'; @@ -36,7 +36,7 @@ import { IIndexPatternsApiClient, IndexPatternAttributes, } from '../types'; -import { FieldFormatsStartCommon } from '../../field_formats'; +import { FieldFormatsStartCommon, FieldFormat } from '../../field_formats'; import { PatternCache } from './_pattern_cache'; import { expandShorthand, FieldMappingSpec, MappingObject } from '../../field_mapping'; import { IndexPatternSpec, TypeMeta, FieldSpec, SourceFilter } from '../types'; @@ -138,12 +138,8 @@ export class IndexPattern implements IIndexPattern { this.shortDotsEnable = uiSettingsValues.shortDotsEnable; this.metaFields = uiSettingsValues.metaFields; - this.createFieldList = getIndexPatternFieldListCreator({ - fieldFormats, - onNotification, - }); + this.fields = new FieldList(this, [], this.shortDotsEnable, this.onUnknownType); - this.fields = this.createFieldList(this, [], this.shortDotsEnable); this.apiClient = apiClient; this.fieldsFetcher = createFieldsFetcher(this, apiClient, uiSettingsValues.metaFields); this.flattenHit = flattenHitWrapper(this, uiSettingsValues.metaFields); @@ -161,11 +157,11 @@ export class IndexPattern implements IIndexPattern { } private deserializeFieldFormatMap(mapping: any) { - const FieldFormat = this.fieldFormats.getType(mapping.id); + const FieldFormatter = this.fieldFormats.getType(mapping.id); return ( - FieldFormat && - new FieldFormat( + FieldFormatter && + new FieldFormatter( mapping.params, (key: string) => this.uiSettingsValues[key]?.userValue || this.uiSettingsValues[key]?.value ) @@ -178,32 +174,34 @@ export class IndexPattern implements IIndexPattern { this.fields = this.createFieldList(this, newValue, this.shortDotsEnable); } - private isFieldRefreshRequired(): boolean { - if (!this.fields) { + private isFieldRefreshRequired(specs?: FieldSpec[]): boolean { + if (!specs) { return true; } - return this.fields.every((field) => { + return this.fields.every((spec) => { // See https://github.com/elastic/kibana/pull/8421 - const hasFieldCaps = 'aggregatable' in field && 'searchable' in field; + const hasFieldCaps = 'aggregatable' in spec && 'searchable' in spec; // See https://github.com/elastic/kibana/pull/11969 - const hasDocValuesFlag = 'readFromDocValues' in field; + const hasDocValuesFlag = 'readFromDocValues' in spec; return !hasFieldCaps || !hasDocValuesFlag; }); } - private async indexFields(forceFieldRefresh: boolean = false) { + private async indexFields(forceFieldRefresh: boolean = false, specs?: FieldSpec[]) { if (!this.id) { return; } - if (forceFieldRefresh || this.isFieldRefreshRequired()) { + if (forceFieldRefresh || this.isFieldRefreshRequired(specs)) { await this.refreshFields(); + } else { + if (specs) { + this.fields.replaceAll(specs); + } } - - this.initFields(); } public initFromSpec(spec: IndexPatternSpec) { @@ -227,9 +225,12 @@ export class IndexPattern implements IIndexPattern { // @ts-expect-error this.fields = spec.fields || []; this.typeMeta = spec.typeMeta; + // /* this.fieldFormatMap = _.mapValues(fieldFormatMap, (mapping) => { return this.deserializeFieldFormatMap(mapping); }); + // */ + // this.fieldFormatMap = fieldFormatMap this.initFields(); return this; @@ -249,14 +250,16 @@ export class IndexPattern implements IIndexPattern { }); // give index pattern all of the values + const fieldList = this.fields; _.assign(this, response); + this.fields = fieldList; if (!this.title && this.id) { this.title = this.id; } this.version = response.version; - return this.indexFields(forceFieldRefresh); + return this.indexFields(forceFieldRefresh, response._source.fields); } getComputedFields() { @@ -359,32 +362,26 @@ export class IndexPattern implements IIndexPattern { throw new DuplicateField(name); } - this.fields.add( - new Field( - this, - { - name, - script, - fieldType, - scripted: true, - lang, - aggregatable: true, - filterable: true, - searchable: true, - }, - false, - { - fieldFormats: this.fieldFormats, - onNotification: this.onNotification, - } - ) - ); + this.fields.add({ + name, + script, + type: fieldType, + scripted: true, + lang, + aggregatable: true, + searchable: true, + count: 0, + readFromDocValues: false, + }); await this.save(); } - removeScriptedField(field: IFieldType) { - this.fields.remove(field); + removeScriptedField(fieldName: string) { + const field = this.fields.getByName(fieldName); + if (field) { + this.fields.remove(field); + } return this.save(); } @@ -417,11 +414,11 @@ export class IndexPattern implements IIndexPattern { } getNonScriptedFields() { - return _.filter(this.fields, { scripted: false }); + return [...this.fields.filter((field) => !field.scripted)]; } getScriptedFields() { - return _.filter(this.fields, { scripted: true }); + return [...this.fields.filter((field) => field.scripted)]; } isTimeBased(): boolean { @@ -438,11 +435,12 @@ export class IndexPattern implements IIndexPattern { } getTimeField() { - if (!this.timeFieldName || !this.fields || !this.fields.getByName) return; - return this.fields.getByName(this.timeFieldName); + // todo perhaps less undefined + if (!this.timeFieldName || !this.fields || !this.fields.getByName) return undefined; + return this.fields.getByName(this.timeFieldName) || undefined; } - getFieldByName(name: string): Field | void { + getFieldByName(name: string): IndexPatternField | void { if (!this.fields || !this.fields.getByName) return; return this.fields.getByName(name); } @@ -470,6 +468,16 @@ export class IndexPattern implements IIndexPattern { return body; } + getFormatterForField(field: IndexPatternField | IndexPatternField['spec']): FieldFormat { + return ( + this.fieldFormatMap[field.name] || + this.fieldFormats.getDefaultInstance( + field.type as KBN_FIELD_TYPES, + field.esTypes as ES_FIELD_TYPES[] + ) + ); + } + async create(allowOverride: boolean = false) { const _create = async (duplicateId?: string) => { if (duplicateId) { @@ -581,9 +589,8 @@ export class IndexPattern implements IIndexPattern { async _fetchFields() { const fields = await this.fieldsFetcher.fetch(this); - const scripted = this.getScriptedFields(); - const all = fields.concat(scripted); - await this.initFields(all); + const scripted = this.getScriptedFields().map((field) => field.spec); + this.fields.replaceAll([...fields, ...scripted]); } refreshFields() { diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts index a07ffaf92aea57..8874ce5f04b7c2 100644 --- a/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts @@ -25,14 +25,13 @@ import { createEnsureDefaultIndexPattern, EnsureDefaultIndexPattern, } from './ensure_default_index_pattern'; -import { getIndexPatternFieldListCreator, CreateIndexPatternFieldList, Field } from '../fields'; +import { IndexPatternField } from '../fields'; import { OnNotification, OnError, UiSettingsCommon, IIndexPatternsApiClient, GetFieldsOptions, - FieldSpec, IndexPatternSpec, } from '../types'; import { FieldFormatsStartCommon } from '../../field_formats'; @@ -65,12 +64,6 @@ export class IndexPatternsService { private onNotification: OnNotification; private onError: OnError; ensureDefaultIndexPattern: EnsureDefaultIndexPattern; - createFieldList: CreateIndexPatternFieldList; - createField: ( - indexPattern: IndexPattern, - spec: FieldSpec | Field, - shortDotsEnable: boolean - ) => Field; constructor({ uiSettings, @@ -91,16 +84,15 @@ export class IndexPatternsService { uiSettings, onRedirectNoIndexPattern ); - this.createFieldList = getIndexPatternFieldListCreator({ - fieldFormats, - onNotification, - }); - this.createField = (indexPattern, spec, shortDotsEnable) => { - return new Field(indexPattern, spec, shortDotsEnable, { - fieldFormats, - onNotification, - }); - }; + } + + public createField( + indexPattern: IndexPattern, + spec: IndexPatternField['spec'], + displayName: string, + onNotification: OnNotification + ) { + return new IndexPatternField(indexPattern, spec, displayName, onNotification); } private async refreshSavedObjectsCache() { diff --git a/src/plugins/data/common/index_patterns/types.ts b/src/plugins/data/common/index_patterns/types.ts index 4241df57182437..3a7cf54843dfcc 100644 --- a/src/plugins/data/common/index_patterns/types.ts +++ b/src/plugins/data/common/index_patterns/types.ts @@ -149,8 +149,21 @@ export interface FieldSpecExportFmt { } export interface FieldSpec { - [key: string]: any; + count: number; + script?: string; + lang?: string; + conflictDescriptions?: Record; format?: SerializedFieldFormat; + + name: string; + type: string; + esTypes?: string[]; + scripted: boolean; + searchable: boolean; + aggregatable: boolean; + readFromDocValues?: boolean; + subType?: IFieldSubType; + indexed?: boolean; } export interface IndexPatternSpec { diff --git a/src/plugins/data/common/kbn_field_types/kbn_field_types.test.ts b/src/plugins/data/common/kbn_field_types/kbn_field_types.test.ts index a3fe19fa9b2fcb..6a2d6edd046923 100644 --- a/src/plugins/data/common/kbn_field_types/kbn_field_types.test.ts +++ b/src/plugins/data/common/kbn_field_types/kbn_field_types.test.ts @@ -55,10 +55,10 @@ describe('utils/kbn_field_types', () => { expect(kbnFieldType).toHaveProperty('name', ES_FIELD_TYPES.STRING); }); - test('returns undefined for invalid name', () => { + test('returns unknown for invalid name', () => { const kbnFieldType = getKbnFieldType('wrongType'); - expect(kbnFieldType).toBeUndefined(); + expect(kbnFieldType).toHaveProperty('name', KBN_FIELD_TYPES.UNKNOWN); }); }); diff --git a/src/plugins/data/common/kbn_field_types/kbn_field_types.ts b/src/plugins/data/common/kbn_field_types/kbn_field_types.ts index ce05dc796bbab7..ffeb9c517daf5c 100644 --- a/src/plugins/data/common/kbn_field_types/kbn_field_types.ts +++ b/src/plugins/data/common/kbn_field_types/kbn_field_types.ts @@ -17,7 +17,7 @@ * under the License. */ -import { createKbnFieldTypes } from './kbn_field_types_factory'; +import { createKbnFieldTypes, kbnFieldTypeUnknown } from './kbn_field_types_factory'; import { KbnFieldType } from './kbn_field_type'; import { ES_FIELD_TYPES, KBN_FIELD_TYPES } from './types'; @@ -30,8 +30,8 @@ const registeredKbnTypes = createKbnFieldTypes(); * @param {string} typeName * @return {KbnFieldType} */ -export const getKbnFieldType = (typeName: string): KbnFieldType | undefined => - registeredKbnTypes.find((t) => t.name === typeName); +export const getKbnFieldType = (typeName: string): KbnFieldType => + registeredKbnTypes.find((t) => t.name === typeName) || kbnFieldTypeUnknown; /** * Get the esTypes known by all kbnFieldTypes diff --git a/src/plugins/data/common/kbn_field_types/kbn_field_types_factory.ts b/src/plugins/data/common/kbn_field_types/kbn_field_types_factory.ts index cb9357eb9865e5..b93ebcbbca9c8a 100644 --- a/src/plugins/data/common/kbn_field_types/kbn_field_types_factory.ts +++ b/src/plugins/data/common/kbn_field_types/kbn_field_types_factory.ts @@ -20,6 +20,10 @@ import { KbnFieldType } from './kbn_field_type'; import { ES_FIELD_TYPES, KBN_FIELD_TYPES } from './types'; +export const kbnFieldTypeUnknown = new KbnFieldType({ + name: KBN_FIELD_TYPES.UNKNOWN, +}); + export const createKbnFieldTypes = (): KbnFieldType[] => [ new KbnFieldType({ name: KBN_FIELD_TYPES.STRING, @@ -103,7 +107,5 @@ export const createKbnFieldTypes = (): KbnFieldType[] => [ new KbnFieldType({ name: KBN_FIELD_TYPES.CONFLICT, }), - new KbnFieldType({ - name: KBN_FIELD_TYPES.UNKNOWN, - }), + kbnFieldTypeUnknown, ]; diff --git a/src/plugins/data/public/index.ts b/src/plugins/data/public/index.ts index 846471420327fa..9e36d3b59bbd62 100644 --- a/src/plugins/data/public/index.ts +++ b/src/plugins/data/public/index.ts @@ -247,9 +247,7 @@ export { IndexPatternsContract, IndexPattern, IIndexPatternFieldList, - Field as IndexPatternField, - // TODO: exported only in stub_index_pattern test. Move into data plugin and remove export. - getIndexPatternFieldListCreator, + IndexPatternField, } from './index_patterns'; export { diff --git a/src/plugins/data/public/index_patterns/index.ts b/src/plugins/data/public/index_patterns/index.ts index a6ee71c624f5af..9cd5e5a4736f10 100644 --- a/src/plugins/data/public/index_patterns/index.ts +++ b/src/plugins/data/public/index_patterns/index.ts @@ -28,11 +28,7 @@ export { } from '../../common/index_patterns/lib'; export { flattenHitWrapper, formatHitProvider, onRedirectNoIndexPattern } from './index_patterns'; -export { - getIndexPatternFieldListCreator, - Field, - IIndexPatternFieldList, -} from '../../common/index_patterns'; +export { IndexPatternField, IIndexPatternFieldList } from '../../common/index_patterns'; export { IndexPatternsService, diff --git a/src/plugins/data/public/search/aggs/agg_configs.test.ts b/src/plugins/data/public/search/aggs/agg_configs.test.ts index df4a5420ae0db3..ff0cc3341929e2 100644 --- a/src/plugins/data/public/search/aggs/agg_configs.test.ts +++ b/src/plugins/data/public/search/aggs/agg_configs.test.ts @@ -22,7 +22,7 @@ import { AggConfig } from './agg_config'; import { AggConfigs } from './agg_configs'; import { AggTypesRegistryStart } from './agg_types_registry'; import { mockAggTypesRegistry } from './test_helpers'; -import { Field as IndexPatternField, IndexPattern } from '../../index_patterns'; +import { IndexPatternField, IndexPattern } from '../../index_patterns'; import { stubIndexPattern, stubIndexPatternWithFields } from '../../../public/stubs'; describe('AggConfigs', () => { diff --git a/src/plugins/data/public/search/aggs/param_types/field.ts b/src/plugins/data/public/search/aggs/param_types/field.ts index cb3617b02e882a..7c00bc668a39f6 100644 --- a/src/plugins/data/public/search/aggs/param_types/field.ts +++ b/src/plugins/data/public/search/aggs/param_types/field.ts @@ -23,7 +23,7 @@ import { SavedObjectNotFound } from '../../../../../../plugins/kibana_utils/comm import { BaseParamType } from './base'; import { propFilter } from '../utils'; import { isNestedField, KBN_FIELD_TYPES } from '../../../../common'; -import { Field as IndexPatternField } from '../../../index_patterns'; +import { IndexPatternField } from '../../../index_patterns'; const filterByType = propFilter('type'); diff --git a/src/plugins/discover/public/application/components/sidebar/discover_field.test.tsx b/src/plugins/discover/public/application/components/sidebar/discover_field.test.tsx index 099ec2e5b1ffcb..3f12a8c0fa7694 100644 --- a/src/plugins/discover/public/application/components/sidebar/discover_field.test.tsx +++ b/src/plugins/discover/public/application/components/sidebar/discover_field.test.tsx @@ -28,7 +28,6 @@ import { mountWithIntl } from 'test_utils/enzyme_helpers'; import { DiscoverField } from './discover_field'; import { coreMock } from '../../../../../../core/public/mocks'; import { IndexPatternField } from '../../../../../data/public'; -import { FieldSpecExportFmt } from '../../../../../data/common'; jest.mock('../../../kibana_services', () => ({ getServices: () => ({ @@ -63,20 +62,21 @@ function getComponent(selected = false, showDetails = false, useShortDots = fals coreMock.createStart() ); - const field = { - name: 'bytes', - type: 'number', - esTypes: ['long'], - count: 10, - scripted: false, - searchable: true, - aggregatable: true, - readFromDocValues: true, - format: null, - routes: {}, - $$spec: {}, - toSpec: () => (({} as unknown) as FieldSpecExportFmt), - } as IndexPatternField; + const field = new IndexPatternField( + indexPattern, + { + name: 'bytes', + type: 'number', + esTypes: ['long'], + count: 10, + scripted: false, + searchable: true, + aggregatable: true, + readFromDocValues: true, + }, + 'bytes', + () => {} + ); const props = { indexPattern, diff --git a/src/plugins/discover/public/application/components/sidebar/discover_sidebar.tsx b/src/plugins/discover/public/application/components/sidebar/discover_sidebar.tsx index e8ed8b80da3bbf..58b468762c5011 100644 --- a/src/plugins/discover/public/application/components/sidebar/discover_sidebar.tsx +++ b/src/plugins/discover/public/application/components/sidebar/discover_sidebar.tsx @@ -29,12 +29,7 @@ import { IndexPatternAttributes } from '../../../../../data/common'; import { SavedObject } from '../../../../../../core/types'; import { FIELDS_LIMIT_SETTING } from '../../../../common'; import { groupFields } from './lib/group_fields'; -import { - IIndexPatternFieldList, - IndexPatternField, - IndexPattern, - UI_SETTINGS, -} from '../../../../../data/public'; +import { IndexPatternField, IndexPattern, UI_SETTINGS } from '../../../../../data/public'; import { AppState } from '../../angular/discover_state'; import { getDetails } from './lib/get_details'; import { getDefaultFieldFilter, setFieldFilterProp } from './lib/field_filter'; @@ -99,12 +94,12 @@ export function DiscoverSidebar({ }: DiscoverSidebarProps) { const [openFieldMap, setOpenFieldMap] = useState(new Map()); const [showFields, setShowFields] = useState(false); - const [fields, setFields] = useState(null); + const [fields, setFields] = useState(null); const [fieldFilterState, setFieldFilterState] = useState(getDefaultFieldFilter()); const services = useMemo(() => getServices(), []); useEffect(() => { - const newFields = getIndexPatternFieldList(selectedIndexPattern, fieldCounts, services); + const newFields = getIndexPatternFieldList(selectedIndexPattern, fieldCounts); setFields(newFields); }, [selectedIndexPattern, fieldCounts, hits, services]); diff --git a/src/plugins/discover/public/application/components/sidebar/lib/get_index_pattern_field_list.ts b/src/plugins/discover/public/application/components/sidebar/lib/get_index_pattern_field_list.ts index 0fcbe925e07983..751a59d9821534 100644 --- a/src/plugins/discover/public/application/components/sidebar/lib/get_index_pattern_field_list.ts +++ b/src/plugins/discover/public/application/components/sidebar/lib/get_index_pattern_field_list.ts @@ -18,25 +18,23 @@ */ import { difference, map } from 'lodash'; import { IndexPattern, IndexPatternField } from 'src/plugins/data/public'; -import { DiscoverServices } from '../../../../build_services'; export function getIndexPatternFieldList( indexPattern: IndexPattern, - fieldCounts: Record, - { data }: DiscoverServices + fieldCounts: Record ) { - if (!indexPattern || !fieldCounts) return data.indexPatterns.createFieldList(indexPattern); + if (!indexPattern || !fieldCounts) return []; - const fieldSpecs = indexPattern.fields.slice(0); const fieldNamesInDocs = Object.keys(fieldCounts); const fieldNamesInIndexPattern = map(indexPattern.fields, 'name'); + const unknownTypes: IndexPatternField[] = []; difference(fieldNamesInDocs, fieldNamesInIndexPattern).forEach((unknownFieldName) => { - fieldSpecs.push({ + unknownTypes.push({ name: String(unknownFieldName), type: 'unknown', } as IndexPatternField); }); - return data.indexPatterns.createFieldList(indexPattern, fieldSpecs); + return [...indexPattern.fields, ...unknownTypes]; } diff --git a/src/plugins/discover/public/application/components/sidebar/lib/group_fields.tsx b/src/plugins/discover/public/application/components/sidebar/lib/group_fields.tsx index fab4637d87ca7a..c6a06618900fd5 100644 --- a/src/plugins/discover/public/application/components/sidebar/lib/group_fields.tsx +++ b/src/plugins/discover/public/application/components/sidebar/lib/group_fields.tsx @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -import { IIndexPatternFieldList, IndexPatternField } from 'src/plugins/data/public'; +import { IndexPatternField } from 'src/plugins/data/public'; import { FieldFilterState, isFieldFiltered } from './field_filter'; interface GroupedFields { @@ -29,7 +29,7 @@ interface GroupedFields { * group the fields into selected, popular and unpopular, filter by fieldFilterState */ export function groupFields( - fields: IIndexPatternFieldList | null, + fields: IndexPatternField[] | null, columns: string[], popularLimit: number, fieldCounts: Record, diff --git a/src/plugins/index_pattern_management/public/components/edit_index_pattern/create_edit_field/create_edit_field.tsx b/src/plugins/index_pattern_management/public/components/edit_index_pattern/create_edit_field/create_edit_field.tsx index f7b982ef1659ee..22bc78ee0538e4 100644 --- a/src/plugins/index_pattern_management/public/components/edit_index_pattern/create_edit_field/create_edit_field.tsx +++ b/src/plugins/index_pattern_management/public/components/edit_index_pattern/create_edit_field/create_edit_field.tsx @@ -21,7 +21,7 @@ import { withRouter, RouteComponentProps } from 'react-router-dom'; import { EuiFlexGroup, EuiFlexItem, EuiPanel } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; -import { IndexPattern } from '../../../../../../plugins/data/public'; +import { IndexPattern, IndexPatternField } from '../../../../../../plugins/data/public'; import { useKibana } from '../../../../../../plugins/kibana_react/public'; import { IndexPatternManagmentContext } from '../../../types'; import { IndexHeader } from '../index_header'; @@ -44,24 +44,21 @@ const newFieldPlaceholder = i18n.translate( export const CreateEditField = withRouter( ({ indexPattern, mode, fieldName, history }: CreateEditFieldProps) => { - const { data, uiSettings, chrome, notifications } = useKibana< + const { uiSettings, chrome, notifications } = useKibana< IndexPatternManagmentContext >().services; - const field = + const spec = mode === 'edit' && fieldName - ? indexPattern.fields.getByName(fieldName) - : data.indexPatterns.createField( - indexPattern, - { - scripted: true, - type: 'number', - }, - false - ); + ? indexPattern.fields.getByName(fieldName)?.spec + : (({ + scripted: true, + type: 'number', + name: undefined, + } as unknown) as IndexPatternField); const url = `/patterns/${indexPattern.id}`; - if (mode === 'edit' && !field) { + if (mode === 'edit' && !spec) { const message = i18n.translate( 'indexPatternManagement.editIndexPattern.scripted.noFieldLabel', { @@ -74,17 +71,17 @@ export const CreateEditField = withRouter( history.push(url); } - const docFieldName = field?.name || newFieldPlaceholder; + const docFieldName = spec?.name || newFieldPlaceholder; chrome.docTitle.change([docFieldName, indexPattern.title]); const redirectAway = () => { history.push( - `${url}#/?_a=(tab:${field?.scripted ? TAB_SCRIPTED_FIELDS : TAB_INDEXED_FIELDS})` + `${url}#/?_a=(tab:${spec?.scripted ? TAB_SCRIPTED_FIELDS : TAB_INDEXED_FIELDS})` ); }; - if (field) { + if (spec) { return ( @@ -97,7 +94,7 @@ export const CreateEditField = withRouter( { return { - ...field, + ...field.spec, displayName: field.displayName, indexPattern: field.indexPattern, format: getFieldFormat(indexPattern, field.name), diff --git a/src/plugins/index_pattern_management/public/components/field_editor/field_editor.tsx b/src/plugins/index_pattern_management/public/components/field_editor/field_editor.tsx index 99ef83604239a5..7755a86b8f26a9 100644 --- a/src/plugins/index_pattern_management/public/components/field_editor/field_editor.tsx +++ b/src/plugins/index_pattern_management/public/components/field_editor/field_editor.tsx @@ -76,7 +76,7 @@ import { executeScript, isScriptValid } from './lib'; import 'brace/mode/groovy'; const getFieldTypeFormatsList = ( - field: IFieldType, + field: IndexPatternField['spec'], defaultFieldFormat: FieldFormatInstanceType, fieldFormats: DataPublicPluginStart['fieldFormats'] ) => { @@ -108,10 +108,6 @@ interface InitialFieldTypeFormat extends FieldTypeFormat { defaultFieldFormat: FieldFormatInstanceType; } -interface FieldClone extends IndexPatternField { - format: any; -} - export interface FieldEditorState { isReady: boolean; isCreating: boolean; @@ -120,7 +116,6 @@ export interface FieldEditorState { fieldTypes: string[]; fieldTypeFormats: FieldTypeFormat[]; existingFieldNames: string[]; - field: FieldClone; fieldFormatId?: string; fieldFormatParams: { [key: string]: unknown }; showScriptingHelp: boolean; @@ -129,11 +124,13 @@ export interface FieldEditorState { hasScriptError: boolean; isSaving: boolean; errors?: string[]; + format: any; + spec: IndexPatternField['spec']; } export interface FieldEdiorProps { indexPattern: IndexPattern; - field: IndexPatternField; + spec: IndexPatternField['spec']; services: { redirectAway: () => void; }; @@ -149,7 +146,7 @@ export class FieldEditor extends PureComponent f.name), - field: { ...field, format: field.format }, fieldFormatId: undefined, fieldFormatParams: {}, showScriptingHelp: false, @@ -167,6 +163,8 @@ export class FieldEditor extends PureComponent f.name === field.name), - isDeprecatedLang: this.deprecatedLangs.includes(field.lang || ''), + isCreating: !indexPattern.fields.find((f) => f.name === spec.name), + isDeprecatedLang: this.deprecatedLangs.includes(spec.lang || ''), errors: [], scriptingLangs, fieldTypes, fieldTypeFormats: getFieldTypeFormatsList( - field, + spec, DefaultFieldFormat as FieldFormatInstanceType, data.fieldFormats ), - fieldFormatId: get(indexPattern, ['fieldFormatMap', field.name, 'type', 'id']), - fieldFormatParams: field.format.params(), + fieldFormatId: get(indexPattern, ['fieldFormatMap', spec.name, 'type', 'id']), + fieldFormatParams: format.params(), }); } onFieldChange = (fieldName: string, value: string | number) => { - const { field } = this.state; - (field as any)[fieldName] = value; + const { spec } = this.state; + (spec as any)[fieldName] = value; this.forceUpdate(); }; onTypeChange = (type: KBN_FIELD_TYPES) => { const { uiSettings, data } = this.context.services; - const { field } = this.state; + const { spec, format } = this.state; const DefaultFieldFormat = data.fieldFormats.getDefaultType(type) as FieldFormatInstanceType; - field.type = type; + spec.type = type; - field.format = new DefaultFieldFormat(null, (key) => uiSettings.get(key)); + spec.format = new DefaultFieldFormat(null, (key) => uiSettings.get(key)); this.setState({ - fieldTypeFormats: getFieldTypeFormatsList(field, DefaultFieldFormat, data.fieldFormats), + fieldTypeFormats: getFieldTypeFormatsList(spec, DefaultFieldFormat, data.fieldFormats), fieldFormatId: DefaultFieldFormat.id, - fieldFormatParams: field.format.params(), + fieldFormatParams: format.params(), }); }; onLangChange = (lang: string) => { - const { field } = this.state; + const { spec } = this.state; const fieldTypes = get(FIELD_TYPES_BY_LANG, lang, DEFAULT_FIELD_TYPES); - field.lang = lang; - field.type = fieldTypes.includes(field.type) ? field.type : fieldTypes[0]; + spec.lang = lang; + spec.type = fieldTypes.includes(spec.type) ? spec.type : fieldTypes[0]; this.setState({ fieldTypes, @@ -244,18 +246,18 @@ export class FieldEditor extends PureComponent { - const { field, fieldTypeFormats } = this.state; + const { spec, format, fieldTypeFormats } = this.state; const { uiSettings, data } = this.context.services; const FieldFormat = data.fieldFormats.getType( formatId || (fieldTypeFormats[0] as InitialFieldTypeFormat).defaultFieldFormat.id ) as FieldFormatInstanceType; - field.format = new FieldFormat(params, (key) => uiSettings.get(key)); + spec.format = new FieldFormat(params, (key) => uiSettings.get(key)); this.setState({ fieldFormatId: FieldFormat.id, - fieldFormatParams: field.format.params(), + fieldFormatParams: format.params(), }); }; @@ -271,13 +273,13 @@ export class FieldEditor extends PureComponent ), - fieldName: {field.name}, + fieldName: {spec.name}, }} /> @@ -316,7 +318,7 @@ export class FieldEditor extends PureComponent {field.lang}, + language: {spec.lang}, painlessLink: ( { return { value: lang, text: lang }; })} @@ -388,15 +390,15 @@ export class FieldEditor extends PureComponent { return { value: type, text: type }; })} @@ -414,8 +416,8 @@ export class FieldEditor extends PureComponent ({ + const items = Object.entries(spec.conflictDescriptions).map(([type, indices]) => ({ type, indices: Array.isArray(indices) ? indices.join(', ') : 'Index names unavailable', })); @@ -466,7 +468,7 @@ export class FieldEditor extends PureComponent { - return { value: format.id || '', text: format.title }; + options={fieldTypeFormats.map((fmt) => { + return { value: fmt.id || '', text: fmt.title }; })} data-test-subj="editorSelectedFormatId" onChange={(e) => { @@ -507,8 +509,8 @@ export class FieldEditor extends PureComponent {fieldFormatId ? ( { this.onFieldChange('count', e.target.value ? Number(e.target.value) : ''); @@ -550,8 +552,8 @@ export class FieldEditor extends PureComponent ); - return field.scripted ? ( + return spec.scripted ? ( { - const { field } = this.state; + const { spec } = this.state; return this.state.showDeleteModal ? ( { @@ -674,7 +676,7 @@ export class FieldEditor extends PureComponent - {!isCreating && field.scripted ? ( + {!isCreating && spec.scripted ? ( @@ -729,9 +731,9 @@ export class FieldEditor extends PureComponent { - const { scriptingLangs, field, showScriptingHelp } = this.state; + const { scriptingLangs, spec, showScriptingHelp } = this.state; - if (!field.scripted) { + if (!spec.scripted) { return; } @@ -743,9 +745,9 @@ export class FieldEditor extends PureComponent @@ -755,14 +757,14 @@ export class FieldEditor extends PureComponent { const { redirectAway } = this.props.services; const { indexPattern } = this.props; - const { field } = this.state; - const remove = indexPattern.removeScriptedField(field); + const { spec } = this.state; + const remove = indexPattern.removeScriptedField(spec.name); if (remove) { remove.then(() => { const message = i18n.translate('indexPatternManagement.deleteField.deletedHeader', { defaultMessage: "Deleted '{fieldName}'", - values: { fieldName: field.name }, + values: { fieldName: spec.name }, }); this.context.services.notifications.toasts.addSuccess(message); redirectAway(); @@ -773,7 +775,7 @@ export class FieldEditor extends PureComponent { - const field = this.state.field; + const field = this.state.spec; const { indexPattern } = this.props; const { fieldFormatId } = this.state; @@ -802,10 +804,10 @@ export class FieldEditor extends PureComponent f.name === field.name); - let oldField: IFieldType | undefined; + let oldField: IndexPatternField['spec']; if (index > -1) { - oldField = indexPattern.fields.getByName(field.name); + oldField = indexPattern.fields.getByName(field.name)!.spec; indexPattern.fields.update(field); } else { indexPattern.fields.add(field); @@ -837,14 +839,14 @@ export class FieldEditor extends PureComponent @@ -868,7 +870,7 @@ export class FieldEditor extends PureComponent )} From ffd03728d69a2c3d5f12e9afe94170d0c686006a Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Thu, 23 Jul 2020 23:17:49 -0500 Subject: [PATCH 02/13] fix index_pattern class --- ...-public.getindexpatternfieldlistcreator.md | 11 -- ...public.iindexpatternfieldlist.getbyname.md | 6 +- ...public.iindexpatternfieldlist.getbytype.md | 6 +- ...gins-data-public.iindexpatternfieldlist.md | 4 +- ...public.iindexpatternfieldlist.removeall.md | 15 +++ ...ublic.iindexpatternfieldlist.replaceall.md | 22 +++ ...data-public.indexpattern.getfieldbyname.md | 4 +- ...ublic.indexpattern.getformatterforfield.md | 22 +++ ...ublic.indexpattern.getnonscriptedfields.md | 4 +- ...a-public.indexpattern.getscriptedfields.md | 4 +- ...s-data-public.indexpattern.gettimefield.md | 4 +- ...plugin-plugins-data-public.indexpattern.md | 3 +- ...public.indexpattern.removescriptedfield.md | 4 +- ...-public.indexpatternfield._constructor_.md | 12 +- ...a-public.indexpatternfield.aggregatable.md | 2 +- ....indexpatternfield.conflictdescriptions.md | 4 +- ...ins-data-public.indexpatternfield.count.md | 4 +- ...ta-public.indexpatternfield.displayname.md | 2 +- ...s-data-public.indexpatternfield.estypes.md | 2 +- ...ata-public.indexpatternfield.filterable.md | 2 +- ...ns-data-public.indexpatternfield.format.md | 2 +- ...a-public.indexpatternfield.indexpattern.md | 2 +- ...gins-data-public.indexpatternfield.lang.md | 4 +- ...n-plugins-data-public.indexpatternfield.md | 30 +++-- ...gins-data-public.indexpatternfield.name.md | 2 +- ...lic.indexpatternfield.readfromdocvalues.md | 2 +- ...ns-data-public.indexpatternfield.script.md | 4 +- ...-data-public.indexpatternfield.scripted.md | 2 +- ...ata-public.indexpatternfield.searchable.md | 2 +- ...-data-public.indexpatternfield.sortable.md | 2 +- ...ins-data-public.indexpatternfield.spec.md} | 6 +- ...s-data-public.indexpatternfield.subtype.md | 2 +- ...ns-data-public.indexpatternfield.tojson.md | 41 ++++++ ...ns-data-public.indexpatternfield.tospec.md | 36 ++++- ...gins-data-public.indexpatternfield.type.md | 2 +- ...a-public.indexpatternfield.visualizable.md | 2 +- .../kibana-plugin-plugins-data-public.md | 1 - .../index_patterns/index_pattern.ts | 4 +- src/plugins/data/public/public.api.md | 127 +++++++++++------- 39 files changed, 288 insertions(+), 122 deletions(-) delete mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.getindexpatternfieldlistcreator.md create mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.iindexpatternfieldlist.removeall.md create mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.iindexpatternfieldlist.replaceall.md create mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.getformatterforfield.md rename docs/development/plugins/data/public/{kibana-plugin-plugins-data-public.indexpatternfield.__spec.md => kibana-plugin-plugins-data-public.indexpatternfield.spec.md} (56%) create mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.tojson.md diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.getindexpatternfieldlistcreator.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.getindexpatternfieldlistcreator.md deleted file mode 100644 index 880acdc8956d49..00000000000000 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.getindexpatternfieldlistcreator.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [getIndexPatternFieldListCreator](./kibana-plugin-plugins-data-public.getindexpatternfieldlistcreator.md) - -## getIndexPatternFieldListCreator variable - -Signature: - -```typescript -getIndexPatternFieldListCreator: ({ fieldFormats, onNotification, }: FieldListDependencies) => CreateIndexPatternFieldList -``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.iindexpatternfieldlist.getbyname.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.iindexpatternfieldlist.getbyname.md index 14b5aa7137dc2c..e277df87fe908c 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.iindexpatternfieldlist.getbyname.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.iindexpatternfieldlist.getbyname.md @@ -7,16 +7,16 @@ Signature: ```typescript -getByName(name: Field['name']): Field | undefined; +getByName(name: IndexPatternField['name']): IndexPatternField | undefined; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| name | Field['name'] | | +| name | IndexPatternField['name'] | | Returns: -`Field | undefined` +`IndexPatternField | undefined` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.iindexpatternfieldlist.getbytype.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.iindexpatternfieldlist.getbytype.md index 3c65b78e5291db..9a7b3ab36b0c12 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.iindexpatternfieldlist.getbytype.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.iindexpatternfieldlist.getbytype.md @@ -7,16 +7,16 @@ Signature: ```typescript -getByType(type: Field['type']): Field[]; +getByType(type: IndexPatternField['type']): IndexPatternField[]; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| type | Field['type'] | | +| type | IndexPatternField['type'] | | Returns: -`Field[]` +`IndexPatternField[]` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.iindexpatternfieldlist.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.iindexpatternfieldlist.md index 47d7c7491aa86f..4ab012a2601d22 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.iindexpatternfieldlist.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.iindexpatternfieldlist.md @@ -7,7 +7,7 @@ Signature: ```typescript -export interface IIndexPatternFieldList extends Array +export interface IIndexPatternFieldList extends Array ``` ## Methods @@ -18,5 +18,7 @@ export interface IIndexPatternFieldList extends Array | [getByName(name)](./kibana-plugin-plugins-data-public.iindexpatternfieldlist.getbyname.md) | | | [getByType(type)](./kibana-plugin-plugins-data-public.iindexpatternfieldlist.getbytype.md) | | | [remove(field)](./kibana-plugin-plugins-data-public.iindexpatternfieldlist.remove.md) | | +| [removeAll()](./kibana-plugin-plugins-data-public.iindexpatternfieldlist.removeall.md) | | +| [replaceAll(specs)](./kibana-plugin-plugins-data-public.iindexpatternfieldlist.replaceall.md) | | | [update(field)](./kibana-plugin-plugins-data-public.iindexpatternfieldlist.update.md) | | diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.iindexpatternfieldlist.removeall.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.iindexpatternfieldlist.removeall.md new file mode 100644 index 00000000000000..55e7ca98e2637a --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.iindexpatternfieldlist.removeall.md @@ -0,0 +1,15 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [IIndexPatternFieldList](./kibana-plugin-plugins-data-public.iindexpatternfieldlist.md) > [removeAll](./kibana-plugin-plugins-data-public.iindexpatternfieldlist.removeall.md) + +## IIndexPatternFieldList.removeAll() method + +Signature: + +```typescript +removeAll(): void; +``` +Returns: + +`void` + diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.iindexpatternfieldlist.replaceall.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.iindexpatternfieldlist.replaceall.md new file mode 100644 index 00000000000000..c7e8cdd578bfe7 --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.iindexpatternfieldlist.replaceall.md @@ -0,0 +1,22 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [IIndexPatternFieldList](./kibana-plugin-plugins-data-public.iindexpatternfieldlist.md) > [replaceAll](./kibana-plugin-plugins-data-public.iindexpatternfieldlist.replaceall.md) + +## IIndexPatternFieldList.replaceAll() method + +Signature: + +```typescript +replaceAll(specs: FieldSpec[]): void; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| specs | FieldSpec[] | | + +Returns: + +`void` + diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.getfieldbyname.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.getfieldbyname.md index e6a23c5c70aab7..d0bafe7fa75951 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.getfieldbyname.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.getfieldbyname.md @@ -7,7 +7,7 @@ Signature: ```typescript -getFieldByName(name: string): Field | void; +getFieldByName(name: string): IndexPatternField | void; ``` ## Parameters @@ -18,5 +18,5 @@ getFieldByName(name: string): Field | void; Returns: -`Field | void` +`IndexPatternField | void` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.getformatterforfield.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.getformatterforfield.md new file mode 100644 index 00000000000000..7984f7aff1d2df --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.getformatterforfield.md @@ -0,0 +1,22 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [IndexPattern](./kibana-plugin-plugins-data-public.indexpattern.md) > [getFormatterForField](./kibana-plugin-plugins-data-public.indexpattern.getformatterforfield.md) + +## IndexPattern.getFormatterForField() method + +Signature: + +```typescript +getFormatterForField(field: IndexPatternField | IndexPatternField['spec']): FieldFormat; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| field | IndexPatternField | IndexPatternField['spec'] | | + +Returns: + +`FieldFormat` + diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.getnonscriptedfields.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.getnonscriptedfields.md index 4e49304484815c..77ce6f6f23a671 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.getnonscriptedfields.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.getnonscriptedfields.md @@ -7,9 +7,9 @@ Signature: ```typescript -getNonScriptedFields(): Field[]; +getNonScriptedFields(): IndexPatternField[]; ``` Returns: -`Field[]` +`IndexPatternField[]` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.getscriptedfields.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.getscriptedfields.md index 9ab4f9a9aaed53..055f07367c96e0 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.getscriptedfields.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.getscriptedfields.md @@ -7,9 +7,9 @@ Signature: ```typescript -getScriptedFields(): Field[]; +getScriptedFields(): IndexPatternField[]; ``` Returns: -`Field[]` +`IndexPatternField[]` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.gettimefield.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.gettimefield.md index 8e68e8c35aff76..24de0be3794bb2 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.gettimefield.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.gettimefield.md @@ -7,9 +7,9 @@ Signature: ```typescript -getTimeField(): Field | undefined; +getTimeField(): IndexPatternField | undefined; ``` Returns: -`Field | undefined` +`IndexPatternField | undefined` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.md index a37f1153589222..d340aaeeef25e0 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.md @@ -42,6 +42,7 @@ export declare class IndexPattern implements IIndexPattern | [getAggregationRestrictions()](./kibana-plugin-plugins-data-public.indexpattern.getaggregationrestrictions.md) | | | | [getComputedFields()](./kibana-plugin-plugins-data-public.indexpattern.getcomputedfields.md) | | | | [getFieldByName(name)](./kibana-plugin-plugins-data-public.indexpattern.getfieldbyname.md) | | | +| [getFormatterForField(field)](./kibana-plugin-plugins-data-public.indexpattern.getformatterforfield.md) | | | | [getNonScriptedFields()](./kibana-plugin-plugins-data-public.indexpattern.getnonscriptedfields.md) | | | | [getScriptedFields()](./kibana-plugin-plugins-data-public.indexpattern.getscriptedfields.md) | | | | [getSourceFiltering()](./kibana-plugin-plugins-data-public.indexpattern.getsourcefiltering.md) | | | @@ -55,7 +56,7 @@ export declare class IndexPattern implements IIndexPattern | [popularizeField(fieldName, unit)](./kibana-plugin-plugins-data-public.indexpattern.popularizefield.md) | | | | [prepBody()](./kibana-plugin-plugins-data-public.indexpattern.prepbody.md) | | | | [refreshFields()](./kibana-plugin-plugins-data-public.indexpattern.refreshfields.md) | | | -| [removeScriptedField(field)](./kibana-plugin-plugins-data-public.indexpattern.removescriptedfield.md) | | | +| [removeScriptedField(fieldName)](./kibana-plugin-plugins-data-public.indexpattern.removescriptedfield.md) | | | | [save(saveAttempts)](./kibana-plugin-plugins-data-public.indexpattern.save.md) | | | | [toJSON()](./kibana-plugin-plugins-data-public.indexpattern.tojson.md) | | | | [toSpec()](./kibana-plugin-plugins-data-public.indexpattern.tospec.md) | | | diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.removescriptedfield.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.removescriptedfield.md index 2a6811f5011524..42c6dd72b8c4ed 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.removescriptedfield.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.removescriptedfield.md @@ -7,14 +7,14 @@ Signature: ```typescript -removeScriptedField(field: IFieldType): Promise; +removeScriptedField(fieldName: string): Promise; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| field | IFieldType | | +| fieldName | string | | Returns: diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield._constructor_.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield._constructor_.md index 7a195702b6f13f..10b65bdccdf87e 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield._constructor_.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield._constructor_.md @@ -4,20 +4,20 @@ ## IndexPatternField.(constructor) -Constructs a new instance of the `Field` class +Constructs a new instance of the `IndexPatternField` class Signature: ```typescript -constructor(indexPattern: IIndexPattern, spec: FieldSpecExportFmt | FieldSpec | Field, shortDotsEnable: boolean, { fieldFormats, onNotification }: FieldDependencies); +constructor(indexPattern: IndexPattern, spec: FieldSpec, displayName: string, onNotification: OnNotification); ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| indexPattern | IIndexPattern | | -| spec | FieldSpecExportFmt | FieldSpec | Field | | -| shortDotsEnable | boolean | | -| { fieldFormats, onNotification } | FieldDependencies | | +| indexPattern | IndexPattern | | +| spec | FieldSpec | | +| displayName | string | | +| onNotification | OnNotification | | diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.aggregatable.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.aggregatable.md index 267c8f786b5dd2..6ef87d08600a3c 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.aggregatable.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.aggregatable.md @@ -7,5 +7,5 @@ Signature: ```typescript -aggregatable?: boolean; +get aggregatable(): boolean; ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.conflictdescriptions.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.conflictdescriptions.md index ec19a4854bf0e6..6d62053726197f 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.conflictdescriptions.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.conflictdescriptions.md @@ -7,5 +7,7 @@ Signature: ```typescript -conflictDescriptions?: FieldSpecConflictDescriptions; +get conflictDescriptions(): Record | undefined; + +set conflictDescriptions(conflictDescriptions: Record | undefined); ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.count.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.count.md index 8e848276f21c4c..84c0a75fd206dd 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.count.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.count.md @@ -7,5 +7,7 @@ Signature: ```typescript -count?: number; +get count(): number; + +set count(count: number); ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.displayname.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.displayname.md index ed9630f92fc975..c0ce2fff419bfc 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.displayname.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.displayname.md @@ -7,5 +7,5 @@ Signature: ```typescript -displayName?: string; +readonly displayName: string; ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.estypes.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.estypes.md index dec74df099d43a..ac088cb69a3d63 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.estypes.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.estypes.md @@ -7,5 +7,5 @@ Signature: ```typescript -esTypes?: string[]; +get esTypes(): string[] | undefined; ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.filterable.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.filterable.md index 4290c4a2f86b3b..1149047c0eccd4 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.filterable.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.filterable.md @@ -7,5 +7,5 @@ Signature: ```typescript -filterable?: boolean; +get filterable(): boolean; ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.format.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.format.md index d5df8ed628cb08..f28d5b1bca7e56 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.format.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.format.md @@ -7,5 +7,5 @@ Signature: ```typescript -format: any; +get format(): FieldFormat; ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.indexpattern.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.indexpattern.md index 4acaaa8c0dc2cc..3d145cce9d07df 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.indexpattern.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.indexpattern.md @@ -7,5 +7,5 @@ Signature: ```typescript -indexPattern?: IIndexPattern; +readonly indexPattern: IndexPattern; ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.lang.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.lang.md index f731be8f613cfa..0a8446d40e5ec0 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.lang.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.lang.md @@ -7,5 +7,7 @@ Signature: ```typescript -lang?: string; +get lang(): string | undefined; + +set lang(lang: string | undefined); ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.md index d82999e7a96af4..e310d6023477ab 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.md @@ -7,37 +7,43 @@ Signature: ```typescript -export declare class Field implements IFieldType +export declare class IndexPatternField implements IFieldType ``` ## Constructors | Constructor | Modifiers | Description | | --- | --- | --- | -| [(constructor)(indexPattern, spec, shortDotsEnable, { fieldFormats, onNotification })](./kibana-plugin-plugins-data-public.indexpatternfield._constructor_.md) | | Constructs a new instance of the Field class | +| [(constructor)(indexPattern, spec, displayName, onNotification)](./kibana-plugin-plugins-data-public.indexpatternfield._constructor_.md) | | Constructs a new instance of the IndexPatternField class | ## Properties | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [$$spec](./kibana-plugin-plugins-data-public.indexpatternfield.__spec.md) | | FieldSpec | | | [aggregatable](./kibana-plugin-plugins-data-public.indexpatternfield.aggregatable.md) | | boolean | | -| [conflictDescriptions](./kibana-plugin-plugins-data-public.indexpatternfield.conflictdescriptions.md) | | FieldSpecConflictDescriptions | | +| [conflictDescriptions](./kibana-plugin-plugins-data-public.indexpatternfield.conflictdescriptions.md) | | Record<string, string[]> | undefined | | | [count](./kibana-plugin-plugins-data-public.indexpatternfield.count.md) | | number | | | [displayName](./kibana-plugin-plugins-data-public.indexpatternfield.displayname.md) | | string | | -| [esTypes](./kibana-plugin-plugins-data-public.indexpatternfield.estypes.md) | | string[] | | +| [esTypes](./kibana-plugin-plugins-data-public.indexpatternfield.estypes.md) | | string[] | undefined | | | [filterable](./kibana-plugin-plugins-data-public.indexpatternfield.filterable.md) | | boolean | | -| [format](./kibana-plugin-plugins-data-public.indexpatternfield.format.md) | | any | | -| [indexPattern](./kibana-plugin-plugins-data-public.indexpatternfield.indexpattern.md) | | IIndexPattern | | -| [lang](./kibana-plugin-plugins-data-public.indexpatternfield.lang.md) | | string | | +| [format](./kibana-plugin-plugins-data-public.indexpatternfield.format.md) | | FieldFormat | | +| [indexPattern](./kibana-plugin-plugins-data-public.indexpatternfield.indexpattern.md) | | IndexPattern | | +| [lang](./kibana-plugin-plugins-data-public.indexpatternfield.lang.md) | | string | undefined | | | [name](./kibana-plugin-plugins-data-public.indexpatternfield.name.md) | | string | | -| [readFromDocValues](./kibana-plugin-plugins-data-public.indexpatternfield.readfromdocvalues.md) | | boolean | | -| [script](./kibana-plugin-plugins-data-public.indexpatternfield.script.md) | | string | | +| [readFromDocValues](./kibana-plugin-plugins-data-public.indexpatternfield.readfromdocvalues.md) | | boolean | undefined | | +| [script](./kibana-plugin-plugins-data-public.indexpatternfield.script.md) | | string | undefined | | | [scripted](./kibana-plugin-plugins-data-public.indexpatternfield.scripted.md) | | boolean | | | [searchable](./kibana-plugin-plugins-data-public.indexpatternfield.searchable.md) | | boolean | | | [sortable](./kibana-plugin-plugins-data-public.indexpatternfield.sortable.md) | | boolean | | -| [subType](./kibana-plugin-plugins-data-public.indexpatternfield.subtype.md) | | IFieldSubType | | -| [toSpec](./kibana-plugin-plugins-data-public.indexpatternfield.tospec.md) | | () => FieldSpecExportFmt | | +| [spec](./kibana-plugin-plugins-data-public.indexpatternfield.spec.md) | | FieldSpec | | +| [subType](./kibana-plugin-plugins-data-public.indexpatternfield.subtype.md) | | import("../types").IFieldSubType | undefined | | | [type](./kibana-plugin-plugins-data-public.indexpatternfield.type.md) | | string | | | [visualizable](./kibana-plugin-plugins-data-public.indexpatternfield.visualizable.md) | | boolean | | +## Methods + +| Method | Modifiers | Description | +| --- | --- | --- | +| [toJSON()](./kibana-plugin-plugins-data-public.indexpatternfield.tojson.md) | | | +| [toSpec()](./kibana-plugin-plugins-data-public.indexpatternfield.tospec.md) | | | + diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.name.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.name.md index cb24621e732093..c690edeafea6e8 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.name.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.name.md @@ -7,5 +7,5 @@ Signature: ```typescript -name: string; +get name(): string; ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.readfromdocvalues.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.readfromdocvalues.md index 4b012c26a8620d..fd85870b2db8eb 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.readfromdocvalues.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.readfromdocvalues.md @@ -7,5 +7,5 @@ Signature: ```typescript -readFromDocValues?: boolean; +get readFromDocValues(): boolean | undefined; ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.script.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.script.md index 132ba25a476374..27f9c797c92f29 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.script.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.script.md @@ -7,5 +7,7 @@ Signature: ```typescript -script?: string; +get script(): string | undefined; + +set script(script: string | undefined); ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.scripted.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.scripted.md index 1dd6bc865a75d9..f3810b9698a115 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.scripted.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.scripted.md @@ -7,5 +7,5 @@ Signature: ```typescript -scripted?: boolean; +get scripted(): boolean; ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.searchable.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.searchable.md index 42f984d851435b..431907b154dc0e 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.searchable.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.searchable.md @@ -7,5 +7,5 @@ Signature: ```typescript -searchable?: boolean; +get searchable(): boolean; ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.sortable.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.sortable.md index 72d225185140be..871320c9586d31 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.sortable.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.sortable.md @@ -7,5 +7,5 @@ Signature: ```typescript -sortable?: boolean; +get sortable(): boolean; ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.__spec.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.spec.md similarity index 56% rename from docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.__spec.md rename to docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.spec.md index f52a3324af36f7..9884faaa6c7bb3 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.__spec.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.spec.md @@ -1,11 +1,11 @@ -[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [IndexPatternField](./kibana-plugin-plugins-data-public.indexpatternfield.md) > [$$spec](./kibana-plugin-plugins-data-public.indexpatternfield.__spec.md) +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [IndexPatternField](./kibana-plugin-plugins-data-public.indexpatternfield.md) > [spec](./kibana-plugin-plugins-data-public.indexpatternfield.spec.md) -## IndexPatternField.$$spec property +## IndexPatternField.spec property Signature: ```typescript -$$spec: FieldSpec; +readonly spec: FieldSpec; ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.subtype.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.subtype.md index 2d807f8a5739ce..5c3c4d54ad0997 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.subtype.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.subtype.md @@ -7,5 +7,5 @@ Signature: ```typescript -subType?: IFieldSubType; +get subType(): import("../types").IFieldSubType | undefined; ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.tojson.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.tojson.md new file mode 100644 index 00000000000000..cde43faaff4636 --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.tojson.md @@ -0,0 +1,41 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [IndexPatternField](./kibana-plugin-plugins-data-public.indexpatternfield.md) > [toJSON](./kibana-plugin-plugins-data-public.indexpatternfield.tojson.md) + +## IndexPatternField.toJSON() method + +Signature: + +```typescript +toJSON(): { + count: number; + script: string | undefined; + lang: string | undefined; + conflictDescriptions: Record | undefined; + name: string; + type: string; + esTypes: string[] | undefined; + scripted: boolean; + searchable: boolean; + aggregatable: boolean; + readFromDocValues: boolean | undefined; + subType: import("../types").IFieldSubType | undefined; + }; +``` +Returns: + +`{ + count: number; + script: string | undefined; + lang: string | undefined; + conflictDescriptions: Record | undefined; + name: string; + type: string; + esTypes: string[] | undefined; + scripted: boolean; + searchable: boolean; + aggregatable: boolean; + readFromDocValues: boolean | undefined; + subType: import("../types").IFieldSubType | undefined; + }` + diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.tospec.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.tospec.md index 35714faa03bc9a..add90c3b1f0bb8 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.tospec.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.tospec.md @@ -2,10 +2,42 @@ [Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [IndexPatternField](./kibana-plugin-plugins-data-public.indexpatternfield.md) > [toSpec](./kibana-plugin-plugins-data-public.indexpatternfield.tospec.md) -## IndexPatternField.toSpec property +## IndexPatternField.toSpec() method Signature: ```typescript -toSpec: () => FieldSpecExportFmt; +toSpec(): { + count: number; + script: string | undefined; + lang: string | undefined; + conflictDescriptions: Record | undefined; + name: string; + type: string; + esTypes: string[] | undefined; + scripted: boolean; + searchable: boolean; + aggregatable: boolean; + readFromDocValues: boolean | undefined; + subType: import("../types").IFieldSubType | undefined; + format: any; + }; ``` +Returns: + +`{ + count: number; + script: string | undefined; + lang: string | undefined; + conflictDescriptions: Record | undefined; + name: string; + type: string; + esTypes: string[] | undefined; + scripted: boolean; + searchable: boolean; + aggregatable: boolean; + readFromDocValues: boolean | undefined; + subType: import("../types").IFieldSubType | undefined; + format: any; + }` + diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.type.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.type.md index c8483c9b83c9a1..45085b9e74bcc7 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.type.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.type.md @@ -7,5 +7,5 @@ Signature: ```typescript -type: string; +get type(): string; ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.visualizable.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.visualizable.md index dd661ae779c117..9ed689752503ad 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.visualizable.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.visualizable.md @@ -7,5 +7,5 @@ Signature: ```typescript -visualizable?: boolean; +get visualizable(): boolean; ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md index db41936f35ccab..6030666ca89bb7 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md @@ -103,7 +103,6 @@ | [extractSearchSourceReferences](./kibana-plugin-plugins-data-public.extractsearchsourcereferences.md) | | | [fieldFormats](./kibana-plugin-plugins-data-public.fieldformats.md) | | | [FilterBar](./kibana-plugin-plugins-data-public.filterbar.md) | | -| [getIndexPatternFieldListCreator](./kibana-plugin-plugins-data-public.getindexpatternfieldlistcreator.md) | | | [getKbnTypeNames](./kibana-plugin-plugins-data-public.getkbntypenames.md) | Get the esTypes known by all kbnFieldTypes {Array} | | [indexPatterns](./kibana-plugin-plugins-data-public.indexpatterns.md) | | | [injectSearchSourceReferences](./kibana-plugin-plugins-data-public.injectsearchsourcereferences.md) | | diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts b/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts index 927655c9309450..065da56fd3f63d 100644 --- a/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts @@ -179,7 +179,7 @@ export class IndexPattern implements IIndexPattern { return true; } - return this.fields.every((spec) => { + return specs.every((spec) => { // See https://github.com/elastic/kibana/pull/8421 const hasFieldCaps = 'aggregatable' in spec && 'searchable' in spec; @@ -259,7 +259,7 @@ export class IndexPattern implements IIndexPattern { } this.version = response.version; - return this.indexFields(forceFieldRefresh, response._source.fields); + return this.indexFields(forceFieldRefresh, response.fields); } getComputedFields() { diff --git a/src/plugins/data/public/public.api.md b/src/plugins/data/public/public.api.md index a8868c07061c3b..6fb68a4accfb00 100644 --- a/src/plugins/data/public/public.api.md +++ b/src/plugins/data/public/public.api.md @@ -766,13 +766,6 @@ export function getDefaultQuery(language?: QueryLanguage): { // @public (undocumented) export function getEsPreference(uiSettings: IUiSettingsClient_2, sessionId?: string): any; -// Warning: (ae-forgotten-export) The symbol "FieldListDependencies" needs to be exported by the entry point index.d.ts -// Warning: (ae-forgotten-export) The symbol "CreateIndexPatternFieldList" needs to be exported by the entry point index.d.ts -// Warning: (ae-missing-release-tag) "getIndexPatternFieldListCreator" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public (undocumented) -export const getIndexPatternFieldListCreator: ({ fieldFormats, onNotification, }: FieldListDependencies) => CreateIndexPatternFieldList; - // Warning: (ae-missing-release-tag) "getKbnTypeNames" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public @@ -964,6 +957,10 @@ export interface IIndexPatternFieldList extends Array { // (undocumented) remove(field: IFieldType): void; // (undocumented) + removeAll(): void; + // (undocumented) + replaceAll(specs: FieldSpec[]): void; + // (undocumented) update(field: FieldSpec): void; } @@ -1039,6 +1036,8 @@ export class IndexPattern implements IIndexPattern { // (undocumented) getFieldByName(name: string): IndexPatternField | void; // (undocumented) + getFormatterForField(field: IndexPatternField | IndexPatternField['spec']): FieldFormat; + // (undocumented) getNonScriptedFields(): IndexPatternField[]; // (undocumented) getScriptedFields(): IndexPatternField[]; @@ -1075,7 +1074,7 @@ export class IndexPattern implements IIndexPattern { // (undocumented) refreshFields(): Promise; // (undocumented) - removeScriptedField(field: IFieldType): Promise; + removeScriptedField(fieldName: string): Promise; // (undocumented) save(saveAttempts?: number): Promise; // (undocumented) @@ -1126,55 +1125,85 @@ export interface IndexPatternAttributes { typeMeta: string; } -// Warning: (ae-missing-release-tag) "Field" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// Warning: (ae-missing-release-tag) "IndexPatternField" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) export class IndexPatternField implements IFieldType { + // Warning: (ae-forgotten-export) The symbol "OnNotification" needs to be exported by the entry point index.d.ts + constructor(indexPattern: IndexPattern, spec: FieldSpec, displayName: string, onNotification: OnNotification); // (undocumented) - $$spec: FieldSpec; - // Warning: (ae-forgotten-export) The symbol "FieldSpecExportFmt" needs to be exported by the entry point index.d.ts - // Warning: (ae-forgotten-export) The symbol "FieldDependencies" needs to be exported by the entry point index.d.ts - constructor(indexPattern: IIndexPattern, spec: FieldSpecExportFmt | FieldSpec | IndexPatternField, shortDotsEnable: boolean, { fieldFormats, onNotification }: FieldDependencies); + get aggregatable(): boolean; // (undocumented) - aggregatable?: boolean; - // Warning: (ae-forgotten-export) The symbol "FieldSpecConflictDescriptions" needs to be exported by the entry point index.d.ts - // + get conflictDescriptions(): Record | undefined; + set conflictDescriptions(conflictDescriptions: Record | undefined); // (undocumented) - conflictDescriptions?: FieldSpecConflictDescriptions; + get count(): number; + set count(count: number); // (undocumented) - count?: number; + readonly displayName: string; // (undocumented) - displayName?: string; + get esTypes(): string[] | undefined; // (undocumented) - esTypes?: string[]; + get filterable(): boolean; // (undocumented) - filterable?: boolean; + get format(): FieldFormat; // (undocumented) - format: any; + readonly indexPattern: IndexPattern; // (undocumented) - indexPattern?: IIndexPattern; + get lang(): string | undefined; + set lang(lang: string | undefined); // (undocumented) - lang?: string; + get name(): string; // (undocumented) - name: string; + get readFromDocValues(): boolean | undefined; // (undocumented) - readFromDocValues?: boolean; + get script(): string | undefined; + set script(script: string | undefined); // (undocumented) - script?: string; + get scripted(): boolean; // (undocumented) - scripted?: boolean; + get searchable(): boolean; // (undocumented) - searchable?: boolean; + get sortable(): boolean; // (undocumented) - sortable?: boolean; + readonly spec: FieldSpec; // (undocumented) - subType?: IFieldSubType; + get subType(): import("../types").IFieldSubType | undefined; // (undocumented) - toSpec: () => FieldSpecExportFmt; + toJSON(): { + count: number; + script: string | undefined; + lang: string | undefined; + conflictDescriptions: Record | undefined; + name: string; + type: string; + esTypes: string[] | undefined; + scripted: boolean; + searchable: boolean; + aggregatable: boolean; + readFromDocValues: boolean | undefined; + subType: import("../types").IFieldSubType | undefined; + }; // (undocumented) - type: string; + toSpec(): { + count: number; + script: string | undefined; + lang: string | undefined; + conflictDescriptions: Record | undefined; + name: string; + type: string; + esTypes: string[] | undefined; + scripted: boolean; + searchable: boolean; + aggregatable: boolean; + readFromDocValues: boolean | undefined; + subType: import("../types").IFieldSubType | undefined; + format: any; + }; // (undocumented) - visualizable?: boolean; + get type(): string; + // (undocumented) + get visualizable(): boolean; } // Warning: (ae-missing-release-tag) "indexPatterns" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) @@ -2004,21 +2033,21 @@ export const UI_SETTINGS: { // src/plugins/data/public/index.ts:232:27 - (ae-forgotten-export) The symbol "getFromSavedObject" needs to be exported by the entry point index.d.ts // src/plugins/data/public/index.ts:232:27 - (ae-forgotten-export) The symbol "flattenHitWrapper" needs to be exported by the entry point index.d.ts // src/plugins/data/public/index.ts:232:27 - (ae-forgotten-export) The symbol "formatHitProvider" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:369:20 - (ae-forgotten-export) The symbol "getRequestInspectorStats" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:369:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:369:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:369:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:371:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:372:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:381:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:382:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:383:1 - (ae-forgotten-export) The symbol "Ipv4Address" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:384:1 - (ae-forgotten-export) The symbol "isDateHistogramBucketAggConfig" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:388:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:389:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:392:1 - (ae-forgotten-export) The symbol "parseInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:393:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:396:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:367:20 - (ae-forgotten-export) The symbol "getRequestInspectorStats" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:367:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:367:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:367:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:369:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:370:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:379:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:380:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:381:1 - (ae-forgotten-export) The symbol "Ipv4Address" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:382:1 - (ae-forgotten-export) The symbol "isDateHistogramBucketAggConfig" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:386:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:387:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:390:1 - (ae-forgotten-export) The symbol "parseInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:391:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:394:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts // src/plugins/data/public/query/state_sync/connect_to_query_state.ts:41:60 - (ae-forgotten-export) The symbol "FilterStateStore" needs to be exported by the entry point index.d.ts // src/plugins/data/public/types.ts:54:5 - (ae-forgotten-export) The symbol "createFiltersFromValueClickAction" needs to be exported by the entry point index.d.ts // src/plugins/data/public/types.ts:55:5 - (ae-forgotten-export) The symbol "createFiltersFromRangeSelectAction" needs to be exported by the entry point index.d.ts From 961b85a3d782714945958eb3e2c2967fe0143959 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Fri, 24 Jul 2020 01:04:29 -0500 Subject: [PATCH 03/13] fix index pattern stub --- .../fields/__snapshots__/field.test.ts.snap | 75 ------------------- src/plugins/data/public/index.ts | 1 + src/test_utils/public/stub_index_pattern.js | 19 +---- .../management/_index_pattern_popularity.js | 2 +- 4 files changed, 4 insertions(+), 93 deletions(-) delete mode 100644 src/plugins/data/common/index_patterns/fields/__snapshots__/field.test.ts.snap diff --git a/src/plugins/data/common/index_patterns/fields/__snapshots__/field.test.ts.snap b/src/plugins/data/common/index_patterns/fields/__snapshots__/field.test.ts.snap deleted file mode 100644 index e61593f6bfb27b..00000000000000 --- a/src/plugins/data/common/index_patterns/fields/__snapshots__/field.test.ts.snap +++ /dev/null @@ -1,75 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Field exports the property to JSON 1`] = ` -Object { - "aggregatable": true, - "conflictDescriptions": Object { - "a": Array [ - "b", - "c", - ], - "d": Array [ - "e", - ], - }, - "count": 1, - "esTypes": Array [ - "type", - ], - "lang": "lang", - "name": "name", - "readFromDocValues": false, - "script": "script", - "scripted": true, - "searchable": true, - "subType": Object { - "multi": Object { - "parent": "parent", - }, - "nested": Object { - "path": "path", - }, - }, - "type": "type", -} -`; - -exports[`Field spec snapshot 1`] = ` -Object { - "aggregatable": true, - "conflictDescriptions": Object { - "a": Array [ - "b", - "c", - ], - "d": Array [ - "e", - ], - }, - "count": 1, - "esTypes": Array [ - "type", - ], - "format": Object { - "id": "number", - "params": Object { - "pattern": "$0,0.[00]", - }, - }, - "lang": "lang", - "name": "name", - "readFromDocValues": false, - "script": "script", - "scripted": true, - "searchable": true, - "subType": Object { - "multi": Object { - "parent": "parent", - }, - "nested": Object { - "path": "path", - }, - }, - "type": "type", -} -`; diff --git a/src/plugins/data/public/index.ts b/src/plugins/data/public/index.ts index 9e36d3b59bbd62..7da7ae003a0626 100644 --- a/src/plugins/data/public/index.ts +++ b/src/plugins/data/public/index.ts @@ -260,6 +260,7 @@ export { UI_SETTINGS, TypeMeta as IndexPatternTypeMeta, AggregationRestrictions as IndexPatternAggRestrictions, + FieldList, } from '../common'; /* diff --git a/src/test_utils/public/stub_index_pattern.js b/src/test_utils/public/stub_index_pattern.js index 5a81139157ceff..4776f03486c21a 100644 --- a/src/test_utils/public/stub_index_pattern.js +++ b/src/test_utils/public/stub_index_pattern.js @@ -22,12 +22,7 @@ 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 { - IndexPattern, - indexPatterns, - KBN_FIELD_TYPES, - getIndexPatternFieldListCreator, -} from '../../plugins/data/public'; +import { IndexPattern, indexPatterns, KBN_FIELD_TYPES, FieldList } from '../../plugins/data/public'; import { setFieldFormats } from '../../plugins/data/public/services'; @@ -42,16 +37,6 @@ import { getFieldFormatsRegistry } from './stub_field_formats'; export default function StubIndexPattern(pattern, getConfig, timeField, fields, core) { const registeredFieldFormats = getFieldFormatsRegistry(core); - const createFieldList = getIndexPatternFieldListCreator({ - fieldFormats: { - getDefaultInstance: () => ({ - convert: (val) => String(val), - }), - }, - toastNotifications: { - addDanger: () => {}, - }, - }); this.id = pattern; this.title = pattern; @@ -76,7 +61,7 @@ export default function StubIndexPattern(pattern, getConfig, timeField, fields, this.formatField = this.formatHit.formatField; this._reindexFields = function () { - this.fields = createFieldList(this, this.fields || fields, false); + this.fields = new FieldList(this, this.fields || fields, false); }; this.stubSetFieldFormat = function (fieldName, id, params) { diff --git a/test/functional/apps/management/_index_pattern_popularity.js b/test/functional/apps/management/_index_pattern_popularity.js index 530b8e1111a0c6..e2fcf50ef2c12c 100644 --- a/test/functional/apps/management/_index_pattern_popularity.js +++ b/test/functional/apps/management/_index_pattern_popularity.js @@ -60,7 +60,7 @@ export default function ({ getService, getPageObjects }) { // check that it is 0 (previous increase was cancelled const popularity = await PageObjects.settings.getPopularity(); log.debug('popularity = ' + popularity); - expect(popularity).to.be('0'); + expect(popularity).to.be(''); }); it('can be saved', async function () { From da420e854a079b9e6046288f0b10998cff1c1295 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Fri, 24 Jul 2020 07:01:18 -0500 Subject: [PATCH 04/13] update docs --- ...ins-data-public.fieldlist._constructor_.md | 23 ++++++ ...lugin-plugins-data-public.fieldlist.add.md | 11 +++ ...plugins-data-public.fieldlist.getbyname.md | 11 +++ ...plugins-data-public.fieldlist.getbytype.md | 11 +++ ...na-plugin-plugins-data-public.fieldlist.md | 31 ++++++++ ...in-plugins-data-public.fieldlist.remove.md | 11 +++ ...plugins-data-public.fieldlist.removeall.md | 11 +++ ...lugins-data-public.fieldlist.replaceall.md | 11 +++ ...in-plugins-data-public.fieldlist.tospec.md | 25 +++++++ ...in-plugins-data-public.fieldlist.update.md | 11 +++ .../kibana-plugin-plugins-data-public.md | 1 + src/plugins/data/public/public.api.md | 70 ++++++++++++++----- 12 files changed, 210 insertions(+), 17 deletions(-) create mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist._constructor_.md create mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.add.md create mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.getbyname.md create mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.getbytype.md create mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.md create mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.remove.md create mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.removeall.md create mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.replaceall.md create mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.tospec.md create mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.update.md diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist._constructor_.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist._constructor_.md new file mode 100644 index 00000000000000..3b60ac0f48edd2 --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist._constructor_.md @@ -0,0 +1,23 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [FieldList](./kibana-plugin-plugins-data-public.fieldlist.md) > [(constructor)](./kibana-plugin-plugins-data-public.fieldlist._constructor_.md) + +## FieldList.(constructor) + +Constructs a new instance of the `FieldList` class + +Signature: + +```typescript +constructor(indexPattern: IndexPattern, specs?: FieldSpec[], shortDotsEnable?: boolean, onNotification?: () => void); +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| indexPattern | IndexPattern | | +| specs | FieldSpec[] | | +| shortDotsEnable | boolean | | +| onNotification | () => void | | + diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.add.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.add.md new file mode 100644 index 00000000000000..61706eb33fdcaf --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.add.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [FieldList](./kibana-plugin-plugins-data-public.fieldlist.md) > [add](./kibana-plugin-plugins-data-public.fieldlist.add.md) + +## FieldList.add property + +Signature: + +```typescript +add: (field: FieldSpec) => void; +``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.getbyname.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.getbyname.md new file mode 100644 index 00000000000000..f6690905f22c11 --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.getbyname.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [FieldList](./kibana-plugin-plugins-data-public.fieldlist.md) > [getByName](./kibana-plugin-plugins-data-public.fieldlist.getbyname.md) + +## FieldList.getByName property + +Signature: + +```typescript +getByName: (name: IndexPatternField['name']) => IndexPatternField | undefined; +``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.getbytype.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.getbytype.md new file mode 100644 index 00000000000000..ae073143b8ab75 --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.getbytype.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [FieldList](./kibana-plugin-plugins-data-public.fieldlist.md) > [getByType](./kibana-plugin-plugins-data-public.fieldlist.getbytype.md) + +## FieldList.getByType property + +Signature: + +```typescript +getByType: (type: IndexPatternField['type']) => any[]; +``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.md new file mode 100644 index 00000000000000..91e1d573dae42f --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.md @@ -0,0 +1,31 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [FieldList](./kibana-plugin-plugins-data-public.fieldlist.md) + +## FieldList class + +Signature: + +```typescript +export declare class FieldList extends Array implements IIndexPatternFieldList +``` + +## Constructors + +| Constructor | Modifiers | Description | +| --- | --- | --- | +| [(constructor)(indexPattern, specs, shortDotsEnable, onNotification)](./kibana-plugin-plugins-data-public.fieldlist._constructor_.md) | | Constructs a new instance of the FieldList class | + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [add](./kibana-plugin-plugins-data-public.fieldlist.add.md) | | (field: FieldSpec) => void | | +| [getByName](./kibana-plugin-plugins-data-public.fieldlist.getbyname.md) | | (name: IndexPatternField['name']) => IndexPatternField | undefined | | +| [getByType](./kibana-plugin-plugins-data-public.fieldlist.getbytype.md) | | (type: IndexPatternField['type']) => any[] | | +| [remove](./kibana-plugin-plugins-data-public.fieldlist.remove.md) | | (field: IFieldType) => void | | +| [removeAll](./kibana-plugin-plugins-data-public.fieldlist.removeall.md) | | () => void | | +| [replaceAll](./kibana-plugin-plugins-data-public.fieldlist.replaceall.md) | | (specs: FieldSpec[]) => void | | +| [toSpec](./kibana-plugin-plugins-data-public.fieldlist.tospec.md) | | () => {
count: number;
script: string | undefined;
lang: string | undefined;
conflictDescriptions: Record<string, string[]> | undefined;
name: string;
type: string;
esTypes: string[] | undefined;
scripted: boolean;
searchable: boolean;
aggregatable: boolean;
readFromDocValues: boolean | undefined;
subType: import("../types").IFieldSubType | undefined;
format: any;
}[] | | +| [update](./kibana-plugin-plugins-data-public.fieldlist.update.md) | | (field: FieldSpec) => void | | + diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.remove.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.remove.md new file mode 100644 index 00000000000000..64ac0fa44425bd --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.remove.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [FieldList](./kibana-plugin-plugins-data-public.fieldlist.md) > [remove](./kibana-plugin-plugins-data-public.fieldlist.remove.md) + +## FieldList.remove property + +Signature: + +```typescript +remove: (field: IFieldType) => void; +``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.removeall.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.removeall.md new file mode 100644 index 00000000000000..a2004d2b1b81be --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.removeall.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [FieldList](./kibana-plugin-plugins-data-public.fieldlist.md) > [removeAll](./kibana-plugin-plugins-data-public.fieldlist.removeall.md) + +## FieldList.removeAll property + +Signature: + +```typescript +removeAll: () => void; +``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.replaceall.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.replaceall.md new file mode 100644 index 00000000000000..d10891babf79ee --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.replaceall.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [FieldList](./kibana-plugin-plugins-data-public.fieldlist.md) > [replaceAll](./kibana-plugin-plugins-data-public.fieldlist.replaceall.md) + +## FieldList.replaceAll property + +Signature: + +```typescript +replaceAll: (specs: FieldSpec[]) => void; +``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.tospec.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.tospec.md new file mode 100644 index 00000000000000..1ad5493a743aea --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.tospec.md @@ -0,0 +1,25 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [FieldList](./kibana-plugin-plugins-data-public.fieldlist.md) > [toSpec](./kibana-plugin-plugins-data-public.fieldlist.tospec.md) + +## FieldList.toSpec property + +Signature: + +```typescript +toSpec: () => { + count: number; + script: string | undefined; + lang: string | undefined; + conflictDescriptions: Record | undefined; + name: string; + type: string; + esTypes: string[] | undefined; + scripted: boolean; + searchable: boolean; + aggregatable: boolean; + readFromDocValues: boolean | undefined; + subType: import("../types").IFieldSubType | undefined; + format: any; + }[]; +``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.update.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.update.md new file mode 100644 index 00000000000000..ce1a1eb73f815f --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.update.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [FieldList](./kibana-plugin-plugins-data-public.fieldlist.md) > [update](./kibana-plugin-plugins-data-public.fieldlist.update.md) + +## FieldList.update property + +Signature: + +```typescript +update: (field: FieldSpec) => void; +``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md index 6030666ca89bb7..c8d45804a37294 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md @@ -10,6 +10,7 @@ | --- | --- | | [AggParamType](./kibana-plugin-plugins-data-public.aggparamtype.md) | | | [FieldFormat](./kibana-plugin-plugins-data-public.fieldformat.md) | | +| [FieldList](./kibana-plugin-plugins-data-public.fieldlist.md) | | | [FilterManager](./kibana-plugin-plugins-data-public.filtermanager.md) | | | [IndexPattern](./kibana-plugin-plugins-data-public.indexpattern.md) | | | [IndexPatternField](./kibana-plugin-plugins-data-public.indexpatternfield.md) | | diff --git a/src/plugins/data/public/public.api.md b/src/plugins/data/public/public.api.md index 6fb68a4accfb00..db12fa0dfdb2f5 100644 --- a/src/plugins/data/public/public.api.md +++ b/src/plugins/data/public/public.api.md @@ -684,6 +684,44 @@ export type FieldFormatsContentType = 'html' | 'text'; // @public (undocumented) export type FieldFormatsGetConfigFn = (key: string, defaultOverride?: T) => T; +// Warning: (ae-missing-release-tag) "FieldList" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export class FieldList extends Array implements IIndexPatternFieldList { + // Warning: (ae-forgotten-export) The symbol "FieldSpec" needs to be exported by the entry point index.d.ts + constructor(indexPattern: IndexPattern, specs?: FieldSpec[], shortDotsEnable?: boolean, onNotification?: () => void); + // (undocumented) + add: (field: FieldSpec) => void; + // (undocumented) + getByName: (name: IndexPatternField['name']) => IndexPatternField | undefined; + // (undocumented) + getByType: (type: IndexPatternField['type']) => any[]; + // (undocumented) + remove: (field: IFieldType) => void; + // (undocumented) + removeAll: () => void; + // (undocumented) + replaceAll: (specs: FieldSpec[]) => void; + // (undocumented) + toSpec: () => { + count: number; + script: string | undefined; + lang: string | undefined; + conflictDescriptions: Record | undefined; + name: string; + type: string; + esTypes: string[] | undefined; + scripted: boolean; + searchable: boolean; + aggregatable: boolean; + readFromDocValues: boolean | undefined; + subType: import("../types").IFieldSubType | undefined; + format: any; + }[]; + // (undocumented) + update: (field: FieldSpec) => void; +} + // @public (undocumented) export interface FieldMappingSpec { // (undocumented) @@ -909,8 +947,6 @@ export interface IFieldType { sortable?: boolean; // (undocumented) subType?: IFieldSubType; - // Warning: (ae-forgotten-export) The symbol "FieldSpec" needs to be exported by the entry point index.d.ts - // // (undocumented) toSpec?: () => FieldSpec; // (undocumented) @@ -2033,21 +2069,21 @@ export const UI_SETTINGS: { // src/plugins/data/public/index.ts:232:27 - (ae-forgotten-export) The symbol "getFromSavedObject" needs to be exported by the entry point index.d.ts // src/plugins/data/public/index.ts:232:27 - (ae-forgotten-export) The symbol "flattenHitWrapper" needs to be exported by the entry point index.d.ts // src/plugins/data/public/index.ts:232:27 - (ae-forgotten-export) The symbol "formatHitProvider" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:367:20 - (ae-forgotten-export) The symbol "getRequestInspectorStats" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:367:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:367:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:367:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:369:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:370:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:379:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:380:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:381:1 - (ae-forgotten-export) The symbol "Ipv4Address" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:382:1 - (ae-forgotten-export) The symbol "isDateHistogramBucketAggConfig" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:386:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:387:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:390:1 - (ae-forgotten-export) The symbol "parseInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:391:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:394:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:368:20 - (ae-forgotten-export) The symbol "getRequestInspectorStats" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:368:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:368:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:368:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:370:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:371:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:380:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:381:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:382:1 - (ae-forgotten-export) The symbol "Ipv4Address" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:383:1 - (ae-forgotten-export) The symbol "isDateHistogramBucketAggConfig" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:387:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:388:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:391:1 - (ae-forgotten-export) The symbol "parseInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:392:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:395:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts // src/plugins/data/public/query/state_sync/connect_to_query_state.ts:41:60 - (ae-forgotten-export) The symbol "FilterStateStore" needs to be exported by the entry point index.d.ts // src/plugins/data/public/types.ts:54:5 - (ae-forgotten-export) The symbol "createFiltersFromValueClickAction" needs to be exported by the entry point index.d.ts // src/plugins/data/public/types.ts:55:5 - (ae-forgotten-export) The symbol "createFiltersFromRangeSelectAction" needs to be exported by the entry point index.d.ts From c05cffa53413be15fb0232bdc563f952acd356f4 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Fri, 24 Jul 2020 22:00:36 -0500 Subject: [PATCH 05/13] partial progress on tests --- .../index_pattern_field.test.ts.snap | 75 +++++++++++++++++++ .../index_patterns/index_pattern.test.ts | 4 +- .../index_patterns/index_pattern.ts | 12 +-- .../__snapshots__/field_editor.test.tsx.snap | 5 ++ .../field_editor/field_editor.test.tsx | 23 +++--- .../public/components/test_utils.tsx | 4 +- src/test_utils/public/stub_index_pattern.js | 5 +- 7 files changed, 101 insertions(+), 27 deletions(-) create mode 100644 src/plugins/data/common/index_patterns/fields/__snapshots__/index_pattern_field.test.ts.snap diff --git a/src/plugins/data/common/index_patterns/fields/__snapshots__/index_pattern_field.test.ts.snap b/src/plugins/data/common/index_patterns/fields/__snapshots__/index_pattern_field.test.ts.snap new file mode 100644 index 00000000000000..e61593f6bfb27b --- /dev/null +++ b/src/plugins/data/common/index_patterns/fields/__snapshots__/index_pattern_field.test.ts.snap @@ -0,0 +1,75 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Field exports the property to JSON 1`] = ` +Object { + "aggregatable": true, + "conflictDescriptions": Object { + "a": Array [ + "b", + "c", + ], + "d": Array [ + "e", + ], + }, + "count": 1, + "esTypes": Array [ + "type", + ], + "lang": "lang", + "name": "name", + "readFromDocValues": false, + "script": "script", + "scripted": true, + "searchable": true, + "subType": Object { + "multi": Object { + "parent": "parent", + }, + "nested": Object { + "path": "path", + }, + }, + "type": "type", +} +`; + +exports[`Field spec snapshot 1`] = ` +Object { + "aggregatable": true, + "conflictDescriptions": Object { + "a": Array [ + "b", + "c", + ], + "d": Array [ + "e", + ], + }, + "count": 1, + "esTypes": Array [ + "type", + ], + "format": Object { + "id": "number", + "params": Object { + "pattern": "$0,0.[00]", + }, + }, + "lang": "lang", + "name": "name", + "readFromDocValues": false, + "script": "script", + "scripted": true, + "searchable": true, + "subType": Object { + "multi": Object { + "parent": "parent", + }, + "nested": Object { + "path": "path", + }, + }, + "type": "type", +} +`; diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_pattern.test.ts b/src/plugins/data/common/index_patterns/index_patterns/index_pattern.test.ts index 97e7b6fde08308..e4f297b29c3728 100644 --- a/src/plugins/data/common/index_patterns/index_patterns/index_pattern.test.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index_pattern.test.ts @@ -287,9 +287,9 @@ describe('IndexPattern', () => { // const saveSpy = sinon.spy(indexPattern, 'save'); const scriptedFields = indexPattern.getScriptedFields(); const oldCount = scriptedFields.length; - const scriptedField = last(scriptedFields) as any; + const scriptedField = last(scriptedFields)!; - await indexPattern.removeScriptedField(scriptedField); + await indexPattern.removeScriptedField(scriptedField.name); // expect(saveSpy.callCount).to.equal(1); expect(indexPattern.getScriptedFields().length).toEqual(oldCount - 1); diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts b/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts index 065da56fd3f63d..7ec51d81950a2d 100644 --- a/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts @@ -168,12 +168,6 @@ export class IndexPattern implements IIndexPattern { ); } - private initFields(input?: any) { - const newValue = input || this.fields; - - this.fields = this.createFieldList(this, newValue, this.shortDotsEnable); - } - private isFieldRefreshRequired(specs?: FieldSpec[]): boolean { if (!specs) { return true; @@ -221,9 +215,7 @@ export class IndexPattern implements IIndexPattern { this.timeFieldName = spec.timeFieldName; this.sourceFilters = spec.sourceFilters; - // ignoring this because the same thing happens elsewhere but via _.assign - // @ts-expect-error - this.fields = spec.fields || []; + this.fields.replaceAll(spec.fields || []); this.typeMeta = spec.typeMeta; // /* this.fieldFormatMap = _.mapValues(fieldFormatMap, (mapping) => { @@ -231,8 +223,6 @@ export class IndexPattern implements IIndexPattern { }); // */ // this.fieldFormatMap = fieldFormatMap - - this.initFields(); return this; } diff --git a/src/plugins/index_pattern_management/public/components/field_editor/__snapshots__/field_editor.test.tsx.snap b/src/plugins/index_pattern_management/public/components/field_editor/__snapshots__/field_editor.test.tsx.snap index 7a7545580d82a3..c22160bc4036d8 100644 --- a/src/plugins/index_pattern_management/public/components/field_editor/__snapshots__/field_editor.test.tsx.snap +++ b/src/plugins/index_pattern_management/public/components/field_editor/__snapshots__/field_editor.test.tsx.snap @@ -30,6 +30,7 @@ exports[`FieldEditor should render create new scripted field correctly 1`] = ` "name": "foobar", }, ], + "getFormatterForField": [Function], } } isVisible={false} @@ -273,6 +274,7 @@ exports[`FieldEditor should render edit scripted field correctly 1`] = ` "type": "number", }, ], + "getFormatterForField": [Function], } } isVisible={false} @@ -523,6 +525,7 @@ exports[`FieldEditor should show conflict field warning 1`] = ` "type": "number", }, ], + "getFormatterForField": [Function], } } isVisible={false} @@ -802,6 +805,7 @@ exports[`FieldEditor should show deprecated lang warning 1`] = ` "type": "number", }, ], + "getFormatterForField": [Function], } } isVisible={false} @@ -1133,6 +1137,7 @@ exports[`FieldEditor should show multiple type field warning with a table contai "type": "number", }, ], + "getFormatterForField": [Function], } } isVisible={false} diff --git a/src/plugins/index_pattern_management/public/components/field_editor/field_editor.test.tsx b/src/plugins/index_pattern_management/public/components/field_editor/field_editor.test.tsx index e0e053d8b606bd..ba1f2ff4b665d9 100644 --- a/src/plugins/index_pattern_management/public/components/field_editor/field_editor.test.tsx +++ b/src/plugins/index_pattern_management/public/components/field_editor/field_editor.test.tsx @@ -26,7 +26,7 @@ import { jest.mock('brace/mode/groovy', () => ({})); -import { FieldEditor } from './field_editor'; +import { FieldEditor, FieldEdiorProps } from './field_editor'; import { mockManagementPlugin } from '../../mocks'; import { createComponentWithContext } from '../test_utils'; @@ -113,15 +113,16 @@ describe('FieldEditor', () => { beforeEach(() => { indexPattern = ({ fields: fields as IIndexPatternFieldList, + getFormatterForField: () => ({ params: () => ({}) }), } as unknown) as IndexPattern; }); it('should render create new scripted field correctly', async () => { - const component = createComponentWithContext( + const component = createComponentWithContext( FieldEditor, { indexPattern, - field: (field as unknown) as IndexPatternField, + spec: (field as unknown) as IndexPatternField, services: { redirectAway: () => {} }, }, mockContext @@ -146,11 +147,11 @@ describe('FieldEditor', () => { return flds[name] as IndexPatternField; }; - const component = createComponentWithContext( + const component = createComponentWithContext( FieldEditor, { indexPattern, - field: (testField as unknown) as IndexPatternField, + spec: (testField as unknown) as IndexPatternField, services: { redirectAway: () => {} }, }, mockContext @@ -176,11 +177,11 @@ describe('FieldEditor', () => { return flds[name] as IndexPatternField; }; - const component = createComponentWithContext( + const component = createComponentWithContext( FieldEditor, { indexPattern, - field: (testField as unknown) as IndexPatternField, + spec: (testField as unknown) as IndexPatternField, services: { redirectAway: () => {} }, }, mockContext @@ -193,11 +194,11 @@ describe('FieldEditor', () => { it('should show conflict field warning', async () => { const testField = { ...field }; - const component = createComponentWithContext( + const component = createComponentWithContext( FieldEditor, { indexPattern, - field: (testField as unknown) as IndexPatternField, + spec: (testField as unknown) as IndexPatternField, services: { redirectAway: () => {} }, }, mockContext @@ -218,11 +219,11 @@ describe('FieldEditor', () => { text: ['index_name_3'], }, }; - const component = createComponentWithContext( + const component = createComponentWithContext( FieldEditor, { indexPattern, - field: (testField as unknown) as IndexPatternField, + spec: (testField as unknown) as IndexPatternField, services: { redirectAway: () => {} }, }, mockContext diff --git a/src/plugins/index_pattern_management/public/components/test_utils.tsx b/src/plugins/index_pattern_management/public/components/test_utils.tsx index 938547cca04ab6..ae968f3069a65b 100644 --- a/src/plugins/index_pattern_management/public/components/test_utils.tsx +++ b/src/plugins/index_pattern_management/public/components/test_utils.tsx @@ -23,9 +23,9 @@ import { shallow } from 'enzyme'; // since the 'shallow' from 'enzyme' doesn't support context API for React 16 and above (https://github.com/facebook/react/pull/14329) // we use this workaround where define legacy contextTypes for react class component -export function createComponentWithContext( +export function createComponentWithContext>( MyComponent: React.ComponentClass, - props: Record, + props: props, mockedContext: Record ) { MyComponent.contextTypes = { diff --git a/src/test_utils/public/stub_index_pattern.js b/src/test_utils/public/stub_index_pattern.js index 4776f03486c21a..2f51a73ea1e6c1 100644 --- a/src/test_utils/public/stub_index_pattern.js +++ b/src/test_utils/public/stub_index_pattern.js @@ -59,9 +59,12 @@ export default function StubIndexPattern(pattern, getConfig, timeField, fields, ); this.fieldsFetcher = { apiClient: { baseUrl: '' } }; this.formatField = this.formatHit.formatField; + this.getFormatterForField = () => ({ + convert: () => ({}), + }); this._reindexFields = function () { - this.fields = new FieldList(this, this.fields || fields, false); + this.fields = new FieldList(this, this.fields || fields, false); // createFieldList(this, this.fields || fields, false); }; this.stubSetFieldFormat = function (fieldName, id, params) { From b6a28b80b32a9841d1962abac0ffbaf999e4e0ce Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Sun, 26 Jul 2020 23:04:05 -0500 Subject: [PATCH 06/13] fix indexed_fields_table_test, field formatters management --- .../indexed_fields_table.test.tsx.snap | 20 +++++++++++++----- .../indexed_fields_table.test.tsx | 21 +++++++++++++------ .../components/field_editor/field_editor.tsx | 8 ++++--- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/__snapshots__/indexed_fields_table.test.tsx.snap b/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/__snapshots__/indexed_fields_table.test.tsx.snap index db2a032b1e4d9c..47cabc4df662f0 100644 --- a/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/__snapshots__/indexed_fields_table.test.tsx.snap +++ b/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/__snapshots__/indexed_fields_table.test.tsx.snap @@ -15,7 +15,9 @@ exports[`IndexedFieldsTable should filter based on the query bar 1`] = ` "displayName": "Elastic", "excluded": false, "format": undefined, - "indexPattern": undefined, + "indexPattern": Object { + "getNonScriptedFields": [Function], + }, "info": Array [], "name": "Elastic", "searchable": true, @@ -42,7 +44,9 @@ exports[`IndexedFieldsTable should filter based on the type filter 1`] = ` "displayName": "timestamp", "excluded": false, "format": undefined, - "indexPattern": undefined, + "indexPattern": Object { + "getNonScriptedFields": [Function], + }, "info": Array [], "name": "timestamp", "type": "date", @@ -68,7 +72,9 @@ exports[`IndexedFieldsTable should render normally 1`] = ` "displayName": "Elastic", "excluded": false, "format": undefined, - "indexPattern": undefined, + "indexPattern": Object { + "getNonScriptedFields": [Function], + }, "info": Array [], "name": "Elastic", "searchable": true, @@ -78,7 +84,9 @@ exports[`IndexedFieldsTable should render normally 1`] = ` "displayName": "timestamp", "excluded": false, "format": undefined, - "indexPattern": undefined, + "indexPattern": Object { + "getNonScriptedFields": [Function], + }, "info": Array [], "name": "timestamp", "type": "date", @@ -87,7 +95,9 @@ exports[`IndexedFieldsTable should render normally 1`] = ` "displayName": "conflictingField", "excluded": false, "format": undefined, - "indexPattern": undefined, + "indexPattern": Object { + "getNonScriptedFields": [Function], + }, "info": Array [], "name": "conflictingField", "type": "conflict", diff --git a/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/indexed_fields_table.test.tsx b/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/indexed_fields_table.test.tsx index 8c024fa7adcf5e..411bbe23e47618 100644 --- a/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/indexed_fields_table.test.tsx +++ b/src/plugins/index_pattern_management/public/components/edit_index_pattern/indexed_fields_table/indexed_fields_table.test.tsx @@ -19,7 +19,7 @@ import React from 'react'; import { shallow } from 'enzyme'; -import { IndexPatternField, IIndexPattern } from 'src/plugins/data/public'; +import { IndexPatternField, IIndexPattern, IndexPattern } from 'src/plugins/data/public'; import { IndexedFieldsTable } from './indexed_fields_table'; jest.mock('@elastic/eui', () => ({ @@ -41,6 +41,19 @@ const helpers = { getFieldInfo: () => [], }; +const indexPattern = ({ + getNonScriptedFields: () => fields, +} as unknown) as IIndexPattern; + +const mockFieldToIndexPatternField = (spec: Record) => { + return new IndexPatternField( + indexPattern as IndexPattern, + (spec as unknown) as IndexPatternField['spec'], + spec.displayName as string, + () => {} + ); +}; + const fields = [ { name: 'Elastic', @@ -50,11 +63,7 @@ const fields = [ }, { name: 'timestamp', displayName: 'timestamp', type: 'date' }, { name: 'conflictingField', displayName: 'conflictingField', type: 'conflict' }, -] as IndexPatternField[]; - -const indexPattern = ({ - getNonScriptedFields: () => fields, -} as unknown) as IIndexPattern; +].map(mockFieldToIndexPatternField); describe('IndexedFieldsTable', () => { test('should render normally', async () => { diff --git a/src/plugins/index_pattern_management/public/components/field_editor/field_editor.tsx b/src/plugins/index_pattern_management/public/components/field_editor/field_editor.tsx index 7755a86b8f26a9..d78e1e1014581e 100644 --- a/src/plugins/index_pattern_management/public/components/field_editor/field_editor.tsx +++ b/src/plugins/index_pattern_management/public/components/field_editor/field_editor.tsx @@ -246,18 +246,20 @@ export class FieldEditor extends PureComponent { - const { spec, format, fieldTypeFormats } = this.state; + const { spec, fieldTypeFormats } = this.state; const { uiSettings, data } = this.context.services; const FieldFormat = data.fieldFormats.getType( formatId || (fieldTypeFormats[0] as InitialFieldTypeFormat).defaultFieldFormat.id ) as FieldFormatInstanceType; - spec.format = new FieldFormat(params, (key) => uiSettings.get(key)); + const newFormat = new FieldFormat(params, (key) => uiSettings.get(key)); + spec.format = newFormat; this.setState({ fieldFormatId: FieldFormat.id, - fieldFormatParams: format.params(), + fieldFormatParams: newFormat.params(), + format: newFormat, }); }; From c26537909cdce04f5842c68b32b51674c0b4b703 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Tue, 28 Jul 2020 00:09:17 -0500 Subject: [PATCH 07/13] fix index pattern functional test --- .../components/field_format_editor/editors/string/string.tsx | 2 +- test/functional/apps/management/_scripted_fields.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/plugins/index_pattern_management/public/components/field_editor/components/field_format_editor/editors/string/string.tsx b/src/plugins/index_pattern_management/public/components/field_editor/components/field_format_editor/editors/string/string.tsx index 7a3bb6f5cd3985..cdc29e129c4577 100644 --- a/src/plugins/index_pattern_management/public/components/field_editor/components/field_format_editor/editors/string/string.tsx +++ b/src/plugins/index_pattern_management/public/components/field_editor/components/field_format_editor/editors/string/string.tsx @@ -68,7 +68,7 @@ export class StringFormatEditor extends DefaultFormatEditor { + options={(format.type.transformOptions || []).map((option: TransformOptions) => { return { value: option.kind, text: option.text, diff --git a/test/functional/apps/management/_scripted_fields.js b/test/functional/apps/management/_scripted_fields.js index 2727313ab23367..116d1eac90cea7 100644 --- a/test/functional/apps/management/_scripted_fields.js +++ b/test/functional/apps/management/_scripted_fields.js @@ -36,6 +36,7 @@ import expect from '@kbn/expect'; export default function ({ getService, getPageObjects }) { + const esArchiver = getService('esArchiver'); const kibanaServer = getService('kibanaServer'); const log = getService('log'); const browser = getService('browser'); @@ -57,9 +58,9 @@ export default function ({ getService, getPageObjects }) { before(async function () { await browser.setWindowSize(1200, 800); + await esArchiver.load('discover'); // delete .kibana index and then wait for Kibana to re-create it await kibanaServer.uiSettings.replace({}); - await PageObjects.settings.createIndexPattern(); await kibanaServer.uiSettings.update({}); }); From b82d623e780a2b2c6df453fcd83e4e8c3fe8175e Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Mon, 3 Aug 2020 14:08:08 -0500 Subject: [PATCH 08/13] disable test for unused functionality --- test/functional/apps/management/_scripted_fields_filter.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/functional/apps/management/_scripted_fields_filter.js b/test/functional/apps/management/_scripted_fields_filter.js index 2eb53508c2846b..2d59d2ba57d5b9 100644 --- a/test/functional/apps/management/_scripted_fields_filter.js +++ b/test/functional/apps/management/_scripted_fields_filter.js @@ -27,7 +27,9 @@ export default function ({ getService, getPageObjects }) { const esArchiver = getService('esArchiver'); const PageObjects = getPageObjects(['settings']); - describe('filter scripted fields', function describeIndexTests() { + // this functionality is no longer functional as of 7.0 but still needs cleanup + // https://github.com/elastic/kibana/issues/74118 + describe.skip('filter scripted fields', function describeIndexTests() { before(async function () { // delete .kibana index and then wait for Kibana to re-create it await browser.setWindowSize(1200, 800); From db0c0f27d7f0f61693a881997ad2e18368039fe2 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Tue, 4 Aug 2020 22:12:39 -0500 Subject: [PATCH 09/13] fix jest test, remove some comments --- .../fields/index_pattern_field.ts | 2 - .../index_patterns/index_pattern.ts | 10 ++--- .../doc_table/components/row_headers.test.js | 43 ++++++++----------- src/test_utils/public/stub_index_pattern.js | 2 +- 4 files changed, 24 insertions(+), 33 deletions(-) diff --git a/src/plugins/data/common/index_patterns/fields/index_pattern_field.ts b/src/plugins/data/common/index_patterns/fields/index_pattern_field.ts index 8d1e45c26cc6af..ee4d6fc65168ed 100644 --- a/src/plugins/data/common/index_patterns/fields/index_pattern_field.ts +++ b/src/plugins/data/common/index_patterns/fields/index_pattern_field.ts @@ -46,8 +46,6 @@ export class IndexPatternField implements IFieldType { this.spec = { ...spec, type: spec.name === '_source' ? '_source' : spec.type }; this.displayName = displayName; - // todo - // try to refactor this code so it can provide a return value which can be handled. this.kbnFieldType = getKbnFieldType(spec.type); if (spec.type && this.kbnFieldType?.name === KBN_FIELD_TYPES.UNKNOWN) { const title = i18n.translate('data.indexPatterns.unknownFieldHeader', { diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts b/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts index 7ec51d81950a2d..211919e8e6b530 100644 --- a/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts @@ -217,12 +217,11 @@ export class IndexPattern implements IIndexPattern { this.fields.replaceAll(spec.fields || []); this.typeMeta = spec.typeMeta; - // /* + this.fieldFormatMap = _.mapValues(fieldFormatMap, (mapping) => { return this.deserializeFieldFormatMap(mapping); }); - // */ - // this.fieldFormatMap = fieldFormatMap + return this; } @@ -425,13 +424,12 @@ export class IndexPattern implements IIndexPattern { } getTimeField() { - // todo perhaps less undefined if (!this.timeFieldName || !this.fields || !this.fields.getByName) return undefined; return this.fields.getByName(this.timeFieldName) || undefined; } - getFieldByName(name: string): IndexPatternField | void { - if (!this.fields || !this.fields.getByName) return; + getFieldByName(name: string): IndexPatternField | undefined { + if (!this.fields || !this.fields.getByName) return undefined; return this.fields.getByName(name); } diff --git a/src/plugins/discover/public/application/angular/doc_table/components/row_headers.test.js b/src/plugins/discover/public/application/angular/doc_table/components/row_headers.test.js index b30b13b1f0b6e2..d85ca6a0728902 100644 --- a/src/plugins/discover/public/application/angular/doc_table/components/row_headers.test.js +++ b/src/plugins/discover/public/application/angular/doc_table/components/row_headers.test.js @@ -23,7 +23,7 @@ import 'angular-sanitize'; import 'angular-route'; import _ from 'lodash'; import sinon from 'sinon'; -import { getFakeRow, getFakeRowVals } from 'fixtures/fake_row'; +import { getFakeRow } from 'fixtures/fake_row'; import $ from 'jquery'; import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern'; import { setScopedHistory, setServices, setDocViewsRegistry } from '../../../../kibana_services'; @@ -33,6 +33,13 @@ import { navigationPluginMock } from '../../../../../../navigation/public/mocks' import { getInnerAngularModule } from '../../../../get_inner_angular'; import { createBrowserHistory } from 'history'; +const fakeRowVals = { + time: 'time_formatted', + bytes: 'bytes_formatted', + '@timestamp': '@timestamp_formatted', + request_body: 'request_body_formatted', +}; + describe('Doc Table', () => { const core = coreMock.createStart(); const dataMock = dataPluginMock.createStartContract(); @@ -45,8 +52,6 @@ describe('Doc Table', () => { // Stub out a minimal mapping of 4 fields let mapping; - let fakeRowVals; - let stubFieldFormatConverter; beforeAll(() => setScopedHistory(createBrowserHistory())); beforeEach(() => { angular.element.prototype.slice = jest.fn(function (index) { @@ -97,21 +102,15 @@ describe('Doc Table', () => { mapping = $parentScope.indexPattern.fields; // Stub `getConverterFor` for a field in the indexPattern to return mock data. - // Returns `val` if provided, otherwise generates fake data for the field. - fakeRowVals = getFakeRowVals('formatted', 0, mapping); - stubFieldFormatConverter = function ($root, field, val) { - const convertFn = (value, type, options) => { - if (val) { - return val; - } - const fieldName = _.get(options, 'field.name', null); - - return fakeRowVals[fieldName] || ''; - }; - - $root.indexPattern.fields.getByName(field).format.convert = convertFn; - $root.indexPattern.fields.getByName(field).format.getConverterFor = () => convertFn; + + const convertFn = (value, type, options) => { + const fieldName = _.get(options, 'field.name', null); + return fakeRowVals[fieldName] || ''; }; + $parentScope.indexPattern.getFormatterForField = () => ({ + convert: convertFn, + getConverterFor: () => convertFn, + }); }) ); @@ -148,9 +147,6 @@ describe('Doc Table', () => { test('should be able to add and remove columns', () => { let childElems; - stubFieldFormatConverter($parentScope, 'bytes'); - stubFieldFormatConverter($parentScope, 'request_body'); - // Should include a column for toggling and the time column by default $parentScope.columns = ['bytes']; $elementScope.$digest(); @@ -302,9 +298,6 @@ describe('Doc Table', () => { $root.mapping = mapping; $root.indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider); - // Stub field format converters for every field in the indexPattern - $root.indexPattern.fields.forEach((f) => stubFieldFormatConverter($root, f.name)); - $row = $('').attr({ 'kbn-table-row': 'row', columns: 'columns', @@ -417,7 +410,8 @@ describe('Doc Table', () => { }); test('handles two columns with the same content', () => { - stubFieldFormatConverter($root, 'request_body', fakeRowVals.bytes); + const tempVal = fakeRowVals.request_body; + fakeRowVals.request_body = 'bytes_formatted'; $root.columns.length = 0; $root.columns.push('bytes'); @@ -428,6 +422,7 @@ describe('Doc Table', () => { expect($after).toHaveLength(4); expect($after.eq(2).text().trim()).toMatch(/^bytes_formatted/); expect($after.eq(3).text().trim()).toMatch(/^bytes_formatted/); + fakeRowVals.request_body = tempVal; }); test('handles two columns swapping position', () => { diff --git a/src/test_utils/public/stub_index_pattern.js b/src/test_utils/public/stub_index_pattern.js index 2f51a73ea1e6c1..0b67023351b1bc 100644 --- a/src/test_utils/public/stub_index_pattern.js +++ b/src/test_utils/public/stub_index_pattern.js @@ -64,7 +64,7 @@ export default function StubIndexPattern(pattern, getConfig, timeField, fields, }); this._reindexFields = function () { - this.fields = new FieldList(this, this.fields || fields, false); // createFieldList(this, this.fields || fields, false); + this.fields = new FieldList(this, this.fields || fields, false); }; this.stubSetFieldFormat = function (fieldName, id, params) { From 60b6ecacb5d9aef0e09d3ff8facb3b80fbc4f0eb Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Wed, 5 Aug 2020 12:38:54 -0500 Subject: [PATCH 10/13] fix jest test --- src/test_utils/public/stub_index_pattern.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test_utils/public/stub_index_pattern.js b/src/test_utils/public/stub_index_pattern.js index 0b67023351b1bc..f7b65930b683d4 100644 --- a/src/test_utils/public/stub_index_pattern.js +++ b/src/test_utils/public/stub_index_pattern.js @@ -60,7 +60,7 @@ export default function StubIndexPattern(pattern, getConfig, timeField, fields, this.fieldsFetcher = { apiClient: { baseUrl: '' } }; this.formatField = this.formatHit.formatField; this.getFormatterForField = () => ({ - convert: () => ({}), + convert: () => '', }); this._reindexFields = function () { From b7872661ba9b2a775173fda5615f00b282170771 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Wed, 5 Aug 2020 16:11:40 -0500 Subject: [PATCH 11/13] update docs --- ...-plugin-plugins-data-public.indexpattern.getfieldbyname.md | 4 ++-- src/plugins/data/public/public.api.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.getfieldbyname.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.getfieldbyname.md index d0bafe7fa75951..75cdfd0a2e22eb 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.getfieldbyname.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpattern.getfieldbyname.md @@ -7,7 +7,7 @@ Signature: ```typescript -getFieldByName(name: string): IndexPatternField | void; +getFieldByName(name: string): IndexPatternField | undefined; ``` ## Parameters @@ -18,5 +18,5 @@ getFieldByName(name: string): IndexPatternField | void; Returns: -`IndexPatternField | void` +`IndexPatternField | undefined` diff --git a/src/plugins/data/public/public.api.md b/src/plugins/data/public/public.api.md index b63a8ad90a6b74..f50d002716d104 100644 --- a/src/plugins/data/public/public.api.md +++ b/src/plugins/data/public/public.api.md @@ -962,7 +962,7 @@ export class IndexPattern implements IIndexPattern { }[]; }; // (undocumented) - getFieldByName(name: string): IndexPatternField | void; + getFieldByName(name: string): IndexPatternField | undefined; // (undocumented) getFormatterForField(field: IndexPatternField | IndexPatternField['spec']): FieldFormat; // (undocumented) From fbf3636af71b047e8cdc206599a526b010764148 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Thu, 6 Aug 2020 09:05:48 -0500 Subject: [PATCH 12/13] only return boolean, not boolean or undefined --- .../public/kibana-plugin-plugins-data-public.fieldlist.md | 2 +- .../kibana-plugin-plugins-data-public.fieldlist.tospec.md | 2 +- ...kibana-plugin-plugins-data-public.indexpatternfield.md | 2 +- ...ins-data-public.indexpatternfield.readfromdocvalues.md | 2 +- ...plugin-plugins-data-public.indexpatternfield.tojson.md | 4 ++-- ...plugin-plugins-data-public.indexpatternfield.tospec.md | 4 ++-- .../common/index_patterns/fields/index_pattern_field.ts | 6 +++--- src/plugins/data/public/public.api.md | 8 ++++---- .../public/components/test_utils.tsx | 4 ++-- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.md index 91e1d573dae42f..ef740575dff4ef 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.md @@ -26,6 +26,6 @@ export declare class FieldList extends Array implements IInde | [remove](./kibana-plugin-plugins-data-public.fieldlist.remove.md) | | (field: IFieldType) => void | | | [removeAll](./kibana-plugin-plugins-data-public.fieldlist.removeall.md) | | () => void | | | [replaceAll](./kibana-plugin-plugins-data-public.fieldlist.replaceall.md) | | (specs: FieldSpec[]) => void | | -| [toSpec](./kibana-plugin-plugins-data-public.fieldlist.tospec.md) | | () => {
count: number;
script: string | undefined;
lang: string | undefined;
conflictDescriptions: Record<string, string[]> | undefined;
name: string;
type: string;
esTypes: string[] | undefined;
scripted: boolean;
searchable: boolean;
aggregatable: boolean;
readFromDocValues: boolean | undefined;
subType: import("../types").IFieldSubType | undefined;
format: any;
}[] | | +| [toSpec](./kibana-plugin-plugins-data-public.fieldlist.tospec.md) | | () => {
count: number;
script: string | undefined;
lang: string | undefined;
conflictDescriptions: Record<string, string[]> | undefined;
name: string;
type: string;
esTypes: string[] | undefined;
scripted: boolean;
searchable: boolean;
aggregatable: boolean;
readFromDocValues: boolean;
subType: import("../types").IFieldSubType | undefined;
format: any;
}[] | | | [update](./kibana-plugin-plugins-data-public.fieldlist.update.md) | | (field: FieldSpec) => void | | diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.tospec.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.tospec.md index 1ad5493a743aea..7b2797aba8594f 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.tospec.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.tospec.md @@ -18,7 +18,7 @@ toSpec: () => { scripted: boolean; searchable: boolean; aggregatable: boolean; - readFromDocValues: boolean | undefined; + readFromDocValues: boolean; subType: import("../types").IFieldSubType | undefined; format: any; }[]; diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.md index e310d6023477ab..713b29ea3a3d30 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.md @@ -30,7 +30,7 @@ export declare class IndexPatternField implements IFieldType | [indexPattern](./kibana-plugin-plugins-data-public.indexpatternfield.indexpattern.md) | | IndexPattern | | | [lang](./kibana-plugin-plugins-data-public.indexpatternfield.lang.md) | | string | undefined | | | [name](./kibana-plugin-plugins-data-public.indexpatternfield.name.md) | | string | | -| [readFromDocValues](./kibana-plugin-plugins-data-public.indexpatternfield.readfromdocvalues.md) | | boolean | undefined | | +| [readFromDocValues](./kibana-plugin-plugins-data-public.indexpatternfield.readfromdocvalues.md) | | boolean | | | [script](./kibana-plugin-plugins-data-public.indexpatternfield.script.md) | | string | undefined | | | [scripted](./kibana-plugin-plugins-data-public.indexpatternfield.scripted.md) | | boolean | | | [searchable](./kibana-plugin-plugins-data-public.indexpatternfield.searchable.md) | | boolean | | diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.readfromdocvalues.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.readfromdocvalues.md index fd85870b2db8eb..22f727e3c00e8d 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.readfromdocvalues.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.readfromdocvalues.md @@ -7,5 +7,5 @@ Signature: ```typescript -get readFromDocValues(): boolean | undefined; +get readFromDocValues(): boolean; ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.tojson.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.tojson.md index cde43faaff4636..a6a3a5a093c8e9 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.tojson.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.tojson.md @@ -18,7 +18,7 @@ toJSON(): { scripted: boolean; searchable: boolean; aggregatable: boolean; - readFromDocValues: boolean | undefined; + readFromDocValues: boolean; subType: import("../types").IFieldSubType | undefined; }; ``` @@ -35,7 +35,7 @@ toJSON(): { scripted: boolean; searchable: boolean; aggregatable: boolean; - readFromDocValues: boolean | undefined; + readFromDocValues: boolean; subType: import("../types").IFieldSubType | undefined; }` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.tospec.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.tospec.md index add90c3b1f0bb8..5037cb0049e829 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.tospec.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.tospec.md @@ -18,7 +18,7 @@ toSpec(): { scripted: boolean; searchable: boolean; aggregatable: boolean; - readFromDocValues: boolean | undefined; + readFromDocValues: boolean; subType: import("../types").IFieldSubType | undefined; format: any; }; @@ -36,7 +36,7 @@ toSpec(): { scripted: boolean; searchable: boolean; aggregatable: boolean; - readFromDocValues: boolean | undefined; + readFromDocValues: boolean; subType: import("../types").IFieldSubType | undefined; format: any; }` diff --git a/src/plugins/data/common/index_patterns/fields/index_pattern_field.ts b/src/plugins/data/common/index_patterns/fields/index_pattern_field.ts index ee4d6fc65168ed..4e22332bef141e 100644 --- a/src/plugins/data/common/index_patterns/fields/index_pattern_field.ts +++ b/src/plugins/data/common/index_patterns/fields/index_pattern_field.ts @@ -111,15 +111,15 @@ export class IndexPatternField implements IFieldType { } public get searchable() { - return this.spec.searchable || this.scripted; + return !!(this.spec.searchable || this.scripted); } public get aggregatable() { - return this.spec.aggregatable || this.scripted; + return !!(this.spec.aggregatable || this.scripted); } public get readFromDocValues() { - return this.spec.readFromDocValues && !this.scripted; + return !!(this.spec.readFromDocValues && !this.scripted); } public get subType() { diff --git a/src/plugins/data/public/public.api.md b/src/plugins/data/public/public.api.md index f50d002716d104..9a1b4580f5724f 100644 --- a/src/plugins/data/public/public.api.md +++ b/src/plugins/data/public/public.api.md @@ -606,7 +606,7 @@ export class FieldList extends Array implements IIndexPattern scripted: boolean; searchable: boolean; aggregatable: boolean; - readFromDocValues: boolean | undefined; + readFromDocValues: boolean; subType: import("../types").IFieldSubType | undefined; format: any; }[]; @@ -1083,7 +1083,7 @@ export class IndexPatternField implements IFieldType { // (undocumented) get name(): string; // (undocumented) - get readFromDocValues(): boolean | undefined; + get readFromDocValues(): boolean; // (undocumented) get script(): string | undefined; set script(script: string | undefined); @@ -1109,7 +1109,7 @@ export class IndexPatternField implements IFieldType { scripted: boolean; searchable: boolean; aggregatable: boolean; - readFromDocValues: boolean | undefined; + readFromDocValues: boolean; subType: import("../types").IFieldSubType | undefined; }; // (undocumented) @@ -1124,7 +1124,7 @@ export class IndexPatternField implements IFieldType { scripted: boolean; searchable: boolean; aggregatable: boolean; - readFromDocValues: boolean | undefined; + readFromDocValues: boolean; subType: import("../types").IFieldSubType | undefined; format: any; }; diff --git a/src/plugins/index_pattern_management/public/components/test_utils.tsx b/src/plugins/index_pattern_management/public/components/test_utils.tsx index ae968f3069a65b..6aa71785d779c2 100644 --- a/src/plugins/index_pattern_management/public/components/test_utils.tsx +++ b/src/plugins/index_pattern_management/public/components/test_utils.tsx @@ -23,9 +23,9 @@ import { shallow } from 'enzyme'; // since the 'shallow' from 'enzyme' doesn't support context API for React 16 and above (https://github.com/facebook/react/pull/14329) // we use this workaround where define legacy contextTypes for react class component -export function createComponentWithContext>( +export function createComponentWithContext>( MyComponent: React.ComponentClass, - props: props, + props: Props, mockedContext: Record ) { MyComponent.contextTypes = { From d6eb0a60046cb77a4a616822a8eb19223f566c6b Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Thu, 6 Aug 2020 14:52:22 -0500 Subject: [PATCH 13/13] readonly for field list attrs --- ...a-plugin-plugins-data-public.fieldlist.add.md | 2 +- ...in-plugins-data-public.fieldlist.getbyname.md | 2 +- ...in-plugins-data-public.fieldlist.getbytype.md | 2 +- ...lugin-plugins-data-public.fieldlist.remove.md | 2 +- ...in-plugins-data-public.fieldlist.removeall.md | 2 +- ...n-plugins-data-public.fieldlist.replaceall.md | 2 +- ...lugin-plugins-data-public.fieldlist.tospec.md | 2 +- ...lugin-plugins-data-public.fieldlist.update.md | 2 +- .../common/index_patterns/fields/field_list.ts | 16 ++++++++-------- src/plugins/data/public/public.api.md | 16 ++++++++-------- 10 files changed, 24 insertions(+), 24 deletions(-) diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.add.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.add.md index 61706eb33fdcaf..ae3d82f0cc3ea1 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.add.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.add.md @@ -7,5 +7,5 @@ Signature: ```typescript -add: (field: FieldSpec) => void; +readonly add: (field: FieldSpec) => void; ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.getbyname.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.getbyname.md index f6690905f22c11..af368d003423a5 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.getbyname.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.getbyname.md @@ -7,5 +7,5 @@ Signature: ```typescript -getByName: (name: IndexPatternField['name']) => IndexPatternField | undefined; +readonly getByName: (name: IndexPatternField['name']) => IndexPatternField | undefined; ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.getbytype.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.getbytype.md index ae073143b8ab75..16bae3ee7c555c 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.getbytype.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.getbytype.md @@ -7,5 +7,5 @@ Signature: ```typescript -getByType: (type: IndexPatternField['type']) => any[]; +readonly getByType: (type: IndexPatternField['type']) => any[]; ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.remove.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.remove.md index 64ac0fa44425bd..149410adb3550a 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.remove.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.remove.md @@ -7,5 +7,5 @@ Signature: ```typescript -remove: (field: IFieldType) => void; +readonly remove: (field: IFieldType) => void; ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.removeall.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.removeall.md index a2004d2b1b81be..92a45349ad0051 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.removeall.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.removeall.md @@ -7,5 +7,5 @@ Signature: ```typescript -removeAll: () => void; +readonly removeAll: () => void; ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.replaceall.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.replaceall.md index d10891babf79ee..5330440e6b96a1 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.replaceall.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.replaceall.md @@ -7,5 +7,5 @@ Signature: ```typescript -replaceAll: (specs: FieldSpec[]) => void; +readonly replaceAll: (specs: FieldSpec[]) => void; ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.tospec.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.tospec.md index 7b2797aba8594f..e646339feb4955 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.tospec.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.tospec.md @@ -7,7 +7,7 @@ Signature: ```typescript -toSpec: () => { +readonly toSpec: () => { count: number; script: string | undefined; lang: string | undefined; diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.update.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.update.md index ce1a1eb73f815f..c718e47b31b50a 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.update.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.fieldlist.update.md @@ -7,5 +7,5 @@ Signature: ```typescript -update: (field: FieldSpec) => void; +readonly update: (field: FieldSpec) => void; ``` diff --git a/src/plugins/data/common/index_patterns/fields/field_list.ts b/src/plugins/data/common/index_patterns/fields/field_list.ts index d0deae28c10010..207002f42bbce5 100644 --- a/src/plugins/data/common/index_patterns/fields/field_list.ts +++ b/src/plugins/data/common/index_patterns/fields/field_list.ts @@ -72,11 +72,11 @@ export class FieldList extends Array implements IIndexPattern specs.map((field) => this.add(field)); } - getByName = (name: IndexPatternField['name']) => this.byName.get(name); - getByType = (type: IndexPatternField['type']) => [ + public readonly getByName = (name: IndexPatternField['name']) => this.byName.get(name); + public readonly getByType = (type: IndexPatternField['type']) => [ ...(this.groups.get(type) || new Map()).values(), ]; - add = (field: FieldSpec) => { + public readonly add = (field: FieldSpec) => { const newField = new IndexPatternField( this.indexPattern, field, @@ -88,7 +88,7 @@ export class FieldList extends Array implements IIndexPattern this.setByGroup(newField); }; - remove = (field: IFieldType) => { + public readonly remove = (field: IFieldType) => { this.removeByGroup(field); this.byName.delete(field.name); @@ -96,7 +96,7 @@ export class FieldList extends Array implements IIndexPattern this.splice(fieldIndex, 1); }; - update = (field: FieldSpec) => { + public readonly update = (field: FieldSpec) => { const newField = new IndexPatternField( this.indexPattern, field, @@ -110,18 +110,18 @@ export class FieldList extends Array implements IIndexPattern this.setByGroup(newField); }; - removeAll = () => { + public readonly removeAll = () => { this.length = 0; this.byName.clear(); this.groups.clear(); }; - replaceAll = (specs: FieldSpec[]) => { + public readonly replaceAll = (specs: FieldSpec[]) => { this.removeAll(); specs.forEach(this.add); }; - toSpec = () => { + public readonly toSpec = () => { return [...this.map((field) => field.toSpec())]; }; } diff --git a/src/plugins/data/public/public.api.md b/src/plugins/data/public/public.api.md index 9a1b4580f5724f..76f88df4dd6fcd 100644 --- a/src/plugins/data/public/public.api.md +++ b/src/plugins/data/public/public.api.md @@ -583,19 +583,19 @@ export class FieldList extends Array implements IIndexPattern // Warning: (ae-forgotten-export) The symbol "FieldSpec" needs to be exported by the entry point index.d.ts constructor(indexPattern: IndexPattern, specs?: FieldSpec[], shortDotsEnable?: boolean, onNotification?: () => void); // (undocumented) - add: (field: FieldSpec) => void; + readonly add: (field: FieldSpec) => void; // (undocumented) - getByName: (name: IndexPatternField['name']) => IndexPatternField | undefined; + readonly getByName: (name: IndexPatternField['name']) => IndexPatternField | undefined; // (undocumented) - getByType: (type: IndexPatternField['type']) => any[]; + readonly getByType: (type: IndexPatternField['type']) => any[]; // (undocumented) - remove: (field: IFieldType) => void; + readonly remove: (field: IFieldType) => void; // (undocumented) - removeAll: () => void; + readonly removeAll: () => void; // (undocumented) - replaceAll: (specs: FieldSpec[]) => void; + readonly replaceAll: (specs: FieldSpec[]) => void; // (undocumented) - toSpec: () => { + readonly toSpec: () => { count: number; script: string | undefined; lang: string | undefined; @@ -611,7 +611,7 @@ export class FieldList extends Array implements IIndexPattern format: any; }[]; // (undocumented) - update: (field: FieldSpec) => void; + readonly update: (field: FieldSpec) => void; } // @public (undocumented)