Commit 9b6639c1 authored by Roman's avatar Roman

BRCD-1688 feat(Import) - Added support for fields types + support for range\s

parent cfe82c59
......@@ -786,6 +786,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 */
......
......@@ -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)) {
......
......@@ -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.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())
......
......@@ -465,6 +465,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