mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
parent
6c4b4d2437
commit
79a8e478cb
25 changed files with 97 additions and 87 deletions
|
@ -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()
|
||||
}));
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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()
|
||||
});
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 = $('<kbn-agg-table-group group="group"></kbn-agg-table-group>');
|
||||
$compile($el)($scope);
|
||||
$scope.$digest();
|
||||
|
|
|
@ -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 }
|
||||
);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -125,7 +125,7 @@ describe('params', function () {
|
|||
}));
|
||||
});
|
||||
|
||||
const output = histoConfig.write();
|
||||
const output = histoConfig.write(vis.aggs);
|
||||
expect(_.has(output, 'metricScale')).to.be(should);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
import { jstz as tzDetect } from 'jstimezonedetect';
|
||||
import _ from 'lodash';
|
||||
import chrome from 'ui/chrome';
|
||||
import chrome from '../../chrome';
|
||||
import moment from 'moment';
|
||||
import '../../filters/field_type';
|
||||
import '../../validate_date_interval';
|
||||
|
@ -120,8 +120,8 @@ export const dateHistogramBucketAgg = new BucketAggType({
|
|||
modifyAggConfigOnSearchRequestStart: function (agg) {
|
||||
setBounds(agg, true);
|
||||
},
|
||||
write: function (agg, output) {
|
||||
setBounds(agg);
|
||||
write: function (agg, output, aggs) {
|
||||
setBounds(agg, true);
|
||||
agg.buckets.setInterval(getInterval(agg));
|
||||
|
||||
const interval = agg.buckets.getInterval();
|
||||
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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()}`;
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 };
|
|
@ -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
|
||||
}
|
||||
];
|
||||
},
|
||||
|
|
|
@ -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 };
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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 }
|
||||
);
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue