Skip to content

Commit 33d9e5e

Browse files
committed
Add documentation for new onAddRule/onAddGroup context parameter
1 parent d2c7512 commit 33d9e5e

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

docs/api/querybuilder.mdx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ The array of combinators that should be used for RuleGroups. The default set inc
171171

172172
```ts
173173
interface Controls {
174-
addGroupAction?: React.ComponentType<ActionWithRulesProps>;
175-
addRuleAction?: React.ComponentType<ActionWithRulesProps>;
174+
addGroupAction?: React.ComponentType<ActionWithRulesAndAddersProps>;
175+
addRuleAction?: React.ComponentType<ActionWithRulesAndAddersProps>;
176176
cloneGroupAction?: React.ComponentType<ActionWithRulesProps>;
177177
cloneRuleAction?: React.ComponentType<ActionProps>;
178178
combinatorSelector?: React.ComponentType<CombinatorSelectorProps>;
@@ -199,11 +199,11 @@ This is a custom controls object that allows you to override the default control
199199
By default a `<button />` is used. The following props are passed:
200200

201201
```ts
202-
interface ActionWithRulesProps {
202+
interface ActionWithRulesAndAddersProps {
203203
label: string; // translations.addGroup.label, e.g. "+Group"
204204
title: string; // translations.addGroup.title, e.g. "Add group"
205205
className: string; // CSS classNames to be applied
206-
handleOnClick: (e: React.MouseEvent) => void; // Callback function to invoke adding a <RuleGroup />
206+
handleOnClick: (e: React.MouseEvent, context?: any) => void; // Callback function to invoke adding a <RuleGroup />
207207
rules: (RuleGroupType | RuleType)[]; // Provides the number of rules already present for this group
208208
level: number; // The level of the current group
209209
context: any; // Container for custom props that are passed to all components
@@ -267,11 +267,11 @@ interface ActionWithRulesProps {
267267
By default a `<button />` is used. The following props are passed:
268268

269269
```ts
270-
interface ActionWithRulesProps {
270+
interface ActionWithRulesAndAddersProps {
271271
label: string; // translations.addGroup.label, e.g. "+Rule"
272272
title: string; // translations.addGroup.title, e.g. "Add rule"
273273
className: string; // CSS classNames to be applied
274-
handleOnClick: (e: React.MouseEvent) => void; // Callback function to invoke adding a <RuleGroup />
274+
handleOnClick: (e: React.MouseEvent, context?: any) => void; // Callback function to invoke adding a <RuleGroup />
275275
rules: (RuleGroupType | RuleType)[]; // Provides the number of rules already present for this group
276276
level: number; // The level of the current group
277277
context: any; // Container for custom props that are passed to all components
@@ -550,9 +550,9 @@ This function returns the default value for new rules.
550550

551551
### `onAddRule`
552552

553-
`(rule: RuleType, parentPath: number[], query: RuleGroupTypeAny) => RuleType | false`
553+
`(rule: RuleType, parentPath: number[], query: RuleGroupTypeAny, context?: any) => RuleType | false`
554554

555-
This callback is invoked before a new rule is added. The function should either manipulate the rule and return it as an object of type `RuleType`, or return `false` to cancel the addition of the rule. You can use [`findPath`](./misc#findpath) to locate the parent group to which the new rule will be added within the query hierarchy.
555+
This callback is invoked before a new rule is added. The function should either manipulate the rule and return it as an object of type `RuleType`, or return `false` to cancel the addition of the rule. You can use [`findPath`](./misc#findpath) to locate the parent group to which the new rule will be added within the query hierarchy. The `context` parameter (fourth argument) can be passed from a custom [`addRuleAction`](#addruleaction) component to its `onHandleClick` callback prop, which will in turn pass it to `onAddRule`. This allows one to change the rule that gets added (or avoid the action completely) based on arbitrary information.
556556

557557
:::tip
558558

@@ -562,9 +562,9 @@ To completely [prevent the addition of new rules](../tips/limit-groups), pass `c
562562

563563
### `onAddGroup`
564564

565-
`<RG extends RuleGroupTypeAny>(ruleGroup: RG, parentPath: number[], query: RG) => RG | false`
565+
`<RG extends RuleGroupTypeAny>(ruleGroup: RG, parentPath: number[], query: RG, context?: any) => RG | false`
566566

567-
This callback is invoked before a new group is added. The function should either manipulate the group and return it as an object of the same type (either `RuleGroupType` or `RuleGroupTypeIC`), or return `false` to cancel the addition of the group. You can use [`findPath`](./misc#findpath) to locate the parent group to which the new group will be added within the query hierarchy.
567+
This callback is invoked before a new group is added. The function should either manipulate the group and return it as an object of the same type (either `RuleGroupType` or `RuleGroupTypeIC`), or return `false` to cancel the addition of the group. You can use [`findPath`](./misc#findpath) to locate the parent group to which the new group will be added within the query hierarchy. The `context` parameter (fourth argument) can be passed from a custom [`addGroupAction`](#addgroupaction) component to its `onHandleClick` callback prop, which will in turn pass it to `onAddGroup`. This allows one to change the group that gets added (or avoid the action completely) based on arbitrary information.
568568

569569
:::tip
570570

0 commit comments

Comments
 (0)