From 49690d7a119467a8c0868e77e3859c8529b38bf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georgiana-Andreea=20Onolea=C8=9B=C4=83?= Date: Thu, 9 Jan 2025 15:51:29 +0200 Subject: [PATCH] [ResponseOps][Rules]Hide number of conditions on Rule page when Rule type do not allow multiple conditions (#204385) Closes https://github.com/elastic/kibana/issues/194809 ## Summary The "Conditions" section on the Rule page definition list is now hidden for the rule types that don't allow multiple conditions https://github.com/user-attachments/assets/eed1518a-91c4-453c-8294-643f86f05e30 todo: add/change tests --- .../components/rule_definition.test.tsx | 23 +++++++-- .../components/rule_definition.tsx | 50 +++++++++++-------- 2 files changed, 48 insertions(+), 25 deletions(-) diff --git a/x-pack/platform/plugins/shared/triggers_actions_ui/public/application/sections/rule_details/components/rule_definition.test.tsx b/x-pack/platform/plugins/shared/triggers_actions_ui/public/application/sections/rule_details/components/rule_definition.test.tsx index bc5da8218d118..e8c8b520f8e38 100644 --- a/x-pack/platform/plugins/shared/triggers_actions_ui/public/application/sections/rule_details/components/rule_definition.test.tsx +++ b/x-pack/platform/plugins/shared/triggers_actions_ui/public/application/sections/rule_details/components/rule_definition.test.tsx @@ -188,10 +188,10 @@ describe('Rule Definition', () => { expect(ruleDescription.find('div.euiText').text()).toEqual('Security detection rule'); }); - it('show rule conditions "', async () => { + it('show rule conditions only if the rule allows multiple conditions', async () => { const ruleConditions = wrapper.find('[data-test-subj="ruleSummaryRuleConditions"]'); expect(ruleConditions).toBeTruthy(); - expect(ruleConditions.find('div.euiText').text()).toEqual(`0 conditions`); + expect(ruleConditions.find('div.euiText').text()).toEqual('1 condition'); }); it('show rule interval with human readable value', async () => { @@ -225,7 +225,24 @@ function mockRule(overwrite = {}): Rule { ruleTypeId: 'test_rule_type', schedule: { interval: '1s' }, actions: [], - params: { name: 'test rule type name', description: 'siem description' }, + params: { + name: 'test rule type name', + description: 'siem description', + criteria: [ + { + comparator: '>', + metrics: [ + { + name: 'A', + aggType: 'count', + }, + ], + threshold: [100], + timeSize: 1, + timeUnit: 'm', + }, + ], + }, createdBy: null, updatedBy: null, apiKeyOwner: null, diff --git a/x-pack/platform/plugins/shared/triggers_actions_ui/public/application/sections/rule_details/components/rule_definition.tsx b/x-pack/platform/plugins/shared/triggers_actions_ui/public/application/sections/rule_details/components/rule_definition.tsx index ed21bb88992a8..371fe483a4695 100644 --- a/x-pack/platform/plugins/shared/triggers_actions_ui/public/application/sections/rule_details/components/rule_definition.tsx +++ b/x-pack/platform/plugins/shared/triggers_actions_ui/public/application/sections/rule_details/components/rule_definition.tsx @@ -49,6 +49,8 @@ export const RuleDefinition: React.FunctionComponent = ({ const [editFlyoutVisible, setEditFlyoutVisible] = useState(false); const [ruleType, setRuleType] = useState(); + + const hasConditions = !!(rule?.params.criteria as any[])?.length; const { ruleTypesState: { data: ruleTypeIndex, isLoading: ruleTypesIsLoading }, } = useLoadRuleTypesQuery({ @@ -159,28 +161,32 @@ export const RuleDefinition: React.FunctionComponent = ({ /> ), }, - { - title: i18n.translate('xpack.triggersActionsUI.ruleDetails.conditionsTitle', { - defaultMessage: 'Conditions', - }), - description: ( - - - {hasEditButton ? ( - - {getRuleConditionsWording()} - - ) : ( - {getRuleConditionsWording()} - )} - - - ), - }, + ...(hasConditions + ? [ + { + title: i18n.translate('xpack.triggersActionsUI.ruleDetails.conditionsTitle', { + defaultMessage: 'Conditions', + }), + description: ( + + + {hasEditButton ? ( + + {getRuleConditionsWording()} + + ) : ( + {getRuleConditionsWording()} + )} + + + ), + }, + ] + : []), { title: i18n.translate('xpack.triggersActionsUI.ruleDetails.actions', { defaultMessage: 'Actions',