Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] [Visualizations] Pass 'aggs' parameter to custom request handlers (#71423) #72153

Merged
merged 2 commits into from
Jul 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,6 +31,7 @@ interface Arguments {
schemas?: string;
visConfig?: string;
uiState?: string;
aggConfigs?: string;
}

export type ExpressionFunctionVisualization = ExpressionFunctionDefinition<
Expand Down Expand Up @@ -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) : {};
Expand All @@ -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,
Expand All @@ -107,6 +118,7 @@ export const visualization = (): ExpressionFunctionVisualization => ({
inspectorAdapters,
queryFilter: getFilterManager(),
forceFetch: true,
aggs,
});
}

Expand Down
5 changes: 4 additions & 1 deletion src/plugins/visualizations/public/legacy/build_pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`;
}
}
}

Expand Down