From 607385be4ce1095bdd22e46101e3696ba5586476 Mon Sep 17 00:00:00 2001 From: Jen Huang Date: Fri, 13 Jul 2018 14:04:32 -0700 Subject: [PATCH] Filter aggregation fields for rollup indices, reorganize rollup directory --- x-pack/plugins/rollup/index.js | 2 +- .../public/visualize/agg_type_field_filter.js | 28 +++++++++++++++++++ .../agg_type_filter.js} | 0 .../index.js | 3 +- 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 x-pack/plugins/rollup/public/visualize/agg_type_field_filter.js rename x-pack/plugins/rollup/public/{vis_type_agg_filter/register.js => visualize/agg_type_filter.js} (100%) rename x-pack/plugins/rollup/public/{vis_type_agg_filter => visualize}/index.js (79%) diff --git a/x-pack/plugins/rollup/index.js b/x-pack/plugins/rollup/index.js index 2bba337b55d4c..42879f503b445 100644 --- a/x-pack/plugins/rollup/index.js +++ b/x-pack/plugins/rollup/index.js @@ -20,7 +20,7 @@ export function rollup(kibana) { 'plugins/rollup/index_pattern_list', ], visualize: [ - 'plugins/rollup/vis_type_agg_filter', + 'plugins/rollup/visualize', ], }, init: function (server) { diff --git a/x-pack/plugins/rollup/public/visualize/agg_type_field_filter.js b/x-pack/plugins/rollup/public/visualize/agg_type_field_filter.js new file mode 100644 index 0000000000000..895b7d64f188b --- /dev/null +++ b/x-pack/plugins/rollup/public/visualize/agg_type_field_filter.js @@ -0,0 +1,28 @@ +/* +* 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 { aggTypeFieldFilters } from 'ui/agg_types/param_types/filter'; + +/** + * If rollup index pattern, check its capabilities + * and limit available fields for a given aggType based on that. + */ +aggTypeFieldFilters.addFilter( + (field, fieldParamType, indexPattern, aggConfig) => { + if(indexPattern.type !== 'rollup') { + return true; + } + + const fieldName = field.name; + const aggName = aggConfig.type.name; + const jobs = indexPattern.typeMeta.jobs; + + return !!jobs.find(job => { + const fields = indexPattern.typeMeta.capabilities[job].fields; + return fields[fieldName] && fields[fieldName].find(agg => agg.agg === aggName); + }); + } +); diff --git a/x-pack/plugins/rollup/public/vis_type_agg_filter/register.js b/x-pack/plugins/rollup/public/visualize/agg_type_filter.js similarity index 100% rename from x-pack/plugins/rollup/public/vis_type_agg_filter/register.js rename to x-pack/plugins/rollup/public/visualize/agg_type_filter.js diff --git a/x-pack/plugins/rollup/public/vis_type_agg_filter/index.js b/x-pack/plugins/rollup/public/visualize/index.js similarity index 79% rename from x-pack/plugins/rollup/public/vis_type_agg_filter/index.js rename to x-pack/plugins/rollup/public/visualize/index.js index 4d2947eb36f46..5961110b5fc07 100644 --- a/x-pack/plugins/rollup/public/vis_type_agg_filter/index.js +++ b/x-pack/plugins/rollup/public/visualize/index.js @@ -4,4 +4,5 @@ * you may not use this file except in compliance with the Elastic License. */ -import './register'; +import './agg_type_filter'; +import './agg_type_field_filter';