From b92535f000b86edee95850701d7cc22f7afdd847 Mon Sep 17 00:00:00 2001 From: ppisljar Date: Tue, 7 Feb 2017 10:38:00 +0100 Subject: [PATCH] extracting to parent agg helper --- src/ui/public/agg_types/metrics/derivative.js | 51 +--------------- .../metrics/lib/parent_pipeline_agg_helper.js | 61 +++++++++++++++++++ 2 files changed, 64 insertions(+), 48 deletions(-) create mode 100644 src/ui/public/agg_types/metrics/lib/parent_pipeline_agg_helper.js diff --git a/src/ui/public/agg_types/metrics/derivative.js b/src/ui/public/agg_types/metrics/derivative.js index 0051908ff29b0..01f075cc9d03b 100644 --- a/src/ui/public/agg_types/metrics/derivative.js +++ b/src/ui/public/agg_types/metrics/derivative.js @@ -1,62 +1,17 @@ import AggTypesMetricsMetricAggTypeProvider from 'ui/agg_types/metrics/metric_agg_type'; -import metricAggTemplate from 'ui/agg_types/controls/sub_agg.html'; -import _ from 'lodash'; -import VisAggConfigProvider from 'ui/vis/agg_config'; -import VisSchemasProvider from 'ui/vis/schemas'; +import ParentPipelineAggHelperProvider from './lib/parent_pipeline_agg_helper'; import { makeNestedLabel } from './lib/make_nested_label'; -import { parentPipelineAggController } from './lib/parent_pipeline_agg_controller'; -import { parentPipelineAggWritter } from './lib/parent_pipeline_agg_writter'; export default function AggTypeMetricDerivativeProvider(Private) { const MetricAggType = Private(AggTypesMetricsMetricAggTypeProvider); - const AggConfig = Private(VisAggConfigProvider); - const Schemas = Private(VisSchemasProvider); - - const aggFilter = ['!top_hits', '!percentiles', '!percentile_ranks', '!median', '!std_dev']; - const orderAggSchema = (new Schemas([ - { - group: 'none', - name: 'orderAgg', - title: 'Order Agg', - aggFilter: aggFilter - } - ])).all[0]; + const parentPipelineAggHelper = Private(ParentPipelineAggHelperProvider); return new MetricAggType({ name: 'derivative', title: 'Derivative', makeLabel: agg => makeNestedLabel(agg, 'derivative'), params: [ - { - name: 'customMetric', - type: AggConfig, - default: null, - serialize: function (customMetric) { - return customMetric.toJSON(); - }, - deserialize: function (state, agg) { - return this.makeAgg(agg, state); - }, - makeAgg: function (termsAgg, state) { - state = state || { type: 'count' }; - state.schema = orderAggSchema; - const metricAgg = new AggConfig(termsAgg.vis, state); - metricAgg.id = termsAgg.id + '-metric'; - return metricAgg; - }, - write: _.noop - }, - { - name: 'buckets_path', - write: _.noop - }, - { - name: 'metricAgg', - editor: metricAggTemplate, - default: 'custom', - controller: parentPipelineAggController, - write: parentPipelineAggWritter - } + ...parentPipelineAggHelper.params() ] }); } diff --git a/src/ui/public/agg_types/metrics/lib/parent_pipeline_agg_helper.js b/src/ui/public/agg_types/metrics/lib/parent_pipeline_agg_helper.js new file mode 100644 index 0000000000000..13c5ae6691711 --- /dev/null +++ b/src/ui/public/agg_types/metrics/lib/parent_pipeline_agg_helper.js @@ -0,0 +1,61 @@ +import metricAggTemplate from 'ui/agg_types/controls/sub_agg.html'; +import _ from 'lodash'; +import VisAggConfigProvider from 'ui/vis/agg_config'; +import VisSchemasProvider from 'ui/vis/schemas'; +import { parentPipelineAggController } from './lib/parent_pipeline_agg_controller'; +import { parentPipelineAggWritter } from './lib/parent_pipeline_agg_writter'; + +const ParentPipelineAggHelperProvider = function (Private) { + + const AggConfig = Private(VisAggConfigProvider); + const Schemas = Private(VisSchemasProvider); + + const metricAggFilter = ['!top_hits', '!percentiles', '!percentile_ranks', '!median', '!std_dev']; + const metricAggSchema = (new Schemas([ + { + group: 'none', + name: 'metricAgg', + title: 'Metric Agg', + aggFilter: metricAggFilter + } + ])).all[0]; + + return { + params: function () { + return [ + { + name: 'customMetric', + type: AggConfig, + default: null, + serialize: function (customMetric) { + return customMetric.toJSON(); + }, + deserialize: function (state, agg) { + return this.makeAgg(agg, state); + }, + makeAgg: function (termsAgg, state) { + state = state || { type: 'count' }; + state.schema = metricAggSchema; + const metricAgg = new AggConfig(termsAgg.vis, state); + metricAgg.id = termsAgg.id + '-metric'; + return metricAgg; + }, + write: _.noop + }, + { + name: 'buckets_path', + write: _.noop + }, + { + name: 'metricAgg', + editor: metricAggTemplate, + default: 'custom', + controller: parentPipelineAggController, + write: parentPipelineAggWritter + } + ]; + } + }; +}; + +export default ParentPipelineAggHelperProvider;