Skip to content

Commit 6d61411

Browse files
committed
Fix display of validation buttons during tab navigation
1 parent d72b344 commit 6d61411

3 files changed

Lines changed: 138 additions & 99 deletions

File tree

lib/AppContext.js

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default class AppContext {
5252
});
5353

5454
$(document).on('dhCurrentSelectionChange', (event, data) => {
55-
const { currentSelection } = data;
55+
const { currentSelection } = data; // Is data mutable?
5656
this.currentSelection = currentSelection;
5757
});
5858
}
@@ -506,6 +506,12 @@ export default class AppContext {
506506
Object.entries(dh.slots).forEach(
507507
([index, slot]) => (dh.slot_name_to_column[slot.name] = parseInt(index))
508508
);
509+
510+
dh.slot_title_to_column = {};
511+
Object.entries(dh.slots).forEach(
512+
([index, slot]) => (dh.slot_title_to_column[slot.title] = parseInt(index))
513+
);
514+
509515
}
510516

511517
/**
@@ -930,7 +936,7 @@ export default class AppContext {
930936
*/
931937
crudFilterDependentViews(class_name) {
932938
let class_dependents = this.relations[class_name].dependents;
933-
this.crudGetDependentRows(class_name, class_dependents);
939+
this.crudGetDependentRows(class_name, false, class_dependents);
934940
for (let [dependent_name] of class_dependents.entries()) {
935941
let dependent_report = this.dependent_rows.get(dependent_name);
936942
//console.log("view refresh", dependent_name, dependent_report)
@@ -1027,25 +1033,28 @@ export default class AppContext {
10271033
* The delete or update in root table is row specific and happens in calling
10281034
* routine via user confirmation.
10291035
* Note: this report is done regardless of visibility of rows/columns to user.
1030-
*
1031-
* INPUT
1032-
* @start_name {String} name of root table to begin looking for cascading effect of foreign key changes. 1st user-selected row is used for all primary key and target class filtering.
10331036
*
10341037
* Builds a list of dependents that have root-related records
1035-
* dependent_rows: {
1036-
[dependent_name]: {
1037-
slots: {} // just like start_name, these are values of all slots that other tables depend on.
1038-
[parent]: {
1039-
slots: {[slot_name]: value, ... },
1040-
incomplete: true | false,
1041-
changed_slots: {[slot_name]: value, ... },
1042-
count: [# records in dependent matching this combo],
1043-
rows: [row # of affected row, ...]
1044-
}
1045-
}
1046-
1038+
* dependent_rows: {
1039+
* [dependent_name]: {
1040+
* slots: {} // just like start_name, these are values of all slots that other tables depend on.
1041+
* [parent]: {
1042+
* slots: {[slot_name]: value, ... },
1043+
* incomplete: true | false,
1044+
* changed_slots: {[slot_name]: value, ... },
1045+
* count: [# records in dependent matching this combo],
1046+
* rows: [row # of affected row, ...]
1047+
* }
1048+
* }
1049+
*
1050+
* For a given DH table, 1st user-selected row is used to get values for all non-foreign key and target slots.
1051+
*
1052+
* @param {String} start_name name of root table to begin looking for cascading effect of foreign key changes.
1053+
* @param {String} class_name name of class (DataHarmonizer instance) to start from.
1054+
* @param {Boolean} skipable: yes = don't do deep dive if no keys have changed for class name.
1055+
* @param {Object} changes dictionary pertaining to a particular dh row's slots.
10471056
*/
1048-
crudGetDependentRows(start_name, changes = {}) {
1057+
crudGetDependentRows(start_name, skippable=false, changes = {}) {
10491058
// For each start class + its dependents
10501059
let family = [start_name,...this.relations[start_name].dependents.keys()];
10511060
family.forEach((class_name) => {
@@ -1058,6 +1067,8 @@ export default class AppContext {
10581067
incomplete: incomplete
10591068
};
10601069

1070+
if (skippable && isEmpty(changed_key_vals))
1071+
return
10611072
/*
10621073
* 2) Query given dependent to see # of rows of dependent retrieved.
10631074
* 3) Add rowcount to dependent_rows.
@@ -1073,7 +1084,7 @@ export default class AppContext {
10731084
}
10741085
}
10751086

1076-
this.dependent_rows.set(class_name, dependent_rows_obj); // Set doesn't bring existing class to end?
1087+
this.dependent_rows.set(class_name, dependent_rows_obj);
10771088

10781089
})
10791090

@@ -1212,7 +1223,10 @@ export default class AppContext {
12121223
foreign_slot_name
12131224
);
12141225
if (value == null) {
1215-
errors += `\n- ${parent_name}.${foreign_slot_name}: _____`;
1226+
const dh = this.dhs[parent_name];
1227+
const parent_title = this.template.current.schema.classes[parent_name].title;
1228+
const foreign_slot_title = dh.slots[dh.slot_name_to_column[foreign_slot_name]].title;
1229+
errors += `\n- ${parent_title}.${foreign_slot_title}: _____`;
12161230
} else {
12171231
required_selections[slot_name] = {
12181232
value: value,
@@ -1330,14 +1344,14 @@ export default class AppContext {
13301344
* @param {String} key_name to examine
13311345
* @param {Object} changes for a row with slot_name as key.
13321346
* @param {Object} dictionary of slots and their new values.
1333-
* @param {String} textual report of any slots which were changed.
1334-
*
1335-
* @return {Boolean} found boolean true if complete keyVals
1336-
* @return {Object} keyVals set of slots and their values from template or change
1337-
* @return {String} change_log report of changed slot values
1347+
* @return {Boolean} found boolean true if complete keyVals
1348+
* @return {Object} keyVals set of slots and their values from template or change
1349+
* @return {String} change_log report of changed slot values
13381350
*/
1339-
crudHasCompleteUniqueKey(dh, row, key_name, changes, keyVals = {}, change_log = '') {
1351+
crudHasCompleteUniqueKey(dh, row, key_name, changes) {
13401352
const key_obj = dh.template.unique_keys[key_name];
1353+
let keyVals = {};
1354+
let change_log = '';
13411355
let changed = false;
13421356
let complete = Object.entries(key_obj.unique_key_slots)
13431357
// If every slot has a value, then the whole key is complete.

lib/DataHarmonizer.js

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ class DataHarmonizer {
361361
// Enables removal of a row and all dependent table rows.
362362
// If there are 1-many cascading deletes, verify if that's ok.
363363
let selection = self.hot.getSelected()[0][0];
364-
let [change_report, change_message] = self.getChangeReport(self.template_name);
364+
let [change_report, change_message] = self.getChangeReport(self.template_name, false);
365365
if (!change_message.length) {
366366
self.hot.alter('remove_row', selection);
367367
return true;
@@ -621,7 +621,8 @@ class DataHarmonizer {
621621
parseInt(row) + 1
622622
} would also change existing dependent table records! Do you want to continue? Check:\n`;
623623

624-
let [change_report, change_message] = self.getChangeReport(self.template_name, changes);
624+
let [change_report, change_message] = self.getChangeReport(self.template_name, true, changes);
625+
console.log("CHANGES", changes,change_report)
625626
// confirm() presents user with report containing notice of subordinate changes
626627
// that need to be acted on.
627628

@@ -681,7 +682,10 @@ class DataHarmonizer {
681682
// ISSUE: "updateData" event getting triggered.
682683
//if (action != 'updateData')
683684
//hotInstance.suspendRender();
684-
self.context.crudFilterDependentViews(self.template_name);
685+
if (action = "loadData")
686+
self.clearValidationResults();
687+
688+
self.context.crudFilterDependentViews(self.template_name);
685689

686690
},
687691

@@ -757,16 +761,49 @@ class DataHarmonizer {
757761
}
758762
}
759763

764+
clearValidationResults() {
765+
$('#next-error-button,#no-error-button').hide();
766+
this.invalid_cells = {};
767+
768+
/* TESTING: Because dh's can be filtered for rows, eliminate validation data.
769+
//this.hideValidationResults();
770+
// See DataHarmonizer . afterRenderer();
771+
//'empty-invalid-cell' : 'invalid-cell'
772+
$('#no-error-button').hide();
773+
if (extraData.dh.invalid_cells.length>0) {
774+
$('#next-error-button').show();
775+
// NEED TO SHOW ALL ROWS
776+
invalid_cells[row][col]
777+
alert('here' + dh.template.template_name)
778+
extraData.dh.changeRowVisibility('show-all-rows-dropdown-item');
779+
}
780+
else {
781+
$('#next-error-button').hide();
782+
}
783+
*/
784+
}
785+
760786
/**
761-
* Regenerates this.context.dependent_rows for given class_name and its dependents.
762-
* Then drafts report if
787+
* Returns a dependent_report of changed table rows, as well as an affected
788+
* key slots summary. Given changes object is user's sot edits, if any, on
789+
* a row. If no class_name primary key related update or delete action is
790+
* asked for by user, i.e. they edited some other slot, then a
791+
* skippable = true parameter enables this report to exit quickly rather than
792+
* doing a deep recursive dive.
793+
* @param {String} class_name name of class (DataHarmonizer instance) to start from.
794+
* @param {Boolean} skippable: yes = don't do deep dive if no keys have changed for class name.
795+
* @param {Object} changes dictionary pertaining to a particular dh row's slots.
796+
* @returns {Object} dependent_report dictionary of class_names and the key slot related data and change-affected rows
797+
* @returns {String} change_message echoes description of entailed changes in dependent tables.
763798
*/
764-
getChangeReport(class_name, changes = {}) {
799+
getChangeReport(class_name, skippable=false, changes = {}) {
765800
let change_message = '';
766801
let dependent_report = {};
767-
this.context.crudGetDependentRows(class_name, changes);
802+
this.context.crudGetDependentRows(class_name, skippable, changes);
768803
for (let [dependent_name] of this.context.relations[class_name].dependents.entries()) {
769804
let dependent_rep = this.context.dependent_rows.get(dependent_name);
805+
if (skippable && isEmpty(dependent_rep.changed_slots))
806+
break;
770807
dependent_report[dependent_name] = dependent_rep;
771808
if (class_name != dependent_name && dependent_rep.count) {
772809
let key_vals = Object.entries(dependent_rep.slots)
@@ -843,6 +880,7 @@ class DataHarmonizer {
843880
this.context.crudGetForeignKeyValues(parents);
844881
if (errors) {
845882
// Prompt user to select appropriate parent table row(s) first.
883+
// FRINGE ISSUE: When user selects row/cell on subordinate table, then mouse-clicks on disabled tab, and then add-row, they get popup pertaining to disabled tab table.
846884
$('#empty-parent-key-modal-info').html(errors);
847885
$('#empty-parent-key-modal').modal('show');
848886
return;
@@ -990,7 +1028,8 @@ class DataHarmonizer {
9901028
if (as_markup) return `[${curieOrURI}](${curieOrURI})`;
9911029

9921030
return `<a href="${curieOrURI}" target="_blank">${curieOrURI}</a>`;
993-
} else if (curieOrURI.includes(':')) {
1031+
}
1032+
else if (curieOrURI.includes(':')) {
9941033
const [prefix, reference] = curieOrURI.split(':', 2);
9951034
if (prefix && reference && prefix in this.schema.prefixes) {
9961035
// Lookup curie
@@ -2807,25 +2846,14 @@ class DataHarmonizer {
28072846
toJSON() {
28082847
const handsontableInstance = this.hot;
28092848
const tableData = this.fullData(handsontableInstance);
2810-
const columnHeaders = handsontableInstance.getColHeader().map(stripDiv); // TODO: use fields() or this.getFlatHeaders()[1];
2849+
const columnHeaders = this.slot_names;
28112850

28122851
function createStruct(row) {
28132852
const structInstance = {};
28142853
// iterate over the columns in a row
28152854
for (let i = 0; i < row.length; i++) {
2816-
const columnHeader = columnHeaders[i];
2817-
2818-
// Optional type checking (adjust data types as needed)
2819-
if (typeof columnHeader === 'string') {
2820-
structInstance[columnHeader] = row[i];
2821-
} else if (typeof columnHeader === 'number') {
2822-
structInstance[columnHeader] = Number(row[i]); // Convert to number
2823-
} else {
2824-
// Handle other data types if needed
2825-
structInstance[columnHeader] = row[i];
2826-
}
2855+
structInstance[columnHeaders[i]] = row[i];
28272856
}
2828-
28292857
return structInstance;
28302858
}
28312859

@@ -2838,7 +2866,7 @@ class DataHarmonizer {
28382866
arrayOfStructs.push(createStruct(row));
28392867
}
28402868
}
2841-
2869+
console.log(arrayOfStructs);
28422870
return arrayOfStructs;
28432871
}
28442872
}

0 commit comments

Comments
 (0)