mirror of
https://github.com/strapi/strapi.git
synced 2025-11-25 14:41:15 +00:00
Synchronize empty values check between admin UI and server validation
This commit is contained in:
parent
2845ba1ec1
commit
8f0906d6af
@ -165,7 +165,7 @@ const types = {
|
|||||||
.test({
|
.test({
|
||||||
name: 'doesNotHaveEmptyValues',
|
name: 'doesNotHaveEmptyValues',
|
||||||
message: getTrad('error.validation.enum-empty-string'),
|
message: getTrad('error.validation.enum-empty-string'),
|
||||||
test: values => !values.some(val => val === ''),
|
test: values => !values.map(toRegressedEnumValue).some(val => val === ''),
|
||||||
})
|
})
|
||||||
.test({
|
.test({
|
||||||
name: 'doesMatchRegex',
|
name: 'doesMatchRegex',
|
||||||
|
|||||||
@ -57,20 +57,25 @@ const contentTypeSchemaValidator = yup.object().shape({
|
|||||||
for (const attrName in attributes) {
|
for (const attrName in attributes) {
|
||||||
const attr = attributes[attrName];
|
const attr = attributes[attrName];
|
||||||
if (attr.type === 'enumeration') {
|
if (attr.type === 'enumeration') {
|
||||||
|
const regressedValues = attr.enum.map(toRegressedEnumValue);
|
||||||
|
|
||||||
// should match the GraphQL regex
|
// should match the GraphQL regex
|
||||||
if (
|
if (!regressedValues.every(value => GRAPHQL_ENUM_REGEX.test(value))) {
|
||||||
!attr.enum.map(toRegressedEnumValue).every(value => GRAPHQL_ENUM_REGEX.test(value))
|
|
||||||
) {
|
|
||||||
const message = `Invalid enumervarion value. Values should always have an alphabetical character preceding any number. Update your enumeration '${attrName}'.`;
|
const message = `Invalid enumervarion value. Values should always have an alphabetical character preceding any number. Update your enumeration '${attrName}'.`;
|
||||||
|
|
||||||
return this.createError({ message });
|
return this.createError({ message });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// should not contain empty values
|
||||||
|
if (regressedValues.some(value => value === '')) {
|
||||||
|
return this.createError({
|
||||||
|
message: `At least one value of the enumeration '${attrName}' appears to be empty.`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// should not collide
|
// should not collide
|
||||||
const duplicates = _.uniq(
|
const duplicates = _.uniq(
|
||||||
attr.enum
|
regressedValues.filter((value, index, values) => values.indexOf(value) !== index)
|
||||||
.map(toRegressedEnumValue)
|
|
||||||
.filter((value, index, values) => values.indexOf(value) !== index)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (duplicates.length) {
|
if (duplicates.length) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user