Skip to content

Commit fb51458

Browse files
remove unused functions
1 parent 149507c commit fb51458

File tree

6 files changed

+107
-111
lines changed

6 files changed

+107
-111
lines changed

lib/AppContext.js

-2
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ export default class AppContext {
226226
const isForcedSchemaProvided = overrides.forced_schema !== null;
227227
const isLocaleChange = overrides.locale !== null;
228228

229-
230229
const clearAndSetup = async (
231230
data_harmonizers = {},
232231
forced_schema = null
@@ -376,7 +375,6 @@ export default class AppContext {
376375
translationsByLanguage[currentLang] = {
377376
...enumResource,
378377
};
379-
380378
});
381379

382380
// Generate translation maps between all possible language combinations

lib/DataHarmonizer.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -2852,14 +2852,13 @@ class DataHarmonizer {
28522852
toJSON() {
28532853
const handsontableInstance = this.hot;
28542854
const tableData = this.fullData(handsontableInstance);
2855-
const columnHeaders = handsontableInstance.getColHeader().map(stripDiv); // TODO: use fields() or this.getFlatHeaders()[1];
2855+
const columnHeaders = handsontableInstance.getColHeader().map(stripDiv); // TODO: use fields() or this.getFlatHeaders()[1];
28562856
console.log(columnHeaders);
28572857

28582858
function createStruct(row) {
28592859
const structInstance = {};
28602860
// iterate over the columns in a row
28612861
for (let i = 0; i < row.length; i++) {
2862-
28632862
const columnHeader = columnHeaders[i];
28642863
console.log(columnHeader);
28652864

lib/Toolbar.js

+91-94
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import {
1515
prependToSheet,
1616
} from '@/lib/utils/files';
1717
import { nullValuesToString, isEmptyUnitVal } from '@/lib/utils/general';
18-
import { MULTIVALUED_DELIMITER, titleOverText, slotNamesForTitlesMap } from '@/lib/utils/fields';
18+
import {
19+
MULTIVALUED_DELIMITER,
20+
titleOverText,
21+
} from '@/lib/utils/fields';
1922
import { takeKeys, invert } from '@/lib/utils/objects';
2023
import {
2124
findBestLocaleMatch,
@@ -164,7 +167,6 @@ class Toolbar {
164167

165168
if (supportsLocale) {
166169
try {
167-
168170
// first cache data
169171
const current_template = this.context.appConfig.template_path;
170172
let _dh_data_cache = {};
@@ -180,7 +182,7 @@ class Toolbar {
180182
}
181183

182184
// reload the context with the new locale
183-
185+
184186
await this.context
185187
.reload(current_template, {
186188
locale: language_update,
@@ -200,9 +202,7 @@ class Toolbar {
200202
// Jump to modal as well
201203
this.setupJumpToModal(initialDh);
202204
this.setupFillModal(initialDh);
203-
204205
});
205-
206206
} catch (error) {
207207
if (error instanceof LocaleNotSupportedError) {
208208
console.warn(error);
@@ -412,7 +412,6 @@ class Toolbar {
412412
}
413413
const locale = in_language;
414414

415-
416415
await this.context
417416
.reload(template_path, { locale })
418417
.then((context) => {
@@ -475,77 +474,75 @@ class Toolbar {
475474
const schema_container =
476475
this.context.template.default.schema.classes.Container;
477476
const Container = Object.entries(
478-
// default schema is guaranteed to feature the Container
479-
schema_container.attributes
480-
).reduce((acc, [cls_key, { name, range }]) => {
481-
482-
// TODO: check if container attributes always have ranges?
483-
if (typeof range !== 'undefined') {
484-
const processedClass = {
485-
[name]: MultiEntityJSON[range]
486-
.map((obj) => nullValuesToString(obj))
487-
.map((entry) => {
488-
// translation: if available, use title over text given a non-default localization for export
489-
// TODO?: check if current lang is equal to current schema lang?
490-
const fields = this.context.dhs[range].getFields();
491-
const findField = (colKey) =>
492-
fields.filter((field) => field.title === colKey)[0];
493-
entry = Object.fromEntries(
494-
Object.entries(entry).map(([k, v]) => {
495-
const field = findField(k);
496-
let nv = v;
497-
if (field.sources && !isEmptyUnitVal(v)) {
498-
const merged_permissible_values = field.sources.reduce(
499-
(acc, source) => {
500-
return Object.assign(
501-
acc,
502-
field.permissible_values[source]
503-
);
504-
},
505-
{}
506-
);
507-
if (field.multivalued === true) {
508-
nv = v
509-
.split(MULTIVALUED_DELIMITER)
510-
.map((_v) => {
511-
if (!(_v in merged_permissible_values))
512-
console.warn(
513-
`${_v} not in merged_permissible_values ${Object.keys(
514-
merged_permissible_values
515-
)}`
516-
);
517-
return _v in merged_permissible_values
518-
? titleOverText(merged_permissible_values[_v])
519-
: _v;
520-
})
521-
.join(MULTIVALUED_DELIMITER);
522-
} else {
523-
if (!(v in merged_permissible_values))
524-
console.warn(
525-
`${v} not in merged_permissible_values ${Object.keys(
526-
merged_permissible_values
527-
)}`
528-
);
529-
nv =
530-
v in merged_permissible_values
531-
? titleOverText(merged_permissible_values[v])
532-
: v;
533-
}
477+
// default schema is guaranteed to feature the Container
478+
schema_container.attributes
479+
).reduce((acc, [cls_key, { name, range }]) => {
480+
// TODO: check if container attributes always have ranges?
481+
if (typeof range !== 'undefined') {
482+
const processedClass = {
483+
[name]: MultiEntityJSON[range]
484+
.map((obj) => nullValuesToString(obj))
485+
.map((entry) => {
486+
// translation: if available, use title over text given a non-default localization for export
487+
// TODO?: check if current lang is equal to current schema lang?
488+
const fields = this.context.dhs[range].getFields();
489+
const findField = (colKey) =>
490+
fields.filter((field) => field.title === colKey)[0];
491+
entry = Object.fromEntries(
492+
Object.entries(entry).map(([k, v]) => {
493+
const field = findField(k);
494+
let nv = v;
495+
if (field.sources && !isEmptyUnitVal(v)) {
496+
const merged_permissible_values = field.sources.reduce(
497+
(acc, source) => {
498+
return Object.assign(
499+
acc,
500+
field.permissible_values[source]
501+
);
502+
},
503+
{}
504+
);
505+
if (field.multivalued === true) {
506+
nv = v
507+
.split(MULTIVALUED_DELIMITER)
508+
.map((_v) => {
509+
if (!(_v in merged_permissible_values))
510+
console.warn(
511+
`${_v} not in merged_permissible_values ${Object.keys(
512+
merged_permissible_values
513+
)}`
514+
);
515+
return _v in merged_permissible_values
516+
? titleOverText(merged_permissible_values[_v])
517+
: _v;
518+
})
519+
.join(MULTIVALUED_DELIMITER);
520+
} else {
521+
if (!(v in merged_permissible_values))
522+
console.warn(
523+
`${v} not in merged_permissible_values ${Object.keys(
524+
merged_permissible_values
525+
)}`
526+
);
527+
nv =
528+
v in merged_permissible_values
529+
? titleOverText(merged_permissible_values[v])
530+
: v;
534531
}
535-
return [k, nv];
536-
})
537-
);
538-
return entry;
539-
}),
540-
};
541-
542-
543-
return Object.assign(acc, processedClass);
544-
} else {
545-
console.warn('Container entry has no range:', cls_key);
546-
return acc;
547-
}
548-
}, {});
532+
}
533+
return [k, nv];
534+
})
535+
);
536+
return entry;
537+
}),
538+
};
539+
540+
return Object.assign(acc, processedClass);
541+
} else {
542+
console.warn('Container entry has no range:', cls_key);
543+
return acc;
544+
}
545+
}, {});
549546

550547
const JSONFormat = {
551548
schema: this.context.template.schema.id,
@@ -556,21 +553,23 @@ class Toolbar {
556553
};
557554

558555
if (ext === 'json') {
559-
560-
const filterFunctionTemplate = (condCallback = () => true, keyCallback = (id) => id) => obj =>
561-
Object.keys(obj).reduce((acc, itemKey) => {
562-
return condCallback(obj, acc, itemKey)
563-
? {
564-
...acc,
565-
[keyCallback(itemKey)]: obj[itemKey],
566-
}
567-
: acc;
568-
}, {});
556+
const filterFunctionTemplate =
557+
(condCallback = () => true, keyCallback = (id) => id) =>
558+
(obj) =>
559+
Object.keys(obj).reduce((acc, itemKey) => {
560+
return condCallback(obj, acc, itemKey)
561+
? {
562+
...acc,
563+
[keyCallback(itemKey)]: obj[itemKey],
564+
}
565+
: acc;
566+
}, {});
569567

570568
const filterEmptyKeys = filterFunctionTemplate(
571-
(obj, acc, itemKey) => itemKey in obj && !(itemKey in acc) && obj[itemKey] != '',
572-
id => id,
573-
)
569+
(obj, acc, itemKey) =>
570+
itemKey in obj && !(itemKey in acc) && obj[itemKey] != '',
571+
(id) => id
572+
);
574573

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

583-
const processEntryKeys = (lst) =>
584-
lst.map(filterEmptyKeys)
585-
// .map(projectSlotNamestToTitles);
582+
const processEntryKeys = (lst) => lst.map(filterEmptyKeys);
583+
// .map(projectSlotNamestToTitles);
586584

587585
for (let concept in JSONFormat.Container) {
588586
JSONFormat.Container[concept] = processEntryKeys(
@@ -596,7 +594,6 @@ class Toolbar {
596594
ext,
597595
]);
598596
} else {
599-
600597
const sectionCoordinatesByClass = Object.values(this.context.dhs).reduce(
601598
(acc, dh) => {
602599
const sectionTiles = dh.sections.map((s) => s.title);
@@ -885,7 +882,7 @@ class Toolbar {
885882
let { template_path, schema } = loadResult;
886883

887884
// RELOAD THE INTERFACE BY INTERACTING WITH THE CONTEXT
888-
885+
889886
this.context
890887
.reload(template_path, {
891888
forced_schema: file ? schema : null,

lib/utils/1m.js

-2
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,8 @@ const updateRows = (dh, [col, oldVal, newVal]) => {
393393
// hot.getDataAtRow(rowIndex)
394394
// );
395395
clearRow(hot, rowIndex);
396-
397396
}
398397
if (shouldRemapChildCol) {
399-
400398
modifyRow(hot, rowIndex, col, newVal);
401399
}
402400
return CONTINUE_SIGNAL;

lib/utils/fields.js

+15-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
parseJsonDate,
77
datatypeIsDateOrTime,
88
} from '@/lib/utils/datatypes';
9-
import { consolidate, invert } from '@/lib/utils/objects';
9+
import { consolidate } from '@/lib/utils/objects';
1010

1111
export const MULTIVALUED_DELIMITER = '; ';
1212

@@ -165,16 +165,19 @@ export function fieldTitleMapFromIndex(fields) {
165165
export function fieldSymbolsAtIndexMap(fields) {
166166
const invertedFieldTitleIndex = fieldTitleMapFromIndex(fields);
167167
const invertedFieldNameMapToIndex = fieldNameMapFromIndex(fields);
168-
if (Object.keys(invertedFieldTitleIndex).length != Object.keys(invertedFieldNameMapToIndex).length) {
169-
console.error("Field Title and Field Index maps are different sizes!");
168+
if (
169+
Object.keys(invertedFieldTitleIndex).length !=
170+
Object.keys(invertedFieldNameMapToIndex).length
171+
) {
172+
console.error('Field Title and Field Index maps are different sizes!');
170173
} else {
171174
const tempObj = {};
172175
for (let i = 0; i < Object.values(invertedFieldTitleIndex).length; i++) {
173176
tempObj[i] = {
174177
slotName: invertedFieldNameMapToIndex[i],
175-
slotTitle: invertedFieldTitleIndex[i]
178+
slotTitle: invertedFieldTitleIndex[i],
176179
};
177-
};
180+
}
178181
return tempObj;
179182
}
180183
return null;
@@ -184,7 +187,8 @@ export function slotNamesForTitlesMap(fields) {
184187
const fieldSymbolsAtIndex = fieldSymbolsAtIndexMap(fields);
185188
let tempObject = {};
186189
for (let index in fieldSymbolsAtIndex) {
187-
tempObject[fieldSymbolsAtIndex[index].slotTitle] = fieldSymbolsAtIndex[index].slotName;
190+
tempObject[fieldSymbolsAtIndex[index].slotTitle] =
191+
fieldSymbolsAtIndex[index].slotName;
188192
}
189193
return tempObject;
190194
}
@@ -193,9 +197,11 @@ export function slotTitleForNameMap(fields) {
193197
const fieldSymbolsAtIndex = fieldSymbolsAtIndexMap(fields);
194198
let tempObject = {};
195199
for (let index in fieldSymbolsAtIndex) {
196-
tempObject[fieldSymbolsAtIndex[index].slotName] = fieldSymbolsAtIndex[index].slotTitle;
200+
tempObject[fieldSymbolsAtIndex[index].slotName] =
201+
fieldSymbolsAtIndex[index].slotTitle;
197202
}
198-
return tempObject;}
203+
return tempObject;
204+
}
199205

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

217223
export function dataObjectToArray(dataObject, fields, options = {}) {
218-
219224
const {
220225
serializedDateFormat,
221226
dateFormat,
@@ -257,7 +262,7 @@ export function dataObjectToArray(dataObject, fields, options = {}) {
257262
return datatypes.stringify(originalValue, datatype);
258263
};
259264

260-
const slotNamesForTitles = slotNamesForTitlesMap(fields)
265+
const slotNamesForTitles = slotNamesForTitlesMap(fields);
261266
for (const [slotTitle, value] of Object.entries(dataObject)) {
262267
const slotName = slotNamesForTitles[slotTitle];
263268
const fieldIdx = findFieldIndex(fields, slotName, translationMap);

lib/utils/templates.js

-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ export function findBestLocaleMatch(
229229
preferredLocales,
230230
strict = false
231231
) {
232-
233232
for (const preferred of preferredLocales) {
234233
// Check for exact match
235234
if (availableLocales.includes(preferred)) {

0 commit comments

Comments
 (0)