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
Changes from 1 commit
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
Next Next commit
[Visualizations] Pass 'aggs' parameter to custom request handlers (#7…
  • Loading branch information
fbaligand authored and lukeelmers committed Jul 16, 2020
commit 1040e64936bed53b1e0ee095c15413b482a931fa
Original file line number Diff line number Diff line change
@@ -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,
});
}

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