mirror of
https://github.com/strapi/strapi.git
synced 2025-10-30 09:23:28 +00:00
Handle add attr logic
This commit is contained in:
parent
be73140600
commit
54aef15b75
@ -137,6 +137,7 @@ class Edit extends React.PureComponent {
|
|||||||
customBootstrapClass={className}
|
customBootstrapClass={className}
|
||||||
customInputs={{ json: InputJSONWithErrors, wysiwyg: WysiwygWithErrors }}
|
customInputs={{ json: InputJSONWithErrors, wysiwyg: WysiwygWithErrors }}
|
||||||
didCheckErrors={this.props.didCheckErrors}
|
didCheckErrors={this.props.didCheckErrors}
|
||||||
|
disabled={!get(details, 'editable', true)}
|
||||||
errors={this.getInputErrors(attr)}
|
errors={this.getInputErrors(attr)}
|
||||||
inputDescription={inputDescription}
|
inputDescription={inputDescription}
|
||||||
key={attr}
|
key={attr}
|
||||||
|
|||||||
@ -137,12 +137,12 @@
|
|||||||
"validations": {}
|
"validations": {}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"label": { "id": "content-manager.form.Input.description" },
|
"label": { "id": "content-manager.form.Input.placeholder" },
|
||||||
"customBootstrapClass": "col-md-12",
|
"customBootstrapClass": "col-md-12",
|
||||||
"didCheckErrors": false,
|
"didCheckErrors": false,
|
||||||
"errors": [],
|
"errors": [],
|
||||||
"name": "placeholder",
|
"name": "placeholder",
|
||||||
"placeholder": "content-manager.form.Input.description.placeholder",
|
"placeholder": "content-manager.form.Input.placeholder.placeholder",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"validations": {}
|
"validations": {}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -614,6 +614,7 @@ class SettingPage extends React.PureComponent {
|
|||||||
const {
|
const {
|
||||||
onSubmit,
|
onSubmit,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
console.log(this.props.schema);
|
||||||
// TODO: Add loader!
|
// TODO: Add loader!
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -95,7 +95,9 @@
|
|||||||
"error.validation.json": "This is not a JSON",
|
"error.validation.json": "This is not a JSON",
|
||||||
|
|
||||||
"form.Input.description": "Description",
|
"form.Input.description": "Description",
|
||||||
|
"form.Input.placeholder": "Placeholder",
|
||||||
"form.Input.description.placeholder": "Please don't forget to fill the full URL!",
|
"form.Input.description.placeholder": "Please don't forget to fill the full URL!",
|
||||||
|
"form.Input.placeholder.placeholder": "My awesome value",
|
||||||
"form.Input.disabled": "Editable field",
|
"form.Input.disabled": "Editable field",
|
||||||
"form.Input.label.inputDescription": "This value overrides the label displayed in the table's head",
|
"form.Input.label.inputDescription": "This value overrides the label displayed in the table's head",
|
||||||
"form.Input.label": "Label",
|
"form.Input.label": "Label",
|
||||||
|
|||||||
@ -94,7 +94,9 @@
|
|||||||
"error.validation.json": "Le format JSON n'est pas respecté",
|
"error.validation.json": "Le format JSON n'est pas respecté",
|
||||||
|
|
||||||
"form.Input.description": "Description",
|
"form.Input.description": "Description",
|
||||||
|
"form.Input.placeholder": "Placeholder",
|
||||||
"form.Input.description.placeholder": "N'oubliez pas de mettre l'URL complète!",
|
"form.Input.description.placeholder": "N'oubliez pas de mettre l'URL complète!",
|
||||||
|
"form.Input.placeholder.placeholder": "Mon super placeholder",
|
||||||
"form.Input.disabled": "Champ editable",
|
"form.Input.disabled": "Champ editable",
|
||||||
"form.Input.label": "Label",
|
"form.Input.label": "Label",
|
||||||
"form.Input.label.inputDescription": "Cette valeur modifie celle du champs de la table",
|
"form.Input.label.inputDescription": "Cette valeur modifie celle du champs de la table",
|
||||||
|
|||||||
@ -25,7 +25,6 @@ module.exports = async cb => {
|
|||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
const tempLayout = Object.keys(strapi.models)
|
const tempLayout = Object.keys(strapi.models)
|
||||||
.filter(m => m !== 'core_store')
|
.filter(m => m !== 'core_store')
|
||||||
.reduce((acc, current) => {
|
.reduce((acc, current) => {
|
||||||
@ -33,7 +32,6 @@ module.exports = async cb => {
|
|||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
}, pluginsLayout);
|
}, pluginsLayout);
|
||||||
|
|
||||||
const models = _.mapValues(strapi.models, pickData);
|
const models = _.mapValues(strapi.models, pickData);
|
||||||
delete models['core_store'];
|
delete models['core_store'];
|
||||||
const pluginsModel = Object.keys(strapi.plugins).reduce((acc, current) => {
|
const pluginsModel = Object.keys(strapi.plugins).reduce((acc, current) => {
|
||||||
@ -43,7 +41,6 @@ module.exports = async cb => {
|
|||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
// Init schema
|
// Init schema
|
||||||
const schema = {
|
const schema = {
|
||||||
generalSettings: {
|
generalSettings: {
|
||||||
@ -76,9 +73,7 @@ module.exports = async cb => {
|
|||||||
relations: [],
|
relations: [],
|
||||||
},
|
},
|
||||||
}, model);
|
}, model);
|
||||||
|
|
||||||
const fieldsToRemove = [];
|
const fieldsToRemove = [];
|
||||||
|
|
||||||
// Fields (non relation)
|
// Fields (non relation)
|
||||||
const fields = _.mapValues(_.pickBy(model.attributes, attribute =>
|
const fields = _.mapValues(_.pickBy(model.attributes, attribute =>
|
||||||
!attribute.model && !attribute.collection
|
!attribute.model && !attribute.collection
|
||||||
@ -241,6 +236,9 @@ module.exports = async cb => {
|
|||||||
return fields.map(field => `${apiPath.join('.')}.fields.${field}`);
|
return fields.map(field => `${apiPath.join('.')}.fields.${field}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const getEditDisplayAvailableFieldsPath = attrPath => [..._.take(attrPath, attrPath.length -2), 'editDisplay', 'availableFields', attrPath[attrPath.length - 1]];
|
||||||
|
const getEditDisplayFieldsPath = attrPath => [..._.take(attrPath, attrPath.length -2), 'editDisplay', 'fields'];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const prevSchema = await pluginStore.get({ key: 'schema' });
|
const prevSchema = await pluginStore.get({ key: 'schema' });
|
||||||
|
|
||||||
@ -270,6 +268,9 @@ module.exports = async cb => {
|
|||||||
|
|
||||||
// Remove API attribute
|
// Remove API attribute
|
||||||
sameApisAttrToRemove.map(attrPath => {
|
sameApisAttrToRemove.map(attrPath => {
|
||||||
|
const editDisplayPath = getEditDisplayAvailableFieldsPath(attrPath);
|
||||||
|
// Remove the field from the available fields in the editDisplayObject
|
||||||
|
_.unset(prevSchema.models, editDisplayPath);
|
||||||
// Check default sort and change it if needed
|
// Check default sort and change it if needed
|
||||||
_.unset(prevSchema.models, attrPath);
|
_.unset(prevSchema.models, attrPath);
|
||||||
const apiPath = attrPath.length > 3 ? _.take(attrPath, 3) : _.take(attrPath, 1);
|
const apiPath = attrPath.length > 3 ? _.take(attrPath, 3) : _.take(attrPath, 1);
|
||||||
@ -277,7 +278,6 @@ module.exports = async cb => {
|
|||||||
const prevListDisplay = _.get(prevSchema.models, listDisplayPath);
|
const prevListDisplay = _.get(prevSchema.models, listDisplayPath);
|
||||||
const defaultSortPath = apiPath.concat('defaultSort');
|
const defaultSortPath = apiPath.concat('defaultSort');
|
||||||
const currentAttr = attrPath.slice(-1);
|
const currentAttr = attrPath.slice(-1);
|
||||||
|
|
||||||
const defaultSort = _.get(prevSchema.models, defaultSortPath);
|
const defaultSort = _.get(prevSchema.models, defaultSortPath);
|
||||||
|
|
||||||
if (_.includes(currentAttr, defaultSort)) {
|
if (_.includes(currentAttr, defaultSort)) {
|
||||||
@ -311,8 +311,18 @@ module.exports = async cb => {
|
|||||||
sameApisAttrToAdd.map(attrPath => {
|
sameApisAttrToAdd.map(attrPath => {
|
||||||
const attr = _.get(schema.models, attrPath);
|
const attr = _.get(schema.models, attrPath);
|
||||||
_.set(prevSchema.models, attrPath, attr);
|
_.set(prevSchema.models, attrPath, attr);
|
||||||
});
|
|
||||||
|
|
||||||
|
// Add the field in the editDisplay object
|
||||||
|
const path = getEditDisplayAvailableFieldsPath(attrPath);
|
||||||
|
const availableAttrToAdd = _.get(schema.models, path);
|
||||||
|
_.set(prevSchema.models, path, availableAttrToAdd);
|
||||||
|
|
||||||
|
// Push the attr into the list
|
||||||
|
const fieldsPath = getEditDisplayFieldsPath(attrPath);
|
||||||
|
const currentFields = _.get(prevSchema.models, fieldsPath, []);
|
||||||
|
currentFields.push(availableAttrToAdd.name);
|
||||||
|
_.set(prevSchema.models, fieldsPath, currentFields);
|
||||||
|
});
|
||||||
|
|
||||||
// Update other keys
|
// Update other keys
|
||||||
sameApis.map(apiPath => {
|
sameApis.map(apiPath => {
|
||||||
@ -326,7 +336,6 @@ module.exports = async cb => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await pluginStore.set({ key: 'schema', value: prevSchema });
|
await pluginStore.set({ key: 'schema', value: prevSchema });
|
||||||
|
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
console.log('error', err);
|
console.log('error', err);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,8 +32,7 @@
|
|||||||
"role": {
|
"role": {
|
||||||
"model": "role",
|
"model": "role",
|
||||||
"via": "permissions",
|
"via": "permissions",
|
||||||
"plugin": "users-permissions",
|
"plugin": "users-permissions"
|
||||||
"configurable": false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -20,16 +20,18 @@
|
|||||||
"unique": true,
|
"unique": true,
|
||||||
"configurable": false
|
"configurable": false
|
||||||
},
|
},
|
||||||
"users": {
|
|
||||||
"collection": "user",
|
|
||||||
"via": "role",
|
|
||||||
"plugin": "users-permissions"
|
|
||||||
},
|
|
||||||
"permissions": {
|
"permissions": {
|
||||||
"collection": "permission",
|
"collection": "permission",
|
||||||
"via": "role",
|
"via": "role",
|
||||||
"plugin": "users-permissions",
|
"plugin": "users-permissions",
|
||||||
"configurable": false
|
"configurable": false,
|
||||||
|
"isVirtual": true
|
||||||
|
},
|
||||||
|
"users": {
|
||||||
|
"collection": "user",
|
||||||
|
"via": "role",
|
||||||
|
"plugin": "users-permissions"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"collectionName": "users-permissions_role"
|
||||||
}
|
}
|
||||||
@ -18,33 +18,19 @@
|
|||||||
"configurable": false,
|
"configurable": false,
|
||||||
"required": true
|
"required": true
|
||||||
},
|
},
|
||||||
"provider": {
|
|
||||||
"type": "string",
|
|
||||||
"configurable": false
|
|
||||||
},
|
|
||||||
"password": {
|
"password": {
|
||||||
"type": "password",
|
"type": "password",
|
||||||
"minLength": 6,
|
"minLength": 6,
|
||||||
"configurable": false,
|
"configurable": false,
|
||||||
"private": true
|
"private": true
|
||||||
},
|
},
|
||||||
"resetPasswordToken": {
|
|
||||||
"type": "string",
|
|
||||||
"configurable": false,
|
|
||||||
"private": true
|
|
||||||
},
|
|
||||||
"role": {
|
"role": {
|
||||||
"model": "role",
|
"model": "role",
|
||||||
"via": "users",
|
"via": "users",
|
||||||
"plugin": "users-permissions",
|
"plugin": "users-permissions"
|
||||||
"configurable": false
|
|
||||||
},
|
},
|
||||||
"infoss": {
|
"newField": {
|
||||||
"type": "text"
|
"type": "string"
|
||||||
},
|
|
||||||
"products": {
|
|
||||||
"collection": "product",
|
|
||||||
"via": "user"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"collectionName": "users-permissions_user"
|
"collectionName": "users-permissions_user"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user