Skip to content

Commit

Permalink
extracting to parent agg helper
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisljar committed Feb 13, 2017
1 parent be27727 commit b92535f
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 48 deletions.
51 changes: 3 additions & 48 deletions src/ui/public/agg_types/metrics/derivative.js
Original file line number Diff line number Diff line change
@@ -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()
]
});
}
61 changes: 61 additions & 0 deletions src/ui/public/agg_types/metrics/lib/parent_pipeline_agg_helper.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit b92535f

Please sign in to comment.