Skip to content

Commit

Permalink
remove unused functions, linter
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethbruskiewicz committed Dec 9, 2024
1 parent a07f894 commit 46d5af4
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 111 deletions.
2 changes: 0 additions & 2 deletions lib/AppContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ export default class AppContext {
const isForcedSchemaProvided = overrides.forced_schema !== null;
const isLocaleChange = overrides.locale !== null;


const clearAndSetup = async (
data_harmonizers = {},
forced_schema = null
Expand Down Expand Up @@ -376,7 +375,6 @@ export default class AppContext {
translationsByLanguage[currentLang] = {
...enumResource,
};

});

// Generate translation maps between all possible language combinations
Expand Down
3 changes: 1 addition & 2 deletions lib/DataHarmonizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2852,14 +2852,13 @@ class DataHarmonizer {
toJSON() {
const handsontableInstance = this.hot;
const tableData = this.fullData(handsontableInstance);
const columnHeaders = handsontableInstance.getColHeader().map(stripDiv); // TODO: use fields() or this.getFlatHeaders()[1];
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);

Expand Down
185 changes: 91 additions & 94 deletions lib/Toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import {
prependToSheet,
} from '@/lib/utils/files';
import { nullValuesToString, isEmptyUnitVal } from '@/lib/utils/general';
import { MULTIVALUED_DELIMITER, titleOverText, slotNamesForTitlesMap } 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 @@ -164,7 +167,6 @@ class Toolbar {

if (supportsLocale) {
try {

// first cache data
const current_template = this.context.appConfig.template_path;
let _dh_data_cache = {};
Expand All @@ -180,7 +182,7 @@ class Toolbar {
}

// reload the context with the new locale

await this.context
.reload(current_template, {
locale: language_update,
Expand All @@ -200,9 +202,7 @@ class Toolbar {
// Jump to modal as well
this.setupJumpToModal(initialDh);
this.setupFillModal(initialDh);

});

} catch (error) {
if (error instanceof LocaleNotSupportedError) {
console.warn(error);
Expand Down Expand Up @@ -412,7 +412,6 @@ class Toolbar {
}
const locale = in_language;


await this.context
.reload(template_path, { locale })
.then((context) => {
Expand Down Expand Up @@ -475,77 +474,75 @@ class Toolbar {
const schema_container =
this.context.template.default.schema.classes.Container;
const Container = Object.entries(
// default schema is guaranteed to feature the Container
schema_container.attributes
).reduce((acc, [cls_key, { name, range }]) => {

// TODO: check if container attributes always have ranges?
if (typeof range !== 'undefined') {
const processedClass = {
[name]: MultiEntityJSON[range]
.map((obj) => nullValuesToString(obj))
.map((entry) => {
// translation: if available, use title over text given a non-default localization for export
// TODO?: check if current lang is equal to current schema lang?
const fields = this.context.dhs[range].getFields();
const findField = (colKey) =>
fields.filter((field) => field.title === colKey)[0];
entry = Object.fromEntries(
Object.entries(entry).map(([k, v]) => {
const field = findField(k);
let nv = v;
if (field.sources && !isEmptyUnitVal(v)) {
const merged_permissible_values = field.sources.reduce(
(acc, source) => {
return Object.assign(
acc,
field.permissible_values[source]
);
},
{}
);
if (field.multivalued === true) {
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 {
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;
}
// default schema is guaranteed to feature the Container
schema_container.attributes
).reduce((acc, [cls_key, { name, range }]) => {
// TODO: check if container attributes always have ranges?
if (typeof range !== 'undefined') {
const processedClass = {
[name]: MultiEntityJSON[range]
.map((obj) => nullValuesToString(obj))
.map((entry) => {
// translation: if available, use title over text given a non-default localization for export
// TODO?: check if current lang is equal to current schema lang?
const fields = this.context.dhs[range].getFields();
const findField = (colKey) =>
fields.filter((field) => field.title === colKey)[0];
entry = Object.fromEntries(
Object.entries(entry).map(([k, v]) => {
const field = findField(k);
let nv = v;
if (field.sources && !isEmptyUnitVal(v)) {
const merged_permissible_values = field.sources.reduce(
(acc, source) => {
return Object.assign(
acc,
field.permissible_values[source]
);
},
{}
);
if (field.multivalued === true) {
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 {
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];
})
);
return entry;
}),
};
return Object.assign(acc, processedClass);
} else {
console.warn('Container entry has no range:', cls_key);
return acc;
}
}, {});
}
return [k, nv];
})
);
return entry;
}),
};

return Object.assign(acc, processedClass);
} else {
console.warn('Container entry has no range:', cls_key);
return acc;
}
}, {});

const JSONFormat = {
schema: this.context.template.schema.id,
Expand All @@ -556,21 +553,23 @@ class Toolbar {
};

if (ext === 'json') {

const filterFunctionTemplate = (condCallback = () => true, keyCallback = (id) => id) => obj =>
Object.keys(obj).reduce((acc, itemKey) => {
return condCallback(obj, acc, itemKey)
? {
...acc,
[keyCallback(itemKey)]: obj[itemKey],
}
: acc;
}, {});
const filterFunctionTemplate =
(condCallback = () => true, keyCallback = (id) => id) =>
(obj) =>
Object.keys(obj).reduce((acc, itemKey) => {
return condCallback(obj, acc, itemKey)
? {
...acc,
[keyCallback(itemKey)]: obj[itemKey],
}
: acc;
}, {});

const filterEmptyKeys = filterFunctionTemplate(
(obj, acc, itemKey) => itemKey in obj && !(itemKey in acc) && obj[itemKey] != '',
id => id,
)
(obj, acc, itemKey) =>
itemKey in obj && !(itemKey in acc) && obj[itemKey] != '',
(id) => id
);

// const fields = this.context.getCurrentDataHarmonizer().getFields();
// const slotNamesForTitles = slotNamesForTitlesMap(fields);
Expand All @@ -580,9 +579,8 @@ class Toolbar {
// (em) => slotNamesForTitles[em],
// )

const processEntryKeys = (lst) =>
lst.map(filterEmptyKeys)
// .map(projectSlotNamestToTitles);
const processEntryKeys = (lst) => lst.map(filterEmptyKeys);
// .map(projectSlotNamestToTitles);

for (let concept in JSONFormat.Container) {
JSONFormat.Container[concept] = processEntryKeys(
Expand All @@ -596,7 +594,6 @@ class Toolbar {
ext,
]);
} else {

const sectionCoordinatesByClass = Object.values(this.context.dhs).reduce(
(acc, dh) => {
const sectionTiles = dh.sections.map((s) => s.title);
Expand Down Expand Up @@ -885,7 +882,7 @@ class Toolbar {
let { template_path, schema } = loadResult;

// RELOAD THE INTERFACE BY INTERACTING WITH THE CONTEXT

this.context
.reload(template_path, {
forced_schema: file ? schema : null,
Expand Down
2 changes: 0 additions & 2 deletions lib/utils/1m.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,8 @@ const updateRows = (dh, [col, oldVal, newVal]) => {
// hot.getDataAtRow(rowIndex)
// );
clearRow(hot, rowIndex);

}
if (shouldRemapChildCol) {

modifyRow(hot, rowIndex, col, newVal);
}
return CONTINUE_SIGNAL;
Expand Down
25 changes: 15 additions & 10 deletions lib/utils/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
parseJsonDate,
datatypeIsDateOrTime,
} from '@/lib/utils/datatypes';
import { consolidate, invert } from '@/lib/utils/objects';
import { consolidate } from '@/lib/utils/objects';

export const MULTIVALUED_DELIMITER = '; ';

Expand Down Expand Up @@ -165,16 +165,19 @@ export function fieldTitleMapFromIndex(fields) {
export function fieldSymbolsAtIndexMap(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!");
if (
Object.keys(invertedFieldTitleIndex).length !=
Object.keys(invertedFieldNameMapToIndex).length
) {
console.error('Field Title and Field Index maps are different sizes!');
} else {
const tempObj = {};
for (let i = 0; i < Object.values(invertedFieldTitleIndex).length; i++) {
tempObj[i] = {
slotName: invertedFieldNameMapToIndex[i],
slotTitle: invertedFieldTitleIndex[i]
slotTitle: invertedFieldTitleIndex[i],
};
};
}
return tempObj;
}
return null;
Expand All @@ -184,7 +187,8 @@ export function slotNamesForTitlesMap(fields) {
const fieldSymbolsAtIndex = fieldSymbolsAtIndexMap(fields);
let tempObject = {};
for (let index in fieldSymbolsAtIndex) {
tempObject[fieldSymbolsAtIndex[index].slotTitle] = fieldSymbolsAtIndex[index].slotName;
tempObject[fieldSymbolsAtIndex[index].slotTitle] =
fieldSymbolsAtIndex[index].slotName;
}
return tempObject;
}
Expand All @@ -193,9 +197,11 @@ export function slotTitleForNameMap(fields) {
const fieldSymbolsAtIndex = fieldSymbolsAtIndexMap(fields);
let tempObject = {};
for (let index in fieldSymbolsAtIndex) {
tempObject[fieldSymbolsAtIndex[index].slotName] = fieldSymbolsAtIndex[index].slotTitle;
tempObject[fieldSymbolsAtIndex[index].slotName] =
fieldSymbolsAtIndex[index].slotTitle;
}
return tempObject;}
return tempObject;
}

export function findFieldIndex(fields, key, translationMap = {}) {
// First try to find a direct match.
Expand All @@ -215,7 +221,6 @@ export function findFieldIndex(fields, key, translationMap = {}) {
}

export function dataObjectToArray(dataObject, fields, options = {}) {

const {
serializedDateFormat,
dateFormat,
Expand Down Expand Up @@ -257,7 +262,7 @@ export function dataObjectToArray(dataObject, fields, options = {}) {
return datatypes.stringify(originalValue, datatype);
};

const slotNamesForTitles = slotNamesForTitlesMap(fields)
const slotNamesForTitles = slotNamesForTitlesMap(fields);
for (const [slotTitle, value] of Object.entries(dataObject)) {
const slotName = slotNamesForTitles[slotTitle];
const fieldIdx = findFieldIndex(fields, slotName, translationMap);
Expand Down
1 change: 0 additions & 1 deletion lib/utils/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ export function findBestLocaleMatch(
preferredLocales,
strict = false
) {

for (const preferred of preferredLocales) {
// Check for exact match
if (availableLocales.includes(preferred)) {
Expand Down

0 comments on commit 46d5af4

Please sign in to comment.