diff --git a/packages/strapi-plugin-content-manager/config/functions/bootstrap.js b/packages/strapi-plugin-content-manager/config/functions/bootstrap.js index 77f53c3202..38f36bb7bb 100644 --- a/packages/strapi-plugin-content-manager/config/functions/bootstrap.js +++ b/packages/strapi-plugin-content-manager/config/functions/bootstrap.js @@ -51,6 +51,12 @@ module.exports = async cb => { return acc; }, {}); + // Reference all current models + const appModels = Object.keys(pluginsModel).reduce((acc, curr) => { + const models = Object.keys(_.get(pluginModels, [currn 'models'], {})); + + return acc.concat(models); + }, Object.keys(strapi.models).filter(m => m !== 'core_store')); // Init schema const schema = { generalSettings: { @@ -102,7 +108,7 @@ module.exports = async cb => { disabled: false, }; }); - + // Don't display fields that are hidden by default like the resetPasswordToken for the model user fieldsToRemove.forEach(field => { _.unset(fields, field); @@ -235,6 +241,16 @@ module.exports = async cb => { pluginStore.set({ key: 'schema', value: schema }); return cb(); + } else { + const modelsLayout = Object.keys(_.get(prevSchema, 'layout', {})); + + // Remove previous model from the schema.layout + // Usually needed when renaming a model + modelsLayout.forEach(model => { + if (!appModels.includes(model)) { + _.unset(prevSchema, ['layout', model]); + } + }); } // Here we do the difference between the previous schema from the database and the new one diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/Form/index.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/Form/index.js index 11ebcc5421..4d61e66ddd 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/containers/Form/index.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/Form/index.js @@ -23,6 +23,7 @@ import { size, split, take, + toLower, toNumber, replace, } from 'lodash'; @@ -378,7 +379,7 @@ export class Form extends React.Component { // eslint-disable-line react/prefer- handleBlur = ({ target }) => { if (target.name === 'name') { - this.props.changeInput(target.name, camelCase(target.value), includes(this.props.hash, 'edit')); + this.props.changeInput(target.name, toLower(camelCase(target.value)), includes(this.props.hash, 'edit')); if (!isEmpty(target.value)) { // The input name for content type doesn't have the default handleBlur validation so we need to manually remove the error this.props.removeContentTypeRequiredError(); @@ -489,7 +490,7 @@ export class Form extends React.Component { // eslint-disable-line react/prefer- return { ...model, - name: camelCase(model.name), + name: toLower(camelCase(model.name)), }; } diff --git a/packages/strapi-plugin-content-type-builder/services/ContentTypeBuilder.js b/packages/strapi-plugin-content-type-builder/services/ContentTypeBuilder.js index 3cfc4e0d2f..68ed48efbd 100644 --- a/packages/strapi-plugin-content-type-builder/services/ContentTypeBuilder.js +++ b/packages/strapi-plugin-content-type-builder/services/ContentTypeBuilder.js @@ -21,7 +21,7 @@ module.exports = { }); const schema = await pluginStore.get({ key: 'schema' }); - const layout = _.get(schema.layout, model, {}); + const layout = _.get(schema.layout, model, { attributes: {} }); // If updating a content-type if (!_.isEmpty(layout)) {