Skip to content

Commit fa711e6

Browse files
authored
Merge pull request #10 from react-querybuilder/v430
Documentation changes for v4.3.1
2 parents 571d042 + 9e0bf57 commit fa711e6

File tree

11 files changed

+897
-738
lines changed

11 files changed

+897
-738
lines changed

docs/api/export.mdx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ formatQuery(query, 'parameterized');
122122

123123
Output:
124124

125-
```ts
125+
```json
126126
{
127-
sql: "(firstName = ? and lastName = ?)",
128-
params: ["Steve", "Vai"]
127+
"sql": "(firstName = ? and lastName = ?)",
128+
"params": ["Steve", "Vai"]
129129
}
130130
```
131131

@@ -139,12 +139,12 @@ formatQuery(query, 'parameterized_named');
139139

140140
Output:
141141

142-
```ts
142+
```json
143143
{
144-
sql: "(firstName = :firstName_1 and lastName = :lastName_1)",
145-
params: {
146-
firstName_1: "Steve",
147-
lastName_1: "Vai"
144+
"sql": "(firstName = :firstName_1 and lastName = :lastName_1)",
145+
"params": {
146+
"firstName_1": "Steve",
147+
"lastName_1": "Vai"
148148
}
149149
}
150150
```
@@ -325,13 +325,17 @@ const pf = formatQuery(
325325

326326
Output:
327327

328-
```ts
328+
```json
329329
{
330-
sql: "(firstName = lastName and firstName like middleName || '%')",
331-
params: {},
330+
"sql": "(firstName = lastName and firstName like middleName || '%')",
331+
"params": {}
332332
}
333333
```
334334

335+
### Placeholder values
336+
337+
Any rule where the `field` or `operator` matches the placeholder value (default `"~"`) will be excluded from the output for most export formats (see [Automatic validation](#automatic-validation)). To use a different string as the placeholder value, set the `fields.placeholderName` and/or the `operators.placeholderName` property as appropriate on the [`translations` prop](./querybuilder#translations) object.
338+
335339
## Validation
336340

337341
The validation options (`validator` and `fields` – see [Validation](./validation) for more information) only affect the output when `format` is "sql", "parameterized", "parameterized_named", or "mongodb". If the `validator` function returns `false`, the `fallbackExpression` will be returned. Otherwise, groups and rules marked as invalid (either by the validation map produced by the `validator` function or the result of the field-based `validator` function) will be ignored.
@@ -383,7 +387,8 @@ formatQuery(query, {
383387

384388
### Automatic validation
385389

386-
A basic form of validation will be used by `formatQuery` for the "in", "notIn", "between", and "notBetween" operators when the output format is "sql", "parameterized", "parameterized_named", or "mongodb". This validation is used regardless of the presence of any `validator` options either at the query or field level:
390+
A basic form of validation will be used by `formatQuery` for the "in", "notIn", "between", and "notBetween" operators when the output format is "sql", "parameterized", "parameterized_named", "mongodb", or "cel". This validation is used regardless of the presence of any `validator` options either at the query or field level:
387391

388392
- Rules that specify an "in" or "notIn" `operator` will be deemed invalid if the rule's `value` is neither an array with at least one element (i.e. `value.length > 0`) nor a non-empty string.
389393
- Rules that specify a "between" or "notBetween" `operator` will be deemed invalid if the rule's `value` is neither an array of length two (`value.length === 2`) nor a string with exactly one comma that isn't the first or last character (i.e. `value.split(',').length === 2` and neither element is an empty string).
394+
- Rules where the following expression is true will be deemed invalid: `field === placeholderFieldName || operator === placeholderOperatorName`.

docs/api/import.mdx

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,19 @@ parseSQL(`SELECT * FROM t WHERE firstName = $p1 AND lastName = $p2`, {
4040

4141
Output (`RuleGroupType`):
4242

43-
```ts
43+
```json
4444
{
45-
combinator: "and",
46-
rules: [
45+
"combinator": "and",
46+
"rules": [
4747
{
48-
field: "firstName",
49-
operator: "=",
50-
value: "Steve"
48+
"field": "firstName",
49+
"operator": "=",
50+
"value": "Steve"
5151
},
5252
{
53-
field: "lastName",
54-
operator: "=",
55-
value: "Vai"
53+
"field": "lastName",
54+
"operator": "=",
55+
"value": "Vai"
5656
}
5757
]
5858
}
@@ -70,19 +70,19 @@ parseSQL(`SELECT * FROM t WHERE lastName IN ('Vai', 'Vaughan') AND age BETWEEN 2
7070

7171
Output:
7272

73-
```ts
73+
```json
7474
{
75-
combinator: "and",
76-
rules: [
75+
"combinator": "and",
76+
"rules": [
7777
{
78-
field: "lastName",
79-
operator: "in",
80-
value: ["Vai", "Vaughan"]
78+
"field": "lastName",
79+
"operator": "in",
80+
"value": ["Vai", "Vaughan"]
8181
},
8282
{
83-
field: "age",
84-
operator: "between",
85-
value: [20, 100]
83+
"field": "age",
84+
"operator": "between",
85+
"value": [20, 100]
8686
}
8787
]
8888
}
@@ -100,21 +100,21 @@ parseSQL(`SELECT * FROM t WHERE firstName = 'Steve' AND lastName = 'Vai'`, {
100100

101101
Output (`RuleGroupTypeIC`):
102102

103-
```ts
103+
```json
104104
{
105-
rules: [
105+
"rules": [
106106
{
107-
field: 'firstName',
108-
operator: '=',
109-
value: 'Steve',
107+
"field": "firstName",
108+
"operator": "=",
109+
"value": "Steve"
110110
},
111-
'and',
111+
"and",
112112
{
113-
field: 'lastName',
114-
operator: '=',
115-
value: 'Vai',
116-
},
117-
];
113+
"field": "lastName",
114+
"operator": "=",
115+
"value": "Vai"
116+
}
117+
]
118118
}
119119
```
120120

@@ -136,17 +136,17 @@ parseSQL(`SELECT * FROM t WHERE firstName = lastName`, {
136136

137137
Output:
138138

139-
```ts
139+
```json
140140
{
141-
combinator: "and",
142-
rules: [
141+
"combinator": "and",
142+
"rules": [
143143
{
144-
field: "firstName",
145-
operator: "=",
146-
value: "lastName",
147-
valueSource: "field",
148-
},
149-
],
144+
"field": "firstName",
145+
"operator": "=",
146+
"value": "lastName",
147+
"valueSource": "field"
148+
}
149+
]
150150
}
151151
```
152152

docs/api/querybuilder.mdx

Lines changed: 58 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -588,69 +588,73 @@ interface Classnames {
588588

589589
This prop can be used to override translatable texts applied to various controls that are created by the `<QueryBuilder />` component. All keys in the object and all properties within each key are optional. Missing translations will default to the values below.
590590

591-
```ts
591+
```json
592592
{
593-
fields: {
594-
title: "Fields",
595-
placeholderLabel: "------",
596-
placeholderGroupLabel: "------",
593+
"fields": {
594+
"title": "Fields",
595+
"placeholderName": "~",
596+
"placeholderLabel": "------",
597+
"placeholderGroupLabel": "------"
597598
},
598-
operators: {
599-
title: "Operators",
599+
"operators": {
600+
"title": "Operators",
601+
"placeholderName": "~",
602+
"placeholderLabel": "------",
603+
"placeholderGroupLabel": "------"
600604
},
601-
value: {
602-
title: "Value",
605+
"value": {
606+
"title": "Value"
603607
},
604-
removeRule: {
605-
label: "x",
606-
title: "Remove rule",
608+
"removeRule": {
609+
"label": "x",
610+
"title": "Remove rule"
607611
},
608-
removeGroup: {
609-
label: "x",
610-
title: "Remove group",
612+
"removeGroup": {
613+
"label": "x",
614+
"title": "Remove group"
611615
},
612-
addRule: {
613-
label: "+Rule",
614-
title: "Add rule",
616+
"addRule": {
617+
"label": "+Rule",
618+
"title": "Add rule"
615619
},
616-
addGroup: {
617-
label: "+Group",
618-
title: "Add group",
620+
"addGroup": {
621+
"label": "+Group",
622+
"title": "Add group"
619623
},
620-
combinators: {
621-
title: "Combinators",
624+
"combinators": {
625+
"title": "Combinators"
622626
},
623-
notToggle: {
624-
label: "Not",
625-
title: "Invert this group",
627+
"notToggle": {
628+
"label": "Not",
629+
"title": "Invert this group"
626630
},
627-
cloneRule: {
628-
label: '',
629-
title: 'Clone rule'
631+
"cloneRule": {
632+
"label": "",
633+
"title": "Clone rule"
630634
},
631-
cloneRuleGroup: {
632-
label: '',
633-
title: 'Clone group'
635+
"cloneRuleGroup": {
636+
"label": "",
637+
"title": "Clone group"
634638
},
635-
dragHandle: {
636-
label: '⁞⁞',
637-
title: 'Drag handle'
639+
"dragHandle": {
640+
"label": "⁞⁞",
641+
"title": "Drag handle"
638642
},
639-
lockRule: {
640-
label: '🔓',
641-
title: 'Lock rule',
643+
"lockRule": {
644+
"label": "🔓",
645+
"title": "Lock rule"
642646
},
643-
lockGroup: {
644-
label: '🔓',
645-
title: 'Lock group',
647+
"lockGroup": {
648+
"label": "🔓",
649+
"title": "Lock group"
646650
},
647-
lockRuleDisabled: {
648-
label: '🔒',
649-
title: 'Unlock rule',
651+
"lockRuleDisabled": {
652+
"label": "🔒",
653+
"title": "Unlock rule"
650654
},
651-
lockGroupDisabled: {
652-
label: '🔒',
653-
title: 'Unlock group',
655+
"lockGroupDisabled": {
656+
"label": "🔒",
657+
"title": "Unlock group"
654658
}
655659
}
656660
```
@@ -699,7 +703,13 @@ Pass `false` to disable the `onQueryChange` call on mount of the component which
699703

700704
`boolean` (default `true`) [_Click for demo with this feature disabled_](https://react-querybuilder.js.org/react-querybuilder/#autoSelectField=false)
701705

702-
Pass `false` to automatically add an "empty" option with label `"------"` (or `translations.fields.placeholderLabel` if provided--see [translations](#translations)) to the `fields` array as the first element. The empty option will be the initial selection for all new rules. When the empty field option is selected, the operator and value components will not display for that rule.
706+
Pass `false` to automatically add an "empty" option with value `"~"` and label `"------"` (see [`translations.fields.placeholder*` to customize](#translations)) to the `fields` array as the first element. The empty option will be the initial selection for all new rules. When the empty field option is selected, the operator and value editor components will not display for that rule.
707+
708+
### `autoSelectOperator`
709+
710+
`boolean` (default `true`) [_Click for demo with this feature disabled_](https://react-querybuilder.js.org/react-querybuilder/#autoSelectOperator=false)
711+
712+
Pass `false` to automatically add an "empty" option with value `"~"` and label `"------"` (see [`translations.operators.placeholder*` to customize](#translations)) to the `operators` array as the first element. The empty option will be the initial selection for all new rules. When the empty operator option is selected, the value editor component will not display for that rule.
703713

704714
### `addRuleToNewGroups`
705715

docs/api/validation.mdx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Validating at the query level can result in the entire query being treated as va
1616
To mark an entire query as valid or invalid, return a `boolean` value from the `validator` callback function (`true` for valid, `false` for invalid).
1717

1818
```tsx
19-
import QueryBuilder, { RuleGroupType } from 'react-querybuilder';
19+
import { QueryBuilder, RuleGroupType } from 'react-querybuilder';
2020

2121
/**
2222
* This function returns false (indicating "invalid") if there are no rules present.
@@ -31,7 +31,7 @@ const App = () => {
3131
The alternate return value from a query-level validator is a validation map, which is an object where each key represents the `id` of a rule or group. Associated values are either `boolean` (`true` for valid, `false` for invalid) or a validation result. Validation results are objects with two keys: a required `boolean` `valid` key and an optional `reasons` array specifying why that rule/group is valid or invalid. (Reasons are assumed to be strings, but the type is `any[]` since the QueryBuilder default components ignore them. Feel free to use them any way you please in your custom components.)
3232

3333
```tsx
34-
import QueryBuilder, { RuleGroupType, ValidationMap } from 'react-querybuilder';
34+
import { QueryBuilder, RuleGroupType, ValidationMap } from 'react-querybuilder';
3535

3636
/**
3737
* This function returns a validation map. A real validator function would
@@ -67,7 +67,8 @@ Assigning a `validator` to individual fields allows you to provide a separate ca
6767
In the following configuration, any rule that specifies `field1` as the field (e.g. the second rule) will be marked invalid.
6868

6969
```tsx
70-
import QueryBuilder, {
70+
import {
71+
QueryBuilder,
7172
Field,
7273
RuleGroupType,
7374
RuleValidator,

0 commit comments

Comments
 (0)