Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RAM] Allow wildcard search on rule's name and tags (#136312)
* bring wildcard search for rules page * [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix' * convert test + add few * fix unit test * to minimyze bundle * miss an import to be specific * remove kbn query to avoid bundle size to grow * metrics II * fix import Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
48b3894
commit d85438f
Showing
20 changed files
with
710 additions
and
151 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
x-pack/plugins/alerting/server/rules_client/lib/build_kuery_node_filter.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { fromKueryExpression } from '@kbn/es-query'; | ||
import { buildKueryNodeFilter } from './build_kuery_node_filter'; | ||
|
||
describe('buildKueryNodeFilter', () => { | ||
test('should convert KQL string into Kuery', () => { | ||
expect(buildKueryNodeFilter('foo: "bar"')).toEqual({ | ||
arguments: [ | ||
{ type: 'literal', value: 'foo' }, | ||
{ type: 'literal', value: 'bar' }, | ||
{ type: 'literal', value: true }, | ||
], | ||
function: 'is', | ||
type: 'function', | ||
}); | ||
}); | ||
|
||
test('should NOT do anything if filter is KueryNode', () => { | ||
expect(buildKueryNodeFilter(fromKueryExpression('foo: "bar"'))).toEqual( | ||
fromKueryExpression('foo: "bar"') | ||
); | ||
}); | ||
|
||
test('should return null if filter is not defined', () => { | ||
expect(buildKueryNodeFilter()).toEqual(null); | ||
}); | ||
|
||
test('should return null if filter is null', () => { | ||
expect(buildKueryNodeFilter(null)).toEqual(null); | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
x-pack/plugins/alerting/server/rules_client/lib/build_kuery_node_filter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { fromKueryExpression, KueryNode } from '@kbn/es-query'; | ||
|
||
export const buildKueryNodeFilter = (filter?: string | KueryNode | null): KueryNode | null => { | ||
let optionsFilter: KueryNode | string | null = filter ?? null; | ||
try { | ||
if (optionsFilter != null && typeof optionsFilter === 'string') { | ||
// FUTURE ENGINEER -> if I can parse it that mean it is a KueryNode or it is a string | ||
optionsFilter = JSON.parse(optionsFilter); | ||
} | ||
} catch (e) { | ||
optionsFilter = filter ?? null; | ||
} | ||
return optionsFilter | ||
? typeof optionsFilter === 'string' | ||
? fromKueryExpression(optionsFilter) | ||
: optionsFilter | ||
: null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.