mirror of
https://github.com/strapi/strapi.git
synced 2025-10-27 16:10:08 +00:00
Handle display edit layout
This commit is contained in:
parent
5830ed4a73
commit
fb8c3d2297
@ -14,15 +14,12 @@ import {
|
||||
isFunction,
|
||||
upperFirst,
|
||||
} from 'lodash';
|
||||
|
||||
// You can find these components in either
|
||||
// ./node_modules/strapi-helper-plugin/lib/src
|
||||
// or strapi/packages/strapi-helper-plugin/lib/src
|
||||
import Input from 'components/InputsIndex';
|
||||
|
||||
import InputJSONWithErrors from 'components/InputJSONWithErrors';
|
||||
import WysiwygWithErrors from 'components/WysiwygWithErrors';
|
||||
|
||||
import styles from './styles.scss';
|
||||
|
||||
const getInputType = (type = '') => {
|
||||
@ -115,41 +112,49 @@ class Edit extends React.PureComponent {
|
||||
|
||||
orderAttributes = () => get(this.props.schema, ['editDisplay', 'fields'], []);
|
||||
|
||||
renderAttr = (attr, key) => {
|
||||
if (attr.includes('__col-md')) {
|
||||
const className = attr.split('__')[1];
|
||||
|
||||
return <div key={key} className={className} />;
|
||||
}
|
||||
|
||||
const details = get(this.props.schema, ['editDisplay', 'availableFields', attr]);
|
||||
// Retrieve the input's bootstrapClass from the layout
|
||||
const layout = this.getInputLayout(attr);
|
||||
const appearance = get(layout, 'appearance');
|
||||
const type = !isEmpty(appearance) ? appearance.toLowerCase() : get(layout, 'type', getInputType(details.type));
|
||||
const inputDescription = get(details, 'description', null);
|
||||
|
||||
return (
|
||||
<Input
|
||||
autoFocus={key === 0}
|
||||
customBootstrapClass={get(layout, 'className')}
|
||||
customInputs={{ json: InputJSONWithErrors, wysiwyg: WysiwygWithErrors }}
|
||||
didCheckErrors={this.props.didCheckErrors}
|
||||
errors={this.getInputErrors(attr)}
|
||||
inputDescription={inputDescription}
|
||||
key={attr}
|
||||
label={get(layout, 'label') || details.label || ''}
|
||||
multiple={this.fileRelationAllowMultipleUpload(attr)}
|
||||
name={attr}
|
||||
onBlur={this.props.onBlur}
|
||||
onChange={this.props.onChange}
|
||||
placeholder={get(layout, 'placeholder') || details.placeholder || ''}
|
||||
resetProps={this.props.resetProps}
|
||||
selectOptions={get(this.props.attributes, [attr, 'enum'])}
|
||||
type={type}
|
||||
validations={this.getInputValidations(attr)}
|
||||
value={this.props.record[attr]}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
render(){
|
||||
return (
|
||||
<div className={styles.form}>
|
||||
<div className="row">
|
||||
{this.orderAttributes().map((attr, key) => {
|
||||
const details = get(this.props.schema, ['editDisplay', 'availableFields', attr]);
|
||||
// Retrieve the input's bootstrapClass from the layout
|
||||
const layout = this.getInputLayout(attr);
|
||||
const appearance = get(layout, 'appearance');
|
||||
const type = !isEmpty(appearance) ? appearance.toLowerCase() : get(layout, 'type', getInputType(details.type));
|
||||
const inputDescription = get(details, 'description', null);
|
||||
|
||||
return (
|
||||
<Input
|
||||
autoFocus={key === 0}
|
||||
customBootstrapClass={get(layout, 'className')}
|
||||
customInputs={{ json: InputJSONWithErrors, wysiwyg: WysiwygWithErrors }}
|
||||
didCheckErrors={this.props.didCheckErrors}
|
||||
errors={this.getInputErrors(attr)}
|
||||
inputDescription={inputDescription}
|
||||
key={attr}
|
||||
label={get(layout, 'label') || details.label || ''}
|
||||
multiple={this.fileRelationAllowMultipleUpload(attr)}
|
||||
name={attr}
|
||||
onBlur={this.props.onBlur}
|
||||
onChange={this.props.onChange}
|
||||
placeholder={get(layout, 'placeholder') || details.placeholder || ''}
|
||||
resetProps={this.props.resetProps}
|
||||
selectOptions={get(this.props.attributes, [attr, 'enum'])}
|
||||
type={type}
|
||||
validations={this.getInputValidations(attr)}
|
||||
value={this.props.record[attr]}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
{this.orderAttributes().map(this.renderAttr)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@ -16,9 +16,8 @@ module.exports = async cb => {
|
||||
'associations'
|
||||
]);
|
||||
|
||||
const tempLayout = Object.keys(strapi.plugins).reduce((acc, current) => {
|
||||
const pluginsLayout = Object.keys(strapi.plugins).reduce((acc, current) => {
|
||||
const models = _.get(strapi.plugins, [current, 'config', 'layout'], {});
|
||||
|
||||
Object.keys(models).forEach(model => {
|
||||
const layout = _.get(strapi.plugins, [current, 'config', 'layout', model], {});
|
||||
acc[model] = layout;
|
||||
@ -27,6 +26,13 @@ module.exports = async cb => {
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
const tempLayout = Object.keys(strapi.models)
|
||||
.filter(m => m !== 'core_store')
|
||||
.reduce((acc, current) => {
|
||||
acc[current] = { attributes: {} };
|
||||
|
||||
return acc;
|
||||
}, pluginsLayout);
|
||||
|
||||
const models = _.mapValues(strapi.models, pickData);
|
||||
delete models['core_store'];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user