Skip to content

Commit

Permalink
remove vis.aggs references from aggTypes (#20508)
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisljar authored Jul 11, 2018
1 parent 676c0bd commit 5042c38
Show file tree
Hide file tree
Showing 25 changed files with 95 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
}));

Expand All @@ -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();
Expand All @@ -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()
}));

Expand All @@ -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()
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/ui/public/agg_response/tabify/__tests__/_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
});
Expand Down Expand Up @@ -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]);
Expand All @@ -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()
});
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
});
Expand Down
30 changes: 15 additions & 15 deletions src/ui/public/agg_response/tabify/__tests__/_response_writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ 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);
});

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()
});
Expand All @@ -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
});
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -105,15 +105,15 @@ 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);
});

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
});
Expand All @@ -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 = [];
Expand Down Expand Up @@ -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
});
Expand All @@ -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
});
Expand Down Expand Up @@ -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()
});

Expand All @@ -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()
});

Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/ui/public/agg_response/tabify/_response_writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/agg_response/tabify/tabify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/ui/public/agg_table/__tests__/_group.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions src/ui/public/agg_table/__tests__/_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
);
Expand Down Expand Up @@ -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()
});
Expand Down Expand Up @@ -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 }
);
Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/agg_types/__tests__/agg_param_writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ describe('params', function () {
}));
});

const output = histoConfig.write();
const output = histoConfig.write(vis.aggs);
expect(_.has(output, 'metricScale')).to.be(should);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/ui/public/agg_types/agg_params.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
6 changes: 3 additions & 3 deletions src/ui/public/agg_types/buckets/date_histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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) {
Expand Down
Loading

0 comments on commit 5042c38

Please sign in to comment.