From 38d896f0ea1df5111cf4a01b7b402d341c4b4dd1 Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Tue, 28 Jul 2020 18:34:14 +0200 Subject: [PATCH] Fix schema handler set disgarding falsy values Signed-off-by: Alexandre Bodin --- .../services/schema-builder/content-type-builder.js | 10 ++++++---- .../services/schema-builder/schema-handler.js | 12 ++---------- .../__snapshots__/content-types.test.e2e.js.snap | 2 ++ 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/packages/strapi-plugin-content-type-builder/services/schema-builder/content-type-builder.js b/packages/strapi-plugin-content-type-builder/services/schema-builder/content-type-builder.js index 5d729a0043..df4876a970 100644 --- a/packages/strapi-plugin-content-type-builder/services/schema-builder/content-type-builder.js +++ b/packages/strapi-plugin-content-type-builder/services/schema-builder/content-type-builder.js @@ -77,13 +77,15 @@ module.exports = function createComponentBuilder() { .setUID(uid) .set('kind', infos.kind || typeKinds.COLLECTION_TYPE) .set('collectionName', infos.collectionName || defaultCollectionName) - .set(['info', 'name'], infos.name) - .set(['info', 'description'], infos.description) + .set('info', { + name: infos.name, + description: infos.description, + }) .set('options', { increments: true, timestamps: true, + draftAndPublish: infos.draftAndPublish || false, }) - .setOption('draftAndPublish', infos.draftAndPublish || false) .setAttributes(this.convertAttributes(infos.attributes)); Object.keys(infos.attributes).forEach(key => { @@ -185,7 +187,7 @@ module.exports = function createComponentBuilder() { .set('kind', infos.kind || contentType.schema.kind) .set(['info', 'name'], infos.name) .set(['info', 'description'], infos.description) - .setOption('draftAndPublish', infos.draftAndPublish || false) + .set(['options', 'draftAndPublish'], infos.draftAndPublish || false) .setAttributes(this.convertAttributes(newAttributes)); return contentType; diff --git a/packages/strapi-plugin-content-type-builder/services/schema-builder/schema-handler.js b/packages/strapi-plugin-content-type-builder/services/schema-builder/schema-handler.js index d5e220c715..1a12cc9a71 100644 --- a/packages/strapi-plugin-content-type-builder/services/schema-builder/schema-handler.js +++ b/packages/strapi-plugin-content-type-builder/services/schema-builder/schema-handler.js @@ -76,15 +76,6 @@ module.exports = function createSchemaHandler(infos) { return this; }, - // Set a particular option inside the schema - setOption(path, val) { - modified = true; - - _.set(state.schema, ['options'].concat(path), val); - - return this; - }, - // get a particuar path inside the schema get(path) { return _.get(state.schema, path); @@ -94,7 +85,8 @@ module.exports = function createSchemaHandler(infos) { set(path, val) { modified = true; - _.set(state.schema, path, val || _.get(state.schema, path)); + const value = _.defaultTo(val, _.get(state.schema, path)); + _.set(state.schema, path, value); return this; }, diff --git a/packages/strapi-plugin-content-type-builder/test/__snapshots__/content-types.test.e2e.js.snap b/packages/strapi-plugin-content-type-builder/test/__snapshots__/content-types.test.e2e.js.snap index 53a95e1853..7dae20100d 100644 --- a/packages/strapi-plugin-content-type-builder/test/__snapshots__/content-types.test.e2e.js.snap +++ b/packages/strapi-plugin-content-type-builder/test/__snapshots__/content-types.test.e2e.js.snap @@ -13,6 +13,7 @@ Object { "collectionName": "test_collection_types", "connection": "default", "description": "", + "draftAndPublish": false, "kind": "collectionType", "name": "Test Collection Type", }, @@ -34,6 +35,7 @@ Object { "collectionName": "test_single_types", "connection": "default", "description": "", + "draftAndPublish": false, "kind": "singleType", "name": "Test Single Type", },