mirror of
https://github.com/strapi/strapi.git
synced 2025-12-27 15:13:21 +00:00
Fix component category edition and allow icon with hyphen in the name
This commit is contained in:
parent
0ab7ffd3c3
commit
e8078c1ee9
@ -17,23 +17,30 @@ const validators = {
|
||||
|
||||
const NAME_REGEX = new RegExp('^[A-Za-z][_0-9A-Za-z]*$');
|
||||
const ENUM_REGEX = new RegExp('^[_A-Za-z][_0-9A-Za-z]*$');
|
||||
const ICON_REGEX = new RegExp('^[A-Za-z0-9][-A-Za-z0-9]*$');
|
||||
|
||||
const isValidName = {
|
||||
name: 'isValidName',
|
||||
message: '${path} must match the following regex: /^[A-Za-z][_0-9A-Za-z]*$/^',
|
||||
message: '${path} must match the following regex: /^[A-Za-z][_0-9A-Za-z]*$/',
|
||||
test: val => val === '' || NAME_REGEX.test(val),
|
||||
};
|
||||
|
||||
const isValidIcon = {
|
||||
name: 'isValidIcon',
|
||||
message:
|
||||
'${path} must match the following regex: /^[A-Za-z0-9][-A-Za-z0-9]*$/',
|
||||
test: val => val === '' || ICON_REGEX.test(val),
|
||||
};
|
||||
|
||||
const isValidKey = key => ({
|
||||
name: 'isValidKey',
|
||||
message: `Attribute name '${key}' must match the following regex: /^[A-Za-z][_0-9A-Za-z]*$/^`,
|
||||
message: `Attribute name '${key}' must match the following regex: /^[A-Za-z][_0-9A-Za-z]*$/`,
|
||||
test: () => NAME_REGEX.test(key),
|
||||
});
|
||||
|
||||
const isValidEnum = {
|
||||
name: 'isValidEnum',
|
||||
message:
|
||||
'${path} must match the following regex: /^[_A-Za-z][_0-9A-Za-z]*$/^',
|
||||
message: '${path} must match the following regex: /^[_A-Za-z][_0-9A-Za-z]*$/',
|
||||
test: val => val === '' || ENUM_REGEX.test(val),
|
||||
};
|
||||
|
||||
@ -41,6 +48,7 @@ module.exports = {
|
||||
validators,
|
||||
|
||||
isValidName,
|
||||
isValidIcon,
|
||||
isValidKey,
|
||||
isValidEnum,
|
||||
};
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
const _ = require('lodash');
|
||||
const yup = require('yup');
|
||||
|
||||
const { isValidName } = require('./common');
|
||||
const { isValidName, isValidIcon } = require('./common');
|
||||
const formatYupErrors = require('./yup-formatter');
|
||||
const createSchema = require('./model-schema');
|
||||
const { modelTypes } = require('./constants');
|
||||
@ -39,7 +39,7 @@ const componentSchema = createSchema(VALID_TYPES, VALID_RELATIONS, {
|
||||
icon: yup
|
||||
.string()
|
||||
.nullable()
|
||||
.test(isValidName)
|
||||
.test(isValidIcon)
|
||||
.required('icon.required'),
|
||||
category: yup
|
||||
.string()
|
||||
|
||||
@ -31,6 +31,9 @@ const editCategory = async (name, infos) => {
|
||||
const oldUID = component.uid;
|
||||
const newUID = `${newName}.${component.modelName}`;
|
||||
|
||||
// only edit the components in this specific category
|
||||
if (component.category !== name) return;
|
||||
|
||||
component.setUID(newUID).setDir(join(componentsDir, newName));
|
||||
|
||||
builder.components.forEach(compo => {
|
||||
@ -60,7 +63,7 @@ const deleteCategory = async name => {
|
||||
|
||||
builder.components.forEach(component => {
|
||||
if (component.category === name) {
|
||||
return component.delete();
|
||||
builder.deleteComponent(component.uid);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@ -155,8 +155,8 @@ module.exports = function createSchemaHandler(infos) {
|
||||
Array.isArray(attr.components) &&
|
||||
attr.components.includes(uid)
|
||||
) {
|
||||
const updatedComponentList = attributes[key].components.map(val =>
|
||||
val === uid ? newUID : uid
|
||||
const updatedComponentList = attr.components.map(val =>
|
||||
val === uid ? newUID : val
|
||||
);
|
||||
|
||||
this.set(['attributes', key, 'components'], updatedComponentList);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user