@akemona-org/strapi-plugin-content-type-builder 3.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +19 -0
- package/admin/src/InjectedComponents/ContentManager/EditSettingViewButton.js +76 -0
- package/admin/src/InjectedComponents/ContentManager/EditViewLink.js +44 -0
- package/admin/src/assets/images/logo.svg +1 -0
- package/admin/src/components/AllowedTypesSelect/MenuList.js +115 -0
- package/admin/src/components/AllowedTypesSelect/Text.js +26 -0
- package/admin/src/components/AllowedTypesSelect/index.js +55 -0
- package/admin/src/components/AttributeOption/Button.js +50 -0
- package/admin/src/components/AttributeOption/Card.js +26 -0
- package/admin/src/components/AttributeOption/index.js +127 -0
- package/admin/src/components/BooleanBox/CT.js +21 -0
- package/admin/src/components/BooleanBox/Enumeration.js +10 -0
- package/admin/src/components/BooleanBox/EnumerationWrapper.js +14 -0
- package/admin/src/components/BooleanBox/Label.js +9 -0
- package/admin/src/components/BooleanBox/ST.js +21 -0
- package/admin/src/components/BooleanBox/Wrapper.js +75 -0
- package/admin/src/components/BooleanBox/icons/CTSelected.js +136 -0
- package/admin/src/components/BooleanBox/icons/CTUnselected.js +136 -0
- package/admin/src/components/BooleanBox/icons/STSelected.js +80 -0
- package/admin/src/components/BooleanBox/icons/STUnselected.js +76 -0
- package/admin/src/components/BooleanBox/index.js +103 -0
- package/admin/src/components/CheckboxWithDescription/Wrapper.js +12 -0
- package/admin/src/components/CheckboxWithDescription/index.js +40 -0
- package/admin/src/components/ComponentCard/Close.js +12 -0
- package/admin/src/components/ComponentCard/Wrapper.js +84 -0
- package/admin/src/components/ComponentCard/index.js +62 -0
- package/admin/src/components/ComponentIconPicker/Cell.js +40 -0
- package/admin/src/components/ComponentIconPicker/CellRenderer.js +36 -0
- package/admin/src/components/ComponentIconPicker/Search.js +12 -0
- package/admin/src/components/ComponentIconPicker/SearchWrapper.js +34 -0
- package/admin/src/components/ComponentIconPicker/Wrapper.js +60 -0
- package/admin/src/components/ComponentIconPicker/index.js +143 -0
- package/admin/src/components/ComponentList/index.js +78 -0
- package/admin/src/components/ComponentSelect/Category.js +20 -0
- package/admin/src/components/ComponentSelect/CategoryName.js +11 -0
- package/admin/src/components/ComponentSelect/MenuList.js +110 -0
- package/admin/src/components/ComponentSelect/MultipleMenuList.js +271 -0
- package/admin/src/components/ComponentSelect/Value.js +83 -0
- package/admin/src/components/ComponentSelect/index.js +83 -0
- package/admin/src/components/ComponentSelect/utils/HasSomeSubArray.js +5 -0
- package/admin/src/components/ComponentSelect/utils/hasSubArray.js +5 -0
- package/admin/src/components/CreatableSelect/index.js +58 -0
- package/admin/src/components/CustomCheckbox/StyledCustomCheckbox.js +25 -0
- package/admin/src/components/CustomCheckbox/index.js +71 -0
- package/admin/src/components/CustomLink/P.js +17 -0
- package/admin/src/components/CustomLink/StyledCustomLink.js +20 -0
- package/admin/src/components/CustomLink/index.js +31 -0
- package/admin/src/components/DynamicZoneList/ComponentButton.js +39 -0
- package/admin/src/components/DynamicZoneList/index.js +124 -0
- package/admin/src/components/HeaderModalNavContainer/index.js +25 -0
- package/admin/src/components/HeaderNavLink/Wrapper.js +21 -0
- package/admin/src/components/HeaderNavLink/index.js +50 -0
- package/admin/src/components/List/List.js +131 -0
- package/admin/src/components/List/index.js +295 -0
- package/admin/src/components/ListButton/index.js +9 -0
- package/admin/src/components/ListHeader/Title.js +19 -0
- package/admin/src/components/ListHeader/Wrapper.js +24 -0
- package/admin/src/components/ListHeader/index.js +37 -0
- package/admin/src/components/ListRow/Wrapper.js +76 -0
- package/admin/src/components/ListRow/index.js +334 -0
- package/admin/src/components/ModalHeader/ComponentIcon.js +21 -0
- package/admin/src/components/ModalHeader/ComponentInfos.js +22 -0
- package/admin/src/components/ModalHeader/ComponentInfosWrapper.js +9 -0
- package/admin/src/components/ModalHeader/DropdownInfos.js +50 -0
- package/admin/src/components/ModalHeader/Icon.js +26 -0
- package/admin/src/components/ModalHeader/IconWrapper.js +11 -0
- package/admin/src/components/ModalHeader/Item.js +19 -0
- package/admin/src/components/ModalHeader/Menu.js +8 -0
- package/admin/src/components/ModalHeader/Toggle.js +14 -0
- package/admin/src/components/ModalHeader/Wrapper.js +12 -0
- package/admin/src/components/ModalHeader/index.js +105 -0
- package/admin/src/components/RelationForm/Wrapper.js +9 -0
- package/admin/src/components/RelationForm/index.js +66 -0
- package/admin/src/components/RelationFormBox/Wrapper.js +34 -0
- package/admin/src/components/RelationFormBox/index.js +85 -0
- package/admin/src/components/RelationFormNaturePicker/Wrapper.js +53 -0
- package/admin/src/components/RelationFormNaturePicker/index.js +112 -0
- package/admin/src/components/RelationTargetPicker/Item.js +62 -0
- package/admin/src/components/RelationTargetPicker/Wrapper.js +89 -0
- package/admin/src/components/RelationTargetPicker/index.js +88 -0
- package/admin/src/components/SelectCheckbox/index.js +8 -0
- package/admin/src/components/SelectMenuSubUl/ToggleUl.js +23 -0
- package/admin/src/components/SelectMenuSubUl/index.js +23 -0
- package/admin/src/components/SelectMenuUl/index.js +66 -0
- package/admin/src/components/Td/index.js +37 -0
- package/admin/src/components/UpperFirst/index.js +14 -0
- package/admin/src/components/WrapperSelect/index.js +89 -0
- package/admin/src/containers/App/Wrapper.js +14 -0
- package/admin/src/containers/App/index.js +39 -0
- package/admin/src/containers/App/utils/icons.json +962 -0
- package/admin/src/containers/DataManagerProvider/constants.js +15 -0
- package/admin/src/containers/DataManagerProvider/index.js +610 -0
- package/admin/src/containers/DataManagerProvider/reducer.js +461 -0
- package/admin/src/containers/DataManagerProvider/selectors.js +25 -0
- package/admin/src/containers/DataManagerProvider/utils/cleanData.js +167 -0
- package/admin/src/containers/DataManagerProvider/utils/createDataObject.js +8 -0
- package/admin/src/containers/DataManagerProvider/utils/createModifiedDataSchema.js +91 -0
- package/admin/src/containers/DataManagerProvider/utils/retrieveComponentsFromSchema.js +55 -0
- package/admin/src/containers/DataManagerProvider/utils/retrieveComponentsThatHaveComponents.js +35 -0
- package/admin/src/containers/DataManagerProvider/utils/retrieveNestedComponents.js +34 -0
- package/admin/src/containers/DataManagerProvider/utils/retrieveSpecificInfoFromComponents.js +12 -0
- package/admin/src/containers/FormModal/CustomButton.js +12 -0
- package/admin/src/containers/FormModal/attributes/advancedForm.js +269 -0
- package/admin/src/containers/FormModal/attributes/attributeOptions.js +99 -0
- package/admin/src/containers/FormModal/attributes/baseForm.js +322 -0
- package/admin/src/containers/FormModal/attributes/commonBaseForm.js +7 -0
- package/admin/src/containers/FormModal/attributes/form.js +9 -0
- package/admin/src/containers/FormModal/attributes/index.js +4 -0
- package/admin/src/containers/FormModal/attributes/nameField.js +19 -0
- package/admin/src/containers/FormModal/attributes/types.js +309 -0
- package/admin/src/containers/FormModal/attributes/uiHelpers.js +11 -0
- package/admin/src/containers/FormModal/attributes/validation/common.js +151 -0
- package/admin/src/containers/FormModal/category/createCategorySchema.js +28 -0
- package/admin/src/containers/FormModal/category/form.js +27 -0
- package/admin/src/containers/FormModal/category/index.js +3 -0
- package/admin/src/containers/FormModal/category/regex.js +3 -0
- package/admin/src/containers/FormModal/component/componentField.js +25 -0
- package/admin/src/containers/FormModal/component/createComponentSchema.js +49 -0
- package/admin/src/containers/FormModal/component/form.js +67 -0
- package/admin/src/containers/FormModal/component/index.js +4 -0
- package/admin/src/containers/FormModal/constants.js +11 -0
- package/admin/src/containers/FormModal/contentType/createContentTypeSchema.js +44 -0
- package/admin/src/containers/FormModal/contentType/form.js +116 -0
- package/admin/src/containers/FormModal/contentType/index.js +2 -0
- package/admin/src/containers/FormModal/dynamicZone/form.js +45 -0
- package/admin/src/containers/FormModal/dynamicZone/index.js +2 -0
- package/admin/src/containers/FormModal/forms/index.js +164 -0
- package/admin/src/containers/FormModal/index.js +1552 -0
- package/admin/src/containers/FormModal/reducer.js +293 -0
- package/admin/src/containers/FormModal/selectors.js +24 -0
- package/admin/src/containers/FormModal/utils/canEditContentType.js +19 -0
- package/admin/src/containers/FormModal/utils/createHeadersArray.js +37 -0
- package/admin/src/containers/FormModal/utils/createHeadersObjectFromArray.js +27 -0
- package/admin/src/containers/FormModal/utils/createUid.js +17 -0
- package/admin/src/containers/FormModal/utils/getAttributesToDisplay.js +35 -0
- package/admin/src/containers/FormModal/utils/getModalTitleSubHeader.js +25 -0
- package/admin/src/containers/FormModal/utils/getNextSearch.js +17 -0
- package/admin/src/containers/FormModal/utils/index.js +6 -0
- package/admin/src/containers/FormModal/utils/relations.js +9 -0
- package/admin/src/containers/FormModal/utils/staticData.js +43 -0
- package/admin/src/containers/Initializer/index.js +26 -0
- package/admin/src/containers/LeftMenu/Wrapper.js +14 -0
- package/admin/src/containers/LeftMenu/index.js +220 -0
- package/admin/src/containers/ListView/Wrapper.js +16 -0
- package/admin/src/containers/ListView/index.js +322 -0
- package/admin/src/containers/NotFoundPage/index.js +20 -0
- package/admin/src/containers/RecursivePath/index.js +22 -0
- package/admin/src/contexts/DataManagerContext.js +5 -0
- package/admin/src/contexts/ListViewContext.js +5 -0
- package/admin/src/hooks/useDataManager.js +6 -0
- package/admin/src/hooks/useListView.js +6 -0
- package/admin/src/icons/Curve.js +26 -0
- package/admin/src/icons/ManyToMany.js +98 -0
- package/admin/src/icons/ManyToOne.js +64 -0
- package/admin/src/icons/ManyWay.js +36 -0
- package/admin/src/icons/OneToMany.js +65 -0
- package/admin/src/icons/OneToOne.js +47 -0
- package/admin/src/icons/OneWay.js +38 -0
- package/admin/src/index.js +83 -0
- package/admin/src/lifecycles.js +13 -0
- package/admin/src/permissions.js +9 -0
- package/admin/src/pluginId.js +5 -0
- package/admin/src/reducers.js +10 -0
- package/admin/src/translations/ar.json +48 -0
- package/admin/src/translations/cs.json +151 -0
- package/admin/src/translations/de.json +187 -0
- package/admin/src/translations/dk.json +181 -0
- package/admin/src/translations/en.json +188 -0
- package/admin/src/translations/es.json +188 -0
- package/admin/src/translations/fr.json +87 -0
- package/admin/src/translations/id.json +187 -0
- package/admin/src/translations/index.js +51 -0
- package/admin/src/translations/it.json +187 -0
- package/admin/src/translations/ja.json +50 -0
- package/admin/src/translations/ko.json +57 -0
- package/admin/src/translations/ms.json +179 -0
- package/admin/src/translations/nl.json +171 -0
- package/admin/src/translations/pl.json +152 -0
- package/admin/src/translations/pt-BR.json +51 -0
- package/admin/src/translations/pt.json +51 -0
- package/admin/src/translations/ru.json +188 -0
- package/admin/src/translations/sk.json +186 -0
- package/admin/src/translations/th.json +181 -0
- package/admin/src/translations/tr.json +51 -0
- package/admin/src/translations/uk.json +180 -0
- package/admin/src/translations/zh-Hans.json +188 -0
- package/admin/src/translations/zh.json +178 -0
- package/admin/src/utils/convertAttrObjToArray.js +7 -0
- package/admin/src/utils/formAPI.js +112 -0
- package/admin/src/utils/getAttributeDisplayedType.js +31 -0
- package/admin/src/utils/getComponents.js +31 -0
- package/admin/src/utils/getTrad.js +5 -0
- package/admin/src/utils/makeSearch.js +15 -0
- package/admin/src/utils/makeUnique.js +3 -0
- package/config/functions/bootstrap.js +14 -0
- package/config/routes.json +144 -0
- package/controllers/Builder.js +7 -0
- package/controllers/ComponentCategories.js +43 -0
- package/controllers/Components.js +152 -0
- package/controllers/Connections.js +9 -0
- package/controllers/ContentTypes.js +143 -0
- package/controllers/validation/common.js +118 -0
- package/controllers/validation/component-category.js +21 -0
- package/controllers/validation/component.js +89 -0
- package/controllers/validation/content-type.js +161 -0
- package/controllers/validation/data-transform.js +32 -0
- package/controllers/validation/model-schema.js +91 -0
- package/controllers/validation/relations.js +56 -0
- package/controllers/validation/types.js +277 -0
- package/package.json +63 -0
- package/services/Builder.js +7 -0
- package/services/ComponentCategories.js +88 -0
- package/services/Components.js +103 -0
- package/services/ContentTypes.js +263 -0
- package/services/api-handler.js +158 -0
- package/services/constants.js +59 -0
- package/services/schema-builder/component-builder.js +137 -0
- package/services/schema-builder/content-type-builder.js +256 -0
- package/services/schema-builder/index.js +196 -0
- package/services/schema-builder/schema-handler.js +297 -0
- package/utils/attributes.js +154 -0
- package/utils/helpers.js +31 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import * as yup from 'yup';
|
|
2
|
+
import { get, toNumber } from 'lodash';
|
|
3
|
+
import { translatedErrors as errorsTrads } from 'strapi-helper-plugin';
|
|
4
|
+
import getTrad from '../../../../utils/getTrad';
|
|
5
|
+
|
|
6
|
+
const NAME_REGEX = new RegExp('^[A-Za-z][_0-9A-Za-z]*$');
|
|
7
|
+
|
|
8
|
+
const alreadyUsedAttributeNames = usedNames => {
|
|
9
|
+
return {
|
|
10
|
+
name: 'attributeNameAlreadyUsed',
|
|
11
|
+
message: errorsTrads.unique,
|
|
12
|
+
test: value => {
|
|
13
|
+
if (!value) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return !usedNames.includes(value);
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const getUsedContentTypeAttributeNames = (ctShema, isEdition, attributeNameToEdit) => {
|
|
23
|
+
const attributes = get(ctShema, ['schema', 'attributes'], {});
|
|
24
|
+
|
|
25
|
+
return Object.keys(attributes).filter(attr => {
|
|
26
|
+
if (isEdition) {
|
|
27
|
+
return attr !== attributeNameToEdit;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return true;
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const isNameAllowed = reservedNames => {
|
|
35
|
+
return {
|
|
36
|
+
name: 'forbiddenAttributeName',
|
|
37
|
+
message: getTrad('error.attributeName.reserved-name'),
|
|
38
|
+
test: value => {
|
|
39
|
+
if (!value) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return !reservedNames.includes(value);
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const validators = {
|
|
49
|
+
default: () => yup.string().nullable(),
|
|
50
|
+
max: () =>
|
|
51
|
+
yup
|
|
52
|
+
.number()
|
|
53
|
+
.integer()
|
|
54
|
+
.nullable(),
|
|
55
|
+
min: () =>
|
|
56
|
+
yup
|
|
57
|
+
.number()
|
|
58
|
+
.integer()
|
|
59
|
+
.when('max', (max, schema) => {
|
|
60
|
+
if (max) {
|
|
61
|
+
return schema.max(max, getTrad('error.validation.minSupMax'));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return schema;
|
|
65
|
+
})
|
|
66
|
+
.nullable(),
|
|
67
|
+
maxLength: () =>
|
|
68
|
+
yup
|
|
69
|
+
.number()
|
|
70
|
+
.integer()
|
|
71
|
+
.nullable(),
|
|
72
|
+
minLength: () =>
|
|
73
|
+
yup
|
|
74
|
+
.number()
|
|
75
|
+
.integer()
|
|
76
|
+
.when('maxLength', (maxLength, schema) => {
|
|
77
|
+
if (maxLength) {
|
|
78
|
+
return schema.max(maxLength, getTrad('error.validation.minSupMax'));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return schema;
|
|
82
|
+
})
|
|
83
|
+
.nullable(),
|
|
84
|
+
name: (usedNames, reservedNames) => {
|
|
85
|
+
return yup
|
|
86
|
+
.string()
|
|
87
|
+
.test(alreadyUsedAttributeNames(usedNames))
|
|
88
|
+
.test(isNameAllowed(reservedNames))
|
|
89
|
+
.matches(NAME_REGEX, errorsTrads.regex)
|
|
90
|
+
.required(errorsTrads.required);
|
|
91
|
+
},
|
|
92
|
+
required: () => yup.boolean(),
|
|
93
|
+
type: () => yup.string().required(errorsTrads.required),
|
|
94
|
+
unique: () => yup.boolean().nullable(),
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const createTextShape = (usedAttributeNames, reservedNames) => {
|
|
98
|
+
const shape = {
|
|
99
|
+
name: validators.name(usedAttributeNames, reservedNames),
|
|
100
|
+
type: validators.type(),
|
|
101
|
+
default: validators.default(),
|
|
102
|
+
unique: validators.unique(),
|
|
103
|
+
required: validators.required(),
|
|
104
|
+
maxLength: validators.maxLength(),
|
|
105
|
+
minLength: validators.minLength(),
|
|
106
|
+
regex: yup
|
|
107
|
+
.string()
|
|
108
|
+
.test({
|
|
109
|
+
name: 'isValidRegExpPattern',
|
|
110
|
+
message: getTrad('error.validation.regex'),
|
|
111
|
+
test: value => {
|
|
112
|
+
return new RegExp(value) !== null;
|
|
113
|
+
},
|
|
114
|
+
})
|
|
115
|
+
.nullable(),
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
return shape;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const isMinSuperiorThanMax = {
|
|
122
|
+
name: 'isMinSuperiorThanMax',
|
|
123
|
+
message: getTrad('error.validation.minSupMax'),
|
|
124
|
+
test(min) {
|
|
125
|
+
if (!min) {
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const { max } = this.parent;
|
|
130
|
+
|
|
131
|
+
if (!max) {
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (Number.isNaN(toNumber(min))) {
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return toNumber(max) >= toNumber(min);
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export {
|
|
144
|
+
alreadyUsedAttributeNames,
|
|
145
|
+
createTextShape,
|
|
146
|
+
getUsedContentTypeAttributeNames,
|
|
147
|
+
isMinSuperiorThanMax,
|
|
148
|
+
isNameAllowed,
|
|
149
|
+
validators,
|
|
150
|
+
NAME_REGEX,
|
|
151
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as yup from 'yup';
|
|
2
|
+
import { toLower } from 'lodash';
|
|
3
|
+
import { translatedErrors as errorsTrads } from 'strapi-helper-plugin';
|
|
4
|
+
import CATEGORY_NAME_REGEX from './regex';
|
|
5
|
+
|
|
6
|
+
const createCategorySchema = usedCategoryNames => {
|
|
7
|
+
const shape = {
|
|
8
|
+
name: yup
|
|
9
|
+
.string()
|
|
10
|
+
.matches(CATEGORY_NAME_REGEX, errorsTrads.regex)
|
|
11
|
+
.test({
|
|
12
|
+
name: 'nameNotAllowed',
|
|
13
|
+
message: errorsTrads.unique,
|
|
14
|
+
test: value => {
|
|
15
|
+
if (!value) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return !usedCategoryNames.includes(toLower(value));
|
|
20
|
+
},
|
|
21
|
+
})
|
|
22
|
+
.required(errorsTrads.required),
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return yup.object(shape);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default createCategorySchema;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import getTrad from '../../../utils/getTrad';
|
|
2
|
+
|
|
3
|
+
const form = {
|
|
4
|
+
base: {
|
|
5
|
+
items: [
|
|
6
|
+
[
|
|
7
|
+
{
|
|
8
|
+
autoFocus: true,
|
|
9
|
+
name: 'name',
|
|
10
|
+
type: 'text',
|
|
11
|
+
label: {
|
|
12
|
+
id: getTrad('modalForm.attribute.form.base.name'),
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
validations: {
|
|
16
|
+
required: true,
|
|
17
|
+
},
|
|
18
|
+
description: {
|
|
19
|
+
id: getTrad('modalForm.editCategory.base.name.description'),
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default form;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import getTrad from '../../../utils/getTrad';
|
|
2
|
+
|
|
3
|
+
const componentField = {
|
|
4
|
+
label: {
|
|
5
|
+
id: getTrad('modalForm.attribute.text.type-selection'),
|
|
6
|
+
},
|
|
7
|
+
name: 'createComponent',
|
|
8
|
+
type: 'booleanBox',
|
|
9
|
+
size: 12,
|
|
10
|
+
options: [
|
|
11
|
+
{
|
|
12
|
+
headerId: getTrad('form.attribute.component.option.create'),
|
|
13
|
+
descriptionId: getTrad('form.attribute.component.option.create.description'),
|
|
14
|
+
value: true,
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
headerId: getTrad('form.attribute.component.option.reuse-existing'),
|
|
18
|
+
descriptionId: getTrad('form.attribute.component.option.reuse-existing.description'),
|
|
19
|
+
value: false,
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
validations: {},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default componentField;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as yup from 'yup';
|
|
2
|
+
import { toLower, trim } from 'lodash';
|
|
3
|
+
import { translatedErrors as errorsTrads } from 'strapi-helper-plugin';
|
|
4
|
+
import getTrad from '../../../utils/getTrad';
|
|
5
|
+
import { createComponentUid } from '../utils/createUid';
|
|
6
|
+
import { CATEGORY_NAME_REGEX } from '../category';
|
|
7
|
+
|
|
8
|
+
const createComponentSchema = (usedComponentNames, reservedNames, category) => {
|
|
9
|
+
const shape = {
|
|
10
|
+
name: yup
|
|
11
|
+
.string()
|
|
12
|
+
.test({
|
|
13
|
+
name: 'nameAlreadyUsed',
|
|
14
|
+
message: errorsTrads.unique,
|
|
15
|
+
test: value => {
|
|
16
|
+
if (!value) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const name = createComponentUid(value, category);
|
|
21
|
+
|
|
22
|
+
return !usedComponentNames.includes(name);
|
|
23
|
+
},
|
|
24
|
+
})
|
|
25
|
+
.test({
|
|
26
|
+
name: 'nameNotAllowed',
|
|
27
|
+
message: getTrad('error.contentTypeName.reserved-name'),
|
|
28
|
+
test: value => {
|
|
29
|
+
if (!value) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return !reservedNames.includes(toLower(trim(value)));
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
.required(errorsTrads.required),
|
|
37
|
+
category: yup
|
|
38
|
+
.string()
|
|
39
|
+
.matches(CATEGORY_NAME_REGEX, errorsTrads.regex)
|
|
40
|
+
.required(errorsTrads.required),
|
|
41
|
+
|
|
42
|
+
icon: yup.string().required(errorsTrads.required),
|
|
43
|
+
collectionName: yup.string().nullable(),
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
return yup.object(shape);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export default createComponentSchema;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import getTrad from '../../../utils/getTrad';
|
|
2
|
+
|
|
3
|
+
const componentForm = {
|
|
4
|
+
base(prefix = '') {
|
|
5
|
+
const items = [
|
|
6
|
+
[
|
|
7
|
+
{
|
|
8
|
+
autoFocus: true,
|
|
9
|
+
name: `${prefix}name`,
|
|
10
|
+
type: 'text',
|
|
11
|
+
label: {
|
|
12
|
+
id: getTrad('modalForm.attribute.form.base.name'),
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
validations: {
|
|
16
|
+
required: true,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
autoFocus: true,
|
|
21
|
+
name: `${prefix}category`,
|
|
22
|
+
type: 'creatableSelect',
|
|
23
|
+
label: {
|
|
24
|
+
id: getTrad('modalForm.components.create-component.category.label'),
|
|
25
|
+
},
|
|
26
|
+
validations: {
|
|
27
|
+
required: true,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
[
|
|
32
|
+
{
|
|
33
|
+
name: `${prefix}icon`,
|
|
34
|
+
type: 'componentIconPicker',
|
|
35
|
+
size: 12,
|
|
36
|
+
label: {
|
|
37
|
+
id: getTrad('modalForm.components.icon.label'),
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
return items;
|
|
44
|
+
},
|
|
45
|
+
advanced(prefix = '') {
|
|
46
|
+
const items = [
|
|
47
|
+
[
|
|
48
|
+
{
|
|
49
|
+
autoFocus: true,
|
|
50
|
+
label: {
|
|
51
|
+
id: getTrad('contentType.collectionName.label'),
|
|
52
|
+
},
|
|
53
|
+
description: {
|
|
54
|
+
id: getTrad('contentType.collectionName.description'),
|
|
55
|
+
},
|
|
56
|
+
name: `${prefix}collectionName`,
|
|
57
|
+
type: 'text',
|
|
58
|
+
validations: {},
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
return items;
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export default componentForm;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const ADD_COMPONENTS_TO_DYNAMIC_ZONE = 'ContentTypeBuilder/FormModal/ADD_COMPONENTS_TO_DYNAMIC_ZONE';
|
|
2
|
+
export const ON_CHANGE = 'ContentTypeBuilder/FormModal/ON_CHANGE';
|
|
3
|
+
export const ON_CHANGE_ALLOWED_TYPE = 'ContentTypeBuilder/FormModal/ON_CHANGE_ALLOWED_TYPE';
|
|
4
|
+
export const RESET_PROPS = 'ContentTypeBuilder/FormModal/RESET_PROPS';
|
|
5
|
+
export const RESET_PROPS_AND_SET_FORM_FOR_ADDING_AN_EXISTING_COMPO = 'ContentTypeBuilder/FormModal/RESET_PROPS_AND_SET_FORM_FOR_ADDING_AN_EXISTING_COMPO';
|
|
6
|
+
export const RESET_PROPS_AND_SAVE_CURRENT_DATA = 'ContentTypeBuilder/FormModal/RESET_PROPS_AND_SAVE_CURRENT_DATA';
|
|
7
|
+
export const RESET_PROPS_AND_SET_THE_FORM_FOR_ADDING_A_COMPO_TO_A_DZ = 'ContentTypeBuilder/FormModal/RESET_PROPS_AND_SET_THE_FORM_FOR_ADDING_A_COMPO_TO_A_DZ';
|
|
8
|
+
export const SET_DATA_TO_EDIT = 'ContentTypeBuilder/FormModal/SET_DATA_TO_EDIT';
|
|
9
|
+
export const SET_ATTRIBUTE_DATA_SCHEMA = 'ContentTypeBuilder/FormModal/SET_ATTRIBUTE_DATA_SCHEMA';
|
|
10
|
+
export const SET_DYNAMIC_ZONE_DATA_SCHEMA = 'ContentTypeBuilder/FormModal/SET_DYNAMIC_ZONE_DATA_SCHEMA';
|
|
11
|
+
export const SET_ERRORS = 'ContentTypeBuilder/FormModal/SET_ERRORS';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as yup from 'yup';
|
|
2
|
+
import { toLower, trim } from 'lodash';
|
|
3
|
+
import { translatedErrors as errorsTrads } from 'strapi-helper-plugin';
|
|
4
|
+
import getTrad from '../../../utils/getTrad';
|
|
5
|
+
import { createUid } from '../utils/createUid';
|
|
6
|
+
|
|
7
|
+
const createContentTypeSchema = (usedContentTypeNames, reservedNames) => {
|
|
8
|
+
const shape = {
|
|
9
|
+
name: yup
|
|
10
|
+
.string()
|
|
11
|
+
.test({
|
|
12
|
+
name: 'nameAlreadyUsed',
|
|
13
|
+
message: errorsTrads.unique,
|
|
14
|
+
test: value => {
|
|
15
|
+
if (!value) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const name = createUid(value);
|
|
20
|
+
|
|
21
|
+
return !usedContentTypeNames.includes(name);
|
|
22
|
+
},
|
|
23
|
+
})
|
|
24
|
+
.test({
|
|
25
|
+
name: 'nameNotAllowed',
|
|
26
|
+
message: getTrad('error.contentTypeName.reserved-name'),
|
|
27
|
+
test: value => {
|
|
28
|
+
if (!value) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return !reservedNames.includes(toLower(trim(value)));
|
|
33
|
+
},
|
|
34
|
+
})
|
|
35
|
+
.required(errorsTrads.required),
|
|
36
|
+
collectionName: yup.string(),
|
|
37
|
+
draftAndPublish: yup.boolean(),
|
|
38
|
+
kind: yup.string().oneOf(['singleType', 'collectionType']),
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return yup.object(shape);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export default createContentTypeSchema;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import getTrad from '../../../utils/getTrad';
|
|
2
|
+
|
|
3
|
+
const nameField = {
|
|
4
|
+
autoFocus: true,
|
|
5
|
+
name: 'name',
|
|
6
|
+
type: 'text',
|
|
7
|
+
label: {
|
|
8
|
+
id: getTrad('contentType.displayName.label'),
|
|
9
|
+
},
|
|
10
|
+
validations: {
|
|
11
|
+
required: true,
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const forms = {
|
|
16
|
+
advanced: {
|
|
17
|
+
default: () => {
|
|
18
|
+
return {
|
|
19
|
+
items: [
|
|
20
|
+
[
|
|
21
|
+
{
|
|
22
|
+
type: 'dividerDraftPublish',
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
[
|
|
26
|
+
{
|
|
27
|
+
label: {
|
|
28
|
+
id: getTrad('contentType.draftAndPublish.label'),
|
|
29
|
+
},
|
|
30
|
+
description: {
|
|
31
|
+
id: getTrad('contentType.draftAndPublish.description'),
|
|
32
|
+
},
|
|
33
|
+
name: 'draftAndPublish',
|
|
34
|
+
type: 'bool',
|
|
35
|
+
validations: {},
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
[{ type: 'divider' }],
|
|
39
|
+
[
|
|
40
|
+
{
|
|
41
|
+
autoFocus: true,
|
|
42
|
+
label: {
|
|
43
|
+
id: getTrad('contentType.collectionName.label'),
|
|
44
|
+
},
|
|
45
|
+
description: {
|
|
46
|
+
id: getTrad('contentType.collectionName.description'),
|
|
47
|
+
},
|
|
48
|
+
name: 'collectionName',
|
|
49
|
+
type: 'text',
|
|
50
|
+
validations: {},
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
],
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
base: {
|
|
58
|
+
create: value => {
|
|
59
|
+
return {
|
|
60
|
+
items: [
|
|
61
|
+
[
|
|
62
|
+
nameField,
|
|
63
|
+
{
|
|
64
|
+
description: {
|
|
65
|
+
id: getTrad('contentType.UID.description'),
|
|
66
|
+
},
|
|
67
|
+
label: 'UID',
|
|
68
|
+
name: 'uid',
|
|
69
|
+
type: 'text',
|
|
70
|
+
readOnly: true,
|
|
71
|
+
disabled: true,
|
|
72
|
+
value,
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
],
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
edit: () => {
|
|
79
|
+
return {
|
|
80
|
+
items: [
|
|
81
|
+
[
|
|
82
|
+
nameField,
|
|
83
|
+
{
|
|
84
|
+
label: {
|
|
85
|
+
id: getTrad('modalForm.attribute.text.type-selection'),
|
|
86
|
+
},
|
|
87
|
+
name: 'kind',
|
|
88
|
+
type: 'booleanBox',
|
|
89
|
+
size: 12,
|
|
90
|
+
onChangeCallback: () =>
|
|
91
|
+
strapi.notification.toggle({
|
|
92
|
+
type: 'info',
|
|
93
|
+
message: { id: getTrad('contentType.kind.change.warning') },
|
|
94
|
+
}),
|
|
95
|
+
options: [
|
|
96
|
+
{
|
|
97
|
+
headerId: getTrad('menu.section.models.name.singular'),
|
|
98
|
+
descriptionId: getTrad('form.button.collection-type.description'),
|
|
99
|
+
value: 'collectionType',
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
headerId: getTrad('menu.section.single-types.name.singular'),
|
|
103
|
+
descriptionId: getTrad('form.button.single-type.description'),
|
|
104
|
+
value: 'singleType',
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
validations: {},
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
],
|
|
111
|
+
};
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export default forms;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import getTrad from '../../../utils/getTrad';
|
|
2
|
+
import { componentField, componentForm } from '../component';
|
|
3
|
+
|
|
4
|
+
const form = {
|
|
5
|
+
advanced: {
|
|
6
|
+
default: () => {
|
|
7
|
+
return {
|
|
8
|
+
items: componentForm.advanced('componentToCreate.'),
|
|
9
|
+
};
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
base: {
|
|
13
|
+
createComponent: () => {
|
|
14
|
+
return {
|
|
15
|
+
items: [
|
|
16
|
+
[componentField],
|
|
17
|
+
[{ type: 'spacer' }],
|
|
18
|
+
...componentForm.base('componentToCreate.'),
|
|
19
|
+
],
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
default: () => {
|
|
23
|
+
return {
|
|
24
|
+
items: [
|
|
25
|
+
[componentField],
|
|
26
|
+
[{ type: 'spacer' }],
|
|
27
|
+
[
|
|
28
|
+
{ type: 'pushRight', size: 6 },
|
|
29
|
+
{
|
|
30
|
+
name: 'components',
|
|
31
|
+
type: 'componentSelect',
|
|
32
|
+
label: {
|
|
33
|
+
id: getTrad('modalForm.attributes.select-components'),
|
|
34
|
+
},
|
|
35
|
+
isMultiple: true,
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
[{ type: 'spacer-small' }],
|
|
39
|
+
],
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export default form;
|