[Dashboard]: Fixes disabled viz filter is applied (#101859)

* Fixes filter is applied even if is disabled on a dashboard

* Fix 18n problem

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Stratoula Kalafateli 2021-06-14 13:04:04 +03:00 committed by GitHub
parent 80b109f95c
commit 06aaa529d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 1 deletions

View file

@ -24,6 +24,9 @@ describe('interpreter/functions#filtersToAst', () => {
expect(actual[0].functions[0]).toHaveProperty('name', 'kibanaFilter'); expect(actual[0].functions[0]).toHaveProperty('name', 'kibanaFilter');
expect(actual[0].functions[0].arguments).toMatchInlineSnapshot(` expect(actual[0].functions[0].arguments).toMatchInlineSnapshot(`
Object { Object {
"disabled": Array [
false,
],
"negate": Array [ "negate": Array [
false, false,
], ],
@ -35,6 +38,9 @@ describe('interpreter/functions#filtersToAst', () => {
expect(actual[1].functions[0]).toHaveProperty('name', 'kibanaFilter'); expect(actual[1].functions[0]).toHaveProperty('name', 'kibanaFilter');
expect(actual[1].functions[0].arguments).toMatchInlineSnapshot(` expect(actual[1].functions[0].arguments).toMatchInlineSnapshot(`
Object { Object {
"disabled": Array [
false,
],
"negate": Array [ "negate": Array [
true, true,
], ],

View file

@ -17,6 +17,7 @@ export const filtersToAst = (filters: Filter[] | Filter) => {
buildExpressionFunction<ExpressionFunctionKibanaFilter>('kibanaFilter', { buildExpressionFunction<ExpressionFunctionKibanaFilter>('kibanaFilter', {
query: JSON.stringify(restOfFilter), query: JSON.stringify(restOfFilter),
negate: filter.meta.negate, negate: filter.meta.negate,
disabled: filter.meta.disabled,
}), }),
]); ]);
}); });

View file

@ -13,6 +13,7 @@ import { KibanaFilter } from './kibana_context_type';
interface Arguments { interface Arguments {
query: string; query: string;
negate?: boolean; negate?: boolean;
disabled?: boolean;
} }
export type ExpressionFunctionKibanaFilter = ExpressionFunctionDefinition< export type ExpressionFunctionKibanaFilter = ExpressionFunctionDefinition<
@ -45,6 +46,13 @@ export const kibanaFilterFunction: ExpressionFunctionKibanaFilter = {
defaultMessage: 'Should the filter be negated', defaultMessage: 'Should the filter be negated',
}), }),
}, },
disabled: {
types: ['boolean'],
default: false,
help: i18n.translate('data.search.functions.kibanaFilter.disabled.help', {
defaultMessage: 'Should the filter be disabled',
}),
},
}, },
fn(input, args) { fn(input, args) {
@ -53,7 +61,7 @@ export const kibanaFilterFunction: ExpressionFunctionKibanaFilter = {
meta: { meta: {
negate: args.negate || false, negate: args.negate || false,
alias: '', alias: '',
disabled: false, disabled: args.disabled || false,
}, },
...JSON.parse(args.query), ...JSON.parse(args.query),
}; };