Skip to content

Commit 0e8979a

Browse files
committed
handle schema editor changes to type,class,enum enums
1 parent e8eae72 commit 0e8979a

File tree

2 files changed

+45
-19
lines changed

2 files changed

+45
-19
lines changed

lib/AppContext.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,15 @@ export default class AppContext {
131131
* 2) Find any DH class / tab's slot that mentions changed enums, and
132132
* regenerate its "cached" flatVocabulary etc.
133133
*
134-
* @param {Array} enums list of special enumeration menus.
134+
* @param {Array} enums list of special enumeration menus. Default list
135+
* covers all menus that schema editor might have changed dynamically.
136+
*
137+
* FUTURE: add SchemaSlotMenu ?
135138
*/
136139
refreshSchemaEditorMenus(enums = ['SchemaTypeMenu','SchemaClassMenu','SchemaEnumMenu']) {
137140
let schema = this.template.current.schema;
138-
139141
if (schema.name === 'DH_LinkML') {
142+
//alert("doing "+enums.join(';'))
140143
for (const enum_name of enums) {
141144
// Initialize TypeMenu, ClassMenu and EnumMenu
142145

@@ -145,7 +148,7 @@ export default class AppContext {
145148
let user_schema_name = 'DH_LinkML'; // default
146149

147150
const selected_schema_row = dh_schema.hot.getSelected()?.[0][0];
148-
if (selected_schema_row) {
151+
if (selected_schema_row >=0) {
149152
const selected_schema_name = dh_schema.hot.getDataAtCell(selected_schema_row, 0);
150153
if (selected_schema_name) {
151154
user_schema_name = selected_schema_name;
@@ -185,9 +188,11 @@ export default class AppContext {
185188
break;
186189
}
187190

188-
// Reset menu's permissible_values to latest.
189-
schema.enums[enum_name].permissible_values = permissible_values;
190-
191+
if (schema.enums[enum_name])
192+
// Reset menu's permissible_values to latest.
193+
schema.enums[enum_name].permissible_values = permissible_values;
194+
else
195+
console.log(`Error in refreshSchemaEditorMenus: Unable to find "${enum_name}" Enumeration.`)
191196
}
192197

193198
// Then trigger update for any slot that has given menu in range.
@@ -205,8 +210,8 @@ export default class AppContext {
205210
}
206211
}
207212
}
208-
209213
}
214+
return false;
210215
}
211216

212217
/** For generating permissible_values for SchemaTypeMenu, SchemaClassMenu,
@@ -293,7 +298,7 @@ export default class AppContext {
293298
minRows: is_child ? 0 : 10,
294299
minSpareRows: 0,
295300
//minHeight: '200px', // nonsensical if no rows exist
296-
height: is_child ? '60vh' : '75vh',
301+
height: is_child ? '60vh' : '75vh', //'400px' : '700px', //
297302
// TODO: Workaround, possibly due to too small section column on child tables
298303
// colWidths: is_child ? 256 : undefined,
299304
colWidths: 200,

lib/DataHarmonizer.js

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -355,14 +355,14 @@ class DataHarmonizer {
355355
columns: this.getColumns(),
356356
colHeaders: true,
357357
rowHeaders: true,
358-
//renderallrows: false, // working?
358+
renderallrows: false, // working?
359359
manualRowMove: true,
360360
copyPaste: true,
361361
outsideClickDeselects: false, // for maintaining selection between tabs
362362
manualColumnResize: true,
363363
//colWidths: [100], //Just fixes first column width
364-
minRows: 10,
365-
minSpareRows: 10,
364+
minRows: 5,
365+
minSpareRows: 5,
366366
width: '100%',
367367
// Future: For empty dependent tables, tailor to minimize height.
368368
height: '75vh',
@@ -513,11 +513,11 @@ class DataHarmonizer {
513513
* # rows, this event can be triggered "silently" on update of fields likedata
514514
* empty provenance field.
515515
* @param {Array} grid_changes array of [row, column, old value (incl. undefined), new value (incl. null)].
516-
* @param {String} action can be CopyPaste.paste, ...
516+
* @param {String} action can be CopyPaste.paste, ... thisChange
517517
*/
518518
beforeChange: function (grid_changes, action) {
519519
// Ignore addition of new records to table.
520-
if (action == 'add_row' || action == 'upload') return;
520+
if (action == 'add_row' || action == 'upload' || action =='thisChange') return;
521521
if (!grid_changes) return; // Is this ever the case?
522522

523523
console.log('beforeChange', grid_changes, action);
@@ -698,17 +698,31 @@ class DataHarmonizer {
698698
// change selection, e.g. just edits 1 cell content, then
699699
// an afterSelection isn't triggered. THEREFORE we have to
700700
// trigger a crudFilterDependentViews() call.
701-
// action e.g. edit, updateData
701+
// action e.g. edit, updateData, CopyPaste.paste
702702
afterChange: function (grid_changes, action) {
703-
704-
//Ignore if partial key left by change. For full dependent key,
705-
// ISSUE: "updateData" event getting triggered.
703+
if (action == 'upload' || action =='updateData') {
704+
// This is being called for every cell change in an 'upload'
705+
// Must block them or it somehow triggers stack overload of new
706+
// afterChange events.
707+
this.counter??= 0;
708+
this.counter ++;
709+
return;
710+
}
711+
// ISSUE: Thousands of upload actions for uploaded schema
712+
// Note: https://github.com/handsontable/handsontable/discussions/9275
713+
//console.log ("upload actions", this.counter)
706714

707715
// Trigger only if change to some key slot child needs.
708716
if (grid_changes) {
709717
let row_changes = self.getRowChanges(grid_changes);
710718
if (self.hasRowKeyChange(self.template_name, row_changes)) {
711719
self.context.crudFilterDependentViews(self.template_name);
720+
// If in schema editor mode, update or insert to name field (a
721+
// key field) of class, slot or enum (should cause update in
722+
// compiled enums and slot flatVocabularies.
723+
if (['Type','Class','Enum'].includes(self.template_name)) {
724+
self.context.refreshSchemaEditorMenus(['Schema'+self.template_name+'Menu']);
725+
}
712726
}
713727
}
714728
},
@@ -721,13 +735,18 @@ class DataHarmonizer {
721735
* foreign key values that make up some dependent table's record(s)
722736
* have changed, so that table's view should be refreshed. Dependent
723737
* tables determine what parent foreign key values they need to filter view by.
724-
* This event is not involved in row content change.
738+
* This event is not directly involved in row content change.
725739
*
740+
* As well, refresh schema menus if selected schema has changed.
726741
*/
727742

728743
//console.log("afterSelectionEnd",row, column, row2, column2, selectionLayerLevel)
729744
if (self.current_selection[0] != row || self.current_selection[1] != column) {
730745
self.context.crudFilterDependentViews(self.template_name);
746+
if (self.template_name == 'Schema' && self.current_selection[0] != row) {
747+
self.context.refreshSchemaEditorMenus();
748+
}
749+
731750
}
732751

733752
self.current_selection = [row, column]; //, row2, column2];
@@ -943,6 +962,7 @@ class DataHarmonizer {
943962
}
944963

945964
// Classes & slots (tables & fields) in loaded schema editor schema guide what can be imported.
965+
// TRY SWITCHING TO hot.updateData()
946966
loadSchemaYAML(text) {
947967
let schema = null;
948968
try {
@@ -1158,14 +1178,15 @@ class DataHarmonizer {
11581178
//dh.hot.resumeExecution();
11591179
//dh.hot.updateSettings({hiddenRows: true});
11601180
dh.hot.resumeRender();
1181+
dh.hot.render();
11611182
//hot.updateSettings({hiddenRows: { rows: myRows}});
11621183

11631184
}
11641185

11651186
// New data type, class & enumeration items need to be reflected in DH
11661187
// schema editor SchemaTypeMenu, SchemaClassMenu and SchemaEnumMenu menus
11671188

1168-
// NEED TO DO THIS EACH TIME NEW SCHEMA ROW IS CALCULATED.
1189+
// Done each time a schema is uploaded or focused on.
11691190
this.context.refreshSchemaEditorMenus();
11701191

11711192
console.table("LOADED SCHEMA", schema);

0 commit comments

Comments
 (0)