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));