Clean code

This commit is contained in:
soupette 2019-11-26 14:17:53 +01:00
parent 570a520d10
commit 3c372ebde6
4 changed files with 63 additions and 27 deletions

View File

@ -8,10 +8,7 @@ import styled from 'styled-components';
const StyledCustomCheckbox = styled.div` const StyledCustomCheckbox = styled.div`
width: 100%; width: 100%;
// padding: 0 15px;
padding: 0; padding: 0;
// margin-top: -6px;
// margin-bottom: 16px;
> label { > label {
font-weight: 500 !important; font-weight: 500 !important;
font-size: 12px; font-size: 12px;
@ -32,10 +29,11 @@ const StyledCustomCheckbox = styled.div`
line-height: 10px; line-height: 10px;
} }
} }
// input[type='number'] { .no-label {
// margin-top: -10px; label {
// margin-bottom: -4px; display: none;
// } }
}
`; `;
export default StyledCustomCheckbox; export default StyledCustomCheckbox;

View File

@ -33,6 +33,7 @@ const CustomCheckbox = ({ label, name, onChange, value, ...rest }) => {
}} }}
/> />
{checked && ( {checked && (
<div className="no-label col-6">
<Inputs <Inputs
{...rest} {...rest}
name={name} name={name}
@ -40,6 +41,7 @@ const CustomCheckbox = ({ label, name, onChange, value, ...rest }) => {
value={value} value={value}
type="number" type="number"
/> />
</div>
)} )}
</StyledCustomCheckbox> </StyledCustomCheckbox>
); );

View File

@ -175,7 +175,7 @@ const DataManagerProvider = ({ children }) => {
return <Redirect to={`/plugins/${pluginId}/content-types/${firstCTUid}`} />; return <Redirect to={`/plugins/${pluginId}/content-types/${firstCTUid}`} />;
} }
console.log({ components }); console.log({ d: modifiedData });
return ( return (
<DataManagerContext.Provider <DataManagerContext.Provider

View File

@ -95,7 +95,11 @@ const forms = {
max: yup.lazy(() => { max: yup.lazy(() => {
let schema = yup.number(); let schema = yup.number();
if (attributeType === 'integer' || attributeType === 'biginteger') { if (
attributeType === 'integer' ||
attributeType === 'biginteger' ||
attributeType === 'dynamiczone'
) {
schema = schema.integer(); schema = schema.integer();
} }
@ -104,7 +108,11 @@ const forms = {
min: yup.lazy(() => { min: yup.lazy(() => {
let schema = yup.number(); let schema = yup.number();
if (attributeType === 'integer' || attributeType === 'biginteger') { if (
attributeType === 'integer' ||
attributeType === 'biginteger' ||
attributeType === 'dynamiczone'
) {
schema = schema.integer(); schema = schema.integer();
} }
@ -145,6 +153,11 @@ const forms = {
}; };
switch (attributeType) { switch (attributeType) {
case 'dynamiczone':
return yup.object().shape({
...commonShape,
...numberTypeShape,
});
case 'enumeration': case 'enumeration':
return yup.object().shape({ return yup.object().shape({
...commonShape, ...commonShape,
@ -240,7 +253,6 @@ const forms = {
}, },
], ],
]; ];
const defaultItems = [ const defaultItems = [
[ [
{ {
@ -287,14 +299,36 @@ const forms = {
}, },
], ],
]; ];
const dynamiczoneItems = [
[
{
autoFocus: false,
name: 'max',
type: 'customCheckboxWithChildren',
label: {
id: getTrad(`form.attribute.item.maximum`),
},
validations: {},
},
],
[
{
autoFocus: false,
name: 'min',
type: 'customCheckboxWithChildren',
label: {
id: getTrad(`form.attribute.item.minimum`),
},
validations: {},
},
],
];
const items = defaultItems.slice(); const items = defaultItems.slice();
if (type === 'media') { if (type === 'media') {
items.splice(0, 1); items.splice(0, 1);
} } else if (type === 'boolean') {
if (type === 'boolean') {
items.splice(0, 1, [ items.splice(0, 1, [
{ {
autoFocus: false, autoFocus: false,
@ -311,9 +345,7 @@ const forms = {
validations: {}, validations: {},
}, },
]); ]);
} } else if (type === 'enumeration') {
if (type === 'enumeration') {
items.splice(0, 1, [ items.splice(0, 1, [
{ {
autoFocus: false, autoFocus: false,
@ -361,9 +393,7 @@ const forms = {
}, },
}, },
]); ]);
} } else if (type === 'date') {
if (type === 'date') {
items.splice(0, 1, [ items.splice(0, 1, [
{ {
autoFocus: false, autoFocus: false,
@ -416,6 +446,12 @@ const forms = {
); );
} }
if (type === 'dynamiczone') {
return {
items: dynamiczoneItems,
};
}
if (type === 'relation') { if (type === 'relation') {
return { return {
items: relationItems, items: relationItems,