Skip to content

Commit 166dafe

Browse files
fix(ui): filtering on hasMany fields (#12579)
1 parent 68ba24d commit 166dafe

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

packages/ui/src/elements/WhereBuilder/field-types.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use client'
2-
const boolean = [
2+
const equalsOperators = [
33
{
44
label: 'equals',
55
value: 'equals',
@@ -10,8 +10,7 @@ const boolean = [
1010
},
1111
]
1212

13-
const base = [
14-
...boolean,
13+
export const arrayOperators = [
1514
{
1615
label: 'isIn',
1716
value: 'in',
@@ -26,6 +25,8 @@ const base = [
2625
},
2726
]
2827

28+
const base = [...equalsOperators, ...arrayOperators]
29+
2930
const numeric = [
3031
...base,
3132
{
@@ -47,7 +48,7 @@ const numeric = [
4748
]
4849

4950
const geo = [
50-
...boolean,
51+
...equalsOperators,
5152
{
5253
label: 'exists',
5354
value: 'exists',
@@ -91,7 +92,7 @@ const fieldTypeConditions: {
9192
} = {
9293
checkbox: {
9394
component: 'Text',
94-
operators: boolean,
95+
operators: equalsOperators,
9596
},
9697
code: {
9798
component: 'Text',

packages/ui/src/elements/WhereBuilder/reduceFields.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type { ReducedField } from './types.js'
1010

1111
import { createNestedClientFieldPath } from '../../forms/Form/createNestedClientFieldPath.js'
1212
import { combineFieldLabel } from '../../utilities/combineFieldLabel.js'
13-
import fieldTypes from './field-types.js'
13+
import fieldTypes, { arrayOperators } from './field-types.js'
1414

1515
type ReduceFieldOptionsArgs = {
1616
fields: ClientField[]
@@ -170,7 +170,10 @@ export const reduceFields = ({
170170
if (typeof fieldTypes[field.type] === 'object') {
171171
const operatorKeys = new Set()
172172

173-
const operators = fieldTypes[field.type].operators.reduce((acc, operator) => {
173+
const fieldOperators =
174+
'hasMany' in field && field.hasMany ? arrayOperators : fieldTypes[field.type].operators
175+
176+
const operators = fieldOperators.reduce((acc, operator) => {
174177
if (!operatorKeys.has(operator.value)) {
175178
operatorKeys.add(operator.value)
176179
const operatorKey = `operators:${operator.label}` as ClientTranslationKeys

0 commit comments

Comments
 (0)