From 659af06c5501da659b7da3b83b6475ba64ef7d61 Mon Sep 17 00:00:00 2001 From: Georgy Karataev Date: Wed, 23 Mar 2022 16:39:19 +0100 Subject: [PATCH] fix(disable modal): bug with multiple selections (#187) This fixes a bug: if user selects multiple clusters, unchecks "Disable recommendation for selected clusters" flag, then the recommendation will only be disabled for selected clusters. This is incorrect, and the recommendation should be disabled for all clusters in this scenario. --- src/Components/Modals/DisableRule.js | 84 ++++++++++++++-------------- 1 file changed, 41 insertions(+), 43 deletions(-) diff --git a/src/Components/Modals/DisableRule.js b/src/Components/Modals/DisableRule.js index 0a312d78..50e1bdf3 100644 --- a/src/Components/Modals/DisableRule.js +++ b/src/Components/Modals/DisableRule.js @@ -24,9 +24,8 @@ const DisableRule = ({ }) => { const intl = useIntl(); const [justification, setJustificaton] = useState(''); - const [singleSystem, setSingleSystem] = useState( - host !== undefined || hosts.length > 0 - ); + const [singleHost, setSingleHost] = useState(!!host); + const [multipleHosts, setMultipleHosts] = useState(hosts.length > 0); const [setAck] = useSetAckMutation(); const dispatch = useDispatch(); const notify = (data) => dispatch(addNotification(data)); @@ -60,49 +59,46 @@ const DisableRule = ({ }; const disableRule = async () => { - if (!rule.disabled && hosts.length === 0) { - try { - if (singleSystem) { - // disable the rec for this single cluster - await disableRuleForCluster({ - uuid: host, - recId: rule.rule_id, - justification, - }); - notify({ - variant: 'success', - timeout: true, - dismissable: true, - title: intl.formatMessage( - messages.recSuccessfullyDisabledForCluster - ), - }); - } else { - // disable the whole rec - await setAck({ - rule_id: rule.rule_id, - justification, - }).unwrap(); - notify({ - variant: 'success', - timeout: true, - dismissable: true, - title: intl.formatMessage(messages.recSuccessfullyDisabled), - }); - } - setJustificaton(''); - afterFn && afterFn(); - } catch (error) { + try { + if (singleHost) { + // disable the rec for this single cluster + await disableRuleForCluster({ + uuid: host, + recId: rule.rule_id, + justification, + }); + notify({ + variant: 'success', + timeout: true, + dismissable: true, + title: intl.formatMessage(messages.recSuccessfullyDisabledForCluster), + }); + } else if (multipleHosts) { + bulkHostActions(); + } else { + // disable the whole rec + await setAck({ + rule_id: rule.rule_id, + justification, + }).unwrap(); notify({ - variant: 'danger', + variant: 'success', + timeout: true, dismissable: true, - title: intl.formatMessage(messages.error), - description: `${error}`, + title: intl.formatMessage(messages.recSuccessfullyDisabled), }); } - } else { - bulkHostActions(); + setJustificaton(''); + afterFn && afterFn(); + } catch (error) { + notify({ + variant: 'danger', + dismissable: true, + title: intl.formatMessage(messages.error), + description: `${error}`, + }); } + handleModalToggle(false); }; @@ -144,9 +140,11 @@ const DisableRule = ({ {(host || hosts.length > 0) && ( { - setSingleSystem(!singleSystem); + host + ? setSingleHost(!singleHost) + : setMultipleHosts(!multipleHosts); }} label={ host