Skip to content

Commit

Permalink
regression during refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethbruskiewicz committed Aug 23, 2024
1 parent 62a7304 commit e7abc84
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 23 deletions.
43 changes: 34 additions & 9 deletions lib/Toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ import {
prependToSheet,
} from '@/lib/utils/files';
import { nullValuesToString, isEmptyUnitVal } from '@/lib/utils/general';
import {
MULTIVALUED_DELIMITER,
singleFieldDisplayName,
multiFieldDisplayName,
mergedPermissibleValues,
} from '@/lib/utils/fields';
import { MULTIVALUED_DELIMITER, titleOverText } from '@/lib/utils/fields';
import { takeKeys, invert } from '@/lib/utils/objects';
import {
findBestLocaleMatch,
Expand Down Expand Up @@ -462,11 +457,41 @@ class Toolbar {
const field = findField(k);
let nv = v;
if (field.sources && !isEmptyUnitVal(v)) {
const permissible_values = mergedPermissibleValues(field);
const merged_permissible_values = field.sources.reduce(
(acc, source) => {
return Object.assign(
acc,
field.permissible_values[source]
);
},
{}
);
if (field.multivalued === true) {
nv = multiFieldDisplayName(permissible_values)(v);
nv = v
.split(MULTIVALUED_DELIMITER)
.map((_v) => {
if (!(_v in merged_permissible_values))
console.warn(
`${_v} not in merged_permissible_values ${Object.keys(
merged_permissible_values
)}`
);
return _v in merged_permissible_values
? titleOverText(merged_permissible_values[_v])
: _v;
})
.join(MULTIVALUED_DELIMITER);
} else {
nv = singleFieldDisplayName(permissible_values)(v);
if (!(v in merged_permissible_values))
console.warn(
`${v} not in merged_permissible_values ${Object.keys(
merged_permissible_values
)}`
);
nv =
v in merged_permissible_values
? titleOverText(merged_permissible_values[v])
: v;
}
}
return [k, nv];
Expand Down
21 changes: 18 additions & 3 deletions lib/editors/KeyValueEditor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Handsontable from 'handsontable';
import { fieldDisplayName, mergedPermissibleValues } from '@/lib/utils/fields';
import { MULTIVALUED_DELIMITER, titleOverText } from '@/lib/utils/fields';
import { isEmptyUnitVal } from '@/lib/utils/general';

// Derived from: https://jsfiddle.net/handsoncode/f0b41jug/
Expand Down Expand Up @@ -148,15 +148,30 @@ export const keyValueListRenderer = function (
};

export const multiKeyValueListRenderer = (field) => {
const permissible_values = mergedPermissibleValues(field);
const merged_permissible_values = field.sources.reduce((acc, source) => {
return Object.assign(acc, field.permissible_values[source]);
}, {});
return function (hot, TD, row, col, prop, value, cellProperties) {
// Call the autocomplete renderer to ensure default styles and behavior are applied
Handsontable.renderers
.getRenderer('autocomplete')
.apply(this, [hot, TD, row, col, prop, value, cellProperties]);

if (!isEmptyUnitVal(value)) {
const label = fieldDisplayName(permissible_values)(value);
const label = value
.split(MULTIVALUED_DELIMITER)
.map((key) => {
if (!(key in merged_permissible_values))
console.warn(
`${key} not in merged_permissible_values ${Object.keys(
merged_permissible_values
)}`
);
return key in merged_permissible_values
? titleOverText(merged_permissible_values[key])
: key;
})
.join(MULTIVALUED_DELIMITER);
TD.innerHTML = `<div class="htAutocompleteArrow">▼</div>${label}`; // This directly sets what is displayed in the cell
}
};
Expand Down
25 changes: 14 additions & 11 deletions lib/utils/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import i18next from 'i18next';
import jqueryI18next from 'jquery-i18next';
// import tags from 'language-tags';

import { flattenObject, consolidate } from '@/lib/utils/objects';
import { flattenObject } from '@/lib/utils/objects';
import label_translations_file from '@/web/translations/translations.json';
import {
MULTIVALUED_DELIMITER,
Expand All @@ -19,15 +19,18 @@ export const interface_translation = transformStructFirstSpec(
const withNamespace =
(namespace, addons = {}) =>
(obj) =>
consolidate(obj, (acc, [lang, translation]) =>
Object.assign(acc, {
[lang]: {
[namespace]: {
...translation,
...addons,
Object.entries(obj).reduce(
(acc, [lang, translation]) => ({
...Object.assign(acc, {
[lang]: {
[namespace]: {
...translation,
...addons,
},
},
},
})
}),
}),
{}
);

const englishIsDefault = (translation_object) => {
Expand Down Expand Up @@ -196,12 +199,12 @@ export function findLocalesForLangcodes(langcodes) {
}

export const translateObject = (obj, lng = i18next.language, delimiter = '_') =>
consolidate(obj, (acc, [key, val]) => {
Object.entries(obj).reduce((acc, [key, val]) => {
return Object.assign(acc, {
[i18next.t(key.replace(/ /g, delimiter), { lng })]:
val !== null ? i18next.t(val, { lng }) : null,
});
});
}, {});

export function getLanguageNameInLanguage(langCode) {
if (typeof Intl.DisplayNames !== 'undefined') {
Expand Down

0 comments on commit e7abc84

Please sign in to comment.