Skip to content

Commit

Permalink
fix maxNesting
Browse files Browse the repository at this point in the history
  • Loading branch information
ukrbublik committed Jul 27, 2023
1 parent 5b21d18 commit 46d9577
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Changelog
- 6.5.0
- 6.4.1
- Fixed import of rule_group in rule_group from SpEL
- Updated type `ItemBuilderProps`
- Fixed drag-n-drop to respect `maxNesting` when moving group into group
- 6.4.0
- Functions can be used in LHS with `fieldSources: ["field", "func"]` in `settings`
Thanks @rhallerman1 (PR #900, #896) (issues #287, #250, #344, #336)
Expand Down
13 changes: 12 additions & 1 deletion packages/core/modules/utils/treeUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,11 @@ export const getFlatTree = (tree) => {
const id = item.get("id");
const children = item.get("children1");
const isLocked = item.getIn(["properties", "isLocked"]);
const childrenIds = children ? children.map((_child, childId) => childId) : null;
const childrenIds = children ? children.map((_child, childId) => childId).toArray() : null;
const isRuleGroup = type == "rule_group";
// tip: count rule_group as 1 rule
const isLeaf = !insideRuleGroup && (!children || isRuleGroup);
const hasChildren = childrenIds?.length > 0;

const itemsBefore = flat.length;
const top = realHeight;
Expand Down Expand Up @@ -221,6 +222,7 @@ export const getFlatTree = (tree) => {
isLocked: isLocked || insideLocked,
};

let depth;
if (children) {
let subinfo = {};
children.map((child, _childId) => {
Expand All @@ -232,6 +234,9 @@ export const getFlatTree = (tree) => {
});
if (!collapsed) {
info.height = (info.height || 0) + (subinfo.height || 0);
if (hasChildren && !isRuleGroup) { // tip: don't count children of rule_group
depth = (subinfo.depth || 0) + 1;
}
}
}

Expand All @@ -248,6 +253,12 @@ export const getFlatTree = (tree) => {
height: height,
bottom: (insideCollapsed ? null : top) + height,
});
if (depth != undefined) {
Object.assign(items[id], {
depth: depth,
});
info.depth = Math.max(info.depth || 0, depth);
}
}

_flatizeTree(tree, [], false, false, false, 0, {}, null, null);
Expand Down
2 changes: 1 addition & 1 deletion packages/tests/specs/QueryWithGroupsAndStructs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ describe("query with nested !group", () => {
describe("with two separate group rules, imported from spel", () => {
export_checks(configs.with_nested_group, inits.spel_two_rules_with_nested_group, "SpEL", {
"spel": "(results.?[user.?[name == 'aaa'].size() > 0].size() > 0 && results.?[score == 11].size() > 0)"
})
});
});

describe("with two nested groups - import with old format, export to new format", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/tests/support/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ export const empty_value = {id: uuid(), type: "group"};
const do_export_checks = (config: Config, tree: ImmutableTree, expects?: ExtectedExports, options?: DoOptions) => {
const doIt = options?.insideIt ? ((name: string, func: Function) => { func(); }) : it;

if (!expects || Object.keys(expects).some(t => (expects as any)[t] === "?")) {
if (!expects || Object.values(expects).some(e => e === "?")) {
const {logic, data, errors} = jsonLogicFormat(tree, config);
const correct = {
query: queryString(tree, config),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ const createSortableContainer = (Builder, CanMoveFn = null) =>

const { canRegroup, canRegroupCases, maxNesting, maxNumberOfRules, canLeaveEmptyCase } = this.props.config.settings;
const newLev = toParentII ? toParentII.lev + 1 : toII.lev;
const newDepthLev = newLev + (fromII.depth || 0);
const isBeforeAfter = placement == constants.PLACEMENT_BEFORE || placement == constants.PLACEMENT_AFTER;
const isPend = placement == constants.PLACEMENT_PREPEND || placement == constants.PLACEMENT_APPEND;
const isLev1 = isBeforeAfter && toII.lev == 1 || isPend && toII.lev == 0;
Expand All @@ -583,8 +584,8 @@ const createSortableContainer = (Builder, CanMoveFn = null) =>
// can't move rule/group to another case
|| !canRegroupCases && fromII.caseId != toII.caseId;
const isLockedChange = toII.isLocked || fromII.isLocked || toParentII && toParentII.isLocked;

if (maxNesting && newLev > maxNesting)
if (maxNesting && newDepthLev > maxNesting)
return false;

if (isStructChange && (!canRegroup || isForbiddenStructChange || isLockedChange))
Expand Down

0 comments on commit 46d9577

Please sign in to comment.