Attributes fixes

This commit is contained in:
Virginie Ky 2019-08-01 19:11:59 +02:00
parent f15098ce69
commit 334e63a9f3
3 changed files with 31 additions and 46 deletions

View File

@ -3,7 +3,15 @@
* App actions * App actions
* *
*/ */
import { cloneDeep, pick, set, camelCase } from 'lodash'; import {
cloneDeep,
isEmpty,
pick,
toInteger,
toNumber,
set,
camelCase,
} from 'lodash';
import { fromJS, OrderedMap } from 'immutable'; import { fromJS, OrderedMap } from 'immutable';
import { import {
ADD_ATTRIBUTE_RELATION, ADD_ATTRIBUTE_RELATION,
@ -734,16 +742,32 @@ export const buildGroupAttributes = attributes =>
}); });
return acc.concat(attribute); return acc.concat(attribute);
} else { } else {
const attribute = { name: current, ...attributes[current] }; if (attributes[current].type === 'enumeration') {
return acc.concat(attribute); return acc.concat({
name: current,
...attributes[current],
enum: attributes[current].enum.join('\n'),
});
}
return acc.concat({ name: current, ...attributes[current] });
} }
}, []); }, []);
export const formatGroupAttributes = attributes => { export const formatGroupAttributes = attributes => {
const formattedAttributes = attributes.reduce((acc, current) => { const formattedAttributes = attributes.reduce((acc, current) => {
const name = current['name']; const { name, ...newAttribute } = current;
const newAttribute = { ...current }; const { type } = newAttribute;
delete newAttribute['name'];
if (type === 'enumeration') {
newAttribute.enum = newAttribute.enum.split('\n');
}
if (type === 'integer' && !isEmpty(newAttribute.default)) {
newAttribute.default = toInteger(newAttribute.default);
}
if (['decimal', 'float'].includes(type) && !isEmpty(newAttribute.default)) {
newAttribute.default = toNumber(newAttribute.default);
}
acc[name] = newAttribute; acc[name] = newAttribute;
return acc; return acc;

View File

@ -93,7 +93,7 @@ class AttributeForm extends React.Component {
const split = value.split('\n'); const split = value.split('\n');
const hasEnumFormatError = split.filter( const hasEnumFormatError = split.filter(
v => !new RegExp('^[A-Za-z][_0-9A-Za-z]*$').test(v) v => !new RegExp('^[_A-Za-z][_0-9A-Za-z]*$').test(v)
); );
if (hasEnumFormatError.length > 0) { if (hasEnumFormatError.length > 0) {

View File

@ -634,15 +634,6 @@
}, },
"advanced": { "advanced": {
"items": [ "items": [
{
"label": {
"id": "content-type-builder.form.attribute.settings.default"
},
"name": "default",
"type": "password",
"value": "",
"validations": {}
},
{ {
"title": { "title": {
"id": "content-type-builder.form.attribute.item.settings.name" "id": "content-type-builder.form.attribute.item.settings.name"
@ -659,19 +650,6 @@
"id": "content-type-builder.form.attribute.item.requiredField.description" "id": "content-type-builder.form.attribute.item.requiredField.description"
} }
}, },
{
"label": {
"id": "content-type-builder.form.attribute.item.uniqueField"
},
"name": "unique",
"type": "checkbox",
"customBootstrapClass": "col-md-12",
"value": false,
"validations": {},
"inputDescription": {
"id": "content-type-builder.form.attribute.item.uniqueField.description"
}
},
{ {
"label": { "label": {
"id": "content-type-builder.form.attribute.item.minimumLength" "id": "content-type-builder.form.attribute.item.minimumLength"
@ -879,23 +857,6 @@
"value": "", "value": "",
"validations": {} "validations": {}
}, },
{
"customBootstrapClass": "col-md-12",
"title": {
"id": "content-type-builder.form.attribute.item.appearance.name"
},
"label": {
"id": "content-type-builder.form.attribute.item.appearance.label"
},
"name": "appearance.WYSIWYG",
"type": "checkbox",
"value": false,
"validations": {},
"inputDescription": {
"id": "content-type-builder.form.attribute.item.appearance.description"
},
"inputStyle": { "fontWeight": "500" }
},
{ {
"title": { "title": {
"id": "content-type-builder.form.attribute.item.settings.name" "id": "content-type-builder.form.attribute.item.settings.name"