[Security Solution][Detection Rules] Fixes rule table sort not working for certain fields (#103960)
This commit is contained in:
parent
e72f82db24
commit
cf4a28dab7
|
@ -215,6 +215,32 @@ describe('Detections Rules API', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('check parameter url, passed sort field is snake case', async () => {
|
||||
await fetchRules({
|
||||
filterOptions: {
|
||||
filter: '',
|
||||
sortField: 'updated_at',
|
||||
sortOrder: 'desc',
|
||||
showCustomRules: false,
|
||||
showElasticRules: false,
|
||||
tags: ['hello', 'world'],
|
||||
},
|
||||
signal: abortCtrl.signal,
|
||||
});
|
||||
|
||||
expect(fetchMock).toHaveBeenCalledWith('/api/detection_engine/rules/_find', {
|
||||
method: 'GET',
|
||||
query: {
|
||||
filter: 'alert.attributes.tags: "hello" AND alert.attributes.tags: "world"',
|
||||
page: 1,
|
||||
per_page: 20,
|
||||
sort_field: 'updatedAt',
|
||||
sort_order: 'desc',
|
||||
},
|
||||
signal: abortCtrl.signal,
|
||||
});
|
||||
});
|
||||
|
||||
test('query with tags KQL parses without errors when tags contain characters such as left parenthesis (', async () => {
|
||||
await fetchRules({
|
||||
filterOptions: {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { camelCase } from 'lodash';
|
||||
import { FullResponseSchema } from '../../../../../common/detection_engine/schemas/request';
|
||||
import { HttpStart } from '../../../../../../../../src/core/public';
|
||||
import {
|
||||
|
@ -117,8 +118,9 @@ export const fetchRules = async ({
|
|||
}: FetchRulesProps): Promise<FetchRulesResponse> => {
|
||||
const filterString = convertRulesFilterToKQL(filterOptions);
|
||||
|
||||
// Sort field is camel cased because we use that in our mapping, but display snake case on the front end
|
||||
const getFieldNameForSortField = (field: string) => {
|
||||
return field === 'name' ? `${field}.keyword` : field;
|
||||
return field === 'name' ? `${field}.keyword` : camelCase(field);
|
||||
};
|
||||
|
||||
const query = {
|
||||
|
|
Loading…
Reference in a new issue