diff --git a/src/pages/CorpImport/api.js b/src/pages/CorpImport/api.js index 2e4eeb50..95fb56d4 100644 --- a/src/pages/CorpImport/api.js +++ b/src/pages/CorpImport/api.js @@ -1,27 +1,7 @@ import { Map } from "immutable"; -/* eslint-disable camelcase */ -function singleColumn(name, value, columnTypes) { - const result = { column_name: name }; - - switch (value) { - case "base": - result.sentence_type = 1; - result.field_id = columnTypes.get(name, new Map()).toArray(); - break; - case "secondary": - result.sentence_type = 2; - result.field_id = columnTypes.get(name, new Map()).toArray(); - break; - } - - return result; -} - -function blobExport(blob, columnTypes, language, license) { - const blob_id = blob.get("id").toArray(); - - const translation_atoms = blob +function baseInfo(baseBlob, language, license) { + const translation_atoms = baseBlob .get("translation", new Map()) .filter(content => content && content.trim() !== "") .map((content, locale_id) => ({ content, locale_id })) @@ -29,33 +9,38 @@ function blobExport(blob, columnTypes, language, license) { const parent_id = language.get("id", new Map()).toArray(); - const values = blob.get("values", new Map()); - - const field_map = blob.getIn(["additional_metadata", "starling_fields"]).reduce((columnList, column, index) => { - const columnIdStr = `${index}:${column}`; - const value = values.get(columnIdStr); - - if (value != null) { - columnList.push(singleColumn(columnIdStr, value, columnTypes)); - } - - return columnList; - }, []); - - const result = { - blob_id, + return { translation_atoms, parent_id, - field_map, license }; +} - return result; +function blobExport(blob, columnTypes) { + const blob_id = blob.get("id").toArray(); + const values = blob.get("values", new Map()); + + const field_map = { + column_name: values.get("sentence", "Sentence in transliteration"), + field_id: columnTypes.get("sentence", new Map()).toArray() + }; + + return { + blob_id, + field_map + }; } export function buildExport({ linking, columnTypes, languages, licenses }) { - return linking.reduce( - (acc, blob, id) => [...acc, blobExport(blob, columnTypes.get(id), languages.get(id), licenses.get(id))], + const baseBlob = linking.first(); + const baseId = baseBlob.get("id"); + + const result = baseInfo(baseBlob, languages.get(baseId), licenses.get(baseId)); + + result.columns = linking.reduce( + (acc, blob, id) => [...acc, blobExport(blob, columnTypes.get(id))], [] ); + + return result; } diff --git a/src/pages/CorpImport/index.js b/src/pages/CorpImport/index.js index ddd4fade..8e6b2468 100644 --- a/src/pages/CorpImport/index.js +++ b/src/pages/CorpImport/index.js @@ -18,7 +18,6 @@ import { setLanguage, setLicense, setTranslation, - toggleAddColumn, updateColumn } from "ducks/dictImport"; import TranslationContext from "Layout/TranslationContext"; @@ -71,7 +70,6 @@ class Info extends React.Component { linkingAdd: PropTypes.func.isRequired, linkingDelete: PropTypes.func.isRequired, updateColumn: PropTypes.func.isRequired, - toggleAddColumn: PropTypes.func.isRequired, setColumnType: PropTypes.func.isRequired, setLanguage: PropTypes.func.isRequired, setTranslation: PropTypes.func.isRequired @@ -84,7 +82,6 @@ class Info extends React.Component { this.onDelete = this.onDelete.bind(this); this.onNextClick = this.onNextClick.bind(this); this.onStepClick = this.onStepClick.bind(this); - this.onToggleColumn = this.onToggleColumn.bind(this); this.onSetColumnType = this.onSetColumnType.bind(this); this.onSetLanguage = this.onSetLanguage.bind(this); this.onSetLicense = this.onSetLicense.bind(this); @@ -121,10 +118,6 @@ class Info extends React.Component { return () => this.props.goToStep(name); } - onToggleColumn(id) { - return () => this.props.toggleAddColumn(id); - } - onSetColumnType(id) { return column => (field, name) => { this.props.setColumnType(id, column, field); @@ -294,7 +287,6 @@ const mapDispatchToProps = { linkingAdd, linkingDelete, updateColumn, - toggleAddColumn, setColumnType, setLanguage, setTranslation,