Skip to content

Commit

Permalink
fixes for auto conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
sijumoncy committed Jul 9, 2024
1 parent 7cf4d54 commit 5db0a77
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 45 deletions.
4 changes: 3 additions & 1 deletion renderer/src/components/SnackBar/SnackBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { XMarkIcon } from '@heroicons/react/24/outline';
import { Popover, Transition } from '@headlessui/react';
import PropTypes from 'prop-types';

const colors = { success: '#82E0AA', failure: '#F5B7B1', warning: '#F8C471' };
const colors = {
success: '#82E0AA', failure: '#F5B7B1', warning: '#F8C471', info: '#17a2b8',
};
const SnackBar = ({
openSnackBar,
snackText,
Expand Down
100 changes: 56 additions & 44 deletions renderer/src/components/TextTranslationMerge/TranslationMergeUI.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,50 +100,6 @@ function TranslationMergeUI({ conflictData, closeMergeWindow, triggerSnackBar })
return usfm;
}

const checkForConflictInSelectedBook = async (selectedBook) => {
// parse imported
const fs = window.require('fs');
const IncomingUsfm = fs.readFileSync(path.join(usfmJsons.conflictMeta.incomingPath, selectedBook), 'utf8');
if (IncomingUsfm) {
const importedJson = await parseUsfm(IncomingUsfm);
if (!importedJson.valid) {
setError('Imported Usfm is invalid');
} else {
// Parse current project same book
const importedBookCode = `${importedJson.data.book.bookCode.toLowerCase()}.usfm`;

setError('');

setUsfmJsons((prev) => ({ ...prev, [selectedBook]: { ...prev[selectedBook], imported: importedJson.data } }));

// setSelectedBookId(importedJson.data.book.bookCode.toLowerCase());
// const currentBookPath = Object.keys(usfmJsons.conflictMeta.currentMeta.ingredients).find((code) => code.toLowerCase().endsWith(importedBookCode));
const { projectFullName } = usfmJsons.conflictMeta;
const currentBookUsfm = await readUsfmFile(selectedBook, projectFullName);
// console.log('FOUND ====> ', { currentBookPath, currentBookUsfm });
if (currentBookUsfm) {
const currentJson = await parseUsfm(currentBookUsfm);
// generate the merge object with current , incoming , merge verses
const processOutArr = await processAndIdentiyVerseChangeinUSFMJsons(currentJson.data, importedJson.data).catch((err) => {
console.log('process usfm : ', err);
});
const mergeJson = processOutArr[0];
const conflcitedChapters = processOutArr[1];
console.log('processOutArr[1] : ', processOutArr[1]);
currentJson && currentJson?.valid && setUsfmJsons((prev) => ({ ...prev, [selectedBook]: { ...prev[selectedBook], current: currentJson.data, mergeJson } }));
setConflictedChapters((prev) => ({ ...prev, [selectedBook]: processOutArr[1] }));
if (conflcitedChapters && conflcitedChapters?.length > 0) {
setSelectedChapter(conflcitedChapters[0]);
}
setLoading(false);
}
}
} else {
setError('unable to read imported USFM');
}
setLoading(false);
};

// INFO : Previous function to handle all books together ( JSON => usfm all together at the end )
// const handleFinishedResolution = async () => {
// const fs = window.require('fs');
Expand Down Expand Up @@ -291,6 +247,62 @@ function TranslationMergeUI({ conflictData, closeMergeWindow, triggerSnackBar })
}
};

/**
*
* @param {*} selectedBook
* function checks the conflict in the book , indenitify the conflicted chapters, generate usfmJson
*/
const checkForConflictInSelectedBook = async (selectedBook) => {
// parse imported
const fs = window.require('fs');
const IncomingUsfm = fs.readFileSync(path.join(usfmJsons.conflictMeta.incomingPath, selectedBook), 'utf8');
if (IncomingUsfm) {
const importedJson = await parseUsfm(IncomingUsfm);
if (!importedJson.valid) {
setError('Imported Usfm is invalid');
} else {
// Parse current project same book
const importedBookCode = `${importedJson.data.book.bookCode.toLowerCase()}.usfm`;

setError('');

setUsfmJsons((prev) => ({ ...prev, [selectedBook]: { ...prev[selectedBook], imported: importedJson.data } }));

// setSelectedBookId(importedJson.data.book.bookCode.toLowerCase());
// const currentBookPath = Object.keys(usfmJsons.conflictMeta.currentMeta.ingredients).find((code) => code.toLowerCase().endsWith(importedBookCode));
const { projectFullName } = usfmJsons.conflictMeta;
const currentBookUsfm = await readUsfmFile(selectedBook, projectFullName);
// console.log('FOUND ====> ', { currentBookPath, currentBookUsfm });
if (currentBookUsfm) {
const currentJson = await parseUsfm(currentBookUsfm);
// generate the merge object with current , incoming , merge verses
const processOutArr = await processAndIdentiyVerseChangeinUSFMJsons(currentJson.data, importedJson.data).catch((err) => {
console.log('process usfm : ', err);
});
const mergeJson = processOutArr[0];
const conflcitedChapters = processOutArr[1];
console.log('processOutArr[1] : ', processOutArr[1]);
currentJson && currentJson?.valid && setUsfmJsons((prev) => ({ ...prev, [selectedBook]: { ...prev[selectedBook], current: currentJson.data, mergeJson } }));
// if processOutArr leng = 0 ; there is not actual conflict on content. so do auto resolve for the book
if (conflcitedChapters?.length > 0) {
setConflictedChapters((prev) => ({ ...prev, [selectedBook]: processOutArr[1] }));
if (conflcitedChapters && conflcitedChapters?.length > 0) {
setSelectedChapter(conflcitedChapters[0]);
}
} else {
// resolve the book automatically ; the conflict in md5 only not on content
await resolveAndMarkDoneChapter();
triggerSnackBar('info', 'No conflict in verse level. The conflict may be because of extra tags.');
}
setLoading(false);
}
}
} else {
setError('unable to read imported USFM');
}
setLoading(false);
};

/**
* existing project merge
* read usfm json data from backend
Expand Down

0 comments on commit 5db0a77

Please sign in to comment.