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] Hides advanced json for count metric (#74636) #76266

Merged
merged 1 commit into from
Aug 31, 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
11 changes: 11 additions & 0 deletions src/plugins/data/common/search/aggs/agg_type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ describe('AggType Class', () => {
expect(aggType.params[1].name).toBe('customLabel');
});

test('disables json param', () => {
const aggType = new AggType({
name: 'name',
title: 'title',
json: false,
});

expect(aggType.params.length).toBe(1);
expect(aggType.params[0].name).toBe('customLabel');
});

test('can disable customLabel', () => {
const aggType = new AggType({
name: 'smart agg',
Expand Down
17 changes: 11 additions & 6 deletions src/plugins/data/common/search/aggs/agg_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface AggTypeConfig<
getRequestAggs?: ((aggConfig: TAggConfig) => TAggConfig[]) | (() => TAggConfig[] | void);
getResponseAggs?: ((aggConfig: TAggConfig) => TAggConfig[]) | (() => TAggConfig[] | void);
customLabels?: boolean;
json?: boolean;
decorateAggConfig?: () => any;
postFlightRequest?: (
resp: any,
Expand Down Expand Up @@ -235,13 +236,17 @@ export class AggType<
if (config.params && config.params.length && config.params[0] instanceof BaseParamType) {
this.params = config.params as TParam[];
} else {
// always append the raw JSON param
// always append the raw JSON param unless it is configured to false
const params: any[] = config.params ? [...config.params] : [];
params.push({
name: 'json',
type: 'json',
advanced: true,
});

if (config.json !== false) {
params.push({
name: 'json',
type: 'json',
advanced: true,
});
}

// always append custom label

if (config.customLabels !== false) {
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/common/search/aggs/metrics/count.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const getCountMetricAgg = () =>
defaultMessage: 'Count',
}),
hasNoDsl: true,
json: false,
makeLabel() {
return i18n.translate('data.search.aggs.metrics.countLabel', {
defaultMessage: 'Count',
Expand Down
14 changes: 0 additions & 14 deletions src/plugins/data/common/search/aggs/metrics/count_fn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,12 @@ describe('agg_expression_functions', () => {
"id": undefined,
"params": Object {
"customLabel": undefined,
"json": undefined,
},
"schema": undefined,
"type": "count",
},
}
`);
});

test('correctly parses json string argument', () => {
const actual = fn({
json: '{ "foo": true }',
});

expect(actual.value.params.json).toEqual({ foo: true });
expect(() => {
fn({
json: '/// intentionally malformed json ///',
});
}).toThrowErrorMatchingInlineSnapshot(`"Unable to parse json argument string"`);
});
});
});
12 changes: 1 addition & 11 deletions src/plugins/data/common/search/aggs/metrics/count_fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import { i18n } from '@kbn/i18n';
import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionType, AggExpressionFunctionArgs, METRIC_TYPES } from '../';
import { getParsedValue } from '../utils/get_parsed_value';

const fnName = 'aggCount';

Expand Down Expand Up @@ -55,12 +54,6 @@ export const aggCount = (): FunctionDefinition => ({
defaultMessage: 'Schema to use for this aggregation',
}),
},
json: {
types: ['string'],
help: i18n.translate('data.search.aggs.metrics.count.json.help', {
defaultMessage: 'Advanced json to include when the agg is sent to Elasticsearch',
}),
},
customLabel: {
types: ['string'],
help: i18n.translate('data.search.aggs.metrics.count.customLabel.help', {
Expand All @@ -78,10 +71,7 @@ export const aggCount = (): FunctionDefinition => ({
enabled,
schema,
type: METRIC_TYPES.COUNT,
params: {
...rest,
json: getParsedValue(args, 'json'),
},
params: rest,
},
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
IAggType,
IndexPattern,
IndexPatternField,
} from 'src/plugins/data/public';
} from '../../../data/public';
import { filterAggTypes, filterAggTypeFields } from '../agg_filters';
import { groupAndSortBy, ComboBoxGroupedOptions } from '../utils';
import { AggTypeState, AggParamsState } from './agg_params_state';
Expand Down
5 changes: 5 additions & 0 deletions test/functional/apps/visualize/_point_series_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default function ({ getService, getPageObjects }) {
const retry = getService('retry');
const kibanaServer = getService('kibanaServer');
const browser = getService('browser');
const testSubjects = getService('testSubjects');
const PageObjects = getPageObjects([
'visualize',
'header',
Expand Down Expand Up @@ -148,6 +149,10 @@ export default function ({ getService, getPageObjects }) {
});
});

it('should not show advanced json for count agg', async function () {
await testSubjects.missingOrFail('advancedParams-1');
});

it('should put secondary axis on the right', async function () {
const length = await PageObjects.visChart.getRightValueAxes();
expect(length).to.be(1);
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,6 @@
"data.search.aggs.metrics.count.customLabel.help": "このアグリゲーションのカスタムラベルを表します",
"data.search.aggs.metrics.count.enabled.help": "このアグリゲーションが有効かどうかを指定します",
"data.search.aggs.metrics.count.id.help": "このアグリゲーションのID",
"data.search.aggs.metrics.count.json.help": "アグリゲーションがElasticsearchに送信されるときに含める高度なJSON",
"data.search.aggs.metrics.count.schema.help": "このアグリゲーションで使用するスキーマ",
"data.search.aggs.metrics.countLabel": "カウント",
"data.search.aggs.metrics.countTitle": "カウント",
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,6 @@
"data.search.aggs.metrics.count.customLabel.help": "表示此聚合的定制标签",
"data.search.aggs.metrics.count.enabled.help": "指定是否启用此聚合",
"data.search.aggs.metrics.count.id.help": "此聚合的 ID",
"data.search.aggs.metrics.count.json.help": "聚合发送至 Elasticsearch 时要包括的高级 json",
"data.search.aggs.metrics.count.schema.help": "要用于此聚合的方案",
"data.search.aggs.metrics.countLabel": "计数",
"data.search.aggs.metrics.countTitle": "计数",
Expand Down