forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpression_helpers.ts
More file actions
42 lines (36 loc) · 1.53 KB
/
expression_helpers.ts
File metadata and controls
42 lines (36 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import { cloneDeep } from 'lodash';
import { OpenSearchaggsExpressionFunctionDefinition } from '../../../../data/public';
import { ExpressionFunctionOpenSearchDashboards } from '../../../../expressions';
import { buildExpressionFunction } from '../../../../expressions/public';
import { VisualizationState } from '../../application/utils/state_management';
import { getAggService, getIndexPatterns } from '../../plugin_services';
export const getAggExpressionFunctions = async (visualization: VisualizationState) => {
const { activeVisualization, indexPattern: indexId = '' } = visualization;
const { aggConfigParams } = activeVisualization || {};
const indexPatternsService = getIndexPatterns();
const indexPattern = await indexPatternsService.get(indexId);
const aggConfigs = getAggService().createAggConfigs(indexPattern, cloneDeep(aggConfigParams));
const opensearchDashboards = buildExpressionFunction<ExpressionFunctionOpenSearchDashboards>(
'opensearchDashboards',
{}
);
// soon this becomes: const opensearchaggs = vis.data.aggs!.toExpressionAst();
const opensearchaggs = buildExpressionFunction<OpenSearchaggsExpressionFunctionDefinition>(
'opensearchaggs',
{
index: indexId,
metricsAtAllLevels: false,
partialRows: false,
aggConfigs: JSON.stringify(aggConfigs.aggs),
includeFormatHints: false,
}
);
return {
aggConfigs,
expressionFns: [opensearchDashboards, opensearchaggs],
};
};