Skip to content

Commit e48b48e

Browse files
committed
Perspectives creation
1 parent 66f7938 commit e48b48e

File tree

3 files changed

+39
-45
lines changed

3 files changed

+39
-45
lines changed

src/pages/CorpImport/ColumnMapper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ function Columns({ blob, index, mode, fieldOptions, columnTypes, onSetColumnType
9292
onSetColumnType={onSetColumnType("sentence")}
9393
fieldOptions={fieldOptions}
9494
/>
95-
// Using negative indexes for json case,
96-
// so they are iterates and do not match with positive ones
95+
{ /* Using negative indexes for json case,
96+
so they are iterates and do not match with positive ones */ }
9797
{ mode === 'json' && (
9898
<ColumnWithData
9999
key={-(index+1)}

src/pages/CorpImport/api.js

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,34 @@
11
import { Map } from "immutable";
22

3-
export function corpusInfo({ linking, languages, licenses }) {
4-
const baseBlob = linking.first();
5-
const baseId = baseBlob.get("id");
6-
const language = languages.get(baseId);
7-
const license = licenses.get(baseId);
3+
export function corporaInfo({ linking, languages, licenses, mode }) {
84

9-
const translation_atoms = baseBlob
10-
.get("translation", new Map())
11-
.filter(content => content && content.trim() !== "")
12-
.map((content, locale_id) => ({ content, locale_id }))
13-
.toArray();
5+
const result = [];
146

15-
const parent_id = language.get("id", new Map()).toArray();
7+
for (const baseBlob of linking.values()) {
8+
const baseId = baseBlob.get("id");
9+
const language = languages.get(baseId);
10+
const license = licenses.get(baseId);
1611

17-
return {
18-
translation_atoms,
19-
parent_id,
20-
license
21-
};
12+
const translation_atoms = baseBlob
13+
.get("translation", new Map())
14+
.filter(content => content && content.trim() !== "")
15+
.map((content, locale_id) => ({ content, locale_id }))
16+
.toArray();
17+
18+
const parent_id = language.get("id", new Map()).toArray();
19+
20+
result.push({
21+
translation_atoms,
22+
parent_id,
23+
license
24+
});
25+
26+
// Only one target language for txt mode
27+
if (mode === 'txt') {
28+
break
29+
}
30+
}
31+
return result;
2232
}
2333

2434
function blobExport(blob, columnType) {

src/pages/CorpImport/index.js

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
import TranslationContext from "Layout/TranslationContext";
2424
import LanguageSelection from "pages/DictImport/LanguageSelection";
2525

26-
import { columnsInfo, corpusInfo } from "./api";
26+
import { columnsInfo, corporaInfo } from "./api";
2727
import ColumnMapper from "./ColumnMapper";
2828
import Linker from "./Linker";
2929

@@ -46,17 +46,9 @@ export const fieldsQuery = gql`
4646
}
4747
`;
4848

49-
const convertJsonMutation = gql`
50-
mutation convertMutation($corpus_inf: CorpusInf!, $columns_inf: [ColumnInf]!) {
51-
convert_parallel_json(corpus_inf: $corpus_inf, columns_inf: $columns_inf) {
52-
triumph
53-
}
54-
}
55-
`;
56-
57-
const convertTxtMutation = gql`
58-
mutation convertMutation($corpus_inf: CorpusInf!, $columns_inf: [ColumnInf]!) {
59-
convert_plain_text(corpus_inf: $corpus_inf, columns_inf: $columns_inf) {
49+
const convertDataMutation = gql`
50+
mutation convertMutation($corpora_inf: [CorpusInf]!, $columns_inf: [ColumnInf]!, $mode: String!) {
51+
convert_plain_text(corpora_inf: $corpora_inf, columns_inf: $columns_inf, mode: $mode) {
6052
triumph
6153
}
6254
}
@@ -148,18 +140,12 @@ class Info extends React.Component {
148140
}
149141

150142
onSubmit() {
151-
const { convertTxt, convertJson, mode } = this.props;
152-
const corpus_inf = corpusInfo(this.props);
143+
const { convertData, mode } = this.props;
144+
const corpora_inf = corporaInfo(this.props);
153145
const columns_inf = columnsInfo(this.props);
154-
if (mode === 'txt') {
155-
convertTxt({
156-
variables: { corpus_inf, columns_inf }
157-
}).then(() => this.props.goToStep("FINISH"));
158-
} else {
159-
convertJson({
160-
variables: { corpus_inf, columns_inf }
161-
}).then(() => this.props.goToStep("FINISH"));
162-
}
146+
convertData({
147+
variables: { corpora_inf, columns_inf, mode }
148+
}).then(() => this.props.goToStep("FINISH"));
163149
}
164150

165151
render() {
@@ -320,15 +306,13 @@ const mapDispatchToProps = {
320306

321307
Info.propTypes = {
322308
data: PropTypes.object,
323-
convertTxt: PropTypes.func.isRequired,
324-
convertJson: PropTypes.func.isRequired,
309+
convertData: PropTypes.func.isRequired,
325310
licenses: PropTypes.object.isRequired,
326311
setLicense: PropTypes.func.isRequired
327312
};
328313

329314
export default compose(
330315
connect(mapStateToProps, mapDispatchToProps),
331316
graphql(fieldsQuery, { options: { fetchPolicy: "network-only" } }),
332-
graphql(convertTxtMutation, { name: "convertTxt" }),
333-
graphql(convertJsonMutation, { name: "convertJson" })
317+
graphql(convertDataMutation, { name: "convertData" })
334318
)(Info);

0 commit comments

Comments
 (0)