Skip to content

Commit

Permalink
Remove duplicated logic for isGlobal
Browse files Browse the repository at this point in the history
  • Loading branch information
Esteban Beltran committed Dec 2, 2021
1 parent a24a200 commit d1f505a
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<EffectedPolicySelection>({
isGlobal,
isGlobal: isGlobalPolicyEffected(exception.tags),
selected: [],
});

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -251,7 +251,7 @@ export const HostIsolationExceptionsForm: React.FC<{
<EuiHorizontalRule />
<EuiFormRow fullWidth={true} data-test-subj={'effectedPolicies-container'}>
<EffectedPolicySelect
isGlobal={isGlobal}
isGlobal={selectedPolicies.isGlobal}
isPlatinumPlus={true}
selected={selectedPolicies.selected}
options={policies}
Expand Down

0 comments on commit d1f505a

Please sign in to comment.