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

View File

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

View File

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

View File

@ -95,7 +95,11 @@ const forms = {
max: yup.lazy(() => {
let schema = yup.number();
if (attributeType === 'integer' || attributeType === 'biginteger') {
if (
attributeType === 'integer' ||
attributeType === 'biginteger' ||
attributeType === 'dynamiczone'
) {
schema = schema.integer();
}
@ -104,7 +108,11 @@ const forms = {
min: yup.lazy(() => {
let schema = yup.number();
if (attributeType === 'integer' || attributeType === 'biginteger') {
if (
attributeType === 'integer' ||
attributeType === 'biginteger' ||
attributeType === 'dynamiczone'
) {
schema = schema.integer();
}
@ -145,6 +153,11 @@ const forms = {
};
switch (attributeType) {
case 'dynamiczone':
return yup.object().shape({
...commonShape,
...numberTypeShape,
});
case 'enumeration':
return yup.object().shape({
...commonShape,
@ -240,7 +253,6 @@ const forms = {
},
],
];
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();
if (type === 'media') {
items.splice(0, 1);
}
if (type === 'boolean') {
} else if (type === 'boolean') {
items.splice(0, 1, [
{
autoFocus: false,
@ -311,9 +345,7 @@ const forms = {
validations: {},
},
]);
}
if (type === 'enumeration') {
} else if (type === 'enumeration') {
items.splice(0, 1, [
{
autoFocus: false,
@ -361,9 +393,7 @@ const forms = {
},
},
]);
}
if (type === 'date') {
} else if (type === 'date') {
items.splice(0, 1, [
{
autoFocus: false,
@ -416,6 +446,12 @@ const forms = {
);
}
if (type === 'dynamiczone') {
return {
items: dynamiczoneItems,
};
}
if (type === 'relation') {
return {
items: relationItems,