Skip to content

Commit

Permalink
format prettier, small bug in createRowManager
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethbruskiewicz committed Aug 21, 2024
1 parent c4b4f82 commit d7a9533
Show file tree
Hide file tree
Showing 8 changed files with 263 additions and 269 deletions.
109 changes: 48 additions & 61 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,23 +47,21 @@ export class AppContext {

// Method to bind event listeners
bindEventListeners() {

$(document).on('dhTabChange', (event, data) => {
const { specName } = data;
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;
this.currentSelection = currentSelection;
});

}

async reload(
template_path,
overrides = { locale: null, forced_schema: null }
Expand All @@ -76,7 +72,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 @@ -116,8 +115,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 @@ -218,7 +217,7 @@ export class AppContext {
return acc;
}
);

let translated_sections = {};
let default_sections = {};
Object.keys(translation.schema.classes)
Expand Down Expand Up @@ -317,44 +316,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
.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 dhTab = createDataHarmonizerTab(
dhId,
spec.name,
index === 0
);
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 @@ -364,21 +352,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
2 changes: 1 addition & 1 deletion lib/editors/KeyValueEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export const multiKeyValueListRenderer = (field) => {
.getRenderer('autocomplete')
.apply(this, [hot, TD, row, col, prop, value, cellProperties]);

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

0 comments on commit d7a9533

Please sign in to comment.