Handle add attr logic

This commit is contained in:
soupette 2018-07-27 17:24:58 +02:00
parent be73140600
commit 54aef15b75
9 changed files with 39 additions and 37 deletions

View File

@ -137,6 +137,7 @@ class Edit extends React.PureComponent {
customBootstrapClass={className}
customInputs={{ json: InputJSONWithErrors, wysiwyg: WysiwygWithErrors }}
didCheckErrors={this.props.didCheckErrors}
disabled={!get(details, 'editable', true)}
errors={this.getInputErrors(attr)}
inputDescription={inputDescription}
key={attr}

View File

@ -137,12 +137,12 @@
"validations": {}
},
{
"label": { "id": "content-manager.form.Input.description" },
"label": { "id": "content-manager.form.Input.placeholder" },
"customBootstrapClass": "col-md-12",
"didCheckErrors": false,
"errors": [],
"name": "placeholder",
"placeholder": "content-manager.form.Input.description.placeholder",
"placeholder": "content-manager.form.Input.placeholder.placeholder",
"type": "string",
"validations": {}
}

View File

@ -614,6 +614,7 @@ class SettingPage extends React.PureComponent {
const {
onSubmit,
} = this.props;
console.log(this.props.schema);
// TODO: Add loader!
return (

View File

@ -95,7 +95,9 @@
"error.validation.json": "This is not a JSON",
"form.Input.description": "Description",
"form.Input.placeholder": "Placeholder",
"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.label.inputDescription": "This value overrides the label displayed in the table's head",
"form.Input.label": "Label",

View File

@ -94,7 +94,9 @@
"error.validation.json": "Le format JSON n'est pas respecté",
"form.Input.description": "Description",
"form.Input.placeholder": "Placeholder",
"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.label": "Label",
"form.Input.label.inputDescription": "Cette valeur modifie celle du champs de la table",

View File

@ -25,7 +25,6 @@ module.exports = async cb => {
return acc;
}, {});
const tempLayout = Object.keys(strapi.models)
.filter(m => m !== 'core_store')
.reduce((acc, current) => {
@ -33,7 +32,6 @@ module.exports = async cb => {
return acc;
}, pluginsLayout);
const models = _.mapValues(strapi.models, pickData);
delete models['core_store'];
const pluginsModel = Object.keys(strapi.plugins).reduce((acc, current) => {
@ -43,7 +41,6 @@ module.exports = async cb => {
return acc;
}, {});
// Init schema
const schema = {
generalSettings: {
@ -76,9 +73,7 @@ module.exports = async cb => {
relations: [],
},
}, model);
const fieldsToRemove = [];
// Fields (non relation)
const fields = _.mapValues(_.pickBy(model.attributes, attribute =>
!attribute.model && !attribute.collection
@ -241,6 +236,9 @@ module.exports = async cb => {
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 {
const prevSchema = await pluginStore.get({ key: 'schema' });
@ -270,6 +268,9 @@ module.exports = async cb => {
// Remove API attribute
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
_.unset(prevSchema.models, attrPath);
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 defaultSortPath = apiPath.concat('defaultSort');
const currentAttr = attrPath.slice(-1);
const defaultSort = _.get(prevSchema.models, defaultSortPath);
if (_.includes(currentAttr, defaultSort)) {
@ -311,8 +311,18 @@ module.exports = async cb => {
sameApisAttrToAdd.map(attrPath => {
const attr = _.get(schema.models, attrPath);
_.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
sameApis.map(apiPath => {
@ -326,7 +336,6 @@ module.exports = async cb => {
});
await pluginStore.set({ key: 'schema', value: prevSchema });
} catch(err) {
console.log('error', err);
}

View File

@ -32,8 +32,7 @@
"role": {
"model": "role",
"via": "permissions",
"plugin": "users-permissions",
"configurable": false
"plugin": "users-permissions"
}
}
}
}

View File

@ -20,16 +20,18 @@
"unique": true,
"configurable": false
},
"users": {
"collection": "user",
"via": "role",
"plugin": "users-permissions"
},
"permissions": {
"collection": "permission",
"via": "role",
"plugin": "users-permissions",
"configurable": false
"configurable": false,
"isVirtual": true
},
"users": {
"collection": "user",
"via": "role",
"plugin": "users-permissions"
}
}
},
"collectionName": "users-permissions_role"
}

View File

@ -18,33 +18,19 @@
"configurable": false,
"required": true
},
"provider": {
"type": "string",
"configurable": false
},
"password": {
"type": "password",
"minLength": 6,
"configurable": false,
"private": true
},
"resetPasswordToken": {
"type": "string",
"configurable": false,
"private": true
},
"role": {
"model": "role",
"via": "users",
"plugin": "users-permissions",
"configurable": false
"plugin": "users-permissions"
},
"infoss": {
"type": "text"
},
"products": {
"collection": "product",
"via": "user"
"newField": {
"type": "string"
}
},
"collectionName": "users-permissions_user"