Skip to content

Commit

Permalink
row selection with blank
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethbruskiewicz committed Aug 22, 2024
1 parent 17a3ac2 commit c6d473b
Showing 1 changed file with 28 additions and 92 deletions.
120 changes: 28 additions & 92 deletions lib/utils/1m.js
Original file line number Diff line number Diff line change
Expand Up @@ -587,91 +587,21 @@ export function attachSelectionHandlersToDataHarmonizers(
schema_tree
) {
Object.values(data_harmonizers).forEach((dh) => {
dh.hot.addHook('afterSelection', (row, col) => {
/* DEPRECATED:
let valueToMatch;
// selecting whole row
if (col === -1) {
// NOTE: ensure that the first column is always the ID column?
// - sections are assumed to be ranked *if possible* by the DataHarmonizer due to the presence of slot_usage
// - Otherwise, should we presume the first column is the ID by convention?
// - Will all ID columns be shared?
// "Round up" the row column to be equal to the single identifying column
const IDColumnIndex = 0;
col = IDColumnIndex;
valueToMatch = dh.hot.getDataAtCell(row, IDColumnIndex);
} else {
valueToMatch = dh.hot.getDataAtCell(row, col);
}

const current_col_name = dh.getFields()[col].name;
dh.hot.addHook('afterSelection', (row, ) => {

if (!isEmptyUnitVal(valueToMatch)) {
// get value at cell
// filter other data harmonizer at cell
const parent_name = dh.class_assignment;
schema_tree[parent_name].children.forEach((child_name) => {
// filter for other data in data harmonizers matching the shared ID iff the selection is not empty
// else return an empty list
const shared_key_name = getSharedKeyNameForParentAndChild(
schema_tree,
parent_name,
child_name
);
const shared_key_column = data_harmonizers[parent_name].getColumnIndexByFieldName(shared_key_name);
if (shared_key_column === -1) {
console.error(
'attachSelectionHandlersToDataHarmonizers: Column name not found',
shared_key_name,
schema_tree
);
return;
}
// NOTE: Need this check to prevent "homonyms" – faceting on a value shared between enums, but one is not an identifying field
// Still assuming singular identifying fields.
if (current_col_name === shared_key_name) {
$(document).trigger('dhCurrentSelectionChange', {
currentSelection: {
source: dh.class_assignment,
shared_key_name,
valueToMatch,
parentCol: shared_key_column,
},
});
propagateFilter(
data_harmonizers,
shared_key_name,
schema_tree,
child_name,
valueToMatch
);
} else {
schema_tree[dh.class_assignment].children.forEach((child_name) => {
data_harmonizers[child_name].filterAll();
});
}
});
} else {
schema_tree[dh.class_assignment].children.forEach((child_name) => {
data_harmonizers[child_name].filterAll();
});
}
*/
// if (col === -1) col = 0;
// const currentValue = dh.hot.getDataAtCell(row, col);
// TODO: generalize to all shared keys!
const idValue = dh.hot.getDataAtCell(row, 0);
if (!isEmptyUnitVal(idValue)) {
const parent_name = dh.class_assignment;
const child_keys = schema_tree[parent_name].shared_keys.filter(el => el.relation === 'child');
child_keys.forEach(child_key => {

const shared_key_name = child_key.name;
const target_child_table = child_key.related_concept;
const shared_key_column = data_harmonizers[parent_name].getColumnIndexByFieldName(shared_key_name);
const shared_key_column = dh.getColumnIndexByFieldName(shared_key_name);
const valueToMatch = dh.hot.getDataAtCell(row, shared_key_column);

if (!isEmptyUnitVal(valueToMatch)) {

$(document).trigger('dhCurrentSelectionChange', {
Expand All @@ -683,17 +613,21 @@ export function attachSelectionHandlersToDataHarmonizers(
},
});

const child_shared_key_column = data_harmonizers[target_child_table].getColumnIndexByFieldName(shared_key_name);
const plugin = data_harmonizers[target_child_table].hot.getPlugin('filters');
const child_dh = data_harmonizers[target_child_table];
const child_shared_key_column = child_dh.getColumnIndexByFieldName(shared_key_name);

// Add a condition where the column value equals the specified value
plugin.clearConditions(child_shared_key_column); // change valueToMatch per new selection in the column
const plugin = child_dh.hot.getPlugin('filters');
plugin.clearConditions(child_shared_key_column);
if (valueToMatch !== null) {
plugin.addCondition(child_shared_key_column, 'eq', [valueToMatch]);
}
plugin.filter();

};
});
} else {
// empty row selection
$(document).trigger('dhCurrentSelectionChange', {
currentSelection: null,
});
Expand All @@ -708,23 +642,25 @@ export function attachSelectionHandlersToDataHarmonizers(
$(document).trigger('dhCurrentSelectionChange', {
currentSelection: null,
});

schema_tree[dh.class_assignment].children.forEach((child_name) => {
data_harmonizers[child_name].filterAll();
});
// get value at cell
// filter other data harmonizer at cell
const parent_name = dh.class_assignment;
schema_tree[parent_name].children.forEach((child_name) => {
const shared_key_name = getSharedKeyNameForParentAndChild(
schema_tree,
parent_name,
child_name
);
propagateFilter(
data_harmonizers,
shared_key_name,
schema_tree,
child_name
);
});
// const parent_name = dh.class_assignment;
// schema_tree[parent_name].children.forEach((child_name) => {
// const shared_key_name = getSharedKeyNameForParentAndChild(
// schema_tree,
// parent_name,
// child_name
// );
// propagateFilter(
// data_harmonizers,
// shared_key_name,
// schema_tree,
// child_name
// );
// });
});
});

Expand Down

0 comments on commit c6d473b

Please sign in to comment.