Skip to content

Commit

Permalink
remove console info logs, optimize a loop
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethbruskiewicz committed Nov 29, 2024
1 parent cf0604e commit a07f894
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 45 deletions.
14 changes: 0 additions & 14 deletions lib/AppContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,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 @@ -411,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
31 changes: 13 additions & 18 deletions lib/Toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,18 @@ class Toolbar {
) => {
// Helper function to translate a single value based on the current language and namespace
const translateValue = (value) => {
console.log(
'executing translateValue for',
value,
i18next.options.resources
);
console.log(
value,
previousLocale,
targetLocale,
i18next.t(value, { lng: i18next.language, ns: 'reverse' }),
i18next.t(value, { lng: i18next.language, ns: 'translation' })
);
// console.log(
// 'executing translateValue for',
// value,
// i18next.options.resources
// );
// console.log(
// value,
// previousLocale,
// targetLocale,
// i18next.t(value, { lng: i18next.language, ns: 'reverse' }),
// i18next.t(value, { lng: i18next.language, ns: 'translation' })
// );
// const namespace = i18next.language === 'default' ? 'reverse' : 'translation';
return i18next.t(value, { lng: previousLocale, ns: namespace });
};
Expand All @@ -140,7 +140,7 @@ class Toolbar {
return dataHarmonizerData.map((row, row_index) => {
return row.map((value, index) => {
if (value != null && value != '' && isTranslatable[index]) {
console.log(
console.warn(
`translating ${value} at ${index} (${this.context
.getCurrentDataHarmonizer()
.hot.getDataAtCell(row_index, index)})`
Expand Down Expand Up @@ -366,7 +366,6 @@ class Toolbar {
context.addTranslationResources(context.template);

const dh = context.getCurrentDataHarmonizer();
console.log("restartInterface", dh, context.getCurrentDataHarmonizer());
this.updateGUI(dh, template_name, exportFormats);
}

Expand All @@ -386,7 +385,6 @@ class Toolbar {
let jsonData;
try {
jsonData = JSON.parse(contentBuffer.text);
console.log("jsonData", jsonData);
} catch (error) {
throw new Error('Invalid JSON data', error);
}
Expand Down Expand Up @@ -436,7 +434,6 @@ class Toolbar {
jsonData.Container[container_class],
locale
);
console.log("list_data", list_data);
if (list_data) context.dhs[dh].hot.loadData(list_data);
else
alert(
Expand Down Expand Up @@ -481,7 +478,6 @@ class Toolbar {
// default schema is guaranteed to feature the Container
schema_container.attributes
).reduce((acc, [cls_key, { name, range }]) => {
console.log(cls_key, { name, range });

// TODO: check if container attributes always have ranges?
if (typeof range !== 'undefined') {
Expand Down Expand Up @@ -932,7 +928,6 @@ class Toolbar {
)) {
translationSelect.append(new Option(nativeName, langcode));
}
console.log('currentTranslationVal', currentTranslationVal);
if (currentTranslationVal) {
translationSelect.val(currentTranslationVal);
translationSelect.trigger('input');
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/1m.js
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ export class OneToManyEventTracker extends EventTracker {
Later we can add an efficiency function that the filtering of records isn’t performed on a subordinate table until the user actually highlights the subordinate table’s tab such that they can see the data. But initially we don’t need that fancy just-in-time thing.
*/
console.log(
console.warn(
`Multi-row selection detected from row ${row} to ${row2}. Emitting empty Read event.`
);

Expand Down
24 changes: 14 additions & 10 deletions lib/utils/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ export function dataArrayToObject(dataArray, fields, options = {}) {
* @param {Object} fields A flat version of data.js.
* @return {Map<String, Integer>} Dictionary of all fields.
*/
export function fieldNameMapToIndex(fields) {
export function fieldNameMapFromIndex(fields) {
const map = {};
for (const [fieldIndex, field] of fields.entries()) {
map[field.name] = fieldIndex;
map[fieldIndex] = field.name;
}
return map;
}
Expand All @@ -149,10 +149,10 @@ export function fieldNameMapToIndex(fields) {
* @param {Object} fields A flat version of data.js.
* @return {Map<String, Integer>} Dictionary of all fields.
*/
export function fieldTitleMapToIndex(fields) {
export function fieldTitleMapFromIndex(fields) {
const map = {};
for (const [fieldIndex, field] of fields.entries()) {
map[field.title] = fieldIndex;
map[fieldIndex] = field.title;
}
return map;
}
Expand All @@ -163,8 +163,8 @@ export function fieldTitleMapToIndex(fields) {
* @return {Map<Integer, Map<String, String>>}
*/
export function fieldSymbolsAtIndexMap(fields) {
const invertedFieldTitleIndex = invert(fieldTitleMapToIndex(fields));
const invertedFieldNameMapToIndex = invert(fieldNameMapToIndex(fields));
const invertedFieldTitleIndex = fieldTitleMapFromIndex(fields);
const invertedFieldNameMapToIndex = fieldNameMapFromIndex(fields);
if (Object.keys(invertedFieldTitleIndex).length != Object.keys(invertedFieldNameMapToIndex).length) {
console.error("Field Title and Field Index maps are different sizes!");
} else {
Expand All @@ -190,8 +190,12 @@ export function slotNamesForTitlesMap(fields) {
}

export function slotTitleForNameMap(fields) {
return invert(slotNamesForTitlesMap(fields));
}
const fieldSymbolsAtIndex = fieldSymbolsAtIndexMap(fields);
let tempObject = {};
for (let index in fieldSymbolsAtIndex) {
tempObject[fieldSymbolsAtIndex[index].slotName] = fieldSymbolsAtIndex[index].slotTitle;
}
return tempObject;}

export function findFieldIndex(fields, key, translationMap = {}) {
// First try to find a direct match.
Expand Down Expand Up @@ -253,9 +257,9 @@ export function dataObjectToArray(dataObject, fields, options = {}) {
return datatypes.stringify(originalValue, datatype);
};

const slotNamesForTitles = slotNamesForTitlesMap(fields)
for (const [slotTitle, value] of Object.entries(dataObject)) {
console.log(slotTitle, slotNamesForTitlesMap(fields))
const slotName = slotNamesForTitlesMap(fields)[slotTitle];
const slotName = slotNamesForTitles[slotTitle];
const fieldIdx = findFieldIndex(fields, slotName, translationMap);

if (fieldIdx < 0) {
Expand Down
2 changes: 0 additions & 2 deletions lib/utils/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,13 +412,11 @@ class TemplateProxy {
* @throws {LocaleNotSupportedError} If the provided locale is not supported by the template.
*/
updateLocale(newLocale = null) {
console.log("updateLocale", newLocale, this._name);
// HACK. rewrite code to allow 'default' to be a locale when accessed to produce this._defaultData
if (newLocale == null || newLocale == 'en') {
this._locale = null;
} else {
const bestLocale = findBestLocaleMatch(this._locales, [newLocale]);
console.log("bestLocale", bestLocale);
if (bestLocale !== null) {
this._locale = bestLocale;
} else {
Expand Down

0 comments on commit a07f894

Please sign in to comment.