Commit ec9b0048 authored by Shani's avatar Shani

Merge branch 'BRCD-1688' into 'dev'

BRCD-1688: Range fields support in subscribers importer

See merge request !954
parents b4721750 fed422fc
......@@ -789,6 +789,9 @@ ul.revision-history-list li.active .cycle {
margin-left: 0;
margin-right: 0;
}
.Importer .form-group.rangesField {
padding: 0;
}
.Importer .panel,
.Importer .Select-control {
/* set select input transparent to not hide wrapper div shadows */
......@@ -806,10 +809,10 @@ ul.revision-history-list li.active .cycle {
min-height: 200px;
}
.Importer .StepMapper {
max-height: 258px;
max-height: 50vh;
}
.Importer .StepValidate .row-fields {
max-height: 300px;
max-height: 50vh;
margin: 0;
}
.Importer .StepResult ol {
......
......@@ -125,7 +125,7 @@ class CustomersList extends Component {
listActions={listActions}
refreshString={refreshString}
/>
<ModalWrapper show={showImport} title="Import" onHide={this.onClickAskCloseImport}>
<ModalWrapper show={showImport} title="Import" onHide={this.onClickAskCloseImport} modalSize="large">
<Importer
entityOptions={['customer', 'subscription']}
onFinish={this.onCloseImport}
......
......@@ -14,6 +14,7 @@ class Ranges extends PureComponent {
multi: PropTypes.bool,
editable: PropTypes.bool,
disabled: PropTypes.bool,
removable: PropTypes.bool,
onChange: PropTypes.func,
};
......@@ -24,6 +25,7 @@ class Ranges extends PureComponent {
inputProps: {},
multi: false,
editable: true,
removable: true,
disabled: true,
onChange: () => {},
};
......@@ -59,6 +61,7 @@ class Ranges extends PureComponent {
disabled,
label,
multi,
removable,
...otherProps
} = this.props;
const { id } = this.state;
......@@ -84,15 +87,15 @@ class Ranges extends PureComponent {
};
return (
<FormGroup key={`range_${id}_${index}`} className="rangesField form-inner-edit-row">
<InputGroup>
<InputGroup style={{ width: '100%' }}>
<Range
{...otherProps}
value={rangeValue}
onChange={onChangeRange}
editable={editable}
editable={true}
disabled={disabled}
/>
{ editable && (
{ removable && (
<InputGroup.Button>
<Button onClick={onRemoveRange} disabled={disabled} >
<i className="fa fa-fw fa-trash-o danger-red" />
......@@ -107,7 +110,7 @@ class Ranges extends PureComponent {
return (
<div>
{ranges}
{editable && (multi || (!multi && value.size === 0)) && (
{(multi || (!multi && value.size === 0)) && (
<CreateButton
buttonStyle={{ marginTop: 5, marginBottom: 10 }}
onClick={this.onAdd}
......
......@@ -141,7 +141,7 @@ class Importer extends Component {
}
getFormatedRows = (limit = -1) => {
const { item, predefinedValues, defaultValues } = this.props;
const { item, predefinedValues, defaultValues, importFields } = this.props;
const { mapperPrefix } = this.state;
const lines = item.get('fileContent', []);
const linker = item.get('linker', null);
......@@ -155,12 +155,26 @@ class Importer extends Component {
for (let idx = 1; idx < linesToParse; idx++) {
const row = Immutable.Map().withMutations((mapWithMutations) => {
map.forEach((mapperValue, fieldName) => {
let columnValue = mapperValue;
if (mapperValue.startsWith(mapperPrefix)) {
const csvIndex = mapperValue.substring(mapperPrefix.length);
mapWithMutations.set(fieldName, lines[idx][csvIndex]);
} else {
mapWithMutations.set(fieldName, mapperValue);
columnValue = lines[idx][csvIndex];
}
const curField = importFields.find(field => field.value === fieldName);
const fieldType = curField ? curField.type : 'string';
if (fieldType === 'ranges') {
columnValue = Immutable.List().withMutations((rangewithMutations) => {
const ranges = columnValue.split(',');
ranges.forEach((range) => {
const rangeValue = range.split('-');
rangewithMutations.push(Immutable.Map({
from: rangeValue[0],
to: rangeValue[1],
}));
});
});
}
mapWithMutations.set(fieldName, columnValue);
});
// Set predefined values
if (predefinedValues.hasOwnProperty(entity)) {
......
......@@ -72,7 +72,7 @@ const StepMapper = (props) => {
return (
<div>
<FormGroup>
<Col sm={3} componentClass={ControlLabel}>Link to field</Col>
<Col sm={3} componentClass={ControlLabel}>Link to field<span className="danger-red"> *</span></Col>
<Col sm={9}>
<Select
onChange={onChangeLinkerField}
......@@ -83,7 +83,7 @@ const StepMapper = (props) => {
</Col>
</FormGroup>
<FormGroup>
<Col sm={3} componentClass={ControlLabel}>Link by value from</Col>
<Col sm={3} componentClass={ControlLabel}>Link by value from<span className="danger-red"> *</span></Col>
<Col sm={9}>
<Select
onChange={onChangeLinkerValue}
......
......@@ -6,11 +6,10 @@ import Field from '../Field';
const StepValidate = ({ fields, getFormatedRows }) => {
const rows = getFormatedRows(1);
const renderLinker = (linker) => {
const renderLinker = (linker, fieldName) => {
const curField = fields.find(field => field.value === linker.get('field', ''));
return (
<Panel header="Linker" className="mb0">
<Panel header="Linker" className="mb0" key={`linker-${fieldName}`}>
<FormGroup>
<Col sm={3} componentClass={ControlLabel}>
{ curField ? curField.label : linker.get('field', '') }
......@@ -23,6 +22,19 @@ const StepValidate = ({ fields, getFormatedRows }) => {
);
};
const renderValue = (value, field) => {
switch (field && field.type) {
case 'ranges':
case 'range':
return (
<Field value={value} disabled={true} fieldType={field.type} compact={true} removable={false} />
);
default: return (
<Field value={value} disabled={true} />
);
}
};
const renderRow = (value, fieldName) => {
const curField = fields.find(field => field.value === fieldName);
return (
......@@ -31,7 +43,7 @@ const StepValidate = ({ fields, getFormatedRows }) => {
{ curField ? curField.label : fieldName }
</Col>
<Col sm={9}>
<Field value={value} disabled={true} />
{ renderValue(value, curField) }
</Col>
</FormGroup>
);
......@@ -39,8 +51,6 @@ const StepValidate = ({ fields, getFormatedRows }) => {
return (
<div className="StepValidate">
<h4>Example Import</h4>
<hr className="mt10 mb0" />
<div className="row-fields scrollbox">
{ rows
.get(0, Immutable.Map())
......
......@@ -495,6 +495,7 @@ export const formatFieldOptions = (fields, item = Immutable.Map()) => {
unique: field.get('unique', false),
mandatory: field.get('mandatory', false),
linker: field.get('linker', false),
type: field.get('type', 'string'),
}));
}
return undefined;
......
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