From 09d0b4c697d17a56c502d675291b9a23dcdd6b9d Mon Sep 17 00:00:00 2001 From: Jen Huang Date: Thu, 21 Jun 2018 14:24:44 -0700 Subject: [PATCH] Initial pass at limiting agg types based on rollup caps --- x-pack/plugins/rollup/index.js | 3 ++ .../public/vis_type_agg_filter/index.js | 7 ++++ .../public/vis_type_agg_filter/register.js | 32 +++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 x-pack/plugins/rollup/public/vis_type_agg_filter/index.js create mode 100644 x-pack/plugins/rollup/public/vis_type_agg_filter/register.js diff --git a/x-pack/plugins/rollup/index.js b/x-pack/plugins/rollup/index.js index 96b9a24d25034..2bba337b55d4c 100644 --- a/x-pack/plugins/rollup/index.js +++ b/x-pack/plugins/rollup/index.js @@ -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); diff --git a/x-pack/plugins/rollup/public/vis_type_agg_filter/index.js b/x-pack/plugins/rollup/public/vis_type_agg_filter/index.js new file mode 100644 index 0000000000000..4d2947eb36f46 --- /dev/null +++ b/x-pack/plugins/rollup/public/vis_type_agg_filter/index.js @@ -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'; diff --git a/x-pack/plugins/rollup/public/vis_type_agg_filter/register.js b/x-pack/plugins/rollup/public/vis_type_agg_filter/register.js new file mode 100644 index 0000000000000..157af07c49003 --- /dev/null +++ b/x-pack/plugins/rollup/public/vis_type_agg_filter/register.js @@ -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); + } +);