Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethbruskiewicz committed Aug 21, 2024
2 parents b404d6c + d7a9533 commit bb30948
Show file tree
Hide file tree
Showing 9 changed files with 594 additions and 532 deletions.
113 changes: 49 additions & 64 deletions lib/AppContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import { findLocalesForLangcodes } from '@/lib/utils/i18n';
import { Template, findSlotNamesForClass } from '@/lib/utils/templates';
import { wait } from '@/lib/utils/general';
import { invert, removeNumericKeys } from '@/lib/utils/objects';
import {
setup1M,
buildSchemaTree
} from '@/lib/utils/1m';
import { setup1M, buildSchemaTree } from '@/lib/utils/1m';
import { createDataHarmonizerContainer, createDataHarmonizerTab } from '@/web';

function getTemplatePath() {
Expand All @@ -23,7 +20,8 @@ function getTemplatePath() {
}
if (templatePath === null || typeof templatePath === 'undefined') {
const schema_name = Object.keys(menu)[0];
const template_name = Object.keys(menu[schema_name])[0]; return `${schema_name}/${template_name}`;
const template_name = Object.keys(menu[schema_name])[0];
return `${schema_name}/${template_name}`;
}
return templatePath;
}
Expand All @@ -49,26 +47,22 @@ export class AppContext {

// Method to bind event listeners
bindEventListeners() {

$(document).on('dhTabChange', (event, data) => {
const { specName } = data;
console.log('dhTabChange')

this.setCurrentDataHarmonizer(specName);
this.setCurrentDataHarmonizer(specName);
// Should trigger Toolbar to refresh sections
$(document).trigger('dhCurrentChange', {
dh: this.getCurrentDataHarmonizer()
dh: this.getCurrentDataHarmonizer(),
});
});

$(document).on('dhCurrentSelectionChange', (event, data) => {
const { currentSelection } = data;
console.log('dhCurrentSelectionChange')
console.log('dhCurrentSelectionChange');
this.currentSelection = currentSelection;
});

}

async reload(
template_path,
overrides = { locale: null, forced_schema: null }
Expand All @@ -79,7 +73,10 @@ export class AppContext {
const isForcedSchemaProvided = overrides.forced_schema !== null;
const isLocaleChange = overrides.locale !== null;

const clearAndSetup = async (data_harmonizers = {}, forced_schema = null) => {
const clearAndSetup = async (
data_harmonizers = {},
forced_schema = null
) => {
this.clearInterface();
return this.setupDataHarmonizers({
data_harmonizers,
Expand Down Expand Up @@ -119,8 +116,8 @@ export class AppContext {
this.template = await Template.create(template_name, options);
return this;
}
/**

/**
* Run void function behind loading screen.
* Adds function to end of call queue. Does not handle functions with return
* vals, unless the return value is a promise. Even then, it only waits for the
Expand Down Expand Up @@ -221,7 +218,7 @@ export class AppContext {
return acc;
}
);

let translated_sections = {};
let default_sections = {};
Object.keys(translation.schema.classes)
Expand Down Expand Up @@ -320,44 +317,33 @@ export class AppContext {
schema_name,
export_formats
) {

let data_harmonizers = {};
Object.entries(schema_tree)
.filter(([cls_key]) => cls_key !== 'Container')
.forEach((obj, index) => {
if (obj.length > 0) {
const [cls_key, spec] = obj;

// if it shares a key with another class which is its parent, this DH must be a child
const is_child = spec.shared_keys.some(
(shared_key_spec) => shared_key_spec.relation === 'parent'
);

const dhId = `data-harmonizer-grid-${index}`;
if (!document.getElementById(dhId)) {
const dhSubroot = createDataHarmonizerContainer(
dhId,
index === 0
);

const dhTab = createDataHarmonizerTab(
dhId,
spec.name,
index === 0
.filter(([cls_key]) => cls_key !== 'Container')
.forEach((obj, index) => {
if (obj.length > 0) {
const [cls_key, spec] = obj;

// if it shares a key with another class which is its parent, this DH must be a child
const is_child = spec.shared_keys.some(
(shared_key_spec) => shared_key_spec.relation === 'parent'
);
dhTab.addEventListener('click', () => {
$(document).trigger('dhTabChange', {
specName: spec.name,

const dhId = `data-harmonizer-grid-${index}`;
if (!document.getElementById(dhId)) {
const dhSubroot = createDataHarmonizerContainer(dhId, index === 0);

const dhTab = createDataHarmonizerTab(dhId, spec.name, index === 0);
dhTab.addEventListener('click', () => {
$(document).trigger('dhTabChange', {
specName: spec.name,
});
});
});

// Different classes have different slots allocated to them. field_filters narrows to those slots.
// idempotent: running this over the same initialization twice is expensive but shouldn't lose state
// in 1-M, different DataHarmonizers have fewer rows to start with and visible if a child. Override the default HoT settings.
data_harmonizers[spec.name] = new DataHarmonizer(
dhSubroot,
this,
{

// Different classes have different slots allocated to them. field_filters narrows to those slots.
// idempotent: running this over the same initialization twice is expensive but shouldn't lose state
// in 1-M, different DataHarmonizers have fewer rows to start with and visible if a child. Override the default HoT settings.
data_harmonizers[spec.name] = new DataHarmonizer(dhSubroot, this, {
loadingScreenRoot: document.body,
class_assignment: cls_key,
field_filters: findSlotNamesForClass(schema, cls_key),
Expand All @@ -367,21 +353,20 @@ export class AppContext {
// colWidths: is_child ? 256 : undefined, // TODO: Workaround, possibly due to too small section column on child tables
colWidths: 256,
},
});
data_harmonizers[spec.name].useSchema(
schema,
export_formats,
schema_name
);

// hide the single row if child
if (is_child) {
data_harmonizers[spec.name].filterAll();
}
);
data_harmonizers[spec.name].useSchema(
schema,
export_formats,
schema_name
);

// hide the single row if child
if (is_child) {
data_harmonizers[spec.name].filterAll();
}
}
}
});
});
delete data_harmonizers[undefined];
return data_harmonizers; // Return the created data harmonizers if needed
}
Expand Down
7 changes: 2 additions & 5 deletions lib/Toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@ import {
importJsonFile,
} from '@/lib/utils/files';
import { nullValuesToString, isEmptyUnitVal } from '@/lib/utils/general';
import {
MULTIVALUED_DELIMITER,
titleOverText,
} from '@/lib/utils/fields';
import { MULTIVALUED_DELIMITER, titleOverText } from '@/lib/utils/fields';
import {
findBestLocaleMatch,
templatePathForSchemaURI,
rangeToContainerClass,
LocaleNotSupportedError
LocaleNotSupportedError,
} from '@/lib/utils/templates';

import {
Expand Down
9 changes: 5 additions & 4 deletions lib/editors/KeyValueEditor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Handsontable from 'handsontable';
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 @@ -134,11 +135,11 @@ export const keyValueListRenderer = function (
cellProperties
) {
// Call the autocomplete renderer to ensure default styles and behavior are applied

const item = cellProperties.source.find(({ _id }) => _id === value);
Handsontable.renderers
.getRenderer('autocomplete')
.apply(this, [hot, TD, row, col, prop, item, cellProperties]);
.apply(this, [hot, TD, row, col, prop, value, cellProperties]);

const item = cellProperties.source.find(({ _id }) => _id === value);
if (item) {
// Use the label as the display value but keep the _id as the stored value
const label = item.label;
Expand All @@ -156,7 +157,7 @@ export const multiKeyValueListRenderer = (field) => {
.getRenderer('autocomplete')
.apply(this, [hot, TD, row, col, prop, value, cellProperties]);

if (!(value === null || value === '' || typeof value === 'undefined')) {
if (!isEmptyUnitVal(value)) {
const label = value
.split(MULTIVALUED_DELIMITER)
.map((key) => titleOverText(merged_permissible_values[key]))
Expand Down
Loading

0 comments on commit bb30948

Please sign in to comment.