diff --git a/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/lib/__tests__/pipeline.js b/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/lib/__tests__/pipeline.js index b3901529c6133..b0a34a5f69072 100644 --- a/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/lib/__tests__/pipeline.js +++ b/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/lib/__tests__/pipeline.js @@ -168,13 +168,15 @@ describe('processor pipeline', function () { const pipeline = new Pipeline(); const testProcessor = new processorTypes.Set('foo'); - testProcessor.foo = 'bar'; - testProcessor.bar = 'baz'; + testProcessor.targetField = 'bar'; + testProcessor.value = 'baz'; + testProcessor.invalid_property = 'bop'; pipeline.addExisting(testProcessor); - expect(pipeline.processors[0].foo).to.be('bar'); - expect(pipeline.processors[0].bar).to.be('baz'); + expect(pipeline.processors[0].targetField).to.be('bar'); + expect(pipeline.processors[0].value).to.be('baz'); + expect(pipeline.processors[0].invalid_property).to.be(undefined); expect(pipeline.processors[0].processorId).to.not.be('foo'); }); diff --git a/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/lib/pipeline.js b/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/lib/pipeline.js index 17f562e677ade..6bb6fcf2ce507 100644 --- a/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/lib/pipeline.js +++ b/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/lib/pipeline.js @@ -109,20 +109,20 @@ export default class Pipeline { processors[index] = temp; } - addExisting(existingProcessor) { - const Type = existingProcessor.constructor; - const newProcessor = this.add(Type); - _.assign(newProcessor, _.omit(existingProcessor, 'processorId')); + addExisting(oldProcessor) { + const Type = oldProcessor.constructor; + const newProcessor = this.add(Type, oldProcessor.model); + newProcessor.collapsed = true; return newProcessor; } - add(ProcessorType) { + add(ProcessorType, oldProcessor) { const processors = this.processors; this.processorCounter += 1; const processorId = `processor_${this.processorCounter}`; - const newProcessor = new ProcessorType(processorId); + const newProcessor = new ProcessorType(processorId, oldProcessor); processors.push(newProcessor); return newProcessor; diff --git a/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/append/view_model.js b/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/append/view_model.js index e5feeb2c946f3..4a8d0a9a2dcfc 100644 --- a/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/append/view_model.js +++ b/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/append/view_model.js @@ -1,7 +1,8 @@ +import _ from 'lodash'; import Processor from '../base/view_model'; export class Append extends Processor { - constructor(processorId) { + constructor(processorId, model) { super( processorId, 'append', @@ -11,8 +12,18 @@ and it is an array. Converts a scalar to an array and appends one or more values to it if the field exists and it is a scalar. Creates an array containing the provided values if the field doesn’t exist.` ); - this.targetField = ''; - this.values = []; + + _.defaults( + this, + _.pick(model, [ + 'targetField', + 'values' + ]), + { + targetField: '', + values: [] + } + ); } get description() { diff --git a/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/convert/view_model.js b/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/convert/view_model.js index 7077b0e737b06..e5e7fb4ec6989 100644 --- a/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/convert/view_model.js +++ b/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/convert/view_model.js @@ -2,7 +2,7 @@ import _ from 'lodash'; import Processor from '../base/view_model'; export class Convert extends Processor { - constructor(processorId) { + constructor(processorId, model) { super( processorId, 'convert', @@ -11,9 +11,20 @@ export class Convert extends Processor { a string to an integer. If the field value is an array, all members will be converted.` ); - this.sourceField = ''; - this.targetField = ''; - this.type = 'auto'; + + _.defaults( + this, + _.pick(model, [ + 'sourceField', + 'targetField', + 'type' + ]), + { + sourceField: '', + targetField: '', + type: 'auto' + } + ); } get description() { diff --git a/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/date/view_model.js b/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/date/view_model.js index 0ab03c34e54a7..160933dabeab6 100644 --- a/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/date/view_model.js +++ b/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/date/view_model.js @@ -1,19 +1,34 @@ +import _ from 'lodash'; import Processor from '../base/view_model'; export class Date extends Processor { - constructor(processorId) { + constructor(processorId, model) { super( processorId, 'date', 'Date', `Parses dates from fields.` ); - this.sourceField = ''; - this.targetField = '@timestamp'; - this.formats = []; - this.timezone = 'Etc/UTC'; - this.locale = 'ENGLISH'; - this.customFormat = ''; + + _.defaults( + this, + _.pick(model, [ + 'sourceField', + 'targetField', + 'formats', + 'timezone', + 'locale', + 'customFormat' + ]), + { + sourceField: '', + targetField: '@timestamp', + formats: [], + timezone: 'Etc/UTC', + locale: 'ENGLISH', + customFormat: '' + } + ); } get description() { diff --git a/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/geoip/view_model.js b/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/geoip/view_model.js index 74524e048d9df..a0c2460f9114b 100644 --- a/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/geoip/view_model.js +++ b/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/geoip/view_model.js @@ -1,7 +1,8 @@ +import _ from 'lodash'; import Processor from '../base/view_model'; export class GeoIp extends Processor { - constructor(processorId) { + constructor(processorId, model) { super( processorId, 'geoip', @@ -9,10 +10,22 @@ export class GeoIp extends Processor { `Adds information about the geographical location of IP addresses, based on data from the Maxmind database.` ); - this.sourceField = ''; - this.targetField = ''; - this.databaseFile = ''; - this.databaseFields = []; + + _.defaults( + this, + _.pick(model, [ + 'sourceField', + 'targetField', + 'databaseFile', + 'databaseFields' + ]), + { + sourceField: '', + targetField: '', + databaseFile: '', + databaseFields: [] + } + ); } get description() { diff --git a/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/grok/view_model.js b/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/grok/view_model.js index fb016fb9dbf34..2bfa7b8164d3f 100644 --- a/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/grok/view_model.js +++ b/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/grok/view_model.js @@ -3,7 +3,7 @@ import keysDeep from '../../lib/keys_deep'; import Processor from '../base/view_model'; export class Grok extends Processor { - constructor(processorId) { + constructor(processorId, model) { super( processorId, 'grok', @@ -13,8 +13,18 @@ You choose which field to extract matched fields from, as well as the grok pattern you expect will match. A grok pattern is like a regular expression that supports aliased expressions that can be reused.` ); - this.sourceField = ''; - this.pattern = ''; + + _.defaults( + this, + _.pick(model, [ + 'sourceField', + 'pattern' + ]), + { + sourceField: '', + pattern: '' + } + ); } get description() { diff --git a/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/gsub/view_model.js b/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/gsub/view_model.js index ee75c1d1225d1..e06a6f2ccf972 100644 --- a/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/gsub/view_model.js +++ b/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/gsub/view_model.js @@ -1,16 +1,28 @@ +import _ from 'lodash'; import Processor from '../base/view_model'; export class Gsub extends Processor { - constructor(processorId) { + constructor(processorId, model) { super( processorId, 'gsub', 'Gsub', `Converts a string field by applying a regular expression and a replacement.` ); - this.sourceField = ''; - this.pattern = ''; - this.replacement = ''; + + _.defaults( + this, + _.pick(model, [ + 'sourceField', + 'pattern', + 'replacement' + ]), + { + sourceField: '', + pattern: '', + replacement: '' + } + ); } get description() { diff --git a/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/join/view_model.js b/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/join/view_model.js index b56c7a040adb3..44dead79f8f59 100644 --- a/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/join/view_model.js +++ b/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/join/view_model.js @@ -1,7 +1,8 @@ +import _ from 'lodash'; import Processor from '../base/view_model'; export class Join extends Processor { - constructor(processorId) { + constructor(processorId, model) { super( processorId, 'join', @@ -9,8 +10,18 @@ export class Join extends Processor { `Joins each element of an array into a single string using a separator character between each element. ` ); - this.sourceField = ''; - this.separator = ''; + + _.defaults( + this, + _.pick(model, [ + 'sourceField', + 'separator' + ]), + { + sourceField: '', + separator: '' + } + ); } get description() { diff --git a/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/lowercase/view_model.js b/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/lowercase/view_model.js index 4348855ffa293..95d88442d4006 100644 --- a/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/lowercase/view_model.js +++ b/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/lowercase/view_model.js @@ -1,14 +1,24 @@ +import _ from 'lodash'; import Processor from '../base/view_model'; export class Lowercase extends Processor { - constructor(processorId) { + constructor(processorId, model) { super( processorId, 'lowercase', 'Lowercase', `Converts a string to its lowercase equivalent.` ); - this.sourceField = ''; + + _.defaults( + this, + _.pick(model, [ + 'sourceField' + ]), + { + sourceField: '' + } + ); } get description() { diff --git a/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/remove/view_model.js b/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/remove/view_model.js index f865f51f90eb3..65d5ed528d018 100644 --- a/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/remove/view_model.js +++ b/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/remove/view_model.js @@ -1,14 +1,24 @@ +import _ from 'lodash'; import Processor from '../base/view_model'; export class Remove extends Processor { - constructor(processorId) { + constructor(processorId, model) { super( processorId, 'remove', 'Remove', `Removes an existing field.` ); - this.sourceField = ''; + + _.defaults( + this, + _.pick(model, [ + 'sourceField' + ]), + { + sourceField: '' + } + ); } get description() { diff --git a/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/rename/view_model.js b/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/rename/view_model.js index 2cea328f5d1ed..3d6f14f6e6e96 100644 --- a/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/rename/view_model.js +++ b/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/rename/view_model.js @@ -1,15 +1,26 @@ +import _ from 'lodash'; import Processor from '../base/view_model'; export class Rename extends Processor { - constructor(processorId) { + constructor(processorId, model) { super( processorId, 'rename', 'Rename', `Renames an existing field.` ); - this.sourceField = ''; - this.targetField = ''; + + _.defaults( + this, + _.pick(model, [ + 'sourceField', + 'targetField' + ]), + { + sourceField: '', + targetField: '' + } + ); } get description() { diff --git a/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/set/view_model.js b/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/set/view_model.js index 312b691761eb2..16972feef8694 100644 --- a/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/set/view_model.js +++ b/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/set/view_model.js @@ -1,7 +1,8 @@ +import _ from 'lodash'; import Processor from '../base/view_model'; export class Set extends Processor { - constructor(processorId) { + constructor(processorId, model) { super( processorId, 'set', @@ -9,8 +10,18 @@ export class Set extends Processor { `Sets one field and associates it with the specified value. If the field already exists, its value will be replaced with the provided one.` ); - this.targetField = ''; - this.value = ''; + + _.defaults( + this, + _.pick(model, [ + 'targetField', + 'value' + ]), + { + targetField: '', + value: '' + } + ); } get description() { diff --git a/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/split/view_model.js b/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/split/view_model.js index c73ae84fee3e5..f6ba59fc1cf83 100644 --- a/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/split/view_model.js +++ b/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/split/view_model.js @@ -1,15 +1,26 @@ +import _ from 'lodash'; import Processor from '../base/view_model'; export class Split extends Processor { - constructor(processorId) { + constructor(processorId, model) { super( processorId, 'split', 'Split', `Splits a field into an array using a separator character.` ); - this.sourceField = ''; - this.separator = ''; + + _.defaults( + this, + _.pick(model, [ + 'sourceField', + 'separator' + ]), + { + sourceField: '', + separator: '' + } + ); } get description() { diff --git a/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/trim/view_model.js b/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/trim/view_model.js index 6ef74f7231844..9ba9ef478b7f9 100644 --- a/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/trim/view_model.js +++ b/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/trim/view_model.js @@ -1,14 +1,24 @@ +import _ from 'lodash'; import Processor from '../base/view_model'; export class Trim extends Processor { - constructor(processorId) { + constructor(processorId, model) { super( processorId, 'trim', 'Trim', `Trims whitespace from field.` ); - this.sourceField = ''; + + _.defaults( + this, + _.pick(model, [ + 'sourceField' + ]), + { + sourceField: '' + } + ); } get description() { diff --git a/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/uppercase/view_model.js b/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/uppercase/view_model.js index b34927469b1c8..97d1215c422b4 100644 --- a/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/uppercase/view_model.js +++ b/src/plugins/kibana/public/settings/sections/indices/add_data_steps/pipeline_setup/processors/uppercase/view_model.js @@ -1,14 +1,24 @@ +import _ from 'lodash'; import Processor from '../base/view_model'; export class Uppercase extends Processor { - constructor(processorId) { + constructor(processorId, model) { super( processorId, 'uppercase', 'Uppercase', `Converts a string to its uppercase equivalent.` ); - this.sourceField = ''; + + _.defaults( + this, + _.pick(model, [ + 'sourceField' + ]), + { + sourceField: '' + } + ); } get description() {