From b2f30f99ee3baf0230dfe59043fb98f6b2566159 Mon Sep 17 00:00:00 2001 From: Maximiliano Ibarra Date: Thu, 18 Feb 2021 13:57:42 -0300 Subject: [PATCH] Fixed disabled switch visual edit button when json is empty (#2968) * Fixed disabled switch visual editar when json is empty * kibana prettier * Fixed disabled switch visual edit when json is empty * updated changelog --- CHANGELOG.md | 1 + .../roles-mapping/components/rule-editor.tsx | 35 ++++++++++++++----- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 629bcebfca..0e69e2d9e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ All notable changes to the Wazuh app project will be documented in this file. ### Fixed +- Fix disabled switch visual edit button when json content is empty [#2957](https://github.com/wazuh/wazuh-kibana-app/issues/2957) - Fix the statusCode error message [#2971](https://github.com/wazuh/wazuh-kibana-app/pull/2971) - Fix the SCA policy stats didn't refresh [#2973](https://github.com/wazuh/wazuh-kibana-app/pull/2973) - Fix some date fields format in FIM and SCA modules [#2975](https://github.com/wazuh/wazuh-kibana-app/pull/2975) diff --git a/public/components/security/roles-mapping/components/rule-editor.tsx b/public/components/security/roles-mapping/components/rule-editor.tsx index 05f6bf5ddc..f6d2c55dfb 100644 --- a/public/components/security/roles-mapping/components/rule-editor.tsx +++ b/public/components/security/roles-mapping/components/rule-editor.tsx @@ -111,17 +111,30 @@ export const RuleEditor = ({ save, initialRule, isLoading, isReserved, internalU rulesTmp.splice(id, 1); setRules(rulesTmp); }; + + const getRulesFromJson = (jsonRule) => { + if (jsonRule !== '{}' && jsonRule !== '') { + // empty json is valid + const { customRules, internalUsersRules, wrongFormat, logicalOperator } = decodeJsonRule( + jsonRule, + internalUsers + ); + setLogicalOperator(logicalOperator); + setHasWrongFormat(wrongFormat); - const getRulesFromJson = jsonRule => { - const { customRules, internalUsersRules, wrongFormat, logicalOperator } = decodeJsonRule( - jsonRule, - internalUsers - ); - setLogicalOperator(logicalOperator); - setHasWrongFormat(wrongFormat); - return { customRules, internalUsersRules, wrongFormat, logicalOperator }; - }; + return { customRules, internalUsersRules, wrongFormat, logicalOperator }; + } else { + setLogicalOperator(''); + setHasWrongFormat(false); + return { + customRules: [], + internalUsersRules: [], + wrongFormat: false, + logicalOperator: 'OR', + }; + } + }; const printRules = () => { const rulesList = rules.map((item, idx) => { return ( @@ -228,6 +241,10 @@ export const RuleEditor = ({ save, initialRule, isLoading, isReserved, internalU const saveRule = () => { if (isJsonEditor) { + // if json editor is empty + if (ruleJson === '') { + setRuleJson('{}'); + } save(JSON.parse(ruleJson)); } else { save(getJsonFromRule(internalUserRules, rules, logicalOperator));