Skip to content

Commit 66f7938

Browse files
committed
Next steps
1 parent 62c8fa1 commit 66f7938

File tree

5 files changed

+49
-15
lines changed

5 files changed

+49
-15
lines changed

src/ducks/dictImport.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export const selectors = {
207207
case "COLUMNS":
208208
const all_fields = state.dictImport.get("columnTypes").reduce((acc, field_map) => [...acc, ...field_map.values()], []);
209209
//console.log(all_fields);
210-
result &&= parallel
210+
result &&= parallel === 'txt'
211211
? all_fields.reduce((acc, value, index, arr) =>
212212
acc && value && arr.findIndex(v => isEqual(v, value)) === index, true)
213213
: state.dictImport.get("columnTypes").every((field_map, blob_id) => {

src/pages/CorpImport/ColumnMapper.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ function FieldButton({ text, onClick, isSelected }) {
1515
return <Button onClick={onClick} content={text} {...color} />;
1616
}
1717

18-
function Column({ index, fieldOptions, type, onSetColumnType, actions }) {
18+
function Column({ index, mode, fieldOptions, type, onSetColumnType, actions }) {
1919
const getTranslation = useContext(TranslationContext);
20-
const name = index ? "sentence" : "base sentence";
21-
const color = index ? "yellow" : "green";
20+
const name = (mode === 'txt')
21+
? (index > 0 ? "sentence" : "base sentence")
22+
: (index < 0 ? "to sentence" : "from sentence");
23+
const color = (mode === 'txt')
24+
? (index > 0 ? "yellow" : "green")
25+
: (index < 0 ? "yellow" : "green");
2226
const columnButton = <Button className="column-button" color={color} content={getTranslation(name)} />;
2327
const selectedField = fieldOptions.find(x => is(x.id, type));
2428
const triggerColor = selectedField ? { color: "blue" } : {};
@@ -72,7 +76,7 @@ const ColumnWithData = compose(
7276
}))
7377
)(Column);
7478

75-
function Columns({ blob, index, fieldOptions, columnTypes, onSetColumnType }) {
79+
function Columns({ blob, index, mode, fieldOptions, columnTypes, onSetColumnType }) {
7680
const getTranslation = useContext(TranslationContext);
7781
const blobId = blob.get("id");
7882

@@ -83,16 +87,29 @@ function Columns({ blob, index, fieldOptions, columnTypes, onSetColumnType }) {
8387
<ColumnWithData
8488
key={index}
8589
index={index}
90+
mode={mode}
8691
type={columnTypes.getIn([blobId, "sentence"])}
8792
onSetColumnType={onSetColumnType("sentence")}
8893
fieldOptions={fieldOptions}
8994
/>
95+
// Using negative indexes for json case,
96+
// so they are iterates and do not match with positive ones
97+
{ mode === 'json' && (
98+
<ColumnWithData
99+
key={-(index+1)}
100+
index={-(index+1)}
101+
mode={mode}
102+
type={columnTypes.getIn([blobId, "to_sentence"])}
103+
onSetColumnType={onSetColumnType("to_sentence")}
104+
fieldOptions={fieldOptions}
105+
/>
106+
)}
90107
</div>
91108
</div>
92109
);
93110
}
94111

95-
function ColumnMapper({ state, types, columnTypes, onSetColumnType }) {
112+
function ColumnMapper({ state, mode, types, columnTypes, onSetColumnType }) {
96113
const typesSortedFiltered = types
97114
.sortBy(type => T(type.get("translations").toJS()))
98115
.filter(type => T(type.get("translations").toJS()).trim() != "");
@@ -123,6 +140,7 @@ function ColumnMapper({ state, types, columnTypes, onSetColumnType }) {
123140
key={id.join("/")}
124141
blob={v}
125142
index={i++}
143+
mode={mode}
126144
fieldOptions={fieldOptions}
127145
columnTypes={columnTypes}
128146
onSetColumnType={onSetColumnType(id)}

src/pages/CorpImport/Linker.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,17 @@ import TranslationContext from "Layout/TranslationContext";
77
function Columns({ blob, index, mode, onDelete, onUpdateColumn }) {
88
const getTranslation = useContext(TranslationContext);
99
const color = (mode === 'json') ? "blue" : index ? "yellow" : "green";
10-
const name = (mode === 'json') ? "both sentences" : index ? "sentence" : "base sentence";
10+
const name = (mode === 'json') ? "both sides" : index ? "sentence" : "base sentence";
1111
const value = blob.getIn(["values", "sentence"], "dash");
12-
useEffect(() => { onUpdateColumn("sentence", value) }, []);
12+
useEffect(
13+
() => {
14+
onUpdateColumn("sentence", value);
15+
if (mode === 'json') {
16+
onUpdateColumn("to_sentence", "json");
17+
}
18+
},
19+
[]
20+
);
1321

1422
return (
1523
<div className="blob blob_corp">

src/pages/CorpImport/api.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ export function corpusInfo({ linking, languages, licenses }) {
2424
function blobExport(blob, columnType) {
2525
const blob_id = blob.get("id").toArray();
2626
const dedash = (blob.getIn(["values", "sentence"], "dash") === "dedash");
27-
const field_id = columnType.get("sentence", new Map()).toArray();
27+
const field_ids = [columnType.get("sentence", new Map()).toArray(),
28+
columnType.get("to_sentence", new Map()).toArray()];
2829

2930
return {
3031
blob_id,
31-
field_id,
32+
field_ids,
3233
dedash
3334
};
3435
}

src/pages/CorpImport/index.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,18 @@ class Info extends React.Component {
148148
}
149149

150150
onSubmit() {
151-
const { convert } = this.props;
151+
const { convertTxt, convertJson, mode } = this.props;
152152
const corpus_inf = corpusInfo(this.props);
153153
const columns_inf = columnsInfo(this.props);
154-
convert({
155-
variables: { corpus_inf, columns_inf }
156-
}).then(() => this.props.goToStep("FINISH"));
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+
}
157163
}
158164

159165
render() {
@@ -211,14 +217,15 @@ class Info extends React.Component {
211217
{step === "COLUMNS" && (
212218
<ColumnMapper
213219
state={linking}
220+
mode={mode}
214221
columnTypes={columnTypes}
215222
types={fieldTypes}
216223
onSetColumnType={this.onSetColumnType}
217224
/>
218225
)}
219226
{step === "LANGUAGES" && (
220227
<LanguageSelection
221-
state={linking.filter(() => !i++)}
228+
state={mode === 'json' ? linking : linking.filter(() => !i++)}
222229
languages={languages}
223230
licenses={licenses}
224231
locales={locales}

0 commit comments

Comments
 (0)