Skip to content

Restrict maximum nesting of groups #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Dec 26, 2021
Merged

Restrict maximum nesting of groups #63

merged 20 commits into from
Dec 26, 2021

Conversation

rtucek
Copy link
Owner

@rtucek rtucek commented Oct 27, 2021

Introduce new, optional setting maxDepth. This setting can be used to restrict maximum nesting of groups.

Configuration:

If maxDepth is undefined, users may have an arbitrary depth of nested groups. This reflects in the current behavior and is backwards compatible.
If typeof maxDepth === 'number' and 0 <= n <= maxDepth, users are only allowed to create up to n groups in deep. If n is 0, users are effectively not allowed to create any groups at all.

groupCtrlSlotProps:

For slots of type groupCtrlSlotProps, the newGroup() callback, passed as slot prop, becomes a noop, if a group has exceeded the maxDepth policy. Additionally, a boolean flag with as maxDepthExeeded property is provided to the slot prop object, so the slot can apply some v-if condition logic for hiding a create-new-group handler.

Drag'n'drop:

Prior dropping a dragged group into another group, the library checks if the max depth policy would be violated and prevents dropping. The user will notice that the drag'n'drop preview will not adjust as usually expected.

Config change at runtime

It is possible and valid to change maxDepth at runtime. As a special chase, if the given query has a higher nested depth and a config change restricts the maxDepth to a lower depth, the library (intentionally) removes any child groups, exceeding the present config limit. This ensures consistency with the maxDepth policy. It's the component's parent responsibility of checking if setting maxDepth may not result in an unwanted side-effect of removing any children from the given query tree.

Bonus

yarn serve's testing setup got a panel for quick config changes at runtime.

TODO:

  • Write unit tests
  • Write documentation (including codesandbox.io sample)

closes #61

@rtucek rtucek added the enhancement New feature or request label Oct 27, 2021
@rtucek rtucek self-assigned this Oct 27, 2021
@rtucek rtucek mentioned this pull request Oct 27, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Nov 28, 2021

Code Coverage Report

Coverage after merging max-depth-for-groups into master

97.70%
Coverage Report
FileBranchesFuncsLinesUncovered Lines
src
   MergeTrap.ts94.44%100%98.25%7, 8
   QueryBuilder.vue100%100%100%
   QueryBuilderChild.vue83.33%100%92.31%..., 55, 59, 67, 71
   QueryBuilderGroup.vue88.10%100%98.06%..., 290, 290, 291, 295
   QueryBuilderRule.vue75%100%94.74%23, 27
   guards.ts100%100%100%

@rtucek rtucek added the testing Change relates to software testing label Nov 29, 2021
@rtucek rtucek marked this pull request as draft November 29, 2021 04:38
@rtucek rtucek force-pushed the max-depth-for-groups branch from 588ba02 to 1321b49 Compare November 30, 2021 02:26
@rtucek rtucek marked this pull request as ready for review December 25, 2021 03:43
Add `maxDepth` to config for restricting depth of the query builder.
Have `maxDepthExeeded` to be passed on to the GroupCtrlSlot prop.
This allows the custom slot handler to identify if the max. depth has been reached. In this case,
the `newGroup` callable will behave as a noop.
The `maxDepth` policy is authoritative. Whenever we detect the query or `maxDepth` has changed,
prune unnecessary children and let the update propagate .
Don't allow dragging groups into another group `maxDepth` policy would be exceeded.
If we drop a deep nested group to another, the end-result may violate the maxDepth policy.
Therefore, decline dropping where this may happen.
@rtucek rtucek force-pushed the max-depth-for-groups branch from d77fbfe to 2fcf689 Compare December 26, 2021 05:26
@rtucek rtucek merged commit 629386c into master Dec 26, 2021
@rtucek rtucek deleted the max-depth-for-groups branch December 26, 2021 05:34
rtucek added a commit that referenced this pull request Dec 26, 2021
Post-release of #63
@rtucek rtucek mentioned this pull request Dec 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request testing Change relates to software testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Max nested groups
1 participant