Skip to content

Commit

Permalink
Merge branch 'dh2-i18n-rc1' into dh2-beta-release
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethbruskiewicz committed Dec 9, 2024
2 parents 43a313e + a07f894 commit 149507c
Show file tree
Hide file tree
Showing 106 changed files with 232,999 additions and 49,986 deletions.
31 changes: 10 additions & 21 deletions lib/AppContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { wait } from '@/lib/utils/general';
import { invert, removeNumericKeys, consolidate } from '@/lib/utils/objects';
import { createDataHarmonizerContainer, createDataHarmonizerTab } from '@/web';

import { buildAppContext, setup1M } from '@/lib/utils/1m';
// COMMENTED OUT: WIP FEATURE
// import { buildAppContext, setup1M } from '@/lib/utils/1m';

/**
* Finds the shared keys per class in a given schema.
Expand Down Expand Up @@ -225,6 +226,7 @@ export default class AppContext {
const isForcedSchemaProvided = overrides.forced_schema !== null;
const isLocaleChange = overrides.locale !== null;


const clearAndSetup = async (
data_harmonizers = {},
forced_schema = null
Expand All @@ -244,7 +246,7 @@ export default class AppContext {

// Handle same template path without uploaded template
if (isSameTemplatePath) {
return clearAndSetup();
return clearAndSetup(this.dhs);
}

// Handle forced schema case
Expand Down Expand Up @@ -375,11 +377,6 @@ export default class AppContext {
...enumResource,
};

console.info(
'Computed translation resources for:',
currentLang,
enumResource
);
});

// Generate translation maps between all possible language combinations
Expand Down Expand Up @@ -409,15 +406,6 @@ export default class AppContext {
reverseNamespace,
removeNumericKeys(reverseTranslationMap)
);

console.info(
`Added translation resources from ${sourceLang} to ${targetLang}:`,
translationNamespace
);
console.info(
`Added reverse translation resources from ${targetLang} to ${sourceLang}:`,
reverseNamespace
);
});
});
}
Expand Down Expand Up @@ -607,11 +595,12 @@ export default class AppContext {
};
context.setDataHarmonizers(dhs);

if (context.oneToManyAppContext) {
context.oneToManyAppContext.destroy();
}
const appContext = buildAppContext(schema);
context.oneToManyAppContext = setup1M(appContext, dhs); // returns an event manager
// COMMENTED OUT: WIP feature
// if (!!context.oneToManyAppContext) {
// context.oneToManyAppContext.destroy();
// }
// const appContext = buildAppContext(schema);
// context.oneToManyAppContext = setup1M(appContext, dhs); // returns an event manager

return context;
});
Expand Down
75 changes: 43 additions & 32 deletions lib/DataHarmonizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,32 @@ class DataHarmonizer {
return false;
}

/**
* Construct a dictionary of source field names pointing to column index
* @param {Object} fields A flat version of data.js.
* @return {Map<String, Integer>} Dictionary of all fields.
*/
getFieldNameMap(fields) {
const map = {};
for (const [fieldIndex, field] of fields.entries()) {
map[field.name] = fieldIndex;
}
return map;
}

/**
* Construct a dictionary of source field TITLES pointing to column index
* @param {Object} fields A flat version of data.js.
* @return {Map<String, Integer>} Dictionary of all fields.
*/
getFieldTitleMap(fields) {
const map = {};
for (const [fieldIndex, field] of fields.entries()) {
map[field.title] = fieldIndex;
}
return map;
}

/**
* Create a matrix containing the grid's headers. Empty strings are used to
* indicate merged cells.
Expand Down Expand Up @@ -2074,32 +2100,6 @@ class DataHarmonizer {
*
*/

/**
* Get a dictionary of source field names pointing to column index
* @param {Object} fields A flat version of data.js.
* @return {Dictionary<Integer>} Dictionary of all fields.
*/
getFieldNameMap(fields) {
const map = {};
for (const [fieldIndex, field] of fields.entries()) {
map[field.name] = fieldIndex;
}
return map;
}

/**
* Get a dictionary of source field TITLES pointing to column index
* @param {Object} fields A flat version of data.js.
* @return {Dictionary<Integer>} Dictionary of all fields.
*/
getFieldTitleMap(fields) {
const map = {};
for (const [fieldIndex, field] of fields.entries()) {
map[field.title] = fieldIndex;
}
return map;
}

/**
* Modifies exportHeaders map of fields so that each field contains an array
* of one or more source fields by name that are used to compose it.
Expand Down Expand Up @@ -2852,21 +2852,30 @@ class DataHarmonizer {
toJSON() {
const handsontableInstance = this.hot;
const tableData = this.fullData(handsontableInstance);
const columnHeaders = handsontableInstance.getColHeader().map(stripDiv);
const columnHeaders = handsontableInstance.getColHeader().map(stripDiv); // TODO: use fields() or this.getFlatHeaders()[1];
console.log(columnHeaders);

function createStruct(row) {
const structInstance = {};
// iterate over the columns in a row
for (let i = 0; i < row.length; i++) {

const columnHeader = columnHeaders[i];
console.log(columnHeader);

// Optional type checking (adjust data types as needed)
if (typeof columnHeaders[i] === 'string') {
structInstance[columnHeaders[i]] = row[i];
} else if (typeof columnHeaders[i] === 'number') {
structInstance[columnHeaders[i]] = Number(row[i]); // Convert to number
if (typeof columnHeader === 'string') {
structInstance[columnHeader] = row[i];
} else if (typeof columnHeader === 'number') {
structInstance[columnHeader] = Number(row[i]); // Convert to number
} else {
// Handle other data types if needed
structInstance[columnHeaders[i]] = row[i];
structInstance[columnHeader] = row[i];
}
}

console.log(structInstance);

return structInstance;
}

Expand All @@ -2880,6 +2889,8 @@ class DataHarmonizer {
}
}

console.log(arrayOfStructs);

return arrayOfStructs;
}
}
Expand Down
Loading

0 comments on commit 149507c

Please sign in to comment.