From 1040e64936bed53b1e0ee095c15413b482a931fa Mon Sep 17 00:00:00 2001 From: Fabien Baligand Date: Thu, 16 Jul 2020 22:13:35 +0200 Subject: [PATCH] [Visualizations] Pass 'aggs' parameter to custom request handlers (#71423) --- .../public/expressions/visualization_function.ts | 14 +++++++++++++- .../visualizations/public/legacy/build_pipeline.ts | 5 ++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/plugins/visualizations/public/expressions/visualization_function.ts b/src/plugins/visualizations/public/expressions/visualization_function.ts index 222479158934b..68a153f4272a3 100644 --- a/src/plugins/visualizations/public/expressions/visualization_function.ts +++ b/src/plugins/visualizations/public/expressions/visualization_function.ts @@ -21,7 +21,7 @@ import { get } from 'lodash'; import { i18n } from '@kbn/i18n'; import { VisResponseValue, PersistedState } from '../../../../plugins/visualizations/public'; import { ExpressionFunctionDefinition, Render } from '../../../../plugins/expressions/public'; -import { getTypes, getIndexPatterns, getFilterManager } from '../services'; +import { getTypes, getIndexPatterns, getFilterManager, getSearch } from '../services'; interface Arguments { index?: string | null; @@ -31,6 +31,7 @@ interface Arguments { schemas?: string; visConfig?: string; uiState?: string; + aggConfigs?: string; } export type ExpressionFunctionVisualization = ExpressionFunctionDefinition< @@ -84,6 +85,11 @@ export const visualization = (): ExpressionFunctionVisualization => ({ default: '"{}"', help: 'User interface state', }, + aggConfigs: { + types: ['string'], + default: '"{}"', + help: 'Aggregation configurations', + }, }, async fn(input, args, { inspectorAdapters }) { const visConfigParams = args.visConfig ? JSON.parse(args.visConfig) : {}; @@ -94,6 +100,11 @@ export const visualization = (): ExpressionFunctionVisualization => ({ const uiStateParams = args.uiState ? JSON.parse(args.uiState) : {}; const uiState = new PersistedState(uiStateParams); + const aggConfigsState = args.aggConfigs ? JSON.parse(args.aggConfigs) : []; + const aggs = indexPattern + ? getSearch().aggs.createAggConfigs(indexPattern, aggConfigsState) + : undefined; + if (typeof visType.requestHandler === 'function') { input = await visType.requestHandler({ partialRows: args.partialRows, @@ -107,6 +118,7 @@ export const visualization = (): ExpressionFunctionVisualization => ({ inspectorAdapters, queryFilter: getFilterManager(), forceFetch: true, + aggs, }); } diff --git a/src/plugins/visualizations/public/legacy/build_pipeline.ts b/src/plugins/visualizations/public/legacy/build_pipeline.ts index 2ef07bf18c91c..e74a83d91fabf 100644 --- a/src/plugins/visualizations/public/legacy/build_pipeline.ts +++ b/src/plugins/visualizations/public/legacy/build_pipeline.ts @@ -535,7 +535,10 @@ export const buildPipeline = async ( metricsAtAllLevels=${vis.isHierarchical()} partialRows=${vis.type.requiresPartialRows || vis.params.showPartialRows || false} `; if (indexPattern) { - pipeline += `${prepareString('index', indexPattern.id)}`; + pipeline += `${prepareString('index', indexPattern.id)} `; + if (vis.data.aggs) { + pipeline += `${prepareJson('aggConfigs', vis.data.aggs!.aggs)}`; + } } }