Skip to content

Commit 77820db

Browse files
Merge pull request #1197 from nataliauvarova/diff_oirats
Diff oirats
2 parents 4118bd7 + 6cc388e commit 77820db

File tree

3 files changed

+58
-44
lines changed

3 files changed

+58
-44
lines changed

src/api/i18n.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,7 @@ export const stringsToTranslate = [
801801
"results on",
802802
"result url",
803803
"Return to tree",
804+
"right",
804805
"Right text",
805806
"Role",
806807
"Role data loading error, please contact adiministrators.",

src/components/CompareModal/index.js

Lines changed: 52 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ const getTwinsDiff = gql`
1919
$perspectiveId: LingvodocID!
2020
) {
2121
twins_diff(
22-
main_ids: $mainIds,
23-
twin_ids: $twinIds,
24-
entry_ids: $entryIds,
25-
field_names: $fieldNames,
26-
pers_id: $perspectiveId)
22+
main_ids: $mainIds
23+
twin_ids: $twinIds
24+
entry_ids: $entryIds
25+
field_names: $fieldNames
26+
pers_id: $perspectiveId
27+
)
2728
}
2829
`;
2930

@@ -66,14 +67,11 @@ const CompareModal = ({ columns, entries, onClose, perspectiveId }) => {
6667
const [highlights, setHighlights] = useState({});
6768
const [xlsxUrl, setXlsxUrl] = useState(null);
6869

69-
const mainIds = entries.map(
70-
le => le.entities.filter(
71-
en => isEqual(en.field_id, columns[0].id))[0]?.id);
70+
const mainIds = entries.map(le => le.entities.filter(en => isEqual(en.field_id, columns[0].id))[0]?.id);
7271

73-
const twinIds = entries.map(
74-
le => columns.slice(1).map(
75-
cl => le.entities.filter(
76-
en => isEqual(en.field_id, cl.id))[0]?.id));
72+
const twinIds = entries.map(le =>
73+
columns.slice(1).map(cl => le.entities.filter(en => isEqual(en.field_id, cl.id))[0]?.id)
74+
);
7775

7876
const highlightMarkers = data => {
7977
const highlights = {};
@@ -332,51 +330,63 @@ const CompareModal = ({ columns, entries, onClose, perspectiveId }) => {
332330
// In field ${twinFieldName}: moved on ${twinDist}, changed at ${twinDiff}
333331
let text = "";
334332
highlightsMark?.forEach(elem => {
335-
336333
let dist = 0;
337334
if (elem?.twinDist) {
338335
if (columnIndex === "0") {
339336
dist = elem.twinDist;
340337
} else {
341-
dist = - elem.twinDist;
338+
dist = -elem.twinDist;
342339
}
343340
}
344341
if (dist > 0) {
345-
dist = String(dist) + " " + getTranslation("right")
342+
dist = String(dist) + " " + getTranslation("right");
346343
}
347344
if (dist < 0) {
348-
dist = String(- dist) + " " + getTranslation("left")
345+
dist = String(-dist) + " " + getTranslation("left");
349346
}
350347

351-
let diff;
348+
let diff = [];
349+
let diffText = "";
352350
if (elem?.twinDiff) {
353-
if (elem?.twinDiff[0][0] === "") {
354-
if (columnIndex === "0") {
355-
diff = "+" + elem?.twinDiff[0][1];
356-
} else {
357-
diff = "-" + elem?.twinDiff[0][1];
358-
}
359-
} else if (elem?.twinDiff[0][1] === "") {
360-
if (columnIndex === "0") {
361-
diff = "-" + elem?.twinDiff[0][0];
351+
elem?.twinDiff?.forEach(item => {
352+
if (item[0] === "") {
353+
if (columnIndex === "0") {
354+
diff.push("+" + item[1]);
355+
} else {
356+
diff.push("-" + item[1]);
357+
}
358+
} else if (item[1] === "") {
359+
if (columnIndex === "0") {
360+
diff.push("-" + item[0]);
361+
} else {
362+
diff.push("+" + item[0]);
363+
}
362364
} else {
363-
diff = "+" + elem?.twinDiff[0][0];
365+
if (columnIndex === "0") {
366+
diff.push(item[0] + " -> " + item[1]);
367+
} else {
368+
diff.push(item[1] + " -> " + item[0]);
369+
}
364370
}
365-
} else {
366-
if (columnIndex === "0") {
367-
diff = elem?.twinDiff[0][0] + " -> " + elem?.twinDiff[0][1];
368-
} else {
369-
diff = elem?.twinDiff[0][1] + " -> " + elem?.twinDiff[0][0];
370-
}
371-
}
371+
});
372+
373+
diff.forEach(item => {
374+
diffText =
375+
diffText +
376+
((diffText !== "" && ", ") || "") +
377+
(getTranslation("changed at") + " «" + item + "»" || "");
378+
});
372379
}
373380

374381
text =
375382
text +
376383
((text !== "" && "<br />") || "") +
377-
getTranslation("In field") + " «" + elem?.twinFieldName + "»: " +
378-
((dist && getTranslation("moved on") + " " + dist + (diff ? ", " : "")) || "" ) +
379-
((diff && getTranslation("changed at") + " «" + diff + "»") || ""); //getTranslation("not changed"));
384+
getTranslation("In field") +
385+
" «" +
386+
elem?.twinFieldName +
387+
"»: " +
388+
((dist && getTranslation("moved on") + " " + dist + (diffText !== "" ? ", " : "")) || "") +
389+
diffText;
380390
});
381391

382392
setTimeout(() => {
@@ -548,6 +558,7 @@ const CompareModal = ({ columns, entries, onClose, perspectiveId }) => {
548558
<Table.Row key={entry.id}>
549559
{columns.map((column, i) => {
550560
const entity = entry.entities.filter(entity => isEqual(entity.field_id, column.id))[0];
561+
551562
return (
552563
<Table.Cell
553564
className={className[i]}
@@ -597,20 +608,18 @@ const CompareModal = ({ columns, entries, onClose, perspectiveId }) => {
597608
</div>
598609
</Modal.Content>
599610
<Modal.Actions>
600-
{ xlsxUrl && !error && !errorXlsx && !loading && !loadingXlsx && (
611+
{(xlsxUrl && !error && !errorXlsx && !loading && !loadingXlsx && (
601612
<a href={xlsxUrl} class="xlsx-link-label">
602613
{getTranslation("Click here to download XLSX report")}
603614
</a>
604-
) || (
615+
)) || (
605616
<Button
606617
content={
607-
!xlsxUrl && !error && !errorXlsx
608-
? getTranslation("Save to XLSX")
609-
: getTranslation("Something went wrong")
618+
!xlsxUrl && !error && !errorXlsx ? getTranslation("Save to XLSX") : getTranslation("Something went wrong")
610619
}
611620
onClick={getTwinsXlsx}
612621
loading={loading || loadingXlsx}
613-
disabled = {error || errorXlsx}
622+
disabled={error || errorXlsx}
614623
className="lingvo-button-greenest"
615624
style={{ float: "left" }}
616625
/>

src/components/CorporaView/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,10 @@ class P extends React.Component {
950950
yield* entries;
951951
}
952952

953+
const fieldsText = fields?.filter(elem => {
954+
return elem.data_type === "Text";
955+
});
956+
953957
return (
954958
<div
955959
style={{ overflowY: "auto" }}
@@ -959,7 +963,7 @@ class P extends React.Component {
959963
(mode === "publish" && isAuthenticated) ||
960964
(mode === "contributions" && isAuthenticated)) && (
961965
<div className="lingvo-perspective-buttons">
962-
{mode === "edit" && (
966+
{mode === "edit" && fieldsText.length > 2 && (
963967
<Button
964968
icon={<i className="lingvo-icon lingvo-icon_check" />}
965969
content={this.context("Compare")}

0 commit comments

Comments
 (0)