Skip to content

Commit d3782a2

Browse files
committed
Add documentation for transformQuery
1 parent 215f583 commit d3782a2

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

docs/api/misc.mdx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import TypeScriptAdmonition from './_ts_admonition.md';
1313
### `defaultValidator`
1414

1515
```ts
16-
function defaultValidator(query: RuleGroupType): {
16+
function defaultValidator(query: RuleGroupTypeAny): {
1717
[id: string]: { valid: boolean; reasons?: string[] };
1818
};
1919
```
@@ -25,7 +25,7 @@ You can see an example of the default validator in action in the [demo](https://
2525
### `findPath`
2626

2727
```ts
28-
function findPath(path: number[], query: RuleGroupType): RuleType | RuleGroupType;
28+
function findPath(path: number[], query: RuleGroupTypeAny): RuleType | RuleGroupTypeAny;
2929
```
3030

3131
`findPath` is a utility function for finding the rule or group within the query hierarchy that has a given `path`. Useful in custom [`onAddRule`](./querybuilder#onaddrule) and [`onAddGroup`](./querybuilder#onaddgroup) functions.
@@ -42,6 +42,22 @@ function convertQuery(query: RuleGroupTypeIC): RuleGroupType;
4242

4343
`convertToIC` and `convertFromIC` do the same thing as `convertQuery`, but only in one direction.
4444

45+
### `transformQuery`
46+
47+
```ts
48+
function transformQuery(query: RuleGroupTypeAny, options: QueryTransformerOptions): any;
49+
```
50+
51+
This function recursively steps through nested `rules` arrays in a `RuleGroupType` or `RuleGroupTypeIC`, passing each `RuleType` object to a provided `ruleProcessor` function. Several other options are also available:
52+
53+
- `ruleGroupProcessor`: Custom processing for each rule group. (The `rules` property will be overwritten.)
54+
- `propertyMap`: Keys in the rule or group objects that match keys in this object will be renamed to the corresponding value.
55+
- `combinatorMap`: Best explained with an example: `{and: "&&", or: "||"}` would translate "and"/"or" combinators to "&&"/"||", respectively.
56+
- `operatorMap`: Convert operators that match the keys in this object to the corresponding values, e.g. `{"=": "=="}`.
57+
- `deleteRemappedProperties`: Defaults to `true`; pass `false` to leave the remapped properties _and_ the original properties in the resulting object.
58+
59+
See the [test suite](https://github.com/react-querybuilder/react-querybuilder/blob/main/packages/react-querybuilder/src/utils/transformQuery.test.ts) for example usage.
60+
4561
## Query tools
4662

4763
Several methods are available to assist with manipulation of query objects outside the context of the `<QueryBuilder />` component:

0 commit comments

Comments
 (0)