From e06ac608ff808b2781a21014eb7c2b82d3d079b9 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Mon, 13 Apr 2020 16:05:39 -0500 Subject: [PATCH] simpler field copy --- src/legacy/ui/public/field_editor/field_editor.js | 15 ++++++++++++--- .../public/index_patterns/fields/field_list.ts | 13 +++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/legacy/ui/public/field_editor/field_editor.js b/src/legacy/ui/public/field_editor/field_editor.js index 4ae1333cad510..5d7fc22f73793 100644 --- a/src/legacy/ui/public/field_editor/field_editor.js +++ b/src/legacy/ui/public/field_editor/field_editor.js @@ -67,7 +67,7 @@ import { FieldFormatEditor } from './components/field_format_editor'; import { FIELD_TYPES_BY_LANG, DEFAULT_FIELD_TYPES } from './constants'; import { executeScript, isScriptValid } from './lib'; -//import { copyField, executeScript, isScriptValid } from './lib'; +// import { copyField, executeScript, isScriptValid } from './lib'; // import { Field } from '../../../../plugins/data/public'; import { i18n } from '@kbn/i18n'; @@ -97,6 +97,12 @@ const getFieldTypeFormatsList = (field, defaultFieldFormat) => { ]; }; +const copyFieldMk = field => { + // console.log('copyField', field.format.params()); + const obj = { ...field, format: field.format }; + return obj; +}; + export class FieldEditor extends PureComponent { static propTypes = { indexPattern: PropTypes.object.isRequired, @@ -122,9 +128,9 @@ export class FieldEditor extends PureComponent { fieldTypes: [], fieldTypeFormats: [], existingFieldNames: indexPattern.fields.map(f => f.name), - // field: copyField(field, indexPattern), + //field: copyField(field, indexPattern), //field: new Field(indexPattern, field.$$spec), // what about short dots? - field: { ...field.$$spec }, + field: copyFieldMk(field), fieldFormatId: undefined, fieldFormatParams: {}, showScriptingHelp: false, @@ -237,6 +243,7 @@ export class FieldEditor extends PureComponent { renderName() { const { isCreating, field } = this.state; const isInvalid = !field.name || !field.name.trim(); + // console.log('renderName', this.state.field); return isCreating ? ( ); + // console.log('field_editor render fieldFormat', field.format); + return ( implements IFieldList { this.splice(fieldIndex, 1); }; - update = (field: Field) => { - const index = this.findIndex(f => f.name === field.name); - this.splice(index, 1, field); - this.setByName(field); - this.removeByGroup(field); - this.setByGroup(field); + update = (field: FieldSpec) => { + const newField = new Field(this.indexPattern, field, this.shortDotsEnable); + const index = this.findIndex(f => f.name === newField.name); + this.splice(index, 1, newField); + this.setByName(newField); + this.removeByGroup(newField); + this.setByGroup(newField); }; }