-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add float field type for keystone-next #4907
Conversation
Based on integer field type with some modifications
🦋 Changeset detectedLatest commit: b02dd7b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/keystonejs/keystone-next-docs/2a2nZEJiiHNPS33gQDgCUQi9VcVA |
This all looks good to me, thanks for the PR @MurzNN 🙏 @mitchellhamilton Could you please review the Admin UI component and if you're happy with it, give this a ✅ Thanks! |
graphqlSelection: config.path, | ||
defaultValue: '', | ||
deserialize: data => (parseFloat(data[config.path]) || '') + '', | ||
serialize: value => ({ [config.path]: parseFloat(value.replace(',', '.')) || null }), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic should be identical to the logic in integer except it should call parseFloat
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this logic I wanted to add support for ,
as decimal separator together with .
, because it is popular in many countries
https://en.wikipedia.org/wiki/Decimal_separator#Countries_using_decimal_comma
So pasting something like 3,14159
should be converted to 3.14159
instead of 314159
or 3
.
But this is debatable change, so now let's keep the previous logic to merge this, I've reverted this line to integer logic.
Co-authored-by: Mitchell Hamilton <[email protected]>
I created a
float
field for Keystone-next, based on code from integer field type with some modifications. Please review it and comment if something done wrong.If all is done right, I will try to implement
double
field type via same way.How to test:
examples-next/basic/schema.ts
add the float field type, for example, to "Posts" list:Post: list({ fields: { ... + float: float(), ... } }),
Tested with mongoose and knex adapters.