Skip to content

Commit

Permalink
Fix integer select admin UI bugs (#5639)
Browse files Browse the repository at this point in the history
  • Loading branch information
timleslie authored May 7, 2021
1 parent 2b3efc8 commit 400d882
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/ninety-buckets-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/fields': patch
---

Fixed Admin UI issues when using `select` fields with `dataType: 'integer'`.
9 changes: 7 additions & 2 deletions packages-next/fields/src/types/select/views/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ export const controller = (
label: x.label,
value: x.value.toString(),
}));

// Transform from string value to dataType appropriate value
const t = (v: string | null) =>
v === null ? null : config.fieldMeta.dataType === 'integer' ? parseInt(v) : v;

return {
path: config.path,
label: config.label,
Expand All @@ -93,7 +98,7 @@ export const controller = (
}
return null;
},
serialize: value => ({ [config.path]: value?.value ?? null }),
serialize: value => ({ [config.path]: t(value?.value ?? null) }),
filter: {
Filter(props) {
return (
Expand Down Expand Up @@ -126,7 +131,7 @@ export const controller = (
key = `${config.path}_not`;
}

const value = isMulti ? options.map(x => x.value) : options[0].value;
const value = isMulti ? options.map(x => t(x.value)) : t(options[0].value);

return { [key]: value };
},
Expand Down

1 comment on commit 400d882

@vercel
Copy link

@vercel vercel bot commented on 400d882 May 7, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.