mirror of
https://github.com/strapi/strapi.git
synced 2025-09-04 14:23:03 +00:00
Add new key in schema to display the editView fields
Design the relation drag & sort
This commit is contained in:
parent
807ded44a1
commit
6cc063e98c
@ -9,9 +9,9 @@ import { FormattedMessage } from 'react-intl';
|
|||||||
|
|
||||||
import styles from './styles.scss';
|
import styles from './styles.scss';
|
||||||
|
|
||||||
const Block = ({ children, description, title }) => (
|
const Block = ({ children, description, style, title }) => (
|
||||||
<div className="col-md-12">
|
<div className="col-md-12">
|
||||||
<div className={styles.ctmBlock}>
|
<div className={styles.ctmBlock} style={style}>
|
||||||
<div className={styles.ctmBlockTitle}>
|
<div className={styles.ctmBlockTitle}>
|
||||||
<FormattedMessage id={title} />
|
<FormattedMessage id={title} />
|
||||||
<FormattedMessage id={description}>
|
<FormattedMessage id={description}>
|
||||||
@ -27,12 +27,14 @@ const Block = ({ children, description, title }) => (
|
|||||||
Block.defaultProps = {
|
Block.defaultProps = {
|
||||||
children: null,
|
children: null,
|
||||||
description: 'app.utils.defaultMessage',
|
description: 'app.utils.defaultMessage',
|
||||||
|
style: {},
|
||||||
title: 'app.utils.defaultMessage',
|
title: 'app.utils.defaultMessage',
|
||||||
};
|
};
|
||||||
|
|
||||||
Block.propTypes = {
|
Block.propTypes = {
|
||||||
children: PropTypes.any,
|
children: PropTypes.any,
|
||||||
description: PropTypes.string,
|
description: PropTypes.string,
|
||||||
|
style: PropTypes.object,
|
||||||
title: PropTypes.string,
|
title: PropTypes.string,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -88,6 +88,14 @@ class SettingPage extends React.PureComponent {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getEditPageDisplaySettings = () => {
|
||||||
|
return get(this.props.schema, 'models.'.concat(this.getPath().concat('.editDisplay')), { fields: [], relations: [] });
|
||||||
|
}
|
||||||
|
|
||||||
|
getEditPageFields = () => get(this.getEditPageDisplaySettings(), ['fields'], []);
|
||||||
|
|
||||||
|
getEditPageRelations = () => get(this.getEditPageDisplaySettings(), ['relations'], []);
|
||||||
|
|
||||||
getListDisplay = () => (
|
getListDisplay = () => (
|
||||||
get(this.props.schema, `models.${this.getPath()}.listDisplay`, [])
|
get(this.props.schema, `models.${this.getPath()}.listDisplay`, [])
|
||||||
);
|
);
|
||||||
@ -207,6 +215,19 @@ class SettingPage extends React.PureComponent {
|
|||||||
return index === -1 ? 0 : index;
|
return index === -1 ? 0 : index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hasRelations = () => {
|
||||||
|
const relations = get(this.props.schema, 'models.'.concat(this.getPath()).concat('.relations'), {});
|
||||||
|
|
||||||
|
return Object.keys(relations)
|
||||||
|
.filter(relation => {
|
||||||
|
const isUploadRelation = get(relations, [relation, 'plugin'], '') === 'upload';
|
||||||
|
const isMorphSide = get(relations, [relation, 'nature'], '').toLowerCase().includes('morph') && get(relations, [relation, relation]) !== undefined;
|
||||||
|
|
||||||
|
return !isUploadRelation && !isMorphSide;
|
||||||
|
})
|
||||||
|
.length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
// We need to remove the Over state on the DraggableAttr component
|
// We need to remove the Over state on the DraggableAttr component
|
||||||
updateSiblingHoverState = () => {
|
updateSiblingHoverState = () => {
|
||||||
this.setState(prevState => ({ isDraggingSibling: !prevState.isDraggingSibling }));
|
this.setState(prevState => ({ isDraggingSibling: !prevState.isDraggingSibling }));
|
||||||
@ -234,7 +255,7 @@ class SettingPage extends React.PureComponent {
|
|||||||
const namePath = this.getPath();
|
const namePath = this.getPath();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<form onSubmit={this.handleSubmit}>
|
||||||
<BackHeader onClick={() => this.props.history.goBack()} />
|
<BackHeader onClick={() => this.props.history.goBack()} />
|
||||||
<div className={cn('container-fluid', styles.containerFluid)}>
|
<div className={cn('container-fluid', styles.containerFluid)}>
|
||||||
<PluginHeader
|
<PluginHeader
|
||||||
@ -271,13 +292,16 @@ class SettingPage extends React.PureComponent {
|
|||||||
this.toggleWarningCancel();
|
this.toggleWarningCancel();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div className={cn('row', styles.container)}>
|
<div className={cn('row', styles.container)}>
|
||||||
<Block
|
<Block
|
||||||
description="content-manager.containers.SettingPage.listSettings.description"
|
description="content-manager.containers.SettingPage.listSettings.description"
|
||||||
title="content-manager.containers.SettingPage.listSettings.title"
|
title="content-manager.containers.SettingPage.listSettings.title"
|
||||||
|
style={{ marginBottom: '25px' }}
|
||||||
>
|
>
|
||||||
<form onSubmit={this.handleSubmit} className={styles.ctmForm}>
|
<div className={styles.ctmForm}>
|
||||||
<div className="row">
|
<div className="row">
|
||||||
|
|
||||||
<div className="col-md-12">
|
<div className="col-md-12">
|
||||||
<div className="row">
|
<div className="row">
|
||||||
{forms.inputs.map(input => {
|
{forms.inputs.map(input => {
|
||||||
@ -296,22 +320,26 @@ class SettingPage extends React.PureComponent {
|
|||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="col-md-12">
|
<div className="col-md-12">
|
||||||
<div className={styles.separator} />
|
<div className={styles.separator} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={styles.listDisplayWrapper}>
|
<div className={styles.listDisplayWrapper}>
|
||||||
<div className="row">
|
<div className="row">
|
||||||
|
|
||||||
<div className={cn('col-md-12', styles.draggedDescription)}>
|
<div className={cn('col-md-12', styles.draggedDescription)}>
|
||||||
<FormattedMessage id="content-manager.containers.SettingPage.attributes" />
|
<FormattedMessage id="content-manager.containers.SettingPage.attributes" />
|
||||||
<p>
|
<p>
|
||||||
<FormattedMessage id="content-manager.containers.SettingPage.attributes.description" />
|
<FormattedMessage id="content-manager.containers.SettingPage.attributes.description" />
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="col-md-5">
|
<div className="col-md-5">
|
||||||
{this.getListDisplay().map((attr, index) => (
|
{this.getListDisplay().map((attr, index) => (
|
||||||
<div key={attr.name} className={styles.draggedWrapper}>
|
<div key={attr.name} className={styles.draggedWrapper}>
|
||||||
<div>{index}.</div>
|
<div>{index + 1}.</div>
|
||||||
<DraggableAttr
|
<DraggableAttr
|
||||||
index={index}
|
index={index}
|
||||||
isDraggingSibling={isDraggingSibling}
|
isDraggingSibling={isDraggingSibling}
|
||||||
@ -360,6 +388,7 @@ class SettingPage extends React.PureComponent {
|
|||||||
</ButtonDropdown>
|
</ButtonDropdown>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="col-md-7">
|
<div className="col-md-7">
|
||||||
<div className={styles.editWrapper}>
|
<div className={styles.editWrapper}>
|
||||||
<div className="row">
|
<div className="row">
|
||||||
@ -391,13 +420,59 @@ class SettingPage extends React.PureComponent {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</div>
|
||||||
|
</Block>
|
||||||
|
|
||||||
|
<Block
|
||||||
|
description="content-manager.containers.SettingPage.editSettings.description"
|
||||||
|
title="content-manager.containers.SettingPage.editSettings.title"
|
||||||
|
>
|
||||||
|
<div className="row">
|
||||||
|
|
||||||
|
<div className={cn('col-md-8', styles.draggedDescription, styles.edit_settings)}>
|
||||||
|
<FormattedMessage id="content-manager.containers.SettingPage.attributes" />
|
||||||
|
<div className={cn(styles.sort_wrapper, 'col-md-12')}>
|
||||||
|
<div className="row">
|
||||||
|
{/* GRID SORT */}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{this.hasRelations() && (
|
||||||
|
<div className={cn('col-md-4', styles.draggedDescription, styles.edit_settings)}>
|
||||||
|
<FormattedMessage id="content-manager.containers.SettingPage.relations" />
|
||||||
|
<div className={cn(styles.sort_wrapper, 'col-md-12')}>
|
||||||
|
<div className="row">
|
||||||
|
{this.getEditPageRelations().map((attr, index) => {
|
||||||
|
return (
|
||||||
|
<DraggableAttr
|
||||||
|
index={index}
|
||||||
|
isDraggingSibling={false}
|
||||||
|
isEditing={false}
|
||||||
|
key={attr}
|
||||||
|
keys=""
|
||||||
|
name={attr}
|
||||||
|
label={attr}
|
||||||
|
moveAttr={() => {}}
|
||||||
|
onClickEditListItem={() => {}}
|
||||||
|
onRemove={() => {}}
|
||||||
|
updateSiblingHoverState={() => {}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
</div>
|
||||||
</Block>
|
</Block>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</React.Fragment>
|
</form>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,3 +126,16 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.edit_settings {
|
||||||
|
padding-top: 25px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sort_wrapper {
|
||||||
|
margin-top: 7px;
|
||||||
|
padding-top: 10px;
|
||||||
|
border: 1px dashed #E3E9F3;
|
||||||
|
> div {
|
||||||
|
padding: 0 10px;
|
||||||
|
}
|
||||||
|
}
|
@ -18,6 +18,10 @@
|
|||||||
"containers.SettingPage.addField": "Add new field",
|
"containers.SettingPage.addField": "Add new field",
|
||||||
"containers.SettingPage.attributes": "Attributes fields",
|
"containers.SettingPage.attributes": "Attributes fields",
|
||||||
"containers.SettingPage.attributes.description": "Define the order of the attributes",
|
"containers.SettingPage.attributes.description": "Define the order of the attributes",
|
||||||
|
"containers.SettingPage.relations": "Relational fields",
|
||||||
|
|
||||||
|
"containers.SettingPage.editSettings.description": "Drag & drop the fields to build the layout",
|
||||||
|
"containers.SettingPage.editSettings.title": "Edit - Settings",
|
||||||
|
|
||||||
"containers.SettingPage.listSettings.title": "List — Settings",
|
"containers.SettingPage.listSettings.title": "List — Settings",
|
||||||
"containers.SettingPage.listSettings.description": "Configure the options for this content type",
|
"containers.SettingPage.listSettings.description": "Configure the options for this content type",
|
||||||
|
@ -18,7 +18,13 @@
|
|||||||
"containers.SettingPage.addField": "Ajouter un nouveau champs",
|
"containers.SettingPage.addField": "Ajouter un nouveau champs",
|
||||||
"containers.SettingPage.attributes": "Attributs",
|
"containers.SettingPage.attributes": "Attributs",
|
||||||
"containers.SettingPage.attributes.description": "Organiser les attributs du modèle",
|
"containers.SettingPage.attributes.description": "Organiser les attributs du modèle",
|
||||||
|
"containers.SettingPage.relations": "Champs relationnels",
|
||||||
|
|
||||||
"containers.SettingPage.pluginHeaderDescription": "Configurez les paramètres de ce modèle",
|
"containers.SettingPage.pluginHeaderDescription": "Configurez les paramètres de ce modèle",
|
||||||
|
|
||||||
|
"containers.SettingPage.editSettings.description": "Glissez & déposez les champs pour construire le layout",
|
||||||
|
"containers.SettingPage.editSettings.title": "Edit - Paramètres",
|
||||||
|
|
||||||
"containers.SettingPage.listSettings.title": "Liste — Paramètres",
|
"containers.SettingPage.listSettings.title": "Liste — Paramètres",
|
||||||
"containers.SettingPage.listSettings.description": "Configurez les options de ce modèle",
|
"containers.SettingPage.listSettings.description": "Configurez les options de ce modèle",
|
||||||
|
|
||||||
|
@ -51,10 +51,14 @@ module.exports = async cb => {
|
|||||||
pageEntries: 10,
|
pageEntries: 10,
|
||||||
defaultSort: model.primaryKey,
|
defaultSort: model.primaryKey,
|
||||||
sort: 'ASC',
|
sort: 'ASC',
|
||||||
|
editDisplay: {
|
||||||
|
fields: [],
|
||||||
|
relations: [],
|
||||||
|
},
|
||||||
}, model);
|
}, model);
|
||||||
|
|
||||||
// Fields (non relation)
|
// Fields (non relation)
|
||||||
schemaModel.fields = _.mapValues(_.pickBy(model.attributes, attribute =>
|
const fields = _.mapValues(_.pickBy(model.attributes, attribute =>
|
||||||
!attribute.model && !attribute.collection
|
!attribute.model && !attribute.collection
|
||||||
), (value, attribute) => ({
|
), (value, attribute) => ({
|
||||||
label: _.upperFirst(attribute),
|
label: _.upperFirst(attribute),
|
||||||
@ -62,8 +66,11 @@ module.exports = async cb => {
|
|||||||
type: value.type || 'string',
|
type: value.type || 'string',
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
schemaModel.fields = fields;
|
||||||
|
schemaModel.editDisplay.fields = Object.keys(fields);
|
||||||
|
|
||||||
|
|
||||||
// Select fields displayed in list view
|
// Select fields displayed in list view
|
||||||
// schemaModel.list = _.slice(_.keys(schemaModel.fields), 0, 4);
|
|
||||||
schemaModel.listDisplay = Object.keys(schemaModel.fields)
|
schemaModel.listDisplay = Object.keys(schemaModel.fields)
|
||||||
// Construct Array of attr ex { type: 'string', label: 'Foo', name: 'Foo', description: '' }
|
// Construct Array of attr ex { type: 'string', label: 'Foo', name: 'Foo', description: '' }
|
||||||
// NOTE: Do we allow sort on boolean?
|
// NOTE: Do we allow sort on boolean?
|
||||||
@ -103,6 +110,15 @@ module.exports = async cb => {
|
|||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
|
const relationsArray = Object.keys(schemaModel.relations).filter(relation => {
|
||||||
|
const isUploadRelation = _.get(schemaModel, ['relations', relation, 'plugin'], '') === 'upload';
|
||||||
|
const isMorphSide = _.get(schemaModel, ['relations', relation, 'nature'], '').toLowerCase().includes('morp') && _.get(schemaModel, ['relations', relation, relation]) !== undefined;
|
||||||
|
|
||||||
|
return !isUploadRelation && !isMorphSide;
|
||||||
|
});
|
||||||
|
|
||||||
|
schemaModel.editDisplay.relations = relationsArray;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin) {
|
if (plugin) {
|
||||||
|
@ -1 +1,25 @@
|
|||||||
{}
|
{
|
||||||
|
"product": {
|
||||||
|
"attributes": {
|
||||||
|
"name": {
|
||||||
|
"appearance": ""
|
||||||
|
},
|
||||||
|
"price": {
|
||||||
|
"appearance": ""
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
|
"appearance": ""
|
||||||
|
},
|
||||||
|
"description_long": {
|
||||||
|
"appearance": "WYSIWYG"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tag": {
|
||||||
|
"attributes": {
|
||||||
|
"name": {
|
||||||
|
"appearance": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -38,6 +38,10 @@
|
|||||||
"via": "users",
|
"via": "users",
|
||||||
"plugin": "users-permissions",
|
"plugin": "users-permissions",
|
||||||
"configurable": false
|
"configurable": false
|
||||||
|
},
|
||||||
|
"products": {
|
||||||
|
"collection": "product",
|
||||||
|
"via": "users"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user