Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethbruskiewicz committed Aug 22, 2024
1 parent 429af4a commit 48b27af
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 29 deletions.
59 changes: 45 additions & 14 deletions lib/Toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,8 @@ class Toolbar {
{}
);

const schema_container = this.context.template.default.schema.classes.Container;
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
Expand Down Expand Up @@ -486,14 +487,24 @@ class Toolbar {
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)}`);
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
? 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)}`);
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])
Expand Down Expand Up @@ -527,27 +538,47 @@ class Toolbar {
ext,
]);
} else {

const sectionCoordinatesByClass = Object.values(this.context.dhs).reduce(
(acc, dh) => {
const sectionTiles = dh.sections.map(s => s.title);
const sectionTiles = dh.sections.map((s) => s.title);
const takeSections = takeKeys(sectionTiles);
return Object.assign(acc, { [rangeToContainerClass(schema_container, dh.class_assignment)]: invert(takeSections(dh.getColumnCoordinates())) });
return Object.assign(acc, {
[rangeToContainerClass(schema_container, dh.class_assignment)]:
invert(takeSections(dh.getColumnCoordinates())),
});
},
{}
);
const columnCoordinatesByClass = Object.values(this.context.dhs).reduce(
(acc, dh) => {
const columnIndexCoordinates = dh.getFields().reduce((acc, field, i) => Object.assign(acc, { [field.name]: i }), {});
return Object.assign(acc, { [rangeToContainerClass(schema_container, dh.class_assignment)]: invert(columnIndexCoordinates) });
}, {});
const columnIndexCoordinates = dh
.getFields()
.reduce(
(acc, field, i) => Object.assign(acc, { [field.name]: i }),
{}
);
return Object.assign(acc, {
[rangeToContainerClass(schema_container, dh.class_assignment)]:
invert(columnIndexCoordinates),
});
},
{}
);

let MultiEntityWorkbook = createWorkbookFromJSON(JSONFormat.Container);
MultiEntityWorkbook.SheetNames.forEach(sheetName => {
MultiEntityWorkbook.SheetNames.forEach((sheetName) => {
if (!(JSONFormat.Container[sheetName].length > 0)) {
prependToSheet(MultiEntityWorkbook, sheetName, columnCoordinatesByClass[sheetName]);
prependToSheet(
MultiEntityWorkbook,
sheetName,
columnCoordinatesByClass[sheetName]
);
}
prependToSheet(MultiEntityWorkbook, sheetName, sectionCoordinatesByClass[sheetName]);
prependToSheet(
MultiEntityWorkbook,
sheetName,
sectionCoordinatesByClass[sheetName]
);
});

await this.context.runBehindLoadingScreen(exportWorkbook, [
Expand Down
11 changes: 9 additions & 2 deletions lib/editors/KeyValueEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,15 @@ export const multiKeyValueListRenderer = (field) => {
const label = value
.split(MULTIVALUED_DELIMITER)
.map((key) => {
if (!(key in merged_permissible_values)) console.warn(`${_v} not in merged_permissible_values ${Object.keys(merged_permissible_values)}`);
return key in merged_permissible_values ? titleOverText(merged_permissible_values[key]) : 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: 15 additions & 10 deletions lib/utils/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export function exportWorkbook(workbook, baseName, ext) {
baseName,
'csv',
',',
'text/plain;charset=UTF-8',
'text/plain;charset=UTF-8'
);
break;

Expand All @@ -179,7 +179,7 @@ export function exportWorkbook(workbook, baseName, ext) {
baseName,
'csv',
',',
'text/plain;charset=UTF-16LE',
'text/plain;charset=UTF-16LE'
);
break;

Expand All @@ -189,7 +189,7 @@ export function exportWorkbook(workbook, baseName, ext) {
baseName,
'tsv',
'\t',
'text/plain;charset=UTF-8',
'text/plain;charset=UTF-8'
);
break;

Expand All @@ -199,7 +199,7 @@ export function exportWorkbook(workbook, baseName, ext) {
baseName,
'tsv',
'\t',
'text/plain;charset=UTF-16LE',
'text/plain;charset=UTF-16LE'
);
break;

Expand Down Expand Up @@ -241,7 +241,7 @@ function processAndSave(

const worksheet = workbook.Sheets[sheetName];
const sheetData = XlsxUtils.sheet_to_json(worksheet, { header: 1 });

console.log(worksheet, sheetData);

const formattedData = sheetData
Expand Down Expand Up @@ -333,8 +333,12 @@ export function importJsonFile(jsonData) {
// Main function to handle the entire process of prepending row to sheets
// Useful for custom binning headers like sections
// NOTE: in-place function!
export const modifySheetRow = (workbook, sheetName, valueCellPairs, targetRow) => {

export const modifySheetRow = (
workbook,
sheetName,
valueCellPairs,
targetRow
) => {
// Utility function to read a worksheet and convert it to a 2D array
const getSheetData = (workbook, sheetName) => {
const worksheet = workbook.Sheets[sheetName];
Expand Down Expand Up @@ -364,13 +368,14 @@ export const modifySheetRow = (workbook, sheetName, valueCellPairs, targetRow) =
updateWorksheet(workbook, sheetName, data);
};

export const prependToSheet = (workbook, sheetName, valueCellPairs) => modifySheetRow(workbook, sheetName, valueCellPairs);
export const prependToSheet = (workbook, sheetName, valueCellPairs) =>
modifySheetRow(workbook, sheetName, valueCellPairs);

// Main function to handle the entire process across all sheets
export function prependRowWithValuesAcrossSheets(workbook, valueCellPairs) {
const newWorkbook = structuredClone(workbook);
newWorkbook.SheetNames.forEach(sheetName => {
newWorkbook.SheetNames.forEach((sheetName) => {
prependToSheet(newWorkbook, sheetName, valueCellPairs[sheetName]);
});
return newWorkbook;
}
}
3 changes: 2 additions & 1 deletion lib/utils/objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,5 @@ export function looseMatchInObject(keys) {
};
}

export const takeKeys = (keys) => (obj) => Object.fromEntries(Object.entries(obj).filter(([key,]) => keys.includes(key)));
export const takeKeys = (keys) => (obj) =>
Object.fromEntries(Object.entries(obj).filter(([key]) => keys.includes(key)));
4 changes: 2 additions & 2 deletions lib/utils/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,8 @@ LocaleNotSupportedError.prototype = Error.prototype;
export const rangeToContainerClass = (Container, cls_key) => {
try {
return Object.values(Container.attributes)
.filter((v) => 'range' in v)
.filter((v) => v.range === cls_key)[0].name;
.filter((v) => 'range' in v)
.filter((v) => v.range === cls_key)[0].name;
} catch {
return cls_key;
}
Expand Down

0 comments on commit 48b27af

Please sign in to comment.