Skip to content

Commit

Permalink
Fixed disabled switch visual edit button when json is empty (#2968)
Browse files Browse the repository at this point in the history
* Fixed disabled switch visual editar when json is empty

* kibana prettier

* Fixed disabled switch visual edit when json is empty

* updated changelog
  • Loading branch information
Machi3mfl authored Feb 18, 2021
1 parent 141b434 commit b2f30f9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit b2f30f9

Please sign in to comment.