mirror of
https://github.com/strapi/strapi.git
synced 2025-09-07 15:49:24 +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;
|
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
|
// Init schema
|
||||||
const schema = {
|
const schema = {
|
||||||
generalSettings: {
|
generalSettings: {
|
||||||
@ -235,6 +241,16 @@ module.exports = async cb => {
|
|||||||
pluginStore.set({ key: 'schema', value: schema });
|
pluginStore.set({ key: 'schema', value: schema });
|
||||||
|
|
||||||
return cb();
|
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
|
// Here we do the difference between the previous schema from the database and the new one
|
||||||
|
@ -23,6 +23,7 @@ import {
|
|||||||
size,
|
size,
|
||||||
split,
|
split,
|
||||||
take,
|
take,
|
||||||
|
toLower,
|
||||||
toNumber,
|
toNumber,
|
||||||
replace,
|
replace,
|
||||||
} from 'lodash';
|
} from 'lodash';
|
||||||
@ -378,7 +379,7 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
|
|||||||
|
|
||||||
handleBlur = ({ target }) => {
|
handleBlur = ({ target }) => {
|
||||||
if (target.name === 'name') {
|
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)) {
|
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
|
// The input name for content type doesn't have the default handleBlur validation so we need to manually remove the error
|
||||||
this.props.removeContentTypeRequiredError();
|
this.props.removeContentTypeRequiredError();
|
||||||
@ -489,7 +490,7 @@ export class Form extends React.Component { // eslint-disable-line react/prefer-
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
...model,
|
...model,
|
||||||
name: camelCase(model.name),
|
name: toLower(camelCase(model.name)),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const schema = await pluginStore.get({ key: 'schema' });
|
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 updating a content-type
|
||||||
if (!_.isEmpty(layout)) {
|
if (!_.isEmpty(layout)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user