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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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