Skip to content
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

Fixes in and not_in filter views for integer, bigInt, decimal and float fields #7930

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/thirty-grapes-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-6/core': patch
---

Fix `in` and `not_in` filter views for `integer`, `bigInt`, `decimal` and `float` fields
21 changes: 10 additions & 11 deletions packages/core/src/fields/types/bigInt/views/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,19 +227,18 @@ export const controller = (
validate: value =>
validate(value, validation, config.label, hasAutoIncrementDefault) === undefined,
filter: {
Filter(props) {
Filter({ autoFocus, type, onChange, value }) {
return (
<TextInput
// this should not be type=number since it shoud allow commas so the one of/not one of
// filters work but really the whole filtering UI needs to be fixed and just removing type=number
// while doing nothing else would probably make it worse since anything would be allowed in the input
// so when a user applies the filter, the query would return an error
type="number"
onChange={event => {
props.onChange(event.target.value.replace(/[^\d,\s-]/g, ''));
if (type === 'in' || type === 'not_in') {
onChange(event.target.value.replace(/[^\d,\s-]/g, ''));
return;
}
onChange(event.target.value.replace(/[^\d\s-]/g, ''));
}}
value={props.value}
autoFocus={props.autoFocus}
value={value}
autoFocus={autoFocus}
/>
);
},
Expand All @@ -248,8 +247,8 @@ export const controller = (
const valueWithoutWhitespace = value.replace(/\s/g, '');
const parsed =
type === 'in' || type === 'not_in'
? valueWithoutWhitespace.split(',').map(x => BigInt(x))
: BigInt(valueWithoutWhitespace);
? valueWithoutWhitespace.split(',')
: valueWithoutWhitespace;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes a JSON serialization error

if (type === 'not') {
return { [config.path]: { not: { equals: parsed } } };
}
Expand Down
13 changes: 9 additions & 4 deletions packages/core/src/fields/types/decimal/views/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,19 @@ export const controller = (
}),
validate: val => validate(val, validation, config.label) === undefined,
filter: {
Filter(props) {
Filter({ autoFocus, type, onChange, value }) {
return (
<TextInput
onChange={event => {
props.onChange(event.target.value.replace(/[^\d\.,\s-]/g, ''));
if (type === 'in' || type === 'not_in') {
onChange(event.target.value.replace(/[^\d,\s-]/g, ''));
return;
}

onChange(event.target.value.replace(/[^\d\s-]/g, ''));
}}
value={props.value}
autoFocus={props.autoFocus}
value={value}
autoFocus={autoFocus}
/>
);
},
Expand Down
12 changes: 8 additions & 4 deletions packages/core/src/fields/types/float/views/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,18 @@ export const controller = (
serialize: value => ({ [config.path]: value.value }),
validate: value => validate(value, config.fieldMeta.validation, config.label) === undefined,
filter: {
Filter(props) {
Filter({ autoFocus, type, onChange, value }) {
return (
<TextInput
onChange={event => {
props.onChange(event.target.value.replace(/[^\d\.,\s-]/g, ''));
if (type === 'in' || type === 'not_in') {
onChange(event.target.value.replace(/[^\d\.,\s-]/g, ''));
return;
}
onChange(event.target.value.replace(/[^\d\.\s-]/g, ''));
}}
value={props.value}
autoFocus={props.autoFocus}
value={value}
autoFocus={autoFocus}
/>
);
},
Expand Down
19 changes: 10 additions & 9 deletions packages/core/src/fields/types/integer/views/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,19 +207,20 @@ export const controller = (
config.fieldMeta.defaultValue === 'autoincrement'
) === undefined,
filter: {
Filter(props) {
Filter({ autoFocus, type, onChange, value }) {
return (
<TextInput
// this should not be type=number since it shoud allow commas so the one of/not one of
// filters work but really the whole filtering UI needs to be fixed and just removing type=number
// while doing nothing else would probably make it worse since anything would be allowed in the input
// so when a user applies the filter, the query would return an error
type="number"
type="text"
onChange={event => {
props.onChange(event.target.value.replace(/[^\d,\s-]/g, ''));
if (type === 'in' || type === 'not_in') {
onChange(event.target.value.replace(/[^\d,\s-]/g, ''));
return;
}

onChange(event.target.value.replace(/[^\d\s-]/g, ''));
}}
value={props.value}
autoFocus={props.autoFocus}
value={value}
autoFocus={autoFocus}
/>
);
},
Expand Down