From d1f505adeb0d61b43d251a660be78eeb398b2249 Mon Sep 17 00:00:00 2001 From: Esteban Beltran Date: Thu, 2 Dec 2021 09:20:34 -0500 Subject: [PATCH] Remove duplicated logic for isGlobal --- .../view/components/form.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/x-pack/plugins/security_solution/public/management/pages/host_isolation_exceptions/view/components/form.tsx b/x-pack/plugins/security_solution/public/management/pages/host_isolation_exceptions/view/components/form.tsx index ec2a3ffe0936d..a9d1572ba5cba 100644 --- a/x-pack/plugins/security_solution/public/management/pages/host_isolation_exceptions/view/components/form.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/host_isolation_exceptions/view/components/form.tsx @@ -66,9 +66,8 @@ export const HostIsolationExceptionsForm: React.FC<{ const [hasNameError, setHasNameError] = useState(!exception.name); const [hasIpError, setHasIpError] = useState(!ipEntry.value); - const [isGlobal, setIsGlobal] = useState(isGlobalPolicyEffected(exception.tags)); const [selectedPolicies, setSelectedPolicies] = useState({ - isGlobal, + isGlobal: isGlobalPolicyEffected(exception.tags), selected: [], }); @@ -120,12 +119,13 @@ export const HostIsolationExceptionsForm: React.FC<{ const handlePolicySelectChange: EffectedPolicySelectProps['onChange'] = useCallback( (selection) => { - setIsGlobal(selection.isGlobal); - // preseve the previous selection between global and not global toggle - if (!selection.isGlobal) { - setSelectedPolicies(() => selection); + if (selection.isGlobal) { + setSelectedPolicies({ isGlobal: true, selected: selection.selected }); + } else { + setSelectedPolicies(selection); } + onChange({ tags: getArtifactTagsByEffectedPolicySelection( selection, @@ -251,7 +251,7 @@ export const HostIsolationExceptionsForm: React.FC<{