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
Support enums when scaffolding models to display values and generate form inputs #4395
Support enums when scaffolding models to display values and generate form inputs #4395
Conversation
packages/cli/src/commands/generate/scaffold/templates/components/NameForm.tsx.template
Show resolved
Hide resolved
packages/cli/src/commands/generate/scaffold/templates/components/Name.tsx.template
Outdated
Show resolved
Hide resolved
packages/cli/src/commands/generate/scaffold/templates/components/Names.tsx.template
Outdated
Show resolved
Hide resolved
packages/cli/src/commands/generate/scaffold/templates/components/NameForm.tsx.template
Outdated
Show resolved
Hide resolved
packages/cli/src/commands/generate/scaffold/templates/components/NameForm.tsx.template
Show resolved
Hide resolved
Per @cannikin improve the text and check label positioning (it's not centered). |
Also, I am using an ES2020 Intl method
I could addd ES2020 to TS but do we think @Tobbe that I should avoid this for browser compatibility? |
I could simply join with ',' and not make a sentence |
I thought about that when you first mentioned using ListFormat. We use a lot of the Intl stuff at work, but have to pollyfill the crap out of almost everything :( Not sure what minimum browser version a default RW app needs to support. Do we have any official guidelines on that? |
ffee0c2
to
f9f190d
Compare
For handling the enum is null to reset, optional lists are not supported: So, an "none" case for an option single enum is needed. But, 9 times out of 10 I'd never have an optional enum, but have one of the options be an empty case like NONE, or N_A. That way if you were to aggregate or count by enum you would never have to deal with nulls -- and counting nulls. |
Now supports an option single enum.
here the The form now adds a "None" radio option and sets to null on save thus unsetting the value to null. Now set ... and un-set to None ... and can see is not set Coercing is done in the onSubmit maybe can be done elsewhere? |
errorClassName="rw-input rw-input-error" | ||
/> | ||
<div> | ||
None |
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.
What do you think about adding some style to this to make it italic? That'd make None stand out a bit to show that it's a special value
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.
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.
Sure. Any other ideas? What about explaining it some more? "* None (will not set this value in the database)". Ideally something a bit shorter than that though 😅
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.
Maybe just "* Not set" is enough? Could also play around with text color to signify that it's a special value, like make it a bit muted maybe
I kept the italics. Let's use that and get feedback from team and community for now. @Tobbe Any items left to do? |
I like a subtle gray for my "empty" or "none" entries! |
I like your approach of getting it in, and then getting feedback. Such an easy thing to iterate on too! This is good to go now! I see you switched to gray for None. I like it as long as people don't mistake it for being disabled, so they don't even reallize they can click it 😬 . But, as said, let's do it, and see if we get any feedback! |
Well done. Looks great 🚀 |
…bundle * 'main' of github.com:redwoodjs/redwood: (324 commits) (render.com deployment) resolve deploy render exceeding memory on free tier (redwoodjs#4433) Update dependency @clerk/types to v1.25.0 (redwoodjs#4419) Update dependency esbuild to v0.14.21 (redwoodjs#4427) Update dependency @types/prettier to v2.4.4 (redwoodjs#4426) Update dependency @envelop/depth-limit to v1.2.3 (redwoodjs#4428) Support enums when scaffolding modes to display values and generate form inputs (redwoodjs#4395) Update dependency @clerk/clerk-js to v2.13.1 (redwoodjs#4418) Update jest monorepo to v27.5.1 (redwoodjs#4421) Update dependency @types/md5 to v2.3.2 (redwoodjs#4420) Polish release script (redwoodjs#4417) Update dependency @azure/msal-browser to v2.22.0 (redwoodjs#4414) Update dependency fastify-http-proxy to v6.2.2 (redwoodjs#4413) Roll back dependency @magic-sdk/admin to 1.3.4 (redwoodjs#4409) update yarn.lock Update typescript-eslint monorepo to v5.11.0 (redwoodjs#4412) v0.44.1 Downgrade Prisma to 3.8.1 (redwoodjs#4411) Downgrade Prisma to 3.8.1 (redwoodjs#4411) update yarn.lock fix(generators): Generate types after gen-ing files (redwoodjs#4376) ...
Fixes: #4384
Fixes #4383
Enums are a defined set values or can be a list of defined set values allowed a model's field.
For example, a
Spot
model can be:This means that a Spot needs to have a material, size, shape and type defined in those enums. It can also be set with multiple colors.
This PR displays enums in scaffold components, including forms to save the values.
Single enums are rendered as RadioFields and multiple lots of enums and CheckboxFields.
And and lists are displayed in words:
Ideally, the generated components would have cleaner markup, but I didn't want to create a lint option after scaffolding.