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

View file

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

View file

@ -13,6 +13,7 @@ import { KibanaFilter } from './kibana_context_type';
interface Arguments {
query: string;
negate?: boolean;
disabled?: boolean;
}
export type ExpressionFunctionKibanaFilter = ExpressionFunctionDefinition<
@ -45,6 +46,13 @@ export const kibanaFilterFunction: ExpressionFunctionKibanaFilter = {
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) {
@ -53,7 +61,7 @@ export const kibanaFilterFunction: ExpressionFunctionKibanaFilter = {
meta: {
negate: args.negate || false,
alias: '',
disabled: false,
disabled: args.disabled || false,
},
...JSON.parse(args.query),
};