Skip to content

Commit

Permalink
Feature 7322/multi ref support (#7326)
Browse files Browse the repository at this point in the history
* update dependencies for verse list support in checks

* update dependencies for verse list support in checks

* update dependencies

* Fixes on GL change to load needed resources

* update dependencies

* fix unit tests

* update resources

* fix unit tests

* fix unit tests

* fix unit tests
  • Loading branch information
PhotoNomad0 authored Jun 17, 2022
1 parent 8f08607 commit e7b7769
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 68 deletions.
76 changes: 38 additions & 38 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
"archiver": "3.0.0",
"axios": "0.19.1",
"babel-polyfill": "6.26.0",
"checking-tool-wrapper": "7.2.2",
"checking-tool-wrapper": "7.4.0",
"crypto-js": "3.1.8",
"csv": "1.2.1",
"deep-equal": "1.0.1",
Expand Down Expand Up @@ -183,12 +183,12 @@
"string-punctuation-tokenizer": "^2.2.0",
"sudo-prompt": "6.2.1",
"tc-electron-env": "0.10.0",
"tc-source-content-updater": "1.3.0",
"tc-source-content-updater": "1.4.0",
"tc-strings": "0.1.7",
"tc-tool": "4.1.0",
"tc-ui-toolkit": "6.0.7",
"tc-ui-toolkit": "6.1.1",
"truncate-utf8-bytes": "1.0.2",
"tsv-groupdata-parser": "0.11.1",
"tsv-groupdata-parser": "0.12.0",
"usfm-js": "3.4.0",
"uuid": "3.2.1",
"word-aligner": "1.0.0",
Expand Down
6 changes: 5 additions & 1 deletion src/__tests__/ProjectDetailsActions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import {
USER_RESOURCES_PATH,
WORD_ALIGNMENT,
TRANSLATION_WORDS,
TRANSLATION_HELPS, TRANSLATION_NOTES,
TRANSLATION_HELPS,
TRANSLATION_NOTES,
} from '../js/common/constants';
import { NT_ORIG_LANG, NT_ORIG_LANG_BIBLE } from '../js/common/BooksOfTheBible';
const middlewares = [thunk];
Expand Down Expand Up @@ -50,6 +51,9 @@ jest.mock('../js/actions/MyProjects/ProjectLoadingActions', () => ({
}));
jest.mock('../js/selectors', () => ({
...require.requireActual('../js/selectors'),
getToolGlOwner: jest.fn(() => `Door43-Catalog`),
getProjectBookId: jest.fn(() => `tit`),
getBibles: jest.fn(() => {}),
getToolsByKey: jest.fn(() => ({
'translationNotes': { api: { trigger: (funcName) => funcName === 'getProgress' ? 0 : null } },
'wordAlignment': { api: { trigger: (funcName) => funcName === 'getProgress' ? 0 : null } },
Expand Down
9 changes: 9 additions & 0 deletions src/js/actions/ProjectDetailsActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
DEFAULT_OWNER,
PROJECTS_PATH,
TRANSLATION_NOTES,
TRANSLATION_WORDS,
} from '../common/constants';
import consts from './ActionTypes';
import { connectToolApi } from './MyProjects/ProjectLoadingActions';
Expand Down Expand Up @@ -169,6 +170,7 @@ export function setProjectToolGL(toolName, selectedGL, owner = null) {
}

const state = getState();
dispatch(ResourcesActions.makeSureBiblesLoadedForTool(null, toolName, selectedGL, owner));
dispatch(ResourcesActions.loadBiblesByLanguageId(selectedGL, owner));
const toolsGLs = getToolsSelectedGLs(state);
const previousGLForTool = toolsGLs[toolName];
Expand All @@ -194,6 +196,13 @@ export function setProjectToolGL(toolName, selectedGL, owner = null) {
dispatch(batchActions([
{ type: consts.OPEN_TOOL, name: null },
]));
} else if (toolName === TRANSLATION_WORDS && (owner !== previousOwnerForTool)) {
const projectDir = getProjectSaveLocation(state);
ResourcesHelpers.copyGroupDataToProject(selectedGL, toolName, projectDir, dispatch, true, owner); // copy group data for GL
await dispatch(prepareToolForLoading(toolName));
dispatch(batchActions([
{ type: consts.OPEN_TOOL, name: null },
]));
}

if (ifGlChanged) { // if GL has been changed
Expand Down
38 changes: 25 additions & 13 deletions src/js/actions/ResourcesActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,31 +323,43 @@ export const updateOrigLangPaneSettings = (bookId) => (dispatch, getState) => {
/**
* Make sure required bible books for current tool are loaded into resources.
* @param {object} contextId - context id.
* @param {string} toolName_ - optional toolName, otherwise will use current tool
* @param {string} selectedGL - optional GL to load
* @param {string} glOwner_ - optional GL owner, otherwise will get from current tool
*/
export const makeSureBiblesLoadedForTool = (contextId) => (dispatch, getState) => {
export const makeSureBiblesLoadedForTool = (contextId, toolName_, selectedGL, glOwner_) => (dispatch, getState) => {
console.log('makeSureBiblesLoadedForTool(): contextId', contextId);
const state = getState();
const toolName = getCurrentToolName(state);
const glOwner = getToolGlOwner(state, toolName) || DEFAULT_ORIG_LANG_OWNER;
const toolName = toolName_ || getCurrentToolName(state);
const glOwner = glOwner_ || getToolGlOwner(state, toolName) || DEFAULT_ORIG_LANG_OWNER;
const { bibles } = state.resourcesReducer;
const bookId = contextId && contextId.reference.bookId || getProjectBookId(state);

dispatch(updateOrigLangPaneSettings(bookId));
const resources = ResourcesHelpers.getResourcesNeededByTool(state, bookId, toolName);
let resources = ResourcesHelpers.getResourcesNeededByTool(state, bookId, toolName, selectedGL, glOwner);

// remove bibles from resources list that are already loaded into resources reducer
if (bookId && bibles && Array.isArray(resources)) {
for (let languageId of Object.keys(bibles)) {
if (bibles[languageId]) {
for (let bibleId of Object.keys(bibles[languageId])) {
const origLangOwner = ResourcesHelpers.getOriginalLangOwner(glOwner);
const key = (languageId === ORIGINAL_LANGUAGE) ?
resourcesHelpers.addOwnerToKey(BibleHelpers.isOldTestament(bookId) ? Bible.OT_ORIG_LANG : Bible.NT_ORIG_LANG, origLangOwner)
: languageId;
removeBibleFromList(resources, bibleId, key);
}
for (let i = 0, l = resources.length; i < l; i++) {
const resource = resources[i];
let resourceLangId = resource.languageId;
let resourceBibleId = resource.bibleId;
let owner = glOwner;

if (BibleHelpers.isOriginalLanguage(resourceLangId)) {
resourceLangId = ORIGINAL_LANGUAGE;
owner = ResourcesHelpers.getOriginalLangOwner(glOwner);
}

const key = resourcesHelpers.addOwnerToKey(resourceLangId, owner);
const bibleFound = bibles[key]?.[resourceBibleId];

if (bibleFound) { // remove if already loaded
resources[i] = null;
}
}

resources = resources.filter(resource => resource); // removed null elements
}

// load resources not in resources reducer
Expand Down
12 changes: 7 additions & 5 deletions src/js/helpers/ResourcesHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ export function updateGroupIndexForGl(toolName, selectedGL, owner) {
(categories?.owner === owner);

if (glUnchanged) {
console.log('updateGroupIndexForGl() - language unchanged, skipping');
console.log('updateGroupIndexForGl() - language/owner unchanged, skipping');
return; // we don't need to do anything since language hasn't changed
}
}
Expand Down Expand Up @@ -1000,17 +1000,19 @@ export function getAvailableScripturePaneSelections(resourceList) {
* @param {Object} state
* @param {String} bookId
* @param {string} toolName - the name of the tool for which resources will be found.
* @param {string} selectedGL - optional GL language to load
* @param {string} glOwner_ - optional GL owner, otherwise will get from current tool
* @return {Array} array of resource in scripture panel
*/
export function getResourcesNeededByTool(state, bookId, toolName) {
export function getResourcesNeededByTool(state, bookId, toolName, selectedGL, glOwner_) {
const resources = [];
const { languageId: olLanguageID, bibleId: olBibleId } = BibleHelpers.getOrigLangforBook(bookId);
const glOwner= getToolGlOwner(state, toolName) || DEFAULT_ORIG_LANG_OWNER;
const glOwner= glOwner_ || getToolGlOwner(state, toolName) || DEFAULT_ORIG_LANG_OWNER;
const currentPaneSettings = _.cloneDeep(SettingsHelpers.getCurrentPaneSetting(state));

// TODO: hardcoded fixed for 1.1.0, the En ULT is used by the expanded scripture pane & if
// not found throws an error. Should be addressed later by 4858.
addResource(resources, 'en', 'ult', DEFAULT_OWNER);
addResource(resources, 'en', 'ult', glOwner_ || DEFAULT_OWNER);

if (Array.isArray(currentPaneSettings)) {
for (let setting of currentPaneSettings) {
Expand All @@ -1033,7 +1035,7 @@ export function getResourcesNeededByTool(state, bookId, toolName) {
console.warn('No Scripture Pane Configuration');
}
addResource(resources, olLanguageID, olBibleId, getOriginalLangOwner(glOwner)); // make sure loaded even if not in pane settings
const gatewayLangId = getToolGatewayLanguage(state, toolName);
const gatewayLangId = selectedGL || getToolGatewayLanguage(state, toolName);
const biblesLoaded = getBibles(state);
const validBibles = getValidGatewayBiblesForTool(
toolName,
Expand Down
6 changes: 3 additions & 3 deletions src/js/helpers/WordAlignmentHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,10 @@ export function getVerseAlignments(verseSpanAlignments) {
* @return {{low, hi}} get range of verses in verse span
*/
export function getRawAlignmentsForVerseSpan(verseSpan, origLangChapterJson, blankVerseAlignments) {
const { low, hi } = verseHelpers.getVerseRangeFromSpan(verseSpan);
const { low, high } = verseHelpers.getVerseSpanRange(verseSpan);

// generate raw alignment data for each verse in range
for (let verse = low; verse <= hi; verse++) {
for (let verse = low; verse <= high; verse++) {
const originalVerse = origLangChapterJson[verse];

if (originalVerse) {
Expand All @@ -232,7 +232,7 @@ export function getRawAlignmentsForVerseSpan(verseSpan, origLangChapterJson, bla
}
}

return { low, hi };
return { low, hi: high };
}

/**
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit e7b7769

Please sign in to comment.