Skip to content

Commit

Permalink
Fix export of not in some!group into JsonLogic (#484)
Browse files Browse the repository at this point in the history
* Fix export of not in some!group into JsonLogic

* chlog

* repro app

* Revert "repro app"

This reverts commit 9dd3d9a.
  • Loading branch information
ukrbublik authored Aug 19, 2021
1 parent cea08ed commit 6143c97
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog
- latest
- 4.4.3
- babel: use "@babel/plugin-transform-runtime" to avoid globally defined regenerator runtime (PR #480)
- Fix export of not in some!group into JsonLogic (issue #476) (PR #484)
- Fixed issue with default import/export in Vite build (PR #481)
- 4.4.2
- Added support of autocomplete for multiselect widget in MUI (PR #475)
Expand Down
21 changes: 17 additions & 4 deletions modules/import/jsonLogic.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,22 @@ const convertOp = (op, vals, conv, config, not, meta, parentField = null) => {
const parseRes = parseRule(op, arity, vals, parentField, conv, config, meta);
if (!parseRes) return undefined;
let {field, fieldConfig, opKey, args, having} = parseRes;

let opConfig = config.operators[opKey];
const canRev = !(fieldConfig.type == "!group");

// Group component in array mode can show NOT checkbox, so do nothing in this case
// Otherwise try to revert
const showNot = fieldConfig.showNot !== undefined ? fieldConfig.showNot : config.settings.showNot;
let canRev = true;
if (fieldConfig.type == "!group" && fieldConfig.mode == "array" && showNot)
canRev = false;

// Fix "some ! in"
if (fieldConfig.type == "!group" && having && Object.keys(having)[0] == "!") {
not = !not;
having = having["!"];
}

// Use reversed op
if (not && canRev && opConfig.reversedOp) {
not = false;
opKey = opConfig.reversedOp;
Expand Down Expand Up @@ -573,7 +586,7 @@ const convertOp = (op, vals, conv, config, not, meta, parentField = null) => {
}
Object.assign(res.properties, {
mode: fieldConfig.mode,
not: not,
not: (canRev ? false : not),
operator: opKey,
});
if (fieldConfig.mode == "array") {
Expand All @@ -590,7 +603,7 @@ const convertOp = (op, vals, conv, config, not, meta, parentField = null) => {
children1: {},
properties: {
conjunction: defaultGroupConjunction(config, fieldConfig),
not: not,
not: (canRev ? false : not),
mode: fieldConfig.mode,
field: field,
operator: opKey,
Expand Down

0 comments on commit 6143c97

Please sign in to comment.