From 57018ae5de0ef9b836ab9371770b4ca0355df472 Mon Sep 17 00:00:00 2001 From: Xavier Mouligneau Date: Mon, 18 Jul 2022 10:16:25 -0400 Subject: [PATCH] to minimyze bundle --- .../hooks/use_load_rule_aggregations.test.ts | 12 +- .../hooks/use_load_rule_aggregations.ts | 4 +- .../application/hooks/use_load_rules.test.ts | 20 +-- .../application/hooks/use_load_rules.ts | 4 +- .../application/lib/rule_api/aggregate.ts | 58 ++------- .../lib/rule_api/aggregate_helpers.ts | 46 +++++++ .../lib/rule_api/aggregate_kuery_filter.ts | 41 ++++++ .../public/application/lib/rule_api/index.ts | 6 +- .../lib/rule_api/map_filters_to_kql.test.ts | 120 ++++++++++++++++- .../lib/rule_api/map_filters_to_kql.ts | 64 +++++++++ .../public/application/lib/rule_api/rules.ts | 35 ++--- .../application/lib/rule_api/rules_helpers.ts | 27 ++++ .../lib/rule_api/rules_kuery_filter.ts | 61 +++++++++ .../rules_list/components/rules_list.test.tsx | 123 +++++++++--------- 14 files changed, 470 insertions(+), 151 deletions(-) create mode 100644 x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/aggregate_helpers.ts create mode 100644 x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/aggregate_kuery_filter.ts create mode 100644 x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/rules_helpers.ts create mode 100644 x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/rules_kuery_filter.ts diff --git a/x-pack/plugins/triggers_actions_ui/public/application/hooks/use_load_rule_aggregations.test.ts b/x-pack/plugins/triggers_actions_ui/public/application/hooks/use_load_rule_aggregations.test.ts index b00101da6be830..d08a33201593a0 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/hooks/use_load_rule_aggregations.test.ts +++ b/x-pack/plugins/triggers_actions_ui/public/application/hooks/use_load_rule_aggregations.test.ts @@ -19,16 +19,16 @@ const MOCK_AGGS = { }; jest.mock('../lib/rule_api', () => ({ - loadRuleAggregations: jest.fn(), + loadRuleAggregationsWithKueryFilter: jest.fn(), })); -const { loadRuleAggregations } = jest.requireMock('../lib/rule_api'); +const { loadRuleAggregationsWithKueryFilter } = jest.requireMock('../lib/rule_api'); const onError = jest.fn(); describe('useLoadRuleAggregations', () => { beforeEach(() => { - loadRuleAggregations.mockResolvedValue(MOCK_AGGS); + loadRuleAggregationsWithKueryFilter.mockResolvedValue(MOCK_AGGS); jest.clearAllMocks(); }); @@ -54,7 +54,7 @@ describe('useLoadRuleAggregations', () => { await waitForNextUpdate(); }); - expect(loadRuleAggregations).toBeCalledWith(expect.objectContaining(params)); + expect(loadRuleAggregationsWithKueryFilter).toBeCalledWith(expect.objectContaining(params)); expect(result.current.rulesStatusesTotal).toEqual(MOCK_AGGS.ruleExecutionStatus); }); @@ -80,12 +80,12 @@ describe('useLoadRuleAggregations', () => { await waitForNextUpdate(); }); - expect(loadRuleAggregations).toBeCalledWith(expect.objectContaining(params)); + expect(loadRuleAggregationsWithKueryFilter).toBeCalledWith(expect.objectContaining(params)); expect(result.current.rulesStatusesTotal).toEqual(MOCK_AGGS.ruleExecutionStatus); }); it('should call onError if API fails', async () => { - loadRuleAggregations.mockRejectedValue(''); + loadRuleAggregationsWithKueryFilter.mockRejectedValue(''); const params = { searchText: '', typesFilter: [], diff --git a/x-pack/plugins/triggers_actions_ui/public/application/hooks/use_load_rule_aggregations.ts b/x-pack/plugins/triggers_actions_ui/public/application/hooks/use_load_rule_aggregations.ts index 75f9e18ec2328c..89a346b2efdfbd 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/hooks/use_load_rule_aggregations.ts +++ b/x-pack/plugins/triggers_actions_ui/public/application/hooks/use_load_rule_aggregations.ts @@ -8,7 +8,7 @@ import { i18n } from '@kbn/i18n'; import { useState, useCallback, useMemo } from 'react'; import { RuleExecutionStatusValues } from '@kbn/alerting-plugin/common'; -import { loadRuleAggregations, LoadRuleAggregationsProps } from '../lib/rule_api'; +import { loadRuleAggregationsWithKueryFilter, LoadRuleAggregationsProps } from '../lib/rule_api'; import { useKibana } from '../../common/lib/kibana'; type UseLoadRuleAggregationsProps = Omit & { @@ -38,7 +38,7 @@ export function useLoadRuleAggregations({ const internalLoadRuleAggregations = useCallback(async () => { try { - const rulesAggs = await loadRuleAggregations({ + const rulesAggs = await loadRuleAggregationsWithKueryFilter({ http, searchText, typesFilter, diff --git a/x-pack/plugins/triggers_actions_ui/public/application/hooks/use_load_rules.test.ts b/x-pack/plugins/triggers_actions_ui/public/application/hooks/use_load_rules.test.ts index d69f4b508dcf57..62b7d37d91860e 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/hooks/use_load_rules.test.ts +++ b/x-pack/plugins/triggers_actions_ui/public/application/hooks/use_load_rules.test.ts @@ -14,10 +14,10 @@ import { import { RuleStatus } from '../../types'; jest.mock('../lib/rule_api', () => ({ - loadRules: jest.fn(), + loadRulesWithKueryFilter: jest.fn(), })); -const { loadRules } = jest.requireMock('../lib/rule_api'); +const { loadRulesWithKueryFilter } = jest.requireMock('../lib/rule_api'); const onError = jest.fn(); const onPage = jest.fn(); @@ -233,7 +233,7 @@ const MOCK_RULE_DATA = { describe('useLoadRules', () => { beforeEach(() => { - loadRules.mockResolvedValue(MOCK_RULE_DATA); + loadRulesWithKueryFilter.mockResolvedValue(MOCK_RULE_DATA); jest.clearAllMocks(); }); @@ -273,7 +273,7 @@ describe('useLoadRules', () => { expect(result.current.rulesState.isLoading).toBeFalsy(); expect(onPage).toBeCalledTimes(0); - expect(loadRules).toBeCalledWith(expect.objectContaining(params)); + expect(loadRulesWithKueryFilter).toBeCalledWith(expect.objectContaining(params)); expect(result.current.rulesState.data).toEqual(expect.arrayContaining(MOCK_RULE_DATA.data)); expect(result.current.rulesState.totalItemCount).toEqual(MOCK_RULE_DATA.total); }); @@ -305,11 +305,11 @@ describe('useLoadRules', () => { await waitForNextUpdate(); }); - expect(loadRules).toBeCalledWith(expect.objectContaining(params)); + expect(loadRulesWithKueryFilter).toBeCalledWith(expect.objectContaining(params)); }); it('should reset the page if the data is fetched while paged', async () => { - loadRules.mockResolvedValue({ + loadRulesWithKueryFilter.mockResolvedValue({ ...MOCK_RULE_DATA, data: [], }); @@ -347,7 +347,7 @@ describe('useLoadRules', () => { }); it('should call onError if API fails', async () => { - loadRules.mockRejectedValue(''); + loadRulesWithKueryFilter.mockRejectedValue(''); const params = { page: { index: 0, @@ -378,7 +378,7 @@ describe('useLoadRules', () => { describe('No data', () => { it('noData should be true, if there is no Filter and no rules', async () => { - loadRules.mockResolvedValue({ ...MOCK_RULE_DATA, data: [] }); + loadRulesWithKueryFilter.mockResolvedValue({ ...MOCK_RULE_DATA, data: [] }); const params = { page: { index: 0, @@ -411,7 +411,7 @@ describe('useLoadRules', () => { }); it('noData should be false, if there is rule types filter and no rules', async () => { - loadRules.mockResolvedValue({ ...MOCK_RULE_DATA, data: [] }); + loadRulesWithKueryFilter.mockResolvedValue({ ...MOCK_RULE_DATA, data: [] }); const params = { page: { index: 0, @@ -444,7 +444,7 @@ describe('useLoadRules', () => { }); it('noData should be true, if there is rule types filter and no rules with hasDefaultRuleTypesFiltersOn = true', async () => { - loadRules.mockResolvedValue({ ...MOCK_RULE_DATA, data: [] }); + loadRulesWithKueryFilter.mockResolvedValue({ ...MOCK_RULE_DATA, data: [] }); const params = { page: { index: 0, diff --git a/x-pack/plugins/triggers_actions_ui/public/application/hooks/use_load_rules.ts b/x-pack/plugins/triggers_actions_ui/public/application/hooks/use_load_rules.ts index 33cee4f2ffa886..f09a14abfc0bcc 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/hooks/use_load_rules.ts +++ b/x-pack/plugins/triggers_actions_ui/public/application/hooks/use_load_rules.ts @@ -8,7 +8,7 @@ import { useMemo, useCallback, useReducer } from 'react'; import { i18n } from '@kbn/i18n'; import { isEmpty } from 'lodash'; import { Rule, Pagination } from '../../types'; -import { loadRules, LoadRulesProps } from '../lib/rule_api'; +import { loadRulesWithKueryFilter, LoadRulesProps } from '../lib/rule_api'; import { useKibana } from '../../common/lib/kibana'; interface RuleState { @@ -112,7 +112,7 @@ export function useLoadRules({ dispatch({ type: ActionTypes.SET_LOADING, payload: true }); try { - const rulesResponse = await loadRules({ + const rulesResponse = await loadRulesWithKueryFilter({ http, page, searchText, diff --git a/x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/aggregate.ts b/x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/aggregate.ts index f2d0e5adad2a40..980571b920036c 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/aggregate.ts +++ b/x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/aggregate.ts @@ -5,36 +5,16 @@ * 2.0. */ import { HttpSetup } from '@kbn/core/public'; -import { AsApiContract, RewriteRequestCase } from '@kbn/actions-plugin/common'; -import { RuleAggregations, RuleStatus } from '../../../types'; +import { AsApiContract } from '@kbn/actions-plugin/common'; +import { RuleAggregations } from '../../../types'; import { INTERNAL_BASE_ALERTING_API_PATH } from '../../constants'; -import { mapFilterToKueryNode } from './map_filters_to_kql'; - -export interface RuleTagsAggregations { - ruleTags: string[]; -} - -const rewriteBodyRes: RewriteRequestCase = ({ - rule_execution_status: ruleExecutionStatus, - rule_enabled_status: ruleEnabledStatus, - rule_muted_status: ruleMutedStatus, - rule_snoozed_status: ruleSnoozedStatus, - rule_tags: ruleTags, - ...rest -}: any) => ({ - ...rest, - ruleExecutionStatus, - ruleEnabledStatus, - ruleMutedStatus, - ruleSnoozedStatus, - ruleTags, -}); - -const rewriteTagsBodyRes: RewriteRequestCase = ({ - rule_tags: ruleTags, -}: any) => ({ - ruleTags, -}); +import { mapFiltersToKql } from './map_filters_to_kql'; +import { + LoadRuleAggregationsProps, + rewriteBodyRes, + rewriteTagsBodyRes, + RuleTagsAggregations, +} from './aggregate_helpers'; // TODO: https://github.com/elastic/kibana/issues/131682 export async function loadRuleTags({ http }: { http: HttpSetup }): Promise { @@ -44,16 +24,6 @@ export async function loadRuleTags({ http }: { http: HttpSetup }): Promise { - const filtersKueryNode = mapFilterToKueryNode({ + const filters = mapFiltersToKql({ typesFilter, actionTypesFilter, - tagsFilter, ruleExecutionStatusesFilter, ruleStatusesFilter, - searchText, + tagsFilter, }); - const res = await http.get>( `${INTERNAL_BASE_ALERTING_API_PATH}/rules/_aggregate`, { query: { - ...(filtersKueryNode ? { filter: JSON.stringify(filtersKueryNode) } : {}), + search_fields: searchText ? JSON.stringify(['name', 'tags']) : undefined, + search: searchText, + filter: filters.length ? filters.join(' and ') : undefined, default_search_operator: 'AND', }, } diff --git a/x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/aggregate_helpers.ts b/x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/aggregate_helpers.ts new file mode 100644 index 00000000000000..7f63fcbaa30495 --- /dev/null +++ b/x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/aggregate_helpers.ts @@ -0,0 +1,46 @@ +/* + * 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 { HttpSetup } from '@kbn/core/public'; +import { RewriteRequestCase } from '@kbn/actions-plugin/common'; +import { RuleAggregations, RuleStatus } from '../../../types'; + +export interface RuleTagsAggregations { + ruleTags: string[]; +} + +export const rewriteBodyRes: RewriteRequestCase = ({ + rule_execution_status: ruleExecutionStatus, + rule_enabled_status: ruleEnabledStatus, + rule_muted_status: ruleMutedStatus, + rule_snoozed_status: ruleSnoozedStatus, + rule_tags: ruleTags, + ...rest +}: any) => ({ + ...rest, + ruleExecutionStatus, + ruleEnabledStatus, + ruleMutedStatus, + ruleSnoozedStatus, + ruleTags, +}); + +export const rewriteTagsBodyRes: RewriteRequestCase = ({ + rule_tags: ruleTags, +}: any) => ({ + ruleTags, +}); + +export interface LoadRuleAggregationsProps { + http: HttpSetup; + searchText?: string; + typesFilter?: string[]; + actionTypesFilter?: string[]; + ruleExecutionStatusesFilter?: string[]; + ruleStatusesFilter?: RuleStatus[]; + tagsFilter?: string[]; +} diff --git a/x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/aggregate_kuery_filter.ts b/x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/aggregate_kuery_filter.ts new file mode 100644 index 00000000000000..3a3ecbcebef574 --- /dev/null +++ b/x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/aggregate_kuery_filter.ts @@ -0,0 +1,41 @@ +/* + * 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 { AsApiContract } from '@kbn/actions-plugin/common'; +import { RuleAggregations } from '../../../types'; +import { INTERNAL_BASE_ALERTING_API_PATH } from '../../constants'; +import { LoadRuleAggregationsProps, rewriteBodyRes } from './aggregate_helpers'; +import { mapFilterToKueryNode } from './map_filters_to_kql'; + +export async function loadRuleAggregationsWithKueryFilter({ + http, + searchText, + typesFilter, + actionTypesFilter, + ruleExecutionStatusesFilter, + ruleStatusesFilter, + tagsFilter, +}: LoadRuleAggregationsProps): Promise { + const filtersKueryNode = mapFilterToKueryNode({ + typesFilter, + actionTypesFilter, + tagsFilter, + ruleExecutionStatusesFilter, + ruleStatusesFilter, + searchText, + }); + + const res = await http.get>( + `${INTERNAL_BASE_ALERTING_API_PATH}/rules/_aggregate`, + { + query: { + ...(filtersKueryNode ? { filter: JSON.stringify(filtersKueryNode) } : {}), + default_search_operator: 'AND', + }, + } + ); + return rewriteBodyRes(res); +} diff --git a/x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/index.ts b/x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/index.ts index ba7b10f6cfb6d8..5ea226c553abd6 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/index.ts +++ b/x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/index.ts @@ -7,8 +7,9 @@ export { alertingFrameworkHealth } from './health'; export { mapFilterToKueryNode } from './map_filters_to_kql'; -export type { LoadRuleAggregationsProps } from './aggregate'; +export type { LoadRuleAggregationsProps } from './aggregate_helpers'; export { loadRuleAggregations, loadRuleTags } from './aggregate'; +export { loadRuleAggregationsWithKueryFilter } from './aggregate_kuery_filter'; export { createRule } from './create'; export { deleteRules } from './delete'; export { disableRule, disableRules } from './disable'; @@ -18,8 +19,9 @@ export { loadRuleSummary } from './rule_summary'; export { muteAlertInstance } from './mute_alert'; export { muteRule, muteRules } from './mute'; export { loadRuleTypes } from './rule_types'; -export type { LoadRulesProps } from './rules'; +export type { LoadRulesProps } from './rules_helpers'; export { loadRules } from './rules'; +export { loadRulesWithKueryFilter } from './rules_kuery_filter'; export { loadRuleState } from './state'; export type { LoadExecutionLogAggregationsProps } from './load_execution_log_aggregations'; export { loadExecutionLogAggregations } from './load_execution_log_aggregations'; diff --git a/x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/map_filters_to_kql.test.ts b/x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/map_filters_to_kql.test.ts index a48a53a42b590b..e485a8854957c0 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/map_filters_to_kql.test.ts +++ b/x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/map_filters_to_kql.test.ts @@ -6,7 +6,7 @@ */ import { KueryNode, fromKueryExpression, toElasticsearchQuery } from '@kbn/es-query'; -import { mapFilterToKueryNode } from './map_filters_to_kql'; +import { mapFiltersToKql, mapFilterToKueryNode } from './map_filters_to_kql'; describe('mapFilterToKueryNode', () => { beforeEach(() => jest.resetAllMocks()); @@ -241,3 +241,121 @@ describe('mapFilterToKueryNode', () => { ); }); }); + +describe('mapFiltersToKql', () => { + beforeEach(() => jest.resetAllMocks()); + + test('should handle no filters', () => { + expect(mapFiltersToKql({})).toEqual([]); + }); + + test('should handle typesFilter', () => { + expect( + mapFiltersToKql({ + typesFilter: ['type', 'filter'], + }) + ).toEqual(['alert.attributes.alertTypeId:(type or filter)']); + }); + + test('should handle actionTypesFilter', () => { + expect( + mapFiltersToKql({ + actionTypesFilter: ['action', 'types', 'filter'], + }) + ).toEqual([ + '(alert.attributes.actions:{ actionTypeId:action } OR alert.attributes.actions:{ actionTypeId:types } OR alert.attributes.actions:{ actionTypeId:filter })', + ]); + }); + + test('should handle ruleExecutionStatusesFilter', () => { + expect( + mapFiltersToKql({ + ruleExecutionStatusesFilter: ['alert', 'statuses', 'filter'], + }) + ).toEqual(['alert.attributes.executionStatus.status:(alert or statuses or filter)']); + }); + + test('should handle ruleStatusesFilter', () => { + expect( + mapFiltersToKql({ + ruleStatusesFilter: ['enabled'], + }) + ).toEqual([ + '(alert.attributes.enabled: true AND NOT (alert.attributes.muteAll:true OR alert.attributes.isSnoozedUntil > now))', + ]); + + expect( + mapFiltersToKql({ + ruleStatusesFilter: ['disabled'], + }) + ).toEqual(['alert.attributes.enabled: false']); + + expect( + mapFiltersToKql({ + ruleStatusesFilter: ['snoozed'], + }) + ).toEqual([ + '((alert.attributes.muteAll:true OR alert.attributes.isSnoozedUntil > now) AND NOT alert.attributes.enabled: false)', + ]); + + expect( + mapFiltersToKql({ + ruleStatusesFilter: ['enabled', 'snoozed'], + }) + ).toEqual([ + '(alert.attributes.enabled: true AND NOT (alert.attributes.muteAll:true OR alert.attributes.isSnoozedUntil > now)) or ((alert.attributes.muteAll:true OR alert.attributes.isSnoozedUntil > now) AND NOT alert.attributes.enabled: false)', + ]); + + expect( + mapFiltersToKql({ + ruleStatusesFilter: ['disabled', 'snoozed'], + }) + ).toEqual([ + 'alert.attributes.enabled: false or ((alert.attributes.muteAll:true OR alert.attributes.isSnoozedUntil > now) AND NOT alert.attributes.enabled: false)', + ]); + + expect( + mapFiltersToKql({ + ruleStatusesFilter: ['enabled', 'disabled', 'snoozed'], + }) + ).toEqual([ + '(alert.attributes.enabled: true AND NOT (alert.attributes.muteAll:true OR alert.attributes.isSnoozedUntil > now)) or alert.attributes.enabled: false or ((alert.attributes.muteAll:true OR alert.attributes.isSnoozedUntil > now) AND NOT alert.attributes.enabled: false)', + ]); + }); + + test('should handle tagsFilter', () => { + expect( + mapFiltersToKql({ + tagsFilter: ['a', 'b', 'c'], + }) + ).toEqual(['alert.attributes.tags:(a or b or c)']); + }); + + test('should handle typesFilter and actionTypesFilter', () => { + expect( + mapFiltersToKql({ + typesFilter: ['type', 'filter'], + actionTypesFilter: ['action', 'types', 'filter'], + }) + ).toEqual([ + 'alert.attributes.alertTypeId:(type or filter)', + '(alert.attributes.actions:{ actionTypeId:action } OR alert.attributes.actions:{ actionTypeId:types } OR alert.attributes.actions:{ actionTypeId:filter })', + ]); + }); + + test('should handle typesFilter, actionTypesFilter, ruleExecutionStatusesFilter, and tagsFilter', () => { + expect( + mapFiltersToKql({ + typesFilter: ['type', 'filter'], + actionTypesFilter: ['action', 'types', 'filter'], + ruleExecutionStatusesFilter: ['alert', 'statuses', 'filter'], + tagsFilter: ['a', 'b', 'c'], + }) + ).toEqual([ + 'alert.attributes.alertTypeId:(type or filter)', + '(alert.attributes.actions:{ actionTypeId:action } OR alert.attributes.actions:{ actionTypeId:types } OR alert.attributes.actions:{ actionTypeId:filter })', + 'alert.attributes.executionStatus.status:(alert or statuses or filter)', + 'alert.attributes.tags:(a or b or c)', + ]); + }); +}); diff --git a/x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/map_filters_to_kql.ts b/x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/map_filters_to_kql.ts index 640223465f5990..61a1a0839dfa34 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/map_filters_to_kql.ts +++ b/x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/map_filters_to_kql.ts @@ -97,3 +97,67 @@ export const mapFilterToKueryNode = ({ return filterKueryNode.length ? nodeBuilder.and(filterKueryNode) : null; }; + +export const mapFiltersToKql = ({ + typesFilter, + actionTypesFilter, + ruleExecutionStatusesFilter, + ruleStatusesFilter, + tagsFilter, +}: { + typesFilter?: string[]; + actionTypesFilter?: string[]; + tagsFilter?: string[]; + ruleExecutionStatusesFilter?: string[]; + ruleStatusesFilter?: RuleStatus[]; +}): string[] => { + const filters = []; + + if (typesFilter && typesFilter.length) { + filters.push(`alert.attributes.alertTypeId:(${typesFilter.join(' or ')})`); + } + if (actionTypesFilter && actionTypesFilter.length) { + filters.push( + [ + '(', + actionTypesFilter + .map((id) => `alert.attributes.actions:{ actionTypeId:${id} }`) + .join(' OR '), + ')', + ].join('') + ); + } + if (ruleExecutionStatusesFilter && ruleExecutionStatusesFilter.length) { + filters.push( + `alert.attributes.executionStatus.status:(${ruleExecutionStatusesFilter.join(' or ')})` + ); + } + + if (ruleStatusesFilter && ruleStatusesFilter.length) { + const snoozedFilter = `(alert.attributes.muteAll:true OR alert.attributes.isSnoozedUntil > now)`; + const enabledFilter = `(alert.attributes.enabled: true AND NOT ${snoozedFilter})`; + const disabledFilter = `alert.attributes.enabled: false`; + + const result = []; + + if (ruleStatusesFilter.includes('enabled')) { + result.push(enabledFilter); + } + + if (ruleStatusesFilter.includes('disabled')) { + result.push(disabledFilter); + } + + if (ruleStatusesFilter.includes('snoozed')) { + result.push(`(${snoozedFilter} AND NOT ${disabledFilter})`); + } + + filters.push(result.join(' or ')); + } + + if (tagsFilter && tagsFilter.length) { + filters.push(`alert.attributes.tags:(${tagsFilter.join(' or ')})`); + } + + return filters; +}; diff --git a/x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/rules.ts b/x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/rules.ts index eea3291189f50e..07a992c66c96ce 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/rules.ts +++ b/x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/rules.ts @@ -4,28 +4,12 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import { HttpSetup } from '@kbn/core/public'; + import { AsApiContract } from '@kbn/actions-plugin/common'; import { INTERNAL_BASE_ALERTING_API_PATH } from '../../constants'; -import { Rule, Pagination, Sorting, RuleStatus } from '../../../types'; -import { mapFilterToKueryNode } from './map_filters_to_kql'; -import { transformRule } from './common_transformations'; - -export interface LoadRulesProps { - http: HttpSetup; - page: Pagination; - searchText?: string; - typesFilter?: string[]; - actionTypesFilter?: string[]; - tagsFilter?: string[]; - ruleExecutionStatusesFilter?: string[]; - ruleStatusesFilter?: RuleStatus[]; - sort?: Sorting; -} - -const rewriteResponseRes = (results: Array>): Rule[] => { - return results.map((item) => transformRule(item)); -}; +import { Rule } from '../../../types'; +import { mapFiltersToKql } from './map_filters_to_kql'; +import { LoadRulesProps, rewriteRulesResponseRes } from './rules_helpers'; export async function loadRules({ http, @@ -43,15 +27,13 @@ export async function loadRules({ total: number; data: Rule[]; }> { - const filtersKueryNode = mapFilterToKueryNode({ + const filters = mapFiltersToKql({ typesFilter, actionTypesFilter, tagsFilter, ruleExecutionStatusesFilter, ruleStatusesFilter, - searchText, }); - const res = await http.get< AsApiContract<{ page: number; @@ -63,7 +45,10 @@ export async function loadRules({ query: { page: page.index + 1, per_page: page.size, - ...(filtersKueryNode ? { filter: JSON.stringify(filtersKueryNode) } : {}), + search_fields: searchText ? JSON.stringify(['name', 'tags']) : undefined, + search: searchText, + filter: filters.length ? filters.join(' and ') : undefined, + default_search_operator: 'AND', sort_field: sort.field, sort_order: sort.direction, }, @@ -72,6 +57,6 @@ export async function loadRules({ page: res.page, perPage: res.per_page, total: res.total, - data: rewriteResponseRes(res.data), + data: rewriteRulesResponseRes(res.data), }; } diff --git a/x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/rules_helpers.ts b/x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/rules_helpers.ts new file mode 100644 index 00000000000000..dab59919092a2d --- /dev/null +++ b/x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/rules_helpers.ts @@ -0,0 +1,27 @@ +/* + * 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 type { HttpSetup } from '@kbn/core/public'; +import type { AsApiContract } from '@kbn/actions-plugin/common'; +import type { Rule, Pagination, Sorting, RuleStatus } from '../../../types'; +import { transformRule } from './common_transformations'; + +export interface LoadRulesProps { + http: HttpSetup; + page: Pagination; + searchText?: string; + typesFilter?: string[]; + actionTypesFilter?: string[]; + tagsFilter?: string[]; + ruleExecutionStatusesFilter?: string[]; + ruleStatusesFilter?: RuleStatus[]; + sort?: Sorting; +} + +export const rewriteRulesResponseRes = (results: Array>): Rule[] => { + return results.map((item) => transformRule(item)); +}; diff --git a/x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/rules_kuery_filter.ts b/x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/rules_kuery_filter.ts new file mode 100644 index 00000000000000..7ad37deb379b03 --- /dev/null +++ b/x-pack/plugins/triggers_actions_ui/public/application/lib/rule_api/rules_kuery_filter.ts @@ -0,0 +1,61 @@ +/* + * 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 { AsApiContract } from '@kbn/actions-plugin/common'; +import { INTERNAL_BASE_ALERTING_API_PATH } from '../../constants'; +import { Rule } from '../../../types'; +import { mapFilterToKueryNode } from './map_filters_to_kql'; +import { LoadRulesProps, rewriteRulesResponseRes } from './rules_helpers'; + +export async function loadRulesWithKueryFilter({ + http, + page, + searchText, + typesFilter, + actionTypesFilter, + ruleExecutionStatusesFilter, + ruleStatusesFilter, + tagsFilter, + sort = { field: 'name', direction: 'asc' }, +}: LoadRulesProps): Promise<{ + page: number; + perPage: number; + total: number; + data: Rule[]; +}> { + const filtersKueryNode = mapFilterToKueryNode({ + typesFilter, + actionTypesFilter, + tagsFilter, + ruleExecutionStatusesFilter, + ruleStatusesFilter, + searchText, + }); + + const res = await http.get< + AsApiContract<{ + page: number; + perPage: number; + total: number; + data: Array>; + }> + >(`${INTERNAL_BASE_ALERTING_API_PATH}/rules/_find`, { + query: { + page: page.index + 1, + per_page: page.size, + ...(filtersKueryNode ? { filter: JSON.stringify(filtersKueryNode) } : {}), + sort_field: sort.field, + sort_order: sort.direction, + }, + }); + return { + page: res.page, + perPage: res.per_page, + total: res.total, + data: rewriteRulesResponseRes(res.data), + }; +} diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/rules_list/components/rules_list.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/rules_list/components/rules_list.test.tsx index e2054ab13cb4cf..b6a1700208cccd 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/rules_list/components/rules_list.test.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/rules_list/components/rules_list.test.tsx @@ -32,9 +32,9 @@ jest.mock('../../../lib/action_connector_api', () => ({ loadAllActions: jest.fn(), })); jest.mock('../../../lib/rule_api', () => ({ - loadRules: jest.fn(), + loadRulesWithKueryFilter: jest.fn(), loadRuleTypes: jest.fn(), - loadRuleAggregations: jest.fn(), + loadRuleAggregationsWithKueryFilter: jest.fn(), updateAPIKey: jest.fn(), loadRuleTags: jest.fn(), alertingFrameworkHealth: jest.fn(() => ({ @@ -70,8 +70,13 @@ jest.mock('../../../../common/get_experimental_features', () => ({ const ruleTags = ['a', 'b', 'c', 'd']; -const { loadRules, loadRuleTypes, loadRuleAggregations, updateAPIKey, loadRuleTags } = - jest.requireMock('../../../lib/rule_api'); +const { + loadRulesWithKueryFilter, + loadRuleTypes, + loadRuleAggregationsWithKueryFilter, + updateAPIKey, + loadRuleTags, +} = jest.requireMock('../../../lib/rule_api'); const { loadActionTypes, loadAllActions } = jest.requireMock('../../../lib/action_connector_api'); const actionTypeRegistry = actionTypeRegistryMock.create(); @@ -320,7 +325,7 @@ describe.skip('Update Api Key', () => { const addError = jest.fn(); beforeAll(() => { - loadRules.mockResolvedValue({ + loadRulesWithKueryFilter.mockResolvedValue({ page: 1, perPage: 10000, total: 0, @@ -368,7 +373,7 @@ describe.skip('Update Api Key', () => { fireEvent.click(screen.getByText('Update')); }); expect(updateAPIKey).toHaveBeenCalledWith(expect.objectContaining({ id: '2' })); - expect(loadRules).toHaveBeenCalledTimes(3); + expect(loadRulesWithKueryFilter).toHaveBeenCalledTimes(3); expect(screen.queryByText("You can't recover the old API key")).not.toBeInTheDocument(); expect(addSuccess).toHaveBeenCalledWith('API key has been updated'); }); @@ -393,7 +398,7 @@ describe.skip('Update Api Key', () => { fireEvent.click(screen.getByText('Update')); }); expect(updateAPIKey).toHaveBeenCalledWith(expect.objectContaining({ id: '2' })); - expect(loadRules).toHaveBeenCalledTimes(3); + expect(loadRulesWithKueryFilter).toHaveBeenCalledTimes(3); expect( screen.queryByText('You will not be able to recover the old API key') ).not.toBeInTheDocument(); @@ -405,7 +410,7 @@ describe.skip('Update Api Key', () => { describe.skip('rules_list component empty', () => { let wrapper: ReactWrapper; async function setup() { - loadRules.mockResolvedValue({ + loadRulesWithKueryFilter.mockResolvedValue({ page: 1, perPage: 10000, total: 0, @@ -470,7 +475,7 @@ describe('rules_list component with props', () => { describe('Status filter', () => { let wrapper: ReactWrapper; async function setup(editable: boolean = true) { - loadRules.mockResolvedValue({ + loadRulesWithKueryFilter.mockResolvedValue({ page: 1, perPage: 10000, total: 4, @@ -488,7 +493,7 @@ describe('rules_list component with props', () => { ]); loadRuleTypes.mockResolvedValue([ruleTypeFromApi]); loadAllActions.mockResolvedValue([]); - loadRuleAggregations.mockResolvedValue({ + loadRuleAggregationsWithKueryFilter.mockResolvedValue({ ruleEnabledStatus: { enabled: 2, disabled: 0 }, ruleExecutionStatus: { ok: 1, active: 2, error: 3, pending: 4, unknown: 5, warning: 6 }, ruleMutedStatus: { muted: 0, unmuted: 2 }, @@ -525,16 +530,16 @@ describe('rules_list component with props', () => { wrapper.update(); }); - expect(loadRules).toHaveBeenCalled(); + expect(loadRulesWithKueryFilter).toHaveBeenCalled(); expect(loadActionTypes).toHaveBeenCalled(); - expect(loadRuleAggregations).toHaveBeenCalled(); + expect(loadRuleAggregationsWithKueryFilter).toHaveBeenCalled(); } it('can filter by rule states', async () => { (getIsExperimentalFeatureEnabled as jest.Mock).mockImplementation(() => true); - loadRules.mockReset(); + loadRulesWithKueryFilter.mockReset(); await setup(); - expect(loadRules).toHaveBeenLastCalledWith( + expect(loadRulesWithKueryFilter).toHaveBeenLastCalledWith( expect.objectContaining({ ruleStatusesFilter: ['disabled'], }) @@ -544,7 +549,7 @@ describe('rules_list component with props', () => { wrapper.find('[data-test-subj="ruleStatusFilterOption-enabled"]').first().simulate('click'); - expect(loadRules).toHaveBeenLastCalledWith( + expect(loadRulesWithKueryFilter).toHaveBeenLastCalledWith( expect.objectContaining({ ruleStatusesFilter: ['disabled', 'enabled'], }) @@ -561,7 +566,7 @@ describe('rules_list component with props', () => { describe('Last response filter', () => { let wrapper: ReactWrapper; async function setup(editable: boolean = true) { - loadRules.mockResolvedValue({ + loadRulesWithKueryFilter.mockResolvedValue({ page: 1, perPage: 10000, total: 4, @@ -579,7 +584,7 @@ describe('rules_list component with props', () => { ]); loadRuleTypes.mockResolvedValue([ruleTypeFromApi]); loadAllActions.mockResolvedValue([]); - loadRuleAggregations.mockResolvedValue({ + loadRuleAggregationsWithKueryFilter.mockResolvedValue({ ruleEnabledStatus: { enabled: 2, disabled: 0 }, ruleExecutionStatus: { ok: 1, active: 2, error: 3, pending: 4, unknown: 5, warning: 6 }, ruleMutedStatus: { muted: 0, unmuted: 2 }, @@ -616,16 +621,16 @@ describe('rules_list component with props', () => { wrapper.update(); }); - expect(loadRules).toHaveBeenCalled(); + expect(loadRulesWithKueryFilter).toHaveBeenCalled(); expect(loadActionTypes).toHaveBeenCalled(); - expect(loadRuleAggregations).toHaveBeenCalled(); + expect(loadRuleAggregationsWithKueryFilter).toHaveBeenCalled(); } it('can filter by last response', async () => { (getIsExperimentalFeatureEnabled as jest.Mock).mockImplementation(() => true); - loadRules.mockReset(); + loadRulesWithKueryFilter.mockReset(); await setup(); - expect(loadRules).toHaveBeenLastCalledWith( + expect(loadRulesWithKueryFilter).toHaveBeenLastCalledWith( expect.objectContaining({ ruleExecutionStatusesFilter: ['error'], }) @@ -638,7 +643,7 @@ describe('rules_list component with props', () => { .first() .simulate('click'); - expect(loadRules).toHaveBeenLastCalledWith( + expect(loadRulesWithKueryFilter).toHaveBeenLastCalledWith( expect.objectContaining({ ruleExecutionStatusesFilter: ['error', 'active'], }) @@ -656,7 +661,7 @@ describe('rules_list component with props', () => { .first() .simulate('click'); - expect(loadRules).toHaveBeenLastCalledWith( + expect(loadRulesWithKueryFilter).toHaveBeenLastCalledWith( expect.objectContaining({ ruleExecutionStatusesFilter: ['active'], }) @@ -670,7 +675,7 @@ describe('rules_list component with props', () => { describe('showActionFilter prop', () => { let wrapper: ReactWrapper; async function setup(editable: boolean = true) { - loadRules.mockResolvedValue({ + loadRulesWithKueryFilter.mockResolvedValue({ page: 1, perPage: 10000, total: 4, @@ -688,7 +693,7 @@ describe('rules_list component with props', () => { ]); loadRuleTypes.mockResolvedValue([ruleTypeFromApi]); loadAllActions.mockResolvedValue([]); - loadRuleAggregations.mockResolvedValue({ + loadRuleAggregationsWithKueryFilter.mockResolvedValue({ ruleEnabledStatus: { enabled: 2, disabled: 0 }, ruleExecutionStatus: { ok: 1, active: 2, error: 3, pending: 4, unknown: 5, warning: 6 }, ruleMutedStatus: { muted: 0, unmuted: 2 }, @@ -725,11 +730,11 @@ describe('rules_list component with props', () => { wrapper.update(); }); - expect(loadRules).toHaveBeenCalled(); + expect(loadRulesWithKueryFilter).toHaveBeenCalled(); expect(loadActionTypes).toHaveBeenCalled(); - expect(loadRuleAggregations).toHaveBeenCalled(); + expect(loadRuleAggregationsWithKueryFilter).toHaveBeenCalled(); (getIsExperimentalFeatureEnabled as jest.Mock).mockImplementation(() => true); - loadRules.mockReset(); + loadRulesWithKueryFilter.mockReset(); await setup(); expect(wrapper.find('ActionTypeFilter')).toHaveLength(0); }); @@ -741,11 +746,11 @@ describe('rules_list component with props', () => { wrapper.update(); }); - expect(loadRules).toHaveBeenCalled(); + expect(loadRulesWithKueryFilter).toHaveBeenCalled(); expect(loadActionTypes).toHaveBeenCalled(); - expect(loadRuleAggregations).toHaveBeenCalled(); + expect(loadRuleAggregationsWithKueryFilter).toHaveBeenCalled(); (getIsExperimentalFeatureEnabled as jest.Mock).mockImplementation(() => true); - loadRules.mockReset(); + loadRulesWithKueryFilter.mockReset(); await setup(); expect(wrapper.find('ActionTypeFilter')).toHaveLength(1); }); @@ -754,7 +759,7 @@ describe('rules_list component with props', () => { describe('showCreateRuleButton prop', () => { let wrapper: ReactWrapper; async function setup(editable: boolean = true) { - loadRules.mockResolvedValue({ + loadRulesWithKueryFilter.mockResolvedValue({ page: 1, perPage: 10000, total: 4, @@ -772,7 +777,7 @@ describe('rules_list component with props', () => { ]); loadRuleTypes.mockResolvedValue([ruleTypeFromApi]); loadAllActions.mockResolvedValue([]); - loadRuleAggregations.mockResolvedValue({ + loadRuleAggregationsWithKueryFilter.mockResolvedValue({ ruleEnabledStatus: { enabled: 2, disabled: 0 }, ruleExecutionStatus: { ok: 1, active: 2, error: 3, pending: 4, unknown: 5, warning: 6 }, ruleMutedStatus: { muted: 0, unmuted: 2 }, @@ -810,7 +815,7 @@ describe('rules_list component with props', () => { wrapper.update(); }); (getIsExperimentalFeatureEnabled as jest.Mock).mockImplementation(() => true); - loadRules.mockReset(); + loadRulesWithKueryFilter.mockReset(); await setup(); expect(wrapper.find('EuiButton[data-test-subj="createRuleButton"]').length).toEqual(0); }); @@ -822,7 +827,7 @@ describe('rules_list component with props', () => { wrapper.update(); }); (getIsExperimentalFeatureEnabled as jest.Mock).mockImplementation(() => true); - loadRules.mockReset(); + loadRulesWithKueryFilter.mockReset(); await setup(); expect(wrapper.find('EuiButton[data-test-subj="createRuleButton"]').length).toEqual(1); }); @@ -954,7 +959,7 @@ describe('rules_list component with props', () => { }, ]; async function setup(editable: boolean = true, filteredRuleTypes: string[]) { - loadRules.mockResolvedValue({ + loadRulesWithKueryFilter.mockResolvedValue({ page: 1, perPage: 10000, total: 2, @@ -976,7 +981,7 @@ describe('rules_list component with props', () => { { ...ruleTypeFromApi, id: 'test_rule_type2' }, ]); loadAllActions.mockResolvedValue([]); - loadRuleAggregations.mockResolvedValue({ + loadRuleAggregationsWithKueryFilter.mockResolvedValue({ ruleEnabledStatus: { enabled: 2, disabled: 0 }, ruleExecutionStatus: { ok: 1, active: 2, error: 3, pending: 4, unknown: 5, warning: 6 }, ruleMutedStatus: { muted: 0, unmuted: 2 }, @@ -1026,7 +1031,7 @@ describe('rules_list component with items', () => { let wrapper: ReactWrapper; async function setup(editable: boolean = true) { - loadRules.mockResolvedValue({ + loadRulesWithKueryFilter.mockResolvedValue({ page: 1, perPage: 10000, total: 4, @@ -1044,7 +1049,7 @@ describe('rules_list component with items', () => { ]); loadRuleTypes.mockResolvedValue([ruleTypeFromApi]); loadAllActions.mockResolvedValue([]); - loadRuleAggregations.mockResolvedValue({ + loadRuleAggregationsWithKueryFilter.mockResolvedValue({ ruleEnabledStatus: { enabled: 2, disabled: 0 }, ruleExecutionStatus: { ok: 1, active: 2, error: 3, pending: 4, unknown: 5, warning: 6 }, ruleMutedStatus: { muted: 0, unmuted: 2 }, @@ -1079,9 +1084,9 @@ describe('rules_list component with items', () => { wrapper.update(); }); - expect(loadRules).toHaveBeenCalled(); + expect(loadRulesWithKueryFilter).toHaveBeenCalled(); expect(loadActionTypes).toHaveBeenCalled(); - expect(loadRuleAggregations).toHaveBeenCalled(); + expect(loadRuleAggregationsWithKueryFilter).toHaveBeenCalled(); } it('renders table of rules', async () => { @@ -1253,7 +1258,7 @@ describe('rules_list component with items', () => { .first() .simulate('click'); - expect(loadRules).toHaveBeenCalledWith( + expect(loadRulesWithKueryFilter).toHaveBeenCalledWith( expect.objectContaining({ sort: { field: percentileFields[Percentiles.P50], @@ -1268,7 +1273,7 @@ describe('rules_list component with items', () => { .first() .simulate('click'); - expect(loadRules).toHaveBeenCalledWith( + expect(loadRulesWithKueryFilter).toHaveBeenCalledWith( expect.objectContaining({ sort: { field: percentileFields[Percentiles.P50], @@ -1326,7 +1331,7 @@ describe('rules_list component with items', () => { .first() .simulate('click'); - expect(loadRules).toHaveBeenCalledWith( + expect(loadRulesWithKueryFilter).toHaveBeenCalledWith( expect.objectContaining({ sort: { field: percentileFields[Percentiles.P95], @@ -1341,7 +1346,7 @@ describe('rules_list component with items', () => { .first() .simulate('click'); - expect(loadRules).toHaveBeenCalledWith( + expect(loadRulesWithKueryFilter).toHaveBeenCalledWith( expect.objectContaining({ sort: { field: percentileFields[Percentiles.P95], @@ -1388,7 +1393,7 @@ describe('rules_list component with items', () => { wrapper.update(); }); - expect(loadRules).toHaveBeenCalledWith( + expect(loadRulesWithKueryFilter).toHaveBeenCalledWith( expect.objectContaining({ sort: { field: 'name', @@ -1410,7 +1415,7 @@ describe('rules_list component with items', () => { wrapper.update(); }); - expect(loadRules).toHaveBeenLastCalledWith( + expect(loadRulesWithKueryFilter).toHaveBeenLastCalledWith( expect.objectContaining({ sort: { field: 'enabled', @@ -1467,10 +1472,10 @@ describe('rules_list component with items', () => { it('can filter by rule states', async () => { (getIsExperimentalFeatureEnabled as jest.Mock).mockImplementation(() => true); - loadRules.mockReset(); + loadRulesWithKueryFilter.mockReset(); await setup(); - expect(loadRules).toHaveBeenLastCalledWith( + expect(loadRulesWithKueryFilter).toHaveBeenLastCalledWith( expect.objectContaining({ ruleStatusesFilter: [], }) @@ -1480,7 +1485,7 @@ describe('rules_list component with items', () => { wrapper.find('[data-test-subj="ruleStatusFilterOption-enabled"]').first().simulate('click'); - expect(loadRules).toHaveBeenLastCalledWith( + expect(loadRulesWithKueryFilter).toHaveBeenLastCalledWith( expect.objectContaining({ ruleStatusesFilter: ['enabled'], }) @@ -1488,7 +1493,7 @@ describe('rules_list component with items', () => { wrapper.find('[data-test-subj="ruleStatusFilterOption-snoozed"]').first().simulate('click'); - expect(loadRules).toHaveBeenLastCalledWith( + expect(loadRulesWithKueryFilter).toHaveBeenLastCalledWith( expect.objectContaining({ ruleStatusesFilter: ['enabled', 'snoozed'], }) @@ -1496,7 +1501,7 @@ describe('rules_list component with items', () => { wrapper.find('[data-test-subj="ruleStatusFilterOption-snoozed"]').first().simulate('click'); - expect(loadRules).toHaveBeenLastCalledWith( + expect(loadRulesWithKueryFilter).toHaveBeenLastCalledWith( expect.objectContaining({ ruleStatusesFilter: ['enabled'], }) @@ -1516,10 +1521,10 @@ describe('rules_list component with items', () => { it('can filter by tags', async () => { (getIsExperimentalFeatureEnabled as jest.Mock).mockImplementation(() => true); - loadRules.mockReset(); + loadRulesWithKueryFilter.mockReset(); await setup(); - expect(loadRules).toHaveBeenLastCalledWith( + expect(loadRulesWithKueryFilter).toHaveBeenLastCalledWith( expect.objectContaining({ tagsFilter: [], }) @@ -1534,7 +1539,7 @@ describe('rules_list component with items', () => { tagFilterListItems.at(0).simulate('click'); - expect(loadRules).toHaveBeenLastCalledWith( + expect(loadRulesWithKueryFilter).toHaveBeenLastCalledWith( expect.objectContaining({ tagsFilter: ['a'], }) @@ -1542,7 +1547,7 @@ describe('rules_list component with items', () => { tagFilterListItems.at(1).simulate('click'); - expect(loadRules).toHaveBeenLastCalledWith( + expect(loadRulesWithKueryFilter).toHaveBeenLastCalledWith( expect.objectContaining({ tagsFilter: ['a', 'b'], }) @@ -1567,7 +1572,7 @@ describe('rules_list component empty with show only capability', () => { let wrapper: ReactWrapper; async function setup() { - loadRules.mockResolvedValue({ + loadRulesWithKueryFilter.mockResolvedValue({ page: 1, perPage: 10000, total: 0, @@ -1610,7 +1615,7 @@ describe('rules_list with show only capability', () => { let wrapper: ReactWrapper; async function setup(editable: boolean = true) { - loadRules.mockResolvedValue({ + loadRulesWithKueryFilter.mockResolvedValue({ page: 1, perPage: 10000, total: 2, @@ -1731,7 +1736,7 @@ describe('rules_list with disabled items', () => { let wrapper: ReactWrapper; async function setup() { - loadRules.mockResolvedValue({ + loadRulesWithKueryFilter.mockResolvedValue({ page: 1, perPage: 10000, total: 2,