Skip to content

Commit

Permalink
simpler field copy
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkime committed Apr 13, 2020
1 parent 82c762d commit e06ac60
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
15 changes: 12 additions & 3 deletions src/legacy/ui/public/field_editor/field_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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 ? (
<EuiFormRow
Expand Down Expand Up @@ -438,6 +445,8 @@ export class FieldEditor extends PureComponent {
<FormattedMessage id="common.ui.fieldEditor.formatHeader" defaultMessage="Format" />
);

// console.log('field_editor render fieldFormat', field.format);

return (
<Fragment>
<EuiFormRow
Expand Down
13 changes: 7 additions & 6 deletions src/plugins/data/public/index_patterns/fields/field_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@ export class FieldList extends Array<Field> 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);
};
}

0 comments on commit e06ac60

Please sign in to comment.