@onehat/ui 0.3.290 → 0.3.292

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/ui",
3
- "version": "0.3.290",
3
+ "version": "0.3.292",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -949,6 +949,18 @@ function Form(props) {
949
949
  const formIsDirty = formState.isDirty;
950
950
  // console.log('formIsDirty', formIsDirty);
951
951
  // console.log('isPhantom', isPhantom);
952
+
953
+
954
+
955
+
956
+ // LEFT OFF HERE
957
+ // The code I wrote below was supposed to be for the Tree search but messed up the standard
958
+ // windowed editors. Need to figure out how to make it work for both.
959
+ // Also, when crudding two records on the same tree in succession, the second record throws an error.
960
+
961
+
962
+
963
+
952
964
  if (editorType === EDITOR_TYPE__WINDOWED && onCancel) {
953
965
  showCancelBtn = true;
954
966
  }
@@ -104,6 +104,8 @@ function TreeComponent(props) {
104
104
  additionalToolbarButtons = [],
105
105
  reload = null, // Whenever this value changes after initial render, the tree will reload from scratch
106
106
  parentIdIx,
107
+ initialSelection,
108
+ onTreeLoad,
107
109
 
108
110
  // withComponent
109
111
  self,
@@ -466,6 +468,11 @@ function TreeComponent(props) {
466
468
  setTreeNodeData(treeNodeData);
467
469
 
468
470
  buildRowToDatumMap();
471
+
472
+ if (onTreeLoad) {
473
+ onTreeLoad();
474
+ }
475
+ return treeNodeData;
469
476
  },
470
477
  buildRowToDatumMap = () => {
471
478
  const rowToDatumMap = {};
@@ -632,6 +639,7 @@ function TreeComponent(props) {
632
639
  buildRowToDatumMap();
633
640
  },
634
641
  loadChildren = async (datum, depth = 1) => {
642
+
635
643
  // Show loading indicator (spinner underneath current node?)
636
644
  datum.isLoading = true;
637
645
  forceUpdate();
@@ -668,8 +676,8 @@ function TreeComponent(props) {
668
676
  }
669
677
  });
670
678
  },
671
- expandPath = async (cPath) => {
672
- // First, close thw whole tree.
679
+ expandPath = async (cPath, highlight = true) => {
680
+ // First, close the whole tree.
673
681
  let newTreeNodeData = _.clone(getTreeNodeData());
674
682
  collapseNodes(newTreeNodeData);
675
683
 
@@ -692,9 +700,16 @@ function TreeComponent(props) {
692
700
  });
693
701
 
694
702
  if (!currentDatum) {
695
- // datum is not currently loaded, so load it
696
- await loadChildren(parentDatum, 1);
697
- currentLevelData = parentDatum.children;
703
+ if (!parentDatum) {
704
+ currentDatum = currentLevelData[0]; // this is essentially the root node (currentLevelData can contain more than one node, so just set it to the first)
705
+ // currentLevelData = currentDatum;
706
+ } else {
707
+ if (!parentDatum.isLoaded) {
708
+ await loadChildren(parentDatum, 1);
709
+ }
710
+ currentLevelData = parentDatum.children;
711
+ }
712
+
698
713
  currentDatum = _.find(currentLevelData, (treeNodeDatum) => {
699
714
  return treeNodeDatum.item.id === id;
700
715
  });
@@ -713,7 +728,9 @@ function TreeComponent(props) {
713
728
 
714
729
  setSelection([currentNode]);
715
730
  scrollToNode(currentNode);
716
- setHighlitedDatum(currentDatum);
731
+ if (highlight) {
732
+ setHighlitedDatum(currentDatum);
733
+ }
717
734
 
718
735
  setTreeNodeData(newTreeNodeData);
719
736
  buildRowToDatumMap();
@@ -1116,19 +1133,11 @@ function TreeComponent(props) {
1116
1133
  return () => {};
1117
1134
  }
1118
1135
 
1119
- if (!_.isEmpty(extraParams)) {
1120
- Repository.setBaseParams(extraParams);
1121
- }
1122
-
1123
- if (autoLoadRootNodes) {
1124
- Repository.loadRootNodes(1);
1125
- }
1126
-
1127
- async function rebuildTree() {
1128
- setIsReady(false);
1129
- await buildAndSetTreeNodeData();
1136
+ (async () => {
1137
+ await reloadTree();
1130
1138
  setIsReady(true);
1131
- }
1139
+ })();
1140
+
1132
1141
 
1133
1142
  // set up @onehat/data repository
1134
1143
  const
@@ -1138,8 +1147,8 @@ function TreeComponent(props) {
1138
1147
  Repository.on('beforeLoad', setTrue);
1139
1148
  Repository.on('load', setFalse);
1140
1149
  Repository.on('loadRootNodes', setFalse);
1141
- Repository.on('loadRootNodes', rebuildTree);
1142
- Repository.on('add', rebuildTree);
1150
+ Repository.on('loadRootNodes', buildAndSetTreeNodeData);
1151
+ Repository.on('add', buildAndSetTreeNodeData);
1143
1152
  Repository.on('changeFilters', reloadTree);
1144
1153
  Repository.on('changeSorters', reloadTree);
1145
1154
 
@@ -1147,8 +1156,8 @@ function TreeComponent(props) {
1147
1156
  Repository.off('beforeLoad', setTrue);
1148
1157
  Repository.off('load', setFalse);
1149
1158
  Repository.off('loadRootNodes', setFalse);
1150
- Repository.off('loadRootNodes', rebuildTree);
1151
- Repository.off('add', rebuildTree);
1159
+ Repository.off('loadRootNodes', buildAndSetTreeNodeData);
1160
+ Repository.off('add', buildAndSetTreeNodeData);
1152
1161
  Repository.off('changeFilters', reloadTree);
1153
1162
  Repository.off('changeSorters', reloadTree);
1154
1163
  };
@@ -1178,6 +1187,13 @@ function TreeComponent(props) {
1178
1187
  onAfterDelete,
1179
1188
  });
1180
1189
  }
1190
+
1191
+ // update self with methods
1192
+ if (self) {
1193
+ self.reloadTree = reloadTree;
1194
+ self.expandPath = expandPath;
1195
+ self.scrollToNode = scrollToNode;
1196
+ }
1181
1197
 
1182
1198
  const
1183
1199
  headerToolbarItemComponents = useMemo(() => getHeaderToolbarItems(), [Repository?.hash, treeSearchValue, isDragMode, getTreeNodeData()]),
@@ -734,7 +734,7 @@ export function runClosureTreeManagerScreenCrudTests(model, schema, newData, edi
734
734
 
735
735
  const
736
736
  managerSelector = '/' + Models + 'Manager',
737
- treeSelector = '/' + Models + 'FilteredTreeEditor';
737
+ treeSelector = '/' + Models + 'TreeEditor';
738
738
 
739
739
  toFullMode(managerSelector);
740
740
  cy.wait(500); // wait for grid to load
@@ -747,7 +747,7 @@ export function runClosureTreeManagerScreenCrudTests(model, schema, newData, edi
747
747
 
748
748
  const
749
749
  managerSelector = '/' + Models + 'Manager',
750
- treeSelector = '/' + Models + 'FilteredSideTreeEditor';
750
+ treeSelector = '/' + Models + 'SideTreeEditor';
751
751
 
752
752
  toSideMode(managerSelector);
753
753
  cy.wait(1000); // wait for grid to load
@@ -847,7 +847,7 @@ export function runManagerScreenCrudTests(model, schema, newData, editData, anci
847
847
 
848
848
  });
849
849
 
850
- it.skip('CRUD in side mode', function() {
850
+ it('CRUD in side mode', function() {
851
851
 
852
852
  const
853
853
  managerSelector = '/' + Models + 'Manager',
@@ -17,10 +17,11 @@ export default async function getSaved(key) {
17
17
 
18
18
  if (entity.isJson) {
19
19
  value = JSON.parse(value);
20
+ const model = entity.model;
20
21
  if (entity.isOneBuild) {
21
22
  // Convert the data to an actual entity (or entities) of the correct type
22
23
  const
23
- Repository = oneHatData.getRepository(entity.model),
24
+ Repository = oneHatData.getRepository(model),
24
25
  entities = [];
25
26
  let i, data, entity;
26
27
  if (_.isArray(value)) {
@@ -81,6 +81,8 @@ function AttachmentsElement(props) {
81
81
  clickable = true,
82
82
  confirmBeforeDelete = false,
83
83
  extraUploadData = {},
84
+ expandedMax = EXPANDED_MAX,
85
+ collapsedMax = COLLAPSED_MAX,
84
86
 
85
87
  // parentContainer
86
88
  selectorSelected,
@@ -231,7 +233,7 @@ function AttachmentsElement(props) {
231
233
  });
232
234
  }
233
235
  Repository.filter(filters);
234
- Repository.setPageSize(showAll ? EXPANDED_MAX : COLLAPSED_MAX);
236
+ Repository.setPageSize(showAll ? expandedMax : collapsedMax);
235
237
  await Repository.load();
236
238
 
237
239
  buildFiles();
@@ -286,7 +288,7 @@ function AttachmentsElement(props) {
286
288
  </Box>;
287
289
  })}
288
290
  </Row>
289
- {Repository.total <= COLLAPSED_MAX ? null :
291
+ {Repository.total <= collapsedMax ? null :
290
292
  <Button
291
293
  onPress={toggleShowAll}
292
294
  mt={4}