@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,322 @@
|
|
|
1
|
+
import React, { Fragment } from 'react';
|
|
2
|
+
import { FormattedMessage } from 'react-intl';
|
|
3
|
+
import getTrad from '../../../utils/getTrad';
|
|
4
|
+
import { componentField, componentForm } from '../component';
|
|
5
|
+
import { nameField } from './nameField';
|
|
6
|
+
import uiHelpers from './uiHelpers';
|
|
7
|
+
|
|
8
|
+
const baseForm = {
|
|
9
|
+
component: (data, step) => {
|
|
10
|
+
if (step === '1') {
|
|
11
|
+
const itemsToConcat =
|
|
12
|
+
data.createComponent === true
|
|
13
|
+
? [[uiHelpers.spacer]].concat(componentForm.base('componentToCreate.'))
|
|
14
|
+
: [[uiHelpers.spacer]];
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
items: [[componentField], ...itemsToConcat],
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
items: [
|
|
23
|
+
[
|
|
24
|
+
nameField,
|
|
25
|
+
{
|
|
26
|
+
name: 'component',
|
|
27
|
+
type: 'componentSelect',
|
|
28
|
+
label: {
|
|
29
|
+
id: getTrad('modalForm.attributes.select-component'),
|
|
30
|
+
},
|
|
31
|
+
isMultiple: false,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
[
|
|
35
|
+
{
|
|
36
|
+
label: {
|
|
37
|
+
id: getTrad('modalForm.attribute.text.type-selection'),
|
|
38
|
+
},
|
|
39
|
+
name: 'repeatable',
|
|
40
|
+
type: 'booleanBox',
|
|
41
|
+
size: 12,
|
|
42
|
+
options: [
|
|
43
|
+
{
|
|
44
|
+
headerId: getTrad('form.attribute.component.option.repeatable'),
|
|
45
|
+
descriptionId: getTrad('form.attribute.component.option.repeatable.description'),
|
|
46
|
+
value: true,
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
headerId: getTrad('form.attribute.component.option.single'),
|
|
50
|
+
descriptionId: getTrad('form.attribute.component.option.single.description'),
|
|
51
|
+
value: false,
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
validations: {},
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
[uiHelpers.spacer],
|
|
58
|
+
],
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
date: () => {
|
|
62
|
+
return {
|
|
63
|
+
items: [
|
|
64
|
+
[
|
|
65
|
+
nameField,
|
|
66
|
+
{
|
|
67
|
+
label: {
|
|
68
|
+
id: getTrad('modalForm.attribute.text.type-selection'),
|
|
69
|
+
},
|
|
70
|
+
name: 'type',
|
|
71
|
+
type: 'select',
|
|
72
|
+
options: [
|
|
73
|
+
{ id: 'components.InputSelect.option.placeholder', value: '' },
|
|
74
|
+
{
|
|
75
|
+
id: 'form.attribute.item.date.type.date',
|
|
76
|
+
value: 'date',
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
id: 'form.attribute.item.date.type.datetime',
|
|
80
|
+
value: 'datetime',
|
|
81
|
+
},
|
|
82
|
+
// Not sure the ctm supports that one
|
|
83
|
+
// {
|
|
84
|
+
// id: 'form.attribute.item.date.type.timestamp',
|
|
85
|
+
// value: 'timestamp',
|
|
86
|
+
// },
|
|
87
|
+
{ id: 'form.attribute.item.date.type.time', value: 'time' },
|
|
88
|
+
].map(({ id, value }, index) => {
|
|
89
|
+
const disabled = index === 0;
|
|
90
|
+
const tradId = index === 0 ? id : getTrad(id);
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<FormattedMessage id={tradId} key={id}>
|
|
94
|
+
{msg => (
|
|
95
|
+
<option disabled={disabled} hidden={disabled} value={value}>
|
|
96
|
+
{msg}
|
|
97
|
+
</option>
|
|
98
|
+
)}
|
|
99
|
+
</FormattedMessage>
|
|
100
|
+
);
|
|
101
|
+
}),
|
|
102
|
+
validations: {
|
|
103
|
+
required: true,
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
],
|
|
108
|
+
};
|
|
109
|
+
},
|
|
110
|
+
enumeration: () => {
|
|
111
|
+
return {
|
|
112
|
+
items: [
|
|
113
|
+
[nameField],
|
|
114
|
+
[
|
|
115
|
+
{
|
|
116
|
+
autoFocus: false,
|
|
117
|
+
name: 'enum',
|
|
118
|
+
type: 'textarea',
|
|
119
|
+
size: 8,
|
|
120
|
+
label: {
|
|
121
|
+
id: getTrad('form.attribute.item.enumeration.rules'),
|
|
122
|
+
},
|
|
123
|
+
placeholder: {
|
|
124
|
+
id: getTrad('form.attribute.item.enumeration.placeholder'),
|
|
125
|
+
},
|
|
126
|
+
validations: {
|
|
127
|
+
required: true,
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
],
|
|
132
|
+
};
|
|
133
|
+
},
|
|
134
|
+
media: () => {
|
|
135
|
+
return {
|
|
136
|
+
items: [
|
|
137
|
+
[nameField],
|
|
138
|
+
[
|
|
139
|
+
{
|
|
140
|
+
label: { id: getTrad('modalForm.attribute.text.type-selection') },
|
|
141
|
+
name: 'multiple',
|
|
142
|
+
size: 12,
|
|
143
|
+
type: 'booleanBox',
|
|
144
|
+
options: [
|
|
145
|
+
{
|
|
146
|
+
headerId: getTrad('form.attribute.media.option.multiple'),
|
|
147
|
+
descriptionId: getTrad('form.attribute.media.option.multiple.description'),
|
|
148
|
+
value: true,
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
headerId: getTrad('form.attribute.media.option.single'),
|
|
152
|
+
descriptionId: getTrad('form.attribute.media.option.single.description'),
|
|
153
|
+
value: false,
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
validations: {},
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
[uiHelpers.spacerMedium],
|
|
160
|
+
],
|
|
161
|
+
};
|
|
162
|
+
},
|
|
163
|
+
number: () => {
|
|
164
|
+
return {
|
|
165
|
+
items: [
|
|
166
|
+
[
|
|
167
|
+
nameField,
|
|
168
|
+
{
|
|
169
|
+
label: {
|
|
170
|
+
id: getTrad('form.attribute.item.number.type'),
|
|
171
|
+
},
|
|
172
|
+
name: 'type',
|
|
173
|
+
type: 'select',
|
|
174
|
+
options: [
|
|
175
|
+
{ id: 'components.InputSelect.option.placeholder', value: '' },
|
|
176
|
+
{
|
|
177
|
+
id: 'form.attribute.item.number.type.integer',
|
|
178
|
+
value: 'integer',
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
id: 'form.attribute.item.number.type.biginteger',
|
|
182
|
+
value: 'biginteger',
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
id: 'form.attribute.item.number.type.decimal',
|
|
186
|
+
value: 'decimal',
|
|
187
|
+
},
|
|
188
|
+
{ id: 'form.attribute.item.number.type.float', value: 'float' },
|
|
189
|
+
].map(({ id, value }, index) => {
|
|
190
|
+
const disabled = index === 0;
|
|
191
|
+
const tradId = index === 0 ? id : getTrad(id);
|
|
192
|
+
|
|
193
|
+
return (
|
|
194
|
+
<FormattedMessage id={tradId} key={id}>
|
|
195
|
+
{msg => (
|
|
196
|
+
<option disabled={disabled} hidden={disabled} value={value}>
|
|
197
|
+
{msg}
|
|
198
|
+
</option>
|
|
199
|
+
)}
|
|
200
|
+
</FormattedMessage>
|
|
201
|
+
);
|
|
202
|
+
}),
|
|
203
|
+
validations: {
|
|
204
|
+
required: true,
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
],
|
|
208
|
+
],
|
|
209
|
+
};
|
|
210
|
+
},
|
|
211
|
+
relation: () => {
|
|
212
|
+
return {
|
|
213
|
+
items: [
|
|
214
|
+
[
|
|
215
|
+
{
|
|
216
|
+
type: 'relation',
|
|
217
|
+
},
|
|
218
|
+
],
|
|
219
|
+
],
|
|
220
|
+
};
|
|
221
|
+
},
|
|
222
|
+
string: () => {
|
|
223
|
+
return {
|
|
224
|
+
items: [
|
|
225
|
+
[nameField],
|
|
226
|
+
[
|
|
227
|
+
{
|
|
228
|
+
label: { id: getTrad('modalForm.attribute.text.type-selection') },
|
|
229
|
+
name: 'type',
|
|
230
|
+
size: 12,
|
|
231
|
+
type: 'booleanBox',
|
|
232
|
+
options: [
|
|
233
|
+
{
|
|
234
|
+
headerId: getTrad('form.attribute.text.option.short-text'),
|
|
235
|
+
descriptionId: getTrad('form.attribute.text.option.short-text.description'),
|
|
236
|
+
value: 'string',
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
headerId: getTrad('form.attribute.text.option.long-text'),
|
|
240
|
+
descriptionId: getTrad('form.attribute.text.option.long-text.description'),
|
|
241
|
+
value: 'text',
|
|
242
|
+
},
|
|
243
|
+
],
|
|
244
|
+
validations: {},
|
|
245
|
+
},
|
|
246
|
+
],
|
|
247
|
+
[uiHelpers.spacerMedium],
|
|
248
|
+
],
|
|
249
|
+
};
|
|
250
|
+
},
|
|
251
|
+
text: () => {
|
|
252
|
+
return {
|
|
253
|
+
items: [
|
|
254
|
+
[nameField],
|
|
255
|
+
[
|
|
256
|
+
{
|
|
257
|
+
label: { id: getTrad('modalForm.attribute.text.type-selection') },
|
|
258
|
+
name: 'type',
|
|
259
|
+
size: 12,
|
|
260
|
+
type: 'booleanBox',
|
|
261
|
+
options: [
|
|
262
|
+
{
|
|
263
|
+
headerId: getTrad('form.attribute.text.option.short-text'),
|
|
264
|
+
descriptionId: getTrad('form.attribute.text.option.short-text.description'),
|
|
265
|
+
value: 'string',
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
headerId: getTrad('form.attribute.text.option.long-text'),
|
|
269
|
+
descriptionId: getTrad('form.attribute.text.option.long-text.description'),
|
|
270
|
+
value: 'text',
|
|
271
|
+
},
|
|
272
|
+
],
|
|
273
|
+
validations: {},
|
|
274
|
+
},
|
|
275
|
+
],
|
|
276
|
+
[uiHelpers.spacerMedium],
|
|
277
|
+
],
|
|
278
|
+
};
|
|
279
|
+
},
|
|
280
|
+
uid: (data, step, attributes) => {
|
|
281
|
+
const options = Object.keys(attributes)
|
|
282
|
+
.filter(key => ['string', 'text'].includes(attributes[key].type))
|
|
283
|
+
.map(key => ({ id: key, value: key }));
|
|
284
|
+
|
|
285
|
+
return {
|
|
286
|
+
items: [
|
|
287
|
+
[
|
|
288
|
+
{
|
|
289
|
+
...nameField,
|
|
290
|
+
placeholder: {
|
|
291
|
+
id: getTrad('modalForm.attribute.form.base.name.placeholder'),
|
|
292
|
+
},
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
label: {
|
|
296
|
+
id: getTrad('modalForm.attribute.target-field'),
|
|
297
|
+
},
|
|
298
|
+
name: 'targetField',
|
|
299
|
+
type: 'select',
|
|
300
|
+
options: [{ id: getTrad('none'), value: '' }, ...options].map((option, index) => (
|
|
301
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
302
|
+
<Fragment key={index}>
|
|
303
|
+
{index === 0 ? (
|
|
304
|
+
<FormattedMessage id={option.id}>
|
|
305
|
+
{msg => <option value={option.value}>{msg}</option>}
|
|
306
|
+
</FormattedMessage>
|
|
307
|
+
) : (
|
|
308
|
+
<option value={option.value}>{option.value}</option>
|
|
309
|
+
)}
|
|
310
|
+
</Fragment>
|
|
311
|
+
)),
|
|
312
|
+
validations: {
|
|
313
|
+
required: true,
|
|
314
|
+
},
|
|
315
|
+
},
|
|
316
|
+
],
|
|
317
|
+
],
|
|
318
|
+
};
|
|
319
|
+
},
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
export default baseForm;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import getTrad from '../../../utils/getTrad';
|
|
2
|
+
|
|
3
|
+
const nameField = {
|
|
4
|
+
autoFocus: true,
|
|
5
|
+
name: 'name',
|
|
6
|
+
type: 'text',
|
|
7
|
+
label: {
|
|
8
|
+
id: getTrad('modalForm.attribute.form.base.name'),
|
|
9
|
+
},
|
|
10
|
+
description: {
|
|
11
|
+
id: getTrad('modalForm.attribute.form.base.name.description'),
|
|
12
|
+
},
|
|
13
|
+
validations: {
|
|
14
|
+
required: true,
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// eslint-disable-next-line import/prefer-default-export
|
|
19
|
+
export { nameField };
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import * as yup from 'yup';
|
|
2
|
+
import { translatedErrors as errorsTrads } from 'strapi-helper-plugin';
|
|
3
|
+
import getTrad from '../../../utils/getTrad';
|
|
4
|
+
import {
|
|
5
|
+
alreadyUsedAttributeNames,
|
|
6
|
+
createTextShape,
|
|
7
|
+
isMinSuperiorThanMax,
|
|
8
|
+
isNameAllowed,
|
|
9
|
+
validators,
|
|
10
|
+
NAME_REGEX,
|
|
11
|
+
} from './validation/common';
|
|
12
|
+
|
|
13
|
+
const types = {
|
|
14
|
+
date: (usedAttributeNames, reservedNames) => {
|
|
15
|
+
const shape = {
|
|
16
|
+
name: validators.name(usedAttributeNames, reservedNames),
|
|
17
|
+
type: validators.type(),
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
return yup.object(shape);
|
|
21
|
+
},
|
|
22
|
+
datetime: (usedAttributeNames, reservedNames) => {
|
|
23
|
+
const shape = {
|
|
24
|
+
name: validators.name(usedAttributeNames, reservedNames),
|
|
25
|
+
type: validators.type(),
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
return yup.object(shape);
|
|
29
|
+
},
|
|
30
|
+
time: (usedAttributeNames, reservedNames) => {
|
|
31
|
+
const shape = {
|
|
32
|
+
name: validators.name(usedAttributeNames, reservedNames),
|
|
33
|
+
type: validators.type(),
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
return yup.object(shape);
|
|
37
|
+
},
|
|
38
|
+
default: (usedAttributeNames, reservedNames) => {
|
|
39
|
+
const shape = {
|
|
40
|
+
name: validators.name(usedAttributeNames, reservedNames),
|
|
41
|
+
type: validators.type(),
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
return yup.object(shape);
|
|
45
|
+
},
|
|
46
|
+
biginteger: (usedAttributeNames, reservedNames) => {
|
|
47
|
+
const shape = {
|
|
48
|
+
name: validators.name(usedAttributeNames, reservedNames),
|
|
49
|
+
type: validators.type(),
|
|
50
|
+
default: yup
|
|
51
|
+
.string()
|
|
52
|
+
.nullable()
|
|
53
|
+
.matches(/^\d*$/),
|
|
54
|
+
unique: validators.unique(),
|
|
55
|
+
required: validators.required(),
|
|
56
|
+
max: yup
|
|
57
|
+
.string()
|
|
58
|
+
.nullable()
|
|
59
|
+
.matches(/^\d*$/, errorsTrads.regex),
|
|
60
|
+
min: yup
|
|
61
|
+
.string()
|
|
62
|
+
.nullable()
|
|
63
|
+
.test(isMinSuperiorThanMax)
|
|
64
|
+
.matches(/^\d*$/, errorsTrads.regex),
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
return yup.object(shape);
|
|
68
|
+
},
|
|
69
|
+
boolean: (usedAttributeNames, reservedNames) => {
|
|
70
|
+
const shape = {
|
|
71
|
+
name: validators.name(usedAttributeNames, reservedNames),
|
|
72
|
+
default: yup.boolean().nullable(),
|
|
73
|
+
required: validators.required(),
|
|
74
|
+
unique: validators.unique(),
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
return yup.object(shape);
|
|
78
|
+
},
|
|
79
|
+
component: (usedAttributeNames, reservedNames) => {
|
|
80
|
+
const shape = {
|
|
81
|
+
name: validators.name(usedAttributeNames, reservedNames),
|
|
82
|
+
type: validators.type(),
|
|
83
|
+
required: validators.required(),
|
|
84
|
+
max: validators.max(),
|
|
85
|
+
min: validators.min(),
|
|
86
|
+
component: yup.string().required(errorsTrads.required),
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
return yup.object(shape);
|
|
90
|
+
},
|
|
91
|
+
decimal: (usedAttributeNames, reservedNames) => {
|
|
92
|
+
const shape = {
|
|
93
|
+
name: validators.name(usedAttributeNames, reservedNames),
|
|
94
|
+
type: validators.type(),
|
|
95
|
+
default: yup.number(),
|
|
96
|
+
required: validators.required(),
|
|
97
|
+
max: yup.number(),
|
|
98
|
+
min: yup.number().test(isMinSuperiorThanMax),
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
return yup.object(shape);
|
|
102
|
+
},
|
|
103
|
+
dynamiczone: (usedAttributeNames, reservedNames) => {
|
|
104
|
+
const shape = {
|
|
105
|
+
name: validators.name(usedAttributeNames, reservedNames),
|
|
106
|
+
type: validators.type(),
|
|
107
|
+
required: validators.required(),
|
|
108
|
+
max: validators.max(),
|
|
109
|
+
min: validators.min(),
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
return yup.object(shape);
|
|
113
|
+
},
|
|
114
|
+
email: (usedAttributeNames, reservedNames) => {
|
|
115
|
+
const shape = {
|
|
116
|
+
name: validators.name(usedAttributeNames, reservedNames),
|
|
117
|
+
type: validators.type(),
|
|
118
|
+
default: yup
|
|
119
|
+
.string()
|
|
120
|
+
.email()
|
|
121
|
+
.nullable(),
|
|
122
|
+
unique: validators.unique(),
|
|
123
|
+
required: validators.required(),
|
|
124
|
+
maxLength: validators.maxLength(),
|
|
125
|
+
minLength: validators.minLength(),
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
return yup.object(shape);
|
|
129
|
+
},
|
|
130
|
+
enumeration: (usedAttributeNames, reservedNames) => {
|
|
131
|
+
const ENUM_REGEX = new RegExp('^[_A-Za-z][_0-9A-Za-z]*$');
|
|
132
|
+
|
|
133
|
+
const shape = {
|
|
134
|
+
name: yup
|
|
135
|
+
.string()
|
|
136
|
+
.test(alreadyUsedAttributeNames(usedAttributeNames))
|
|
137
|
+
.test(isNameAllowed(reservedNames))
|
|
138
|
+
.matches(ENUM_REGEX, errorsTrads.regex)
|
|
139
|
+
.required(errorsTrads.required),
|
|
140
|
+
type: validators.type(),
|
|
141
|
+
default: validators.default(),
|
|
142
|
+
unique: validators.unique(),
|
|
143
|
+
required: validators.required(),
|
|
144
|
+
enum: yup
|
|
145
|
+
.array()
|
|
146
|
+
.of(yup.string())
|
|
147
|
+
.min(1, errorsTrads.min)
|
|
148
|
+
.test({
|
|
149
|
+
name: 'areEnumValuesUnique',
|
|
150
|
+
message: getTrad('error.validation.enum-duplicate'),
|
|
151
|
+
test: values => {
|
|
152
|
+
const filtered = [...new Set(values)];
|
|
153
|
+
|
|
154
|
+
return filtered.length === values.length;
|
|
155
|
+
},
|
|
156
|
+
})
|
|
157
|
+
.test({
|
|
158
|
+
name: 'valuesMatchesRegex',
|
|
159
|
+
message: errorsTrads.regex,
|
|
160
|
+
test: values => {
|
|
161
|
+
return values.every(val => val === '' || ENUM_REGEX.test(val));
|
|
162
|
+
},
|
|
163
|
+
})
|
|
164
|
+
.test({
|
|
165
|
+
name: 'doesNotHaveEmptyValues',
|
|
166
|
+
message: getTrad('error.validation.enum-empty-string'),
|
|
167
|
+
test: values => !values.some(val => val === ''),
|
|
168
|
+
}),
|
|
169
|
+
enumName: yup.string().nullable(),
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
return yup.object(shape);
|
|
173
|
+
},
|
|
174
|
+
float: (usedAttributeNames, reservedNames) => {
|
|
175
|
+
const shape = {
|
|
176
|
+
name: validators.name(usedAttributeNames, reservedNames),
|
|
177
|
+
type: validators.type(),
|
|
178
|
+
required: validators.required(),
|
|
179
|
+
default: yup.number(),
|
|
180
|
+
max: yup.number(),
|
|
181
|
+
min: yup.number().test(isMinSuperiorThanMax),
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
return yup.object(shape);
|
|
185
|
+
},
|
|
186
|
+
integer: (usedAttributeNames, reservedNames) => {
|
|
187
|
+
const shape = {
|
|
188
|
+
name: validators.name(usedAttributeNames, reservedNames),
|
|
189
|
+
type: validators.type(),
|
|
190
|
+
default: yup.number().integer(),
|
|
191
|
+
unique: validators.unique(),
|
|
192
|
+
required: validators.required(),
|
|
193
|
+
max: validators.max(),
|
|
194
|
+
min: validators.min(),
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
return yup.object(shape);
|
|
198
|
+
},
|
|
199
|
+
json: (usedAttributeNames, reservedNames) => {
|
|
200
|
+
const shape = {
|
|
201
|
+
name: validators.name(usedAttributeNames, reservedNames),
|
|
202
|
+
type: validators.type(),
|
|
203
|
+
required: validators.required(),
|
|
204
|
+
unique: validators.unique(),
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
return yup.object(shape);
|
|
208
|
+
},
|
|
209
|
+
media: (usedAttributeNames, reservedNames) => {
|
|
210
|
+
const shape = {
|
|
211
|
+
name: validators.name(usedAttributeNames, reservedNames),
|
|
212
|
+
type: validators.type(),
|
|
213
|
+
multiple: yup.boolean(),
|
|
214
|
+
required: validators.required(),
|
|
215
|
+
allowedTypes: yup
|
|
216
|
+
.array()
|
|
217
|
+
.of(yup.string().oneOf(['images', 'videos', 'files']))
|
|
218
|
+
.min(1)
|
|
219
|
+
.nullable(),
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
return yup.object(shape);
|
|
223
|
+
},
|
|
224
|
+
password: (usedAttributeNames, reservedNames) => {
|
|
225
|
+
const shape = {
|
|
226
|
+
name: validators.name(usedAttributeNames, reservedNames),
|
|
227
|
+
type: validators.type(),
|
|
228
|
+
default: validators.default(),
|
|
229
|
+
unique: validators.unique(),
|
|
230
|
+
required: validators.required(),
|
|
231
|
+
maxLength: validators.maxLength(),
|
|
232
|
+
minLength: validators.minLength(),
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
return yup.object(shape);
|
|
236
|
+
},
|
|
237
|
+
relation: (
|
|
238
|
+
usedAttributeNames,
|
|
239
|
+
reservedNames,
|
|
240
|
+
alreadyTakenTargetAttributes,
|
|
241
|
+
{ initialData, modifiedData }
|
|
242
|
+
) => {
|
|
243
|
+
const shape = {
|
|
244
|
+
name: validators.name(usedAttributeNames, reservedNames),
|
|
245
|
+
target: yup.string().required(errorsTrads.required),
|
|
246
|
+
nature: yup.string().required(),
|
|
247
|
+
dominant: yup.boolean().nullable(),
|
|
248
|
+
unique: yup.boolean().nullable(),
|
|
249
|
+
targetAttribute: yup.lazy(() => {
|
|
250
|
+
let schema = yup.string().test(isNameAllowed(reservedNames));
|
|
251
|
+
const initialForbiddenName = [...alreadyTakenTargetAttributes, modifiedData.name];
|
|
252
|
+
|
|
253
|
+
let forbiddenTargetAttributeName = initialForbiddenName.filter(
|
|
254
|
+
val => val !== initialData.targetAttribute
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
if (!['oneWay', 'manyWay'].includes(modifiedData.nature)) {
|
|
258
|
+
schema = schema.matches(NAME_REGEX, errorsTrads.regex);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return schema
|
|
262
|
+
.test({
|
|
263
|
+
name: 'forbiddenTargetAttributeName',
|
|
264
|
+
message: getTrad('error.validation.relation.targetAttribute-taken'),
|
|
265
|
+
test: value => {
|
|
266
|
+
if (!value) {
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return !forbiddenTargetAttributeName.includes(value);
|
|
271
|
+
},
|
|
272
|
+
})
|
|
273
|
+
.required(errorsTrads.required);
|
|
274
|
+
}),
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
return yup.object(shape);
|
|
278
|
+
},
|
|
279
|
+
richtext: (usedAttributeNames, reservedNames) => {
|
|
280
|
+
const shape = {
|
|
281
|
+
name: validators.name(usedAttributeNames, reservedNames),
|
|
282
|
+
type: validators.type(),
|
|
283
|
+
default: validators.default(),
|
|
284
|
+
unique: validators.unique(),
|
|
285
|
+
required: validators.required(),
|
|
286
|
+
maxLength: validators.maxLength(),
|
|
287
|
+
minLength: validators.minLength(),
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
return yup.object(shape);
|
|
291
|
+
},
|
|
292
|
+
string: (usedAttributeNames, reservedNames) => {
|
|
293
|
+
const shape = createTextShape(usedAttributeNames, reservedNames);
|
|
294
|
+
|
|
295
|
+
return yup.object(shape);
|
|
296
|
+
},
|
|
297
|
+
text: (usedAttributeNames, reservedNames) => {
|
|
298
|
+
const shape = createTextShape(usedAttributeNames, reservedNames);
|
|
299
|
+
|
|
300
|
+
return yup.object(shape);
|
|
301
|
+
},
|
|
302
|
+
uid: (usedAttributeNames, reservedNames) => {
|
|
303
|
+
const shape = createTextShape(usedAttributeNames, reservedNames);
|
|
304
|
+
|
|
305
|
+
return yup.object(shape);
|
|
306
|
+
},
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
export default types;
|