Commit 47faec3e authored by Roman's avatar Roman

BRCD-1684 feat(CustomFields) - create configuration file and allow to set fied entities

parent 3d3af209
......@@ -9,6 +9,7 @@ import mainMenu from '../config/mainMenu.json';
import eventsConfig from '../config/events.json';
import ratesConfig from '../config/rates.json';
import collectionsConfig from '../config/collections.json';
import customFieldsConfig from '../config/customFields.json';
/**
* Get data from config files
......@@ -39,6 +40,8 @@ export const getConfig = (key, defaultValue = null) => {
break;
case 'collections': configCache = configCache.set('collections', Immutable.fromJS(collectionsConfig));
break;
case 'customFields': configCache = configCache.set('customFields', Immutable.fromJS(customFieldsConfig));
break;
default: console.log(`Config caregory not exists ${path}`);
}
}
......
......@@ -10,6 +10,10 @@ import Field from '../Field';
import {
availablePlaysSettingsSelector,
} from '../../selectors/settingsSelector';
import {
getConfig,
parseConfigSelectOptions,
} from '../../common/Util';
class CustomField extends Component {
......@@ -24,6 +28,7 @@ class CustomField extends Component {
onChange: PropTypes.func.isRequired,
onRemove: PropTypes.func.isRequired,
availablePlays: PropTypes.instanceOf(Immutable.List),
customFieldsConfig: PropTypes.instanceOf(Immutable.List),
};
static defaultProps = {
......@@ -32,6 +37,7 @@ class CustomField extends Component {
existing: false,
sortable: true,
availablePlays: Immutable.List(),
customFieldsConfig: getConfig(['customFields'], Immutable.List()),
};
state = {
......@@ -105,8 +111,24 @@ class CustomField extends Component {
label: play.get('label', play.get('name', '')),
})).toArray());
inBlackList = (option, entity) => {
const blackList = option.get('exclude', Immutable.List());
if (blackList.isEmpty()) {
return false;
}
return blackList.includes(entity);
}
inWhiteList = (option, entity) => {
const whiteList = option.get('include', Immutable.List());
if (whiteList.isEmpty()) {
return true;
}
return whiteList.includes(entity);
}
renderAdvancedEdit = () => {
const { field, entity } = this.props;
const { field, entity, customFieldsConfig } = this.props;
const { showAdvancedEdit } = this.state;
const modalTitle = changeCase.titleCase(`Edit ${field.get('field_name', 'field')} Details`);
const checkboxStyle = { marginTop: 10, paddingLeft: 26 };
......@@ -122,12 +144,10 @@ class CustomField extends Component {
const disableSearchable = isBoolean || !this.hasEditableField('searchable');
const disableSelectList = this.getFieldType(field) !== 'text' || !this.hasEditableField('select_list');
const disableSelectOptions = !field.get('select_list', false) || !this.hasEditableField('select_options');
const fieldTypesOptions = [
{ value: 'text', label: 'Text' }, // must be first because text is default option
{ value: 'boolean', label: 'Boolean' },
{ value: 'textarea', label: 'Text Area' },
{ value: 'ranges', label: 'Range' },
];
const fieldTypesOptions = customFieldsConfig
.filter(option => (!this.inBlackList(option, entity) && this.inWhiteList(option, entity)))
.map(parseConfigSelectOptions)
.toArray();
return (
<ModalWrapper show={showAdvancedEdit} onOk={this.onCloseModal} title={modalTitle}>
<Form horizontal>
......
[
{
"id": "text",
"title": "Text",
"unique": true,
"mandatory": true,
"editable": true,
"display": true,
"showInList": true,
"searchable": true,
"multiple": true,
"selectOptions": true
}, {
"id": "boolean",
"title": "Boolean",
"unique": false,
"mandatory": false,
"searchable": false,
"multiple": false,
"selectOptions": false
}, {
"id": "textarea",
"title": "Text Area",
"multiple": false,
"selectOptions": false
}, {
"id": "ranges",
"title": "Range",
"unique": false,
"selectOptions": false,
"include": ["subscriber"]
}
]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment