mirror of
https://github.com/strapi/strapi.git
synced 2025-12-27 07:03:38 +00:00
Start buffet migration in editview
This commit is contained in:
parent
61234c9610
commit
c18a46f015
@ -14,6 +14,9 @@
|
||||
"comment": ""
|
||||
},
|
||||
"attributes": {
|
||||
"since": {
|
||||
"type": "date"
|
||||
},
|
||||
"name": {
|
||||
"maxLength": 50,
|
||||
"required": true,
|
||||
|
||||
@ -2,7 +2,7 @@ import React, { memo } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
const DynamicZone = ({ name }) => {
|
||||
return <div>{name}</div>;
|
||||
return <div>DYNAMIC ZONE: {name}</div>;
|
||||
};
|
||||
|
||||
DynamicZone.propTypes = {
|
||||
|
||||
@ -1,8 +1,13 @@
|
||||
import React, { memo, useMemo } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { get, omit } from 'lodash';
|
||||
import {
|
||||
get,
|
||||
// omit,
|
||||
} from 'lodash';
|
||||
// import { InputsIndex } from 'strapi-helper-plugin';
|
||||
import { InputFileWithErrors } from 'strapi-helper-plugin';
|
||||
import { Inputs as InputsIndex } from '@buffetjs/custom';
|
||||
|
||||
import { InputsIndex } from 'strapi-helper-plugin';
|
||||
import { useEditView } from '../../contexts/EditView';
|
||||
import InputJSONWithErrors from '../InputJSONWithErrors';
|
||||
import WysiwygWithErrors from '../WysiwygWithErrors';
|
||||
@ -10,7 +15,7 @@ import WysiwygWithErrors from '../WysiwygWithErrors';
|
||||
const getInputType = (type = '') => {
|
||||
switch (type.toLowerCase()) {
|
||||
case 'boolean':
|
||||
return 'toggle';
|
||||
return 'bool';
|
||||
case 'biginteger':
|
||||
case 'decimal':
|
||||
case 'float':
|
||||
@ -18,7 +23,8 @@ const getInputType = (type = '') => {
|
||||
return 'number';
|
||||
case 'date':
|
||||
case 'datetime':
|
||||
return 'date';
|
||||
case 'time':
|
||||
return type;
|
||||
case 'email':
|
||||
return 'email';
|
||||
case 'enumeration':
|
||||
@ -32,7 +38,7 @@ const getInputType = (type = '') => {
|
||||
case 'media':
|
||||
case 'file':
|
||||
case 'files':
|
||||
return 'file';
|
||||
return 'media';
|
||||
case 'json':
|
||||
return 'json';
|
||||
case 'wysiwyg':
|
||||
@ -44,16 +50,9 @@ const getInputType = (type = '') => {
|
||||
}
|
||||
};
|
||||
|
||||
function Inputs({
|
||||
autoFocus,
|
||||
keys,
|
||||
layout,
|
||||
modifiedData,
|
||||
name,
|
||||
onBlur,
|
||||
onChange,
|
||||
}) {
|
||||
const { didCheckErrors, errors } = useEditView();
|
||||
function Inputs({ autoFocus, keys, name, onBlur, onChange }) {
|
||||
const { didCheckErrors, errors, layout, modifiedData } = useEditView();
|
||||
console.log({ errors });
|
||||
const attribute = useMemo(
|
||||
() => get(layout, ['schema', 'attributes', name], {}),
|
||||
[layout, name]
|
||||
@ -66,24 +65,26 @@ function Inputs({
|
||||
metadatas,
|
||||
]);
|
||||
const type = useMemo(() => get(attribute, 'type', null), [attribute]);
|
||||
const inputStyle = type === 'text' ? { height: '196px' } : {};
|
||||
const validations = omit(attribute, [
|
||||
'type',
|
||||
'model',
|
||||
'via',
|
||||
'collection',
|
||||
'default',
|
||||
'plugin',
|
||||
'enum',
|
||||
]);
|
||||
|
||||
// const inputStyle = type === 'text' ? { height: '196px' } : {};
|
||||
// const validations = omit(attribute, [
|
||||
// 'type',
|
||||
// 'model',
|
||||
// 'via',
|
||||
// 'collection',
|
||||
// 'default',
|
||||
// 'plugin',
|
||||
// 'enum',
|
||||
// ]);
|
||||
const { description, visible } = metadatas;
|
||||
const value = get(modifiedData, keys);
|
||||
|
||||
if (visible === false) {
|
||||
return null;
|
||||
}
|
||||
const inputErrors = get(errors, keys, []);
|
||||
const withOptionPlaceholder = get(attribute, 'type', '') === 'enumeration';
|
||||
|
||||
// const inputErrors = get(errors, keys, []);
|
||||
// const withOptionPlaceholder = get(attribute, 'type', '') === 'enumeration';
|
||||
|
||||
return (
|
||||
<InputsIndex
|
||||
@ -91,10 +92,13 @@ function Inputs({
|
||||
autoFocus={autoFocus}
|
||||
didCheckErrors={didCheckErrors}
|
||||
disabled={disabled}
|
||||
errors={inputErrors}
|
||||
inputDescription={description}
|
||||
inputStyle={inputStyle}
|
||||
// errors={errors}
|
||||
// errors={inputErrors}
|
||||
// inputDescription={description}
|
||||
description={description}
|
||||
// inputStyle={inputStyle}
|
||||
customInputs={{
|
||||
media: InputFileWithErrors,
|
||||
json: InputJSONWithErrors,
|
||||
wysiwyg: WysiwygWithErrors,
|
||||
}}
|
||||
@ -102,11 +106,12 @@ function Inputs({
|
||||
name={name}
|
||||
onBlur={onBlur}
|
||||
onChange={onChange}
|
||||
selectOptions={get(attribute, 'enum', [])}
|
||||
options={get(attribute, 'enum', [])}
|
||||
type={getInputType(type)}
|
||||
validations={validations}
|
||||
// validations={null}
|
||||
// validations={validations}
|
||||
value={value}
|
||||
withOptionPlaceholder={withOptionPlaceholder}
|
||||
// withOptionPlaceholder={withOptionPlaceholder}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@ -120,7 +125,6 @@ Inputs.propTypes = {
|
||||
autoFocus: PropTypes.bool,
|
||||
keys: PropTypes.string.isRequired,
|
||||
layout: PropTypes.object.isRequired,
|
||||
modifiedData: PropTypes.object.isRequired,
|
||||
name: PropTypes.string.isRequired,
|
||||
onBlur: PropTypes.func,
|
||||
onChange: PropTypes.func.isRequired,
|
||||
|
||||
@ -31,7 +31,7 @@ import Container from '../../components/Container';
|
||||
import DynamicZone from '../../components/DynamicZone';
|
||||
import FormWrapper from '../../components/FormWrapper';
|
||||
// import ComponentField from '../../components/ComponentField';
|
||||
// import Inputs from '../../components/Inputs';
|
||||
import Inputs from '../../components/Inputs';
|
||||
import SelectWrapper from '../../components/SelectWrapper';
|
||||
// import createYupSchema from './utils/schema';
|
||||
// import setDefaultForm from './utils/createDefaultForm';
|
||||
@ -153,7 +153,7 @@ const EditView = ({
|
||||
};
|
||||
|
||||
return (
|
||||
<EditViewProvider>
|
||||
<EditViewProvider layout={currentContentTypeLayoutData}>
|
||||
<BackHeader onClick={() => redirectToPreviousPage()} />
|
||||
<Container className="container-fluid">
|
||||
<form onSubmit={handleSubmit}>
|
||||
@ -204,10 +204,36 @@ const EditView = ({
|
||||
},
|
||||
} = block;
|
||||
|
||||
return <DynamicZone name={name} />;
|
||||
return <DynamicZone key={blockIndex} name={name} />;
|
||||
}
|
||||
|
||||
return <FormWrapper key={blockIndex}>SUBBLOCK</FormWrapper>;
|
||||
return (
|
||||
<FormWrapper key={blockIndex}>
|
||||
{block.map((fieldsBlock, fieldsBlockIndex) => {
|
||||
return (
|
||||
<div className="row" key={fieldsBlockIndex}>
|
||||
{fieldsBlock.map(({ name, size }, fieldIndex) => {
|
||||
return (
|
||||
<div className={`col-${size}`} key={name}>
|
||||
<Inputs
|
||||
autoFocus={
|
||||
blockIndex === 0 &&
|
||||
fieldsBlockIndex === 0 &&
|
||||
fieldIndex === 0
|
||||
}
|
||||
keys={name}
|
||||
layout={currentContentTypeLayoutData}
|
||||
name={name}
|
||||
onChange={() => {}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</FormWrapper>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
|
||||
@ -14,11 +14,22 @@ function useEditView() {
|
||||
}
|
||||
|
||||
EditViewProvider.propTypes = {
|
||||
addRelation: PropTypes.func,
|
||||
children: PropTypes.node.isRequired,
|
||||
didCheckErrors: PropTypes.bool,
|
||||
errors: PropTypes.object,
|
||||
layout: PropTypes.object,
|
||||
moveRelation: PropTypes.func,
|
||||
onRemove: PropTypes.func,
|
||||
onChange: PropTypes.func,
|
||||
};
|
||||
|
||||
EditViewProvider.defaultProps = {
|
||||
addRelation: () => {},
|
||||
didCheckErrors: false,
|
||||
errors: {},
|
||||
layout: {},
|
||||
modifiedData: {},
|
||||
moveRelation: () => {},
|
||||
onChange: () => {},
|
||||
onRemove: () => {},
|
||||
|
||||
@ -74,11 +74,11 @@ const getInputSize = type => {
|
||||
switch (type) {
|
||||
case 'boolean':
|
||||
case 'date':
|
||||
case 'datetime':
|
||||
case 'integer':
|
||||
case 'float':
|
||||
case 'biginteger':
|
||||
case 'decimal':
|
||||
case 'time':
|
||||
return 4;
|
||||
case 'json':
|
||||
case 'component':
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user