Skip to content

Commit effa943

Browse files
popup for blocking innapropriate addrows
1 parent 6a931d0 commit effa943

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

lib/DataHarmonizer.js

+35-9
Original file line numberDiff line numberDiff line change
@@ -776,17 +776,43 @@ class DataHarmonizer {
776776
// Get the starting row index where the new rows will be added
777777
const startRowIndex = this.hot.countRows();
778778

779-
// Insert the new rows below the last existing row
780-
this.hot.alter('insert_row_below', startRowIndex, numRows);
781779
// Validate and process the current selection
782-
if (
783-
this.context.currentSelection !== null &&
784-
this.context.currentSelection.valueToMatch !== null
785-
) {
786-
// Find the nearest index after the last non-empty row in the specified column
787-
this.populateNewRows(numRows, startRowIndex);
780+
const is1mAndHasParent = (class_assignment) => {
781+
console.log(this.context.currentSelection, this.context.oneToManyAppContext.appContext[class_assignment]);
782+
const unique_keys = this.context.oneToManyAppContext.appContext[class_assignment].unique_keys;
783+
for (let key in unique_keys) {
784+
if ('foreign_key' in unique_keys[key]) {
785+
return unique_keys[key].foreign_key;
786+
}
787+
}
788+
return false;
789+
};
790+
const classIsForeignKeyForClassAndCurrentSelection = (maybe_child_class, currentSelection) => {
791+
const unique_keys = this.context.oneToManyAppContext.appContext[maybe_child_class].unique_keys;
792+
return !isEmptyUnitVal(unique_keys[currentSelection.shared_key_name]) && maybe_child_class !== currentSelection.source;
793+
794+
}
795+
// check if the DH refers to a parent class or class with no children.
796+
// if it has a parent, ensure a foreign key is selected in some parent
797+
// if it doesn't have a parent, use regular add rows implementation
798+
if (is1mAndHasParent(this.class_assignment)) {
799+
if (
800+
!isEmptyUnitVal(this.context.currentSelection) &&
801+
!isEmptyUnitVal(this.context.currentSelection.valueToMatch) &&
802+
classIsForeignKeyForClassAndCurrentSelection(this.class_assignment, this.context.currentSelection)
803+
) {
804+
805+
// Insert the new rows below the last existing row
806+
this.hot.alter('insert_row_below', startRowIndex, numRows);
807+
// Find the nearest index after the last non-empty row in the specified column
808+
this.populateNewRows(numRows, startRowIndex);
809+
} else {
810+
console.warn('No current selection to populate the new rows.');
811+
$('#empty-parent-key-modal').modal('show');
812+
}
788813
} else {
789-
console.warn('No current selection to populate the new rows.');
814+
// Insert the new rows below the last existing row
815+
this.hot.alter('insert_row_below', startRowIndex, numRows);
790816
}
791817
}
792818

lib/Toolbar.js

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import pkg from '../package.json';
3535

3636
const VERSION = pkg.version;
3737

38+
3839
class Toolbar {
3940
constructor(root, context, options = {}) {
4041
this.context = context;

0 commit comments

Comments
 (0)