From 435fc9b74904701bcc8b915a7865e035928db7b2 Mon Sep 17 00:00:00 2001 From: Ievgen Sorokopud Date: Wed, 25 Oct 2023 14:18:37 +0200 Subject: [PATCH] [Security Solution] User is not able to create/edit an exception after an error has been displayed #168217 --- .../logic/use_add_rule_exception.tsx | 31 ++++++++------- .../logic/use_create_update_exception.tsx | 39 +++++++++++-------- 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/x-pack/plugins/security_solution/public/detection_engine/rule_exceptions/logic/use_add_rule_exception.tsx b/x-pack/plugins/security_solution/public/detection_engine/rule_exceptions/logic/use_add_rule_exception.tsx index c25ffda8ece14..e7b44a9d6a737 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/rule_exceptions/logic/use_add_rule_exception.tsx +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_exceptions/logic/use_add_rule_exception.tsx @@ -43,22 +43,27 @@ export const useAddRuleDefaultException = (): ReturnUseAddRuleException => { exceptions: CreateRuleExceptionListItemSchema[], rules: Rule[] ): Promise => { - setIsLoading(true); + try { + setIsLoading(true); - // TODO: Update once bulk route is added - const result = await Promise.all( - rules.map(async (rule) => - addRuleExceptions({ - items: exceptions, - ruleId: rule.id, - signal: abortCtrl.signal, - }) - ) - ); + // TODO: Update once bulk route is added + const result = await Promise.all( + rules.map(async (rule) => + addRuleExceptions({ + items: exceptions, + ruleId: rule.id, + signal: abortCtrl.signal, + }) + ) + ); - setIsLoading(false); + setIsLoading(false); - return result.flatMap((r) => r); + return result.flatMap((r) => r); + } catch (e) { + setIsLoading(false); + throw e; + } }; addRuleExceptionFunc.current = addExceptionItemsToRule; diff --git a/x-pack/plugins/security_solution/public/detection_engine/rule_exceptions/logic/use_create_update_exception.tsx b/x-pack/plugins/security_solution/public/detection_engine/rule_exceptions/logic/use_create_update_exception.tsx index fbe9c0d46e6b3..2a302a8b0577c 100644 --- a/x-pack/plugins/security_solution/public/detection_engine/rule_exceptions/logic/use_create_update_exception.tsx +++ b/x-pack/plugins/security_solution/public/detection_engine/rule_exceptions/logic/use_create_update_exception.tsx @@ -36,25 +36,30 @@ export const useCreateOrUpdateException = (): ReturnUseCreateOrUpdateException = const abortCtrl = new AbortController(); const onCreateOrUpdateExceptionItem: CreateOrUpdateExceptionItemsFunc = async (items) => { - setIsLoading(true); - const itemsAdded = await Promise.all( - items.map((item: ExceptionListItemSchema | CreateExceptionListItemSchema) => { - if ('id' in item && item.id != null) { - const formattedExceptionItem = formatExceptionItemForUpdate(item); - return updateExceptionListItem({ - listItem: formattedExceptionItem, - }); - } else { - return addExceptionListItem({ - listItem: item, - }); - } - }) - ); + try { + setIsLoading(true); + const itemsAdded = await Promise.all( + items.map((item: ExceptionListItemSchema | CreateExceptionListItemSchema) => { + if ('id' in item && item.id != null) { + const formattedExceptionItem = formatExceptionItemForUpdate(item); + return updateExceptionListItem({ + listItem: formattedExceptionItem, + }); + } else { + return addExceptionListItem({ + listItem: item, + }); + } + }) + ); - setIsLoading(false); + setIsLoading(false); - return itemsAdded; + return itemsAdded; + } catch (e) { + setIsLoading(false); + throw e; + } }; addOrUpdateExceptionRef.current = onCreateOrUpdateExceptionItem;