handle toggle i18n on CT and fields

This commit is contained in:
Pierre Noël 2021-02-12 11:29:43 +01:00
parent 2b342ec69d
commit 22d38b5ffc
12 changed files with 93 additions and 7 deletions

View File

@ -16,6 +16,7 @@ const createSchema = (types, relations, { modelType } = {}) => {
.required('name.required'),
description: yup.string(),
draftAndPublish: yup.boolean(),
pluginOptions: yup.object(),
connection: yup.string(),
collectionName: yup
.string()
@ -45,16 +46,13 @@ const createAttributesValidator = ({ types, modelType, relations }) => {
}
if (_.has(attribute, 'type')) {
return getTypeValidator(attribute, { types, modelType, attributes })
.test(isValidKey(key))
.noUnknown();
return getTypeValidator(attribute, { types, modelType, attributes }).test(
isValidKey(key)
);
}
if (_.has(attribute, 'target')) {
return yup
.object(getRelationValidator(attribute, relations))
.test(isValidKey(key))
.noUnknown();
return yup.object(getRelationValidator(attribute, relations)).test(isValidKey(key));
}
return typeOrRelationValidator;

View File

@ -51,5 +51,6 @@ module.exports = (obj, validNatures) => {
.nullable(),
targetColumnName: yup.string().nullable(),
private: yup.boolean().nullable(),
pluginOptions: yup.object(),
};
};

View File

@ -36,6 +36,7 @@ const getTypeValidator = (attribute, { types, modelType, attributes }) => {
.required(),
configurable: yup.boolean().nullable(),
private: yup.boolean().nullable(),
pluginOptions: yup.object(),
...getTypeShape(attribute, { modelType, attributes }),
});
};

View File

@ -24,6 +24,7 @@ const formatComponent = component => {
description: _.get(info, 'description', ''),
connection,
collectionName,
pluginOptions: component.pluginOptions,
attributes: formatAttributes(component),
},
};

View File

@ -49,6 +49,7 @@ const formatContentType = contentType => {
name: getformattedName(contentType),
description: _.get(info, 'description', ''),
draftAndPublish: contentTypesUtils.hasDraftAndPublish({ options }),
pluginOptions: contentType.pluginOptions,
connection,
kind: kind || 'collectionType',
collectionName,

View File

@ -16,6 +16,11 @@ Object {
"draftAndPublish": false,
"kind": "singleType",
"name": "My name",
"pluginOptions": Object {
"content-manager": Object {
"visible": true,
},
},
"restrictRelationsTo": null,
"visible": true,
},

View File

@ -18,6 +18,11 @@ describe('Content types service', () => {
options: {
draftAndPublish: false,
},
pluginOptions: {
'content-manager': {
visible: true,
},
},
attributes: {
title: {
type: 'string',

View File

@ -52,6 +52,7 @@ module.exports = function createComponentBuilder() {
.set(['info', 'name'], infos.name)
.set(['info', 'icon'], infos.icon)
.set(['info', 'description'], infos.description)
.set('pluginOptions', infos.pluginOptions)
.setAttributes(this.convertAttributes(infos.attributes));
if (this.components.size === 0) {
@ -101,6 +102,7 @@ module.exports = function createComponentBuilder() {
.set(['info', 'name'], infos.name)
.set(['info', 'icon'], infos.icon)
.set(['info', 'description'], infos.description)
.set('pluginOptions', infos.pluginOptions)
.setAttributes(this.convertAttributes(newAttributes));
if (newUID !== uid) {

View File

@ -86,6 +86,7 @@ module.exports = function createComponentBuilder() {
timestamps: true,
draftAndPublish: infos.draftAndPublish || false,
})
.set('pluginOptions', infos.pluginOptions)
.setAttributes(this.convertAttributes(infos.attributes));
Object.keys(infos.attributes).forEach(key => {
@ -188,6 +189,7 @@ module.exports = function createComponentBuilder() {
.set(['info', 'name'], infos.name)
.set(['info', 'description'], infos.description)
.set(['options', 'draftAndPublish'], infos.draftAndPublish || false)
.set('pluginOptions', infos.pluginOptions)
.setAttributes(this.convertAttributes(newAttributes));
return contentType;

View File

@ -52,9 +52,19 @@ describe('Content Type Builder - Components', () => {
category: 'default',
icon: 'default',
name: 'Some Component',
pluginOptions: {
pluginName: {
option: true,
},
},
attributes: {
title: {
type: 'string',
pluginOptions: {
pluginName: {
option: true,
},
},
},
pic: {
type: 'media',
@ -152,9 +162,19 @@ describe('Content Type Builder - Components', () => {
description: '',
connection: 'default',
collectionName: 'components_default_some_components',
pluginOptions: {
pluginName: {
option: true,
},
},
attributes: {
title: {
type: 'string',
pluginOptions: {
pluginName: {
option: true,
},
},
},
pic: {
type: 'media',
@ -212,6 +232,11 @@ describe('Content Type Builder - Components', () => {
icon: 'default',
name: 'New Component',
attributes: {},
pluginOptions: {
pluginName: {
option: false,
},
},
},
},
});
@ -236,6 +261,11 @@ describe('Content Type Builder - Components', () => {
uid: 'default.some-component',
schema: {
name: 'New Component',
pluginOptions: {
pluginName: {
option: false,
},
},
},
},
});

View File

@ -51,9 +51,19 @@ describe('Content Type Builder - Content types', () => {
body: {
contentType: {
name: 'Test Collection Type',
pluginOptions: {
i18n: {
localized: true,
},
},
attributes: {
title: {
type: 'string',
pluginOptions: {
i18n: {
localized: true,
},
},
},
},
},
@ -125,9 +135,19 @@ describe('Content Type Builder - Content types', () => {
contentType: {
kind: 'singleType',
name: 'Test Single Type',
pluginOptions: {
i18n: {
localized: true,
},
},
attributes: {
title: {
type: 'string',
pluginOptions: {
i18n: {
localized: true,
},
},
},
},
},

View File

@ -317,6 +317,11 @@ Object {
"schema": Object {
"attributes": Object {
"title": Object {
"pluginOptions": Object {
"i18n": Object {
"localized": true,
},
},
"type": "string",
},
},
@ -326,6 +331,11 @@ Object {
"draftAndPublish": false,
"kind": "collectionType",
"name": "Test Collection Type",
"pluginOptions": Object {
"i18n": Object {
"localized": true,
},
},
"restrictRelationsTo": null,
"visible": true,
},
@ -365,6 +375,11 @@ Object {
"schema": Object {
"attributes": Object {
"title": Object {
"pluginOptions": Object {
"i18n": Object {
"localized": true,
},
},
"type": "string",
},
},
@ -374,6 +389,11 @@ Object {
"draftAndPublish": false,
"kind": "singleType",
"name": "Test Single Type",
"pluginOptions": Object {
"i18n": Object {
"localized": true,
},
},
"restrictRelationsTo": null,
"visible": true,
},