diff --git a/src/core_plugins/table_vis/public/__tests__/_table_vis_controller.js b/src/core_plugins/table_vis/public/__tests__/_table_vis_controller.js index 50677a771085f..d13075ed2c043 100644 --- a/src/core_plugins/table_vis/public/__tests__/_table_vis_controller.js +++ b/src/core_plugins/table_vis/public/__tests__/_table_vis_controller.js @@ -26,7 +26,7 @@ import { VisProvider } from 'ui/vis'; import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern'; import { AppStateProvider } from 'ui/state_management/app_state'; -describe('Controller', function () { +describe('Table Vis Controller', function () { let $rootScope; let $compile; let Private; @@ -106,7 +106,7 @@ describe('Controller', function () { expect(!$scope.tableGroups).to.be.ok(); expect(!$scope.hasSomeRows).to.be.ok(); - attachEsResponseToScope(tabifyAggResponse(vis.getAggConfig().getResponseAggs(), fixtures.oneRangeBucket, { + attachEsResponseToScope(tabifyAggResponse(vis.getAggConfig(), fixtures.oneRangeBucket, { isHierarchical: vis.isHierarchical() })); @@ -121,7 +121,7 @@ describe('Controller', function () { const vis = new OneRangeVis(); initController(vis); - attachEsResponseToScope(tabifyAggResponse(vis.getAggConfig().getResponseAggs(), fixtures.oneRangeBucket, { + attachEsResponseToScope(tabifyAggResponse(vis.getAggConfig(), fixtures.oneRangeBucket, { isHierarchical: vis.isHierarchical() })); removeEsResponseFromScope(); @@ -142,7 +142,7 @@ describe('Controller', function () { const resp = _.cloneDeep(fixtures.oneRangeBucket); resp.aggregations.agg_2.buckets = {}; - attachEsResponseToScope(tabifyAggResponse(vis.getAggConfig().getResponseAggs(), resp, { + attachEsResponseToScope(tabifyAggResponse(vis.getAggConfig(), resp, { isHierarchical: vis.isHierarchical() })); @@ -158,7 +158,7 @@ describe('Controller', function () { const resp = _.cloneDeep(fixtures.oneRangeBucket); resp.aggregations.agg_2.buckets = {}; - attachEsResponseToScope(tabifyAggResponse(vis.getAggConfig().getResponseAggs(), resp, { + attachEsResponseToScope(tabifyAggResponse(vis.getAggConfig(), resp, { isHierarchical: vis.isHierarchical() })); diff --git a/src/core_plugins/tile_map/public/coordinatemap_response_handler.js b/src/core_plugins/tile_map/public/coordinatemap_response_handler.js index 56dde0614d426..b99cef25104bb 100644 --- a/src/core_plugins/tile_map/public/coordinatemap_response_handler.js +++ b/src/core_plugins/tile_map/public/coordinatemap_response_handler.js @@ -34,7 +34,7 @@ export function makeGeoJsonResponseHandler() { //double conversion, first to table, then to geojson //This is to future-proof this code for Canvas-refactoring - const tabifiedResponse = tabifyAggResponse(vis.getAggConfig().getResponseAggs(), esResponse, { + const tabifiedResponse = tabifyAggResponse(vis.getAggConfig(), esResponse, { asAggConfigResults: false }); lastGeoJsonResponse = convertToGeoJson(tabifiedResponse); diff --git a/src/ui/public/agg_response/tabify/__tests__/_integration.js b/src/ui/public/agg_response/tabify/__tests__/_integration.js index 422e212587405..b06293fa48093 100644 --- a/src/ui/public/agg_response/tabify/__tests__/_integration.js +++ b/src/ui/public/agg_response/tabify/__tests__/_integration.js @@ -48,7 +48,7 @@ describe('tabifyAggResponse Integration', function () { }); normalizeIds(vis); - const resp = tabifyAggResponse(vis.getAggConfig().getResponseAggs(), fixtures.metricOnly, { + const resp = tabifyAggResponse(vis.getAggConfig(), fixtures.metricOnly, { canSplit: false, isHierarchical: vis.isHierarchical() }); @@ -174,7 +174,7 @@ describe('tabifyAggResponse Integration', function () { // only complete rows, and only put the metrics at the end. vis.isHierarchical = _.constant(false); - const tabbed = tabifyAggResponse(vis.getAggConfig().getResponseAggs(), esResp, { isHierarchical: vis.isHierarchical() }); + const tabbed = tabifyAggResponse(vis.getAggConfig(), esResp, { isHierarchical: vis.isHierarchical() }); expectRootGroup(tabbed, function expectTable(table, splitKey) { expectColumns(table, [src, os, avg]); @@ -200,7 +200,7 @@ describe('tabifyAggResponse Integration', function () { // the existing bucket and it's metric vis.isHierarchical = _.constant(true); - const tabbed = tabifyAggResponse(vis.getAggConfig().getResponseAggs(), esResp, { + const tabbed = tabifyAggResponse(vis.getAggConfig(), esResp, { partialRows: true, isHierarchical: vis.isHierarchical() }); @@ -235,7 +235,7 @@ describe('tabifyAggResponse Integration', function () { // the end vis.isHierarchical = _.constant(true); - const tabbed = tabifyAggResponse(vis.getAggConfig().getResponseAggs(), esResp, { + const tabbed = tabifyAggResponse(vis.getAggConfig(), esResp, { partialRows: true, minimalColumns: true, isHierarchical: vis.isHierarchical() @@ -268,7 +268,7 @@ describe('tabifyAggResponse Integration', function () { // create metric columns after each bucket vis.isHierarchical = _.constant(false); - const tabbed = tabifyAggResponse(vis.getAggConfig().getResponseAggs(), esResp, { + const tabbed = tabifyAggResponse(vis.getAggConfig(), esResp, { minimalColumns: false, isHierarchical: vis.isHierarchical() }); diff --git a/src/ui/public/agg_response/tabify/__tests__/_response_writer.js b/src/ui/public/agg_response/tabify/__tests__/_response_writer.js index af5587a1bf705..3835e4ceb3398 100644 --- a/src/ui/public/agg_response/tabify/__tests__/_response_writer.js +++ b/src/ui/public/agg_response/tabify/__tests__/_response_writer.js @@ -47,7 +47,7 @@ describe('TabbedAggResponseWriter class', function () { it('sets canSplit=true by default', function () { const vis = new Vis(indexPattern, { type: 'histogram', aggs: [] }); - const writer = new TabbedAggResponseWriter(vis.getAggConfig().getResponseAggs(), { + const writer = new TabbedAggResponseWriter(vis.getAggConfig(), { isHierarchical: vis.isHierarchical() }); expect(writer).to.have.property('canSplit', true); @@ -55,7 +55,7 @@ describe('TabbedAggResponseWriter class', function () { it('sets canSplit=false when config says to', function () { const vis = new Vis(indexPattern, { type: 'histogram', aggs: [] }); - const writer = new TabbedAggResponseWriter(vis.getAggConfig().getResponseAggs(), { + const writer = new TabbedAggResponseWriter(vis.getAggConfig(), { canSplit: false, isHierarchical: vis.isHierarchical() }); @@ -67,7 +67,7 @@ describe('TabbedAggResponseWriter class', function () { const vis = new Vis(indexPattern, { type: 'histogram', aggs: [] }); const partial = Boolean(Math.round(Math.random())); - const writer = new TabbedAggResponseWriter(vis.getAggConfig().getResponseAggs(), { + const writer = new TabbedAggResponseWriter(vis.getAggConfig(), { isHierarchical: vis.isHierarchical(), partialRows: partial }); @@ -79,7 +79,7 @@ describe('TabbedAggResponseWriter class', function () { const hierarchical = Boolean(Math.round(Math.random())); sinon.stub(vis, 'isHierarchical').returns(hierarchical); - const writer = new TabbedAggResponseWriter(vis.getAggConfig().getResponseAggs(), { + const writer = new TabbedAggResponseWriter(vis.getAggConfig(), { isHierarchical: vis.isHierarchical() }); expect(writer).to.have.property('partialRows', hierarchical); @@ -89,7 +89,7 @@ describe('TabbedAggResponseWriter class', function () { it('starts off with a root TabifyTableGroup', function () { const vis = new Vis(indexPattern, { type: 'histogram', aggs: [] }); - const writer = new TabbedAggResponseWriter(vis.getAggConfig().getResponseAggs(), { + const writer = new TabbedAggResponseWriter(vis.getAggConfig(), { isHierarchical: vis.isHierarchical() }); expect(writer.root).to.be.a(TabifyTableGroup); @@ -105,7 +105,7 @@ describe('TabbedAggResponseWriter class', function () { describe('#response()', function () { it('returns the root TabifyTableGroup if splitting', function () { const vis = new Vis(indexPattern, { type: 'histogram', aggs: [] }); - const writer = new TabbedAggResponseWriter(vis.getAggConfig().getResponseAggs(), { + const writer = new TabbedAggResponseWriter(vis.getAggConfig(), { isHierarchical: vis.isHierarchical() }); expect(writer.response()).to.be(writer.root); @@ -113,7 +113,7 @@ describe('TabbedAggResponseWriter class', function () { it('returns the first table if not splitting', function () { const vis = new Vis(indexPattern, { type: 'histogram', aggs: [] }); - const writer = new TabbedAggResponseWriter(vis.getAggConfig().getResponseAggs(), { + const writer = new TabbedAggResponseWriter(vis.getAggConfig(), { isHierarchical: vis.isHierarchical(), canSplit: false }); @@ -130,7 +130,7 @@ describe('TabbedAggResponseWriter class', function () { ] }); const buckets = new TabifyBuckets({ buckets: [ { key: 'nginx' }, { key: 'apache' } ] }); - const writer = new TabbedAggResponseWriter(vis.getAggConfig().getResponseAggs(), { + const writer = new TabbedAggResponseWriter(vis.getAggConfig(), { isHierarchical: vis.isHierarchical() }); const tables = []; @@ -184,7 +184,7 @@ describe('TabbedAggResponseWriter class', function () { }); const agg = vis.aggs.bySchemaName.split[0]; const buckets = new TabifyBuckets({ buckets: [ { key: 'apache' } ] }); - const writer = new TabbedAggResponseWriter(vis.getAggConfig().getResponseAggs(), { + const writer = new TabbedAggResponseWriter(vis.getAggConfig(), { isHierarchical: vis.isHierarchical(), canSplit: false }); @@ -205,7 +205,7 @@ describe('TabbedAggResponseWriter class', function () { ] }); - const writer = new TabbedAggResponseWriter(vis.getAggConfig().getResponseAggs(), { + const writer = new TabbedAggResponseWriter(vis.getAggConfig(), { isHierarchical: vis.isHierarchical(), asAggConfigResults: true }); @@ -256,7 +256,7 @@ describe('TabbedAggResponseWriter class', function () { it('logs a cell in the TabbedAggResponseWriters row buffer, calls the block arg, then removes the value from the buffer', function () { const vis = new Vis(indexPattern, { type: 'histogram', aggs: [] }); - const writer = new TabbedAggResponseWriter(vis.getAggConfig().getResponseAggs(), { + const writer = new TabbedAggResponseWriter(vis.getAggConfig(), { isHierarchical: vis.isHierarchical() }); @@ -272,7 +272,7 @@ describe('TabbedAggResponseWriter class', function () { describe('#row()', function () { it('writes the TabbedAggResponseWriters internal rowBuffer into a table', function () { const vis = new Vis(indexPattern, { type: 'histogram', aggs: [] }); - const writer = new TabbedAggResponseWriter(vis.getAggConfig().getResponseAggs(), { + const writer = new TabbedAggResponseWriter(vis.getAggConfig(), { isHierarchical: vis.isHierarchical() }); @@ -312,7 +312,7 @@ describe('TabbedAggResponseWriter class', function () { const count = vis.aggs[3]; - const writer = new TabbedAggResponseWriter(vis.getAggConfig().getResponseAggs(), { + const writer = new TabbedAggResponseWriter(vis.getAggConfig(), { isHierarchical: vis.isHierarchical() }); writer.split(type, typeTabifyBuckets, function () { @@ -358,7 +358,7 @@ describe('TabbedAggResponseWriter class', function () { ] }); - const writer = new TabbedAggResponseWriter(vis.getAggConfig().getResponseAggs(), { + const writer = new TabbedAggResponseWriter(vis.getAggConfig(), { isHierarchical: vis.isHierarchical() }); const table = writer._table(); @@ -379,7 +379,7 @@ describe('TabbedAggResponseWriter class', function () { ] }); - const writer = new TabbedAggResponseWriter(vis.getAggConfig().getResponseAggs(), { + const writer = new TabbedAggResponseWriter(vis.getAggConfig(), { isHierarchical: vis.isHierarchical() }); const table = writer._table(); diff --git a/src/ui/public/agg_response/tabify/_response_writer.js b/src/ui/public/agg_response/tabify/_response_writer.js index 55deb4f578690..1d0bd1c23863c 100644 --- a/src/ui/public/agg_response/tabify/_response_writer.js +++ b/src/ui/public/agg_response/tabify/_response_writer.js @@ -63,7 +63,8 @@ function TabbedAggResponseWriter(aggs, opts) { // to their aggConfig and enable the filterbar and tooltip formatters this.asAggConfigResults = !!this.opts.asAggConfigResults; - this.columns = tabifyGetColumns(aggs, this.minimalColumns); + this.aggs = aggs; + this.columns = tabifyGetColumns(aggs.getResponseAggs(), this.minimalColumns); this.aggStack = _.pluck(this.columns, 'aggConfig'); this.root = new TabifyTableGroup(); diff --git a/src/ui/public/agg_response/tabify/tabify.js b/src/ui/public/agg_response/tabify/tabify.js index fdd0e10bec35c..e12d4e43c45f2 100644 --- a/src/ui/public/agg_response/tabify/tabify.js +++ b/src/ui/public/agg_response/tabify/tabify.js @@ -44,7 +44,7 @@ export function tabifyAggResponse(aggs, esResponse, respOpts = {}) { */ function collectBucket(write, bucket, key, aggScale) { const agg = write.aggStack.shift(); - const aggInfo = agg.write(); + const aggInfo = agg.write(write.aggs); aggScale *= aggInfo.metricScale || 1; switch (agg.schema.group) { diff --git a/src/ui/public/agg_table/__tests__/_group.js b/src/ui/public/agg_table/__tests__/_group.js index add9cbff8dc8b..5bf8741362ee0 100644 --- a/src/ui/public/agg_table/__tests__/_group.js +++ b/src/ui/public/agg_table/__tests__/_group.js @@ -51,7 +51,7 @@ describe('AggTableGroup Directive', function () { it('renders a simple split response properly', function () { const vis = new Vis(indexPattern, 'table'); - $scope.group = tabifyAggResponse(vis.getAggConfig().getResponseAggs(), fixtures.metricOnly); + $scope.group = tabifyAggResponse(vis.getAggConfig(), fixtures.metricOnly); $scope.sort = { columnIndex: null, direction: null @@ -93,7 +93,7 @@ describe('AggTableGroup Directive', function () { agg.id = 'agg_' + (i + 1); }); - const group = $scope.group = tabifyAggResponse(vis.getAggConfig().getResponseAggs(), fixtures.threeTermBuckets); + const group = $scope.group = tabifyAggResponse(vis.getAggConfig(), fixtures.threeTermBuckets); const $el = $(''); $compile($el)($scope); $scope.$digest(); diff --git a/src/ui/public/agg_table/__tests__/_table.js b/src/ui/public/agg_table/__tests__/_table.js index e11e0e53d66ed..4d556bfafe9fc 100644 --- a/src/ui/public/agg_table/__tests__/_table.js +++ b/src/ui/public/agg_table/__tests__/_table.js @@ -57,7 +57,7 @@ describe('AggTable Directive', function () { it('renders a simple response properly', function () { const vis = new Vis(indexPattern, 'table'); $scope.table = tabifyAggResponse( - vis.getAggConfig().getResponseAggs(), + vis.getAggConfig(), fixtures.metricOnly, { canSplit: false, hierarchical: vis.isHierarchical() } ); @@ -92,7 +92,7 @@ describe('AggTable Directive', function () { agg.id = 'agg_' + (i + 1); }); - $scope.table = tabifyAggResponse(vis.getAggConfig().getResponseAggs(), fixtures.threeTermBuckets, { + $scope.table = tabifyAggResponse(vis.getAggConfig(), fixtures.threeTermBuckets, { canSplit: false, isHierarchical: vis.isHierarchical() }); @@ -158,7 +158,7 @@ describe('AggTable Directive', function () { const oldTimezoneSetting = settings.get('dateFormat:tz'); settings.set('dateFormat:tz', 'UTC'); - $scope.table = tabifyAggResponse(vis.getAggConfig().getResponseAggs(), + $scope.table = tabifyAggResponse(vis.getAggConfig(), fixtures.oneTermOneHistogramBucketWithTwoMetricsOneTopHitOneDerivative, { canSplit: false, minimalColumns: true, asAggConfigResults: true } ); diff --git a/src/ui/public/agg_types/__tests__/agg_param_writer.js b/src/ui/public/agg_types/__tests__/agg_param_writer.js index 9e76dc5481aae..c9182b2271428 100644 --- a/src/ui/public/agg_types/__tests__/agg_param_writer.js +++ b/src/ui/public/agg_types/__tests__/agg_param_writer.js @@ -124,7 +124,7 @@ export default function AggParamWriterHelper(Private) { return aggConfig.type === self.aggType; }); - return aggConfig.type.params.write(aggConfig); + return aggConfig.type.params.write(aggConfig, self.vis.aggs); }; return AggParamWriter; diff --git a/src/ui/public/agg_types/__tests__/buckets/date_histogram/_params.js b/src/ui/public/agg_types/__tests__/buckets/date_histogram/_params.js index f535763bffa49..a66b27d5493f8 100644 --- a/src/ui/public/agg_types/__tests__/buckets/date_histogram/_params.js +++ b/src/ui/public/agg_types/__tests__/buckets/date_histogram/_params.js @@ -125,7 +125,7 @@ describe('params', function () { })); }); - const output = histoConfig.write(); + const output = histoConfig.write(vis.aggs); expect(_.has(output, 'metricScale')).to.be(should); }); }); diff --git a/src/ui/public/agg_types/__tests__/metrics/parent_pipeline.js b/src/ui/public/agg_types/__tests__/metrics/parent_pipeline.js index 26760d285bef4..d149fd34a2a0f 100644 --- a/src/ui/public/agg_types/__tests__/metrics/parent_pipeline.js +++ b/src/ui/public/agg_types/__tests__/metrics/parent_pipeline.js @@ -86,7 +86,7 @@ describe('parent pipeline aggs', function () { // Grab the aggConfig off the vis (we don't actually use the vis for anything else) aggConfig = vis.aggs[1]; - aggDsl = aggConfig.toDsl(); + aggDsl = aggConfig.toDsl(vis.aggs); }); } diff --git a/src/ui/public/agg_types/__tests__/metrics/sibling_pipeline.js b/src/ui/public/agg_types/__tests__/metrics/sibling_pipeline.js index 7a2cbf4da6646..e3e09b886d03d 100644 --- a/src/ui/public/agg_types/__tests__/metrics/sibling_pipeline.js +++ b/src/ui/public/agg_types/__tests__/metrics/sibling_pipeline.js @@ -89,7 +89,7 @@ describe('sibling pipeline aggs', function () { // Grab the aggConfig off the vis (we don't actually use the vis for anything else) aggConfig = vis.aggs[1]; - aggDsl = aggConfig.toDsl(); + aggDsl = aggConfig.toDsl(vis.aggs); }); } diff --git a/src/ui/public/agg_types/agg_params.js b/src/ui/public/agg_types/agg_params.js index 886670aa86764..621aef1383e1f 100644 --- a/src/ui/public/agg_types/agg_params.js +++ b/src/ui/public/agg_types/agg_params.js @@ -75,13 +75,13 @@ function AggParams(params) { * output object which is used to create the agg dsl for the search request. All other properties * are dependent on the AggParam#write methods which should be studied for each AggType. */ -AggParams.prototype.write = function (aggConfig, locals) { +AggParams.prototype.write = function (aggConfig, aggs, locals) { const output = { params: {} }; locals = locals || {}; this.forEach(function (param) { if (param.write) { - param.write(aggConfig, output, locals); + param.write(aggConfig, output, aggs, locals); } else { output.params[param.name] = aggConfig.params[param.name]; } diff --git a/src/ui/public/agg_types/buckets/date_histogram.js b/src/ui/public/agg_types/buckets/date_histogram.js index 14ecc7d911795..528f73fa3904e 100644 --- a/src/ui/public/agg_types/buckets/date_histogram.js +++ b/src/ui/public/agg_types/buckets/date_histogram.js @@ -120,7 +120,7 @@ export const dateHistogramBucketAgg = new BucketAggType({ modifyAggConfigOnSearchRequestStart: function (agg) { setBounds(agg, true); }, - write: function (agg, output) { + write: function (agg, output, aggs) { setBounds(agg, true); agg.buckets.setInterval(getInterval(agg)); @@ -136,8 +136,8 @@ export const dateHistogramBucketAgg = new BucketAggType({ } const scaleMetrics = interval.scaled && interval.scale < 1; - if (scaleMetrics) { - const all = _.every(agg.vis.getAggConfig().bySchemaGroup.metrics, function (agg) { + if (scaleMetrics && aggs) { + const all = _.every(aggs.bySchemaGroup.metrics, function (agg) { return agg.type && agg.type.isScalable(); }); if (all) { diff --git a/src/ui/public/agg_types/buckets/terms.js b/src/ui/public/agg_types/buckets/terms.js index 6a99f861137f6..0c1f6b71f4651 100644 --- a/src/ui/public/agg_types/buckets/terms.js +++ b/src/ui/public/agg_types/buckets/terms.js @@ -98,13 +98,13 @@ export const termsBucketAgg = new BucketAggType({ }; }, createFilter: createFilterTerms, - postFlightRequest: async (resp, aggConfigs, aggConfig, searchSource) => { + postFlightRequest: async (resp, aggConfigs, aggConfig, searchSource, inspectorAdapters) => { const nestedSearchSource = searchSource.createChild(); if (aggConfig.params.otherBucket) { const filterAgg = buildOtherBucketAgg(aggConfigs, aggConfig, resp); nestedSearchSource.setField('aggs', filterAgg); - const request = aggConfigs.vis.API.inspectorAdapters.requests.start('Other bucket', { + const request = inspectorAdapters.requests.start('Other bucket', { description: `This request counts the number of documents that fall outside the criterion of the data buckets.` }); @@ -212,12 +212,11 @@ export const termsBucketAgg = new BucketAggType({ params.orderAgg = params.orderAgg || paramDef.makeOrderAgg(agg); } }, - write: function (agg, output) { - const vis = agg.vis; + write: function (agg, output, aggs) { const dir = agg.params.order.val; const order = output.params.order = {}; - let orderAgg = agg.params.orderAgg || vis.aggs.getResponseAggById(agg.params.orderBy); + let orderAgg = agg.params.orderAgg || aggs.getResponseAggById(agg.params.orderBy); // TODO: This works around an Elasticsearch bug the always casts terms agg scripts to strings // thus causing issues with filtering. This probably causes other issues since float might not @@ -245,7 +244,7 @@ export const termsBucketAgg = new BucketAggType({ const orderAggId = orderAgg.id; if (orderAgg.parentId) { - orderAgg = vis.aggs.byId[orderAgg.parentId]; + orderAgg = aggs.byId[orderAgg.parentId]; } output.subAggs = (output.subAggs || []).concat(orderAgg); diff --git a/src/ui/public/agg_types/metrics/lib/make_nested_label.js b/src/ui/public/agg_types/metrics/lib/make_nested_label.js index 83b3fa85a6d63..5ced0753282d7 100644 --- a/src/ui/public/agg_types/metrics/lib/make_nested_label.js +++ b/src/ui/public/agg_types/metrics/lib/make_nested_label.js @@ -35,7 +35,7 @@ const makeNestedLabel = function (aggConfig, label) { } return metricLabel; } - const metric = aggConfig.vis.aggs.find(agg => agg.id === aggConfig.params.metricAgg); + const metric = aggConfig._aggs.find(agg => agg.id === aggConfig.params.metricAgg); if (!metric) return ''; return `${uppercaseLabel} of ${metric.makeLabel()}`; }; 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 index 66dae6a70bf0a..c9687b1c4903f 100644 --- 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 @@ -22,7 +22,7 @@ import _ from 'lodash'; import { AggConfig } from '../../../vis/agg_config'; import { Schemas } from '../../../vis/editors/default/schemas'; import { parentPipelineAggController } from './parent_pipeline_agg_controller'; -import { parentPipelineAggWritter } from './parent_pipeline_agg_writter'; +import { parentPipelineAggWriter } from './parent_pipeline_agg_writer'; import { forwardModifyAggConfigOnSearchRequestStart } from './nested_agg_helpers'; @@ -70,7 +70,7 @@ const parentPipelineAggHelper = { editor: metricAggTemplate, default: 'custom', controller: parentPipelineAggController, - write: parentPipelineAggWritter + write: parentPipelineAggWriter } ]; }, @@ -79,7 +79,7 @@ const parentPipelineAggHelper = { if (agg.params.customMetric) { subAgg = agg.params.customMetric; } else { - subAgg = agg.vis.getAggConfig().byId[agg.params.metricAgg]; + subAgg = agg._aggs.byId[agg.params.metricAgg]; } return subAgg.type.getFormat(subAgg); } diff --git a/src/ui/public/agg_types/metrics/lib/parent_pipeline_agg_writter.js b/src/ui/public/agg_types/metrics/lib/parent_pipeline_agg_writer.js similarity index 83% rename from src/ui/public/agg_types/metrics/lib/parent_pipeline_agg_writter.js rename to src/ui/public/agg_types/metrics/lib/parent_pipeline_agg_writer.js index 645f7d69b0c9c..65a194b0d23a9 100644 --- a/src/ui/public/agg_types/metrics/lib/parent_pipeline_agg_writter.js +++ b/src/ui/public/agg_types/metrics/lib/parent_pipeline_agg_writer.js @@ -17,9 +17,8 @@ * under the License. */ -const parentPipelineAggWritter = function (agg, output) { - const vis = agg.vis; - const selectedMetric = agg.params.customMetric || vis.aggs.getResponseAggById(agg.params.metricAgg); +const parentPipelineAggWriter = function (agg, output, aggs) { + const selectedMetric = agg.params.customMetric || aggs.getResponseAggById(agg.params.metricAgg); if (agg.params.customMetric && agg.params.customMetric.type.name !== 'count') { output.parentAggs = (output.parentAggs || []).concat(selectedMetric); @@ -33,4 +32,4 @@ const parentPipelineAggWritter = function (agg, output) { } }; -export { parentPipelineAggWritter }; +export { parentPipelineAggWriter }; diff --git a/src/ui/public/agg_types/metrics/lib/sibling_pipeline_agg_helper.js b/src/ui/public/agg_types/metrics/lib/sibling_pipeline_agg_helper.js index 4c8f72df68c0a..befc8c0c95fe2 100644 --- a/src/ui/public/agg_types/metrics/lib/sibling_pipeline_agg_helper.js +++ b/src/ui/public/agg_types/metrics/lib/sibling_pipeline_agg_helper.js @@ -22,7 +22,7 @@ import { AggConfig } from '../../../vis/agg_config'; import { Schemas } from '../../../vis/editors/default/schemas'; import { siblingPipelineAggController } from './sibling_pipeline_agg_controller'; -import { siblingPipelineAggWritter } from './sibling_pipeline_agg_writter'; +import { siblingPipelineAggWriter } from './sibling_pipeline_agg_writer'; import metricAggTemplate from '../../controls/sub_metric.html'; import { forwardModifyAggConfigOnSearchRequestStart } from './nested_agg_helpers'; @@ -97,7 +97,7 @@ const siblingPipelineAggHelper = { editor: metricAggTemplate, controller: siblingPipelineAggController('customMetric'), modifyAggConfigOnSearchRequestStart: forwardModifyAggConfigOnSearchRequestStart('customMetric'), - write: siblingPipelineAggWritter + write: siblingPipelineAggWriter } ]; }, diff --git a/src/ui/public/agg_types/metrics/lib/sibling_pipeline_agg_writter.js b/src/ui/public/agg_types/metrics/lib/sibling_pipeline_agg_writer.js similarity index 93% rename from src/ui/public/agg_types/metrics/lib/sibling_pipeline_agg_writter.js rename to src/ui/public/agg_types/metrics/lib/sibling_pipeline_agg_writer.js index bc8d957bbeae5..61124c15fb7c5 100644 --- a/src/ui/public/agg_types/metrics/lib/sibling_pipeline_agg_writter.js +++ b/src/ui/public/agg_types/metrics/lib/sibling_pipeline_agg_writer.js @@ -17,7 +17,7 @@ * under the License. */ -const siblingPipelineAggWritter = function (agg, output) { +const siblingPipelineAggWriter = function (agg, output) { if (!agg.params.customMetric) return; const metricAgg = agg.params.customMetric; @@ -35,4 +35,4 @@ const siblingPipelineAggWritter = function (agg, output) { }; -export { siblingPipelineAggWritter }; +export { siblingPipelineAggWriter }; diff --git a/src/ui/public/vis/agg_config.js b/src/ui/public/vis/agg_config.js index aa571b2f83efb..1df28693e1b52 100644 --- a/src/ui/public/vis/agg_config.js +++ b/src/ui/public/vis/agg_config.js @@ -62,10 +62,11 @@ class AggConfig { }, 0); } - constructor(vis, opts = {}) { + constructor(vis, opts = {}, aggs) { this.id = String(opts.id || AggConfig.nextId(vis.aggs)); this.vis = vis; this._indexPattern = vis.indexPattern; + this._aggs = aggs || vis.aggs; this._opts = opts; this.enabled = typeof opts.enabled === 'boolean' ? opts.enabled : true; @@ -125,8 +126,8 @@ class AggConfig { }); } - write() { - return this.type.params.write(this); + write(aggs) { + return this.type.params.write(this, aggs); } isFilterable() { @@ -172,13 +173,13 @@ class AggConfig { * * Adds params and adhoc subaggs to a pojo, then returns it * - * @param {AggConfig} aggConfig - the config object to convert + * @param {AggConfigs} aggConfigs - the config object to convert * @return {void|Object} - if the config has a dsl representation, it is * returned, else undefined is returned */ - toDsl() { + toDsl(aggConfigs) { if (this.type.hasNoDsl) return; - const output = this.write(); + const output = this.write(aggConfigs); const configDsl = {}; configDsl[this.type.dslName || this.type.name] = output.params; @@ -188,14 +189,14 @@ class AggConfig { if (output.subAggs) { const subDslLvl = configDsl.aggs || (configDsl.aggs = {}); output.subAggs.forEach(function nestAdhocSubAggs(subAggConfig) { - subDslLvl[subAggConfig.id] = subAggConfig.toDsl(); + subDslLvl[subAggConfig.id] = subAggConfig.toDsl(aggConfigs); }); } if (output.parentAggs) { const subDslLvl = configDsl.parentAggs || (configDsl.parentAggs = {}); output.parentAggs.forEach(function nestAdhocSubAggs(subAggConfig) { - subDslLvl[subAggConfig.id] = subAggConfig.toDsl(); + subDslLvl[subAggConfig.id] = subAggConfig.toDsl(aggConfigs); }); } diff --git a/src/ui/public/vis/agg_configs.js b/src/ui/public/vis/agg_configs.js index 6fcbf86506008..c6c688db666f1 100644 --- a/src/ui/public/vis/agg_configs.js +++ b/src/ui/public/vis/agg_configs.js @@ -49,15 +49,19 @@ function parseParentAggs(dslLvlCursor, dsl) { class AggConfigs extends IndexedArray { constructor(vis, configStates = []) { configStates = AggConfig.ensureIds(configStates); + super({ index: ['id'], group: ['schema.group', 'type.name', 'schema.name'], - initialSet: configStates.map(function (aggConfigState) { - if (aggConfigState instanceof AggConfig) return aggConfigState; - return new AggConfig(vis, aggConfigState); - }) }); + this.push(...configStates.map(aggConfigState => { + if (aggConfigState instanceof AggConfig) { + return aggConfigState; + } + return new AggConfig(vis, aggConfigState, this); + })); + this.vis = vis; // Set the defaults for any schema which has them. If the defaults @@ -75,7 +79,7 @@ class AggConfigs extends IndexedArray { const defaults = schema.defaults.slice(0, schema.max); _.each(defaults, defaultState => { const state = _.defaults({ id: AggConfig.nextId(this) }, defaultState); - this.push(new AggConfig(vis, state)); + this.push(new AggConfig(vis, state, this)); }); } }) @@ -111,17 +115,17 @@ class AggConfigs extends IndexedArray { .filter(function (agg) { return agg.type.name !== 'count'; }) - .map(function (agg) { + .map(agg => { return { config: agg, - dsl: agg.toDsl() + dsl: agg.toDsl(this) }; }) .value(); } this.getRequestAggs() .filter(config => !config.type.hasNoDsl) - .forEach(function nestEachConfig(config, i, list) { + .forEach((config, i, list) => { if (!dslLvlCursor) { // start at the top level dslLvlCursor = dslTopLvl; @@ -135,7 +139,7 @@ class AggConfigs extends IndexedArray { dslLvlCursor = prevDsl.aggs || dslLvlCursor; } - const dsl = dslLvlCursor[config.id] = config.toDsl(); + const dsl = dslLvlCursor[config.id] = config.toDsl(this); let subAggs; parseParentAggs(dslLvlCursor, dsl); @@ -146,7 +150,7 @@ class AggConfigs extends IndexedArray { } if (subAggs && nestedMetrics) { - nestedMetrics.forEach(function (agg) { + nestedMetrics.forEach(agg => { subAggs[agg.config.id] = agg.dsl; }); } diff --git a/src/ui/public/vis/request_handlers/courier.js b/src/ui/public/vis/request_handlers/courier.js index c9750f936e9b4..b894a07f5f4ec 100644 --- a/src/ui/public/vis/request_handlers/courier.js +++ b/src/ui/public/vis/request_handlers/courier.js @@ -33,8 +33,8 @@ const CourierRequestHandlerProvider = function () { * This function builds tabular data from the response and attaches it to the * inspector. It will only be called when the data view in the inspector is opened. */ - async function buildTabularInspectorData(vis, searchSource, responseAggs) { - const table = tabifyAggResponse(responseAggs, searchSource.finalResponse, { + async function buildTabularInspectorData(vis, searchSource, aggConfigs) { + const table = tabifyAggResponse(aggConfigs, searchSource.finalResponse, { canSplit: false, asAggConfigResults: false, partialRows: true, @@ -121,7 +121,7 @@ const CourierRequestHandlerProvider = function () { return requestSearchSource.getSearchRequestBody().then(q => { const queryHash = calculateObjectHash(q); if (shouldQuery(queryHash)) { - const lastResponseAggs = vis.getAggConfig().getResponseAggs(); + const lastAggConfig = vis.getAggConfig(); vis.API.inspectorAdapters.requests.reset(); const request = vis.API.inspectorAdapters.requests.start('Data', { description: `This request queries Elasticsearch to fetch the data for the visualization.`, @@ -140,14 +140,20 @@ const CourierRequestHandlerProvider = function () { }).then(async resp => { for (const agg of aggs) { if (_.has(agg, 'type.postFlightRequest')) { - resp = await agg.type.postFlightRequest(resp, aggs, agg, requestSearchSource); + resp = await agg.type.postFlightRequest( + resp, + aggs, + agg, + requestSearchSource, + vis.API.inspectorAdapters + ); } } searchSource.finalResponse = resp; vis.API.inspectorAdapters.data.setTabularLoader( - () => buildTabularInspectorData(vis, searchSource, lastResponseAggs), + () => buildTabularInspectorData(vis, searchSource, lastAggConfig), { returnsFormattedValues: true } ); diff --git a/src/ui/public/vis/response_handlers/basic.js b/src/ui/public/vis/response_handlers/basic.js index f4a8663ed30e7..d8ce9942a8898 100644 --- a/src/ui/public/vis/response_handlers/basic.js +++ b/src/ui/public/vis/response_handlers/basic.js @@ -71,7 +71,7 @@ const BasicResponseHandlerProvider = function (Private) { resolve(aggResponse.hierarchical(vis, response)); } - const tableGroup = aggResponse.tabify(vis.getAggConfig().getResponseAggs(), response, { + const tableGroup = aggResponse.tabify(vis.getAggConfig(), response, { canSplit: true, asAggConfigResults: true, isHierarchical: vis.isHierarchical() diff --git a/src/ui/public/vis/response_handlers/tabify.js b/src/ui/public/vis/response_handlers/tabify.js index a5d32be55ec71..1b3cc3a1c3346 100644 --- a/src/ui/public/vis/response_handlers/tabify.js +++ b/src/ui/public/vis/response_handlers/tabify.js @@ -29,7 +29,7 @@ const TabifyResponseHandlerProvider = function (Private) { handler: function (vis, response) { return new Promise((resolve) => { - const tableGroup = aggResponse.tabify(vis.getAggConfig().getResponseAggs(), response, { + const tableGroup = aggResponse.tabify(vis.getAggConfig(), response, { canSplit: true, asAggConfigResults: _.get(vis, 'type.responseHandlerConfig.asAggConfigResults', false), isHierarchical: vis.isHierarchical()