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
CTB: Improve UI validation for enum values #13717
Conversation
Co-authored-by: omacovei <omacovei@users.noreply.github.com>
Codecov Report
@@ Coverage Diff @@
## master #13717 +/- ##
==========================================
- Coverage 54.33% 48.72% -5.62%
==========================================
Files 1197 216 -981
Lines 30591 8464 -22127
Branches 5562 1916 -3646
==========================================
- Hits 16622 4124 -12498
+ Misses 12160 3563 -8597
+ Partials 1809 777 -1032
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
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.
Thanks for the change. It looks like we're also operating the doesNotStartWithANumber check in the content-type domain code.
Should we add some consistency between both the front & back validations?
@Convly I think it's a good idea! I've added the GraphQL enum check and another for empty values - duplicates are checked already. I've changed the empty values check from checking the raw values to checking the regressed values, as this is the behavior I want I think. Does that work for you? |
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.
Thanks for the update, I just have some questions
packages/core/content-type-builder/admin/src/translations/en.json
Outdated
Show resolved
Hide resolved
@@ -24,6 +24,9 @@ const LIFECYCLES = [ | |||
'afterDeleteMany', | |||
]; | |||
|
|||
// See GraphQL Spec https://spec.graphql.org/June2018/#sec-Names | |||
const GRAPHQL_ENUM_REGEX = new RegExp('^[_A-Za-z][_0-9A-Za-z]*$'); |
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 it's better if we're talking about the enum regexp instead?
I would prefer we avoid coupling/referencing GraphQL to core code
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.
I agree, but on the other hand the coupling with GraphQL is the reason why need to this. Therefore I'd prefer to explicit here and to explain why ...
Would it help if I expand on the comment?
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.
Yep might be a good idea to explain a bit more why we're referencing GraphQL here?
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.
Ah the good old chicken 🐓 vs egg 🥚 issue.
Please let me know when this one is merged so that I can merge documentation PR #984 😊 — if it's still worth it. |
@pwizla I will. Doing my best to get this one merged, so that we do not have to introduce the disclaimer :) |
packages/core/content-type-builder/admin/src/components/FormModal/attributes/types.js
Show resolved
Hide resolved
packages/core/content-type-builder/admin/src/translations/en.json
Outdated
Show resolved
Hide resolved
packages/core/content-type-builder/admin/src/translations/en.json
Outdated
Show resolved
Hide resolved
3e19092
to
2f2f975
Compare
Co-authored-by: Pierre Noël <petersg83@users.noreply.github.com>
2f2f975
to
6d26ff5
Compare
Co-authored-by: Pierre Noel <pierre.noel@strapi.io>
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.
LGTM :)
What does it do?
Builds on top of #13503, to improve the enum values validation in the admin UI. Instead of testing each value directly this PR tests the
regressed
value. This will allow more values and only fail on the ones that GraphQL can not deal with.Why is it needed?
It helps to prevent crashing Strapi at the bootstrap phase, after a new invalid value has been added to an enum field in the admin UI.
How to test it?
--1
)Related issue(s)/PR(s)