mirror of
https://github.com/strapi/strapi.git
synced 2025-09-06 23:28:02 +00:00
Fix schema
Force lowerCase on content type name (since it is not supported by the backend) Clean layout when the model has been removed
This commit is contained in:
parent
d279ae8fa3
commit
428a9ca62d
@ -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
|
||||
|
@ -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)),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user