Skip to content

Commit

Permalink
popup for blocking innapropriate addrows
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethbruskiewicz committed Dec 18, 2024
1 parent 6a931d0 commit effa943
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
44 changes: 35 additions & 9 deletions lib/DataHarmonizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -776,17 +776,43 @@ class DataHarmonizer {
// Get the starting row index where the new rows will be added
const startRowIndex = this.hot.countRows();

// Insert the new rows below the last existing row
this.hot.alter('insert_row_below', startRowIndex, numRows);
// Validate and process the current selection
if (
this.context.currentSelection !== null &&
this.context.currentSelection.valueToMatch !== null
) {
// Find the nearest index after the last non-empty row in the specified column
this.populateNewRows(numRows, startRowIndex);
const is1mAndHasParent = (class_assignment) => {
console.log(this.context.currentSelection, this.context.oneToManyAppContext.appContext[class_assignment]);
const unique_keys = this.context.oneToManyAppContext.appContext[class_assignment].unique_keys;
for (let key in unique_keys) {
if ('foreign_key' in unique_keys[key]) {
return unique_keys[key].foreign_key;
}
}
return false;
};
const classIsForeignKeyForClassAndCurrentSelection = (maybe_child_class, currentSelection) => {
const unique_keys = this.context.oneToManyAppContext.appContext[maybe_child_class].unique_keys;
return !isEmptyUnitVal(unique_keys[currentSelection.shared_key_name]) && maybe_child_class !== currentSelection.source;

}
// check if the DH refers to a parent class or class with no children.
// if it has a parent, ensure a foreign key is selected in some parent
// if it doesn't have a parent, use regular add rows implementation
if (is1mAndHasParent(this.class_assignment)) {
if (
!isEmptyUnitVal(this.context.currentSelection) &&
!isEmptyUnitVal(this.context.currentSelection.valueToMatch) &&
classIsForeignKeyForClassAndCurrentSelection(this.class_assignment, this.context.currentSelection)
) {

// Insert the new rows below the last existing row
this.hot.alter('insert_row_below', startRowIndex, numRows);
// Find the nearest index after the last non-empty row in the specified column
this.populateNewRows(numRows, startRowIndex);
} else {
console.warn('No current selection to populate the new rows.');
$('#empty-parent-key-modal').modal('show');
}
} else {
console.warn('No current selection to populate the new rows.');
// Insert the new rows below the last existing row
this.hot.alter('insert_row_below', startRowIndex, numRows);
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/Toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import pkg from '../package.json';

const VERSION = pkg.version;


class Toolbar {
constructor(root, context, options = {}) {
this.context = context;
Expand Down

0 comments on commit effa943

Please sign in to comment.