Skip to content

Commit 9ddd49a

Browse files
Hides advanced json for count metric (#74636)
* remove advanced json for count agg * Remove only advanced json from count agg * use Constant from data plugin * add the logic to data plugin * remove json arg from function definition * remove unecessary translations Co-authored-by: Elastic Machine <[email protected]>
1 parent 5f781dc commit 9ddd49a

File tree

9 files changed

+30
-34
lines changed

9 files changed

+30
-34
lines changed

src/plugins/data/common/search/aggs/agg_type.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,17 @@ describe('AggType Class', () => {
9999
expect(aggType.params[1].name).toBe('customLabel');
100100
});
101101

102+
test('disables json param', () => {
103+
const aggType = new AggType({
104+
name: 'name',
105+
title: 'title',
106+
json: false,
107+
});
108+
109+
expect(aggType.params.length).toBe(1);
110+
expect(aggType.params[0].name).toBe('customLabel');
111+
});
112+
102113
test('can disable customLabel', () => {
103114
const aggType = new AggType({
104115
name: 'smart agg',

src/plugins/data/common/search/aggs/agg_type.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export interface AggTypeConfig<
4747
getRequestAggs?: ((aggConfig: TAggConfig) => TAggConfig[]) | (() => TAggConfig[] | void);
4848
getResponseAggs?: ((aggConfig: TAggConfig) => TAggConfig[]) | (() => TAggConfig[] | void);
4949
customLabels?: boolean;
50+
json?: boolean;
5051
decorateAggConfig?: () => any;
5152
postFlightRequest?: (
5253
resp: any,
@@ -235,13 +236,17 @@ export class AggType<
235236
if (config.params && config.params.length && config.params[0] instanceof BaseParamType) {
236237
this.params = config.params as TParam[];
237238
} else {
238-
// always append the raw JSON param
239+
// always append the raw JSON param unless it is configured to false
239240
const params: any[] = config.params ? [...config.params] : [];
240-
params.push({
241-
name: 'json',
242-
type: 'json',
243-
advanced: true,
244-
});
241+
242+
if (config.json !== false) {
243+
params.push({
244+
name: 'json',
245+
type: 'json',
246+
advanced: true,
247+
});
248+
}
249+
245250
// always append custom label
246251

247252
if (config.customLabels !== false) {

src/plugins/data/common/search/aggs/metrics/count.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const getCountMetricAgg = () =>
2828
defaultMessage: 'Count',
2929
}),
3030
hasNoDsl: true,
31+
json: false,
3132
makeLabel() {
3233
return i18n.translate('data.search.aggs.metrics.countLabel', {
3334
defaultMessage: 'Count',

src/plugins/data/common/search/aggs/metrics/count_fn.test.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,12 @@ describe('agg_expression_functions', () => {
3434
"id": undefined,
3535
"params": Object {
3636
"customLabel": undefined,
37-
"json": undefined,
3837
},
3938
"schema": undefined,
4039
"type": "count",
4140
},
4241
}
4342
`);
4443
});
45-
46-
test('correctly parses json string argument', () => {
47-
const actual = fn({
48-
json: '{ "foo": true }',
49-
});
50-
51-
expect(actual.value.params.json).toEqual({ foo: true });
52-
expect(() => {
53-
fn({
54-
json: '/// intentionally malformed json ///',
55-
});
56-
}).toThrowErrorMatchingInlineSnapshot(`"Unable to parse json argument string"`);
57-
});
5844
});
5945
});

src/plugins/data/common/search/aggs/metrics/count_fn.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import { i18n } from '@kbn/i18n';
2121
import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
2222
import { AggExpressionType, AggExpressionFunctionArgs, METRIC_TYPES } from '../';
23-
import { getParsedValue } from '../utils/get_parsed_value';
2423

2524
const fnName = 'aggCount';
2625

@@ -55,12 +54,6 @@ export const aggCount = (): FunctionDefinition => ({
5554
defaultMessage: 'Schema to use for this aggregation',
5655
}),
5756
},
58-
json: {
59-
types: ['string'],
60-
help: i18n.translate('data.search.aggs.metrics.count.json.help', {
61-
defaultMessage: 'Advanced json to include when the agg is sent to Elasticsearch',
62-
}),
63-
},
6457
customLabel: {
6558
types: ['string'],
6659
help: i18n.translate('data.search.aggs.metrics.count.customLabel.help', {
@@ -78,10 +71,7 @@ export const aggCount = (): FunctionDefinition => ({
7871
enabled,
7972
schema,
8073
type: METRIC_TYPES.COUNT,
81-
params: {
82-
...rest,
83-
json: getParsedValue(args, 'json'),
84-
},
74+
params: rest,
8575
},
8676
};
8777
},

src/plugins/vis_default_editor/public/components/agg_params_helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
IAggType,
2727
IndexPattern,
2828
IndexPatternField,
29-
} from 'src/plugins/data/public';
29+
} from '../../../data/public';
3030
import { filterAggTypes, filterAggTypeFields } from '../agg_filters';
3131
import { groupAndSortBy, ComboBoxGroupedOptions } from '../utils';
3232
import { AggTypeState, AggParamsState } from './agg_params_state';

test/functional/apps/visualize/_point_series_options.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export default function ({ getService, getPageObjects }) {
2424
const retry = getService('retry');
2525
const kibanaServer = getService('kibanaServer');
2626
const browser = getService('browser');
27+
const testSubjects = getService('testSubjects');
2728
const PageObjects = getPageObjects([
2829
'visualize',
2930
'header',
@@ -148,6 +149,10 @@ export default function ({ getService, getPageObjects }) {
148149
});
149150
});
150151

152+
it('should not show advanced json for count agg', async function () {
153+
await testSubjects.missingOrFail('advancedParams-1');
154+
});
155+
151156
it('should put secondary axis on the right', async function () {
152157
const length = await PageObjects.visChart.getRightValueAxes();
153158
expect(length).to.be(1);

x-pack/plugins/translations/translations/ja-JP.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,6 @@
11151115
"data.search.aggs.metrics.count.customLabel.help": "このアグリゲーションのカスタムラベルを表します",
11161116
"data.search.aggs.metrics.count.enabled.help": "このアグリゲーションが有効かどうかを指定します",
11171117
"data.search.aggs.metrics.count.id.help": "このアグリゲーションのID",
1118-
"data.search.aggs.metrics.count.json.help": "アグリゲーションがElasticsearchに送信されるときに含める高度なJSON",
11191118
"data.search.aggs.metrics.count.schema.help": "このアグリゲーションで使用するスキーマ",
11201119
"data.search.aggs.metrics.countLabel": "カウント",
11211120
"data.search.aggs.metrics.countTitle": "カウント",

x-pack/plugins/translations/translations/zh-CN.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,6 @@
11161116
"data.search.aggs.metrics.count.customLabel.help": "表示此聚合的定制标签",
11171117
"data.search.aggs.metrics.count.enabled.help": "指定是否启用此聚合",
11181118
"data.search.aggs.metrics.count.id.help": "此聚合的 ID",
1119-
"data.search.aggs.metrics.count.json.help": "聚合发送至 Elasticsearch 时要包括的高级 json",
11201119
"data.search.aggs.metrics.count.schema.help": "要用于此聚合的方案",
11211120
"data.search.aggs.metrics.countLabel": "计数",
11221121
"data.search.aggs.metrics.countTitle": "计数",

0 commit comments

Comments
 (0)