Skip to content

Commit

Permalink
Initial pass at limiting agg types based on rollup caps
Browse files Browse the repository at this point in the history
  • Loading branch information
jen-huang committed Jul 5, 2018
1 parent 09ec12e commit 09d0b4c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
3 changes: 3 additions & 0 deletions x-pack/plugins/rollup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export function rollup(kibana) {
'plugins/rollup/index_pattern_creation',
'plugins/rollup/index_pattern_list',
],
visualize: [
'plugins/rollup/vis_type_agg_filter',
],
},
init: function (server) {
registerLicenseChecker(server);
Expand Down
7 changes: 7 additions & 0 deletions x-pack/plugins/rollup/public/vis_type_agg_filter/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import './register';
32 changes: 32 additions & 0 deletions x-pack/plugins/rollup/public/vis_type_agg_filter/register.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { aggTypeFilters } from 'ui/agg_types/filter';
import { uniq } from 'lodash';

/**
* If rollup index pattern, check its capabilities
* and limit available aggregations based on that.
*/
aggTypeFilters.addFilter(
(aggType, indexPattern) => {
if(indexPattern.type !== 'rollup') {
return true;
}

const jobs = indexPattern.typeMeta.jobs;
let allAggs = [];

jobs.forEach(job => {
const fields = indexPattern.typeMeta.capabilities[job].fields;
Object.keys(fields).forEach(field => {
allAggs = [...allAggs, ...fields[field].map(agg => agg.agg)];
});
});

return uniq(allAggs).includes(aggType.name);
}
);

0 comments on commit 09d0b4c

Please sign in to comment.