@onehat/ui 0.3.288 → 0.3.291
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
|
@@ -5,11 +5,12 @@ import testProps from '../../Functions/testProps.js';
|
|
|
5
5
|
import IconButton from './IconButton.js';
|
|
6
6
|
import Rotate from '../Icons/Rotate.js';
|
|
7
7
|
|
|
8
|
-
export default function ReloadButton(props
|
|
8
|
+
export default function ReloadButton(props) {
|
|
9
9
|
const {
|
|
10
10
|
iconProps ={},
|
|
11
11
|
self,
|
|
12
12
|
Repository,
|
|
13
|
+
isTree = false,
|
|
13
14
|
} = props,
|
|
14
15
|
onPress = () => {
|
|
15
16
|
if (isTree) {
|
|
@@ -134,8 +134,8 @@ function Form(props) {
|
|
|
134
134
|
}
|
|
135
135
|
const
|
|
136
136
|
isMultiple = _.isArray(record),
|
|
137
|
-
isSingle = !
|
|
138
|
-
isPhantom = !skipAll && !!record?.isPhantom,
|
|
137
|
+
isSingle = _.isNil(record) || !_.isArray(record),
|
|
138
|
+
isPhantom = !skipAll && !!record?.isPhantom,
|
|
139
139
|
forceUpdate = useForceUpdate(),
|
|
140
140
|
[previousRecord, setPreviousRecord] = useState(record),
|
|
141
141
|
[containerWidth, setContainerWidth] = useState(),
|
|
@@ -949,6 +949,21 @@ 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
|
+
|
|
964
|
+
if (editorType === EDITOR_TYPE__WINDOWED && onCancel) {
|
|
965
|
+
showCancelBtn = true;
|
|
966
|
+
}
|
|
952
967
|
if (formIsDirty || isPhantom) {
|
|
953
968
|
if (isSingle && onCancel) {
|
|
954
969
|
showCancelBtn = true;
|
|
@@ -70,6 +70,9 @@ function TreeComponent(props) {
|
|
|
70
70
|
}
|
|
71
71
|
return item[displayIx];
|
|
72
72
|
},
|
|
73
|
+
getDisplayTextFromSearchResults = (item) => {
|
|
74
|
+
return item.id
|
|
75
|
+
},
|
|
73
76
|
getNodeIcon = (which, item) => { // decides what icon to show for this node
|
|
74
77
|
// TODO: Allow for dynamic props on the icon (e.g. special color for some icons)
|
|
75
78
|
let icon;
|
|
@@ -101,6 +104,8 @@ function TreeComponent(props) {
|
|
|
101
104
|
additionalToolbarButtons = [],
|
|
102
105
|
reload = null, // Whenever this value changes after initial render, the tree will reload from scratch
|
|
103
106
|
parentIdIx,
|
|
107
|
+
initialSelection,
|
|
108
|
+
onTreeLoad,
|
|
104
109
|
|
|
105
110
|
// withComponent
|
|
106
111
|
self,
|
|
@@ -383,7 +388,7 @@ function TreeComponent(props) {
|
|
|
383
388
|
// Show modal so user can select which node to go to
|
|
384
389
|
const searchFormData = [];
|
|
385
390
|
_.each(found, (item) => {
|
|
386
|
-
searchFormData.push([item.id,
|
|
391
|
+
searchFormData.push([item.id, getDisplayTextFromSearchResults(item)]);
|
|
387
392
|
});
|
|
388
393
|
setSearchFormData(searchFormData);
|
|
389
394
|
setSearchResults(found);
|
|
@@ -463,6 +468,11 @@ function TreeComponent(props) {
|
|
|
463
468
|
setTreeNodeData(treeNodeData);
|
|
464
469
|
|
|
465
470
|
buildRowToDatumMap();
|
|
471
|
+
|
|
472
|
+
if (onTreeLoad) {
|
|
473
|
+
onTreeLoad();
|
|
474
|
+
}
|
|
475
|
+
return treeNodeData;
|
|
466
476
|
},
|
|
467
477
|
buildRowToDatumMap = () => {
|
|
468
478
|
const rowToDatumMap = {};
|
|
@@ -629,6 +639,7 @@ function TreeComponent(props) {
|
|
|
629
639
|
buildRowToDatumMap();
|
|
630
640
|
},
|
|
631
641
|
loadChildren = async (datum, depth = 1) => {
|
|
642
|
+
|
|
632
643
|
// Show loading indicator (spinner underneath current node?)
|
|
633
644
|
datum.isLoading = true;
|
|
634
645
|
forceUpdate();
|
|
@@ -665,8 +676,8 @@ function TreeComponent(props) {
|
|
|
665
676
|
}
|
|
666
677
|
});
|
|
667
678
|
},
|
|
668
|
-
expandPath = async (cPath) => {
|
|
669
|
-
// First, close
|
|
679
|
+
expandPath = async (cPath, highlight = true) => {
|
|
680
|
+
// First, close the whole tree.
|
|
670
681
|
let newTreeNodeData = _.clone(getTreeNodeData());
|
|
671
682
|
collapseNodes(newTreeNodeData);
|
|
672
683
|
|
|
@@ -689,9 +700,16 @@ function TreeComponent(props) {
|
|
|
689
700
|
});
|
|
690
701
|
|
|
691
702
|
if (!currentDatum) {
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
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
|
+
|
|
695
713
|
currentDatum = _.find(currentLevelData, (treeNodeDatum) => {
|
|
696
714
|
return treeNodeDatum.item.id === id;
|
|
697
715
|
});
|
|
@@ -699,8 +717,9 @@ function TreeComponent(props) {
|
|
|
699
717
|
|
|
700
718
|
currentNode = currentDatum.item;
|
|
701
719
|
|
|
702
|
-
|
|
703
|
-
|
|
720
|
+
if (!currentDatum.isExpanded) {
|
|
721
|
+
await loadChildren(currentDatum, 1);
|
|
722
|
+
}
|
|
704
723
|
|
|
705
724
|
cPath = cPathParts.slice(1).join('/'); // put the rest of it back together
|
|
706
725
|
currentLevelData = currentDatum.children;
|
|
@@ -709,7 +728,9 @@ function TreeComponent(props) {
|
|
|
709
728
|
|
|
710
729
|
setSelection([currentNode]);
|
|
711
730
|
scrollToNode(currentNode);
|
|
712
|
-
|
|
731
|
+
if (highlight) {
|
|
732
|
+
setHighlitedDatum(currentDatum);
|
|
733
|
+
}
|
|
713
734
|
|
|
714
735
|
setTreeNodeData(newTreeNodeData);
|
|
715
736
|
buildRowToDatumMap();
|
|
@@ -1112,19 +1133,11 @@ function TreeComponent(props) {
|
|
|
1112
1133
|
return () => {};
|
|
1113
1134
|
}
|
|
1114
1135
|
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
}
|
|
1118
|
-
|
|
1119
|
-
if (autoLoadRootNodes) {
|
|
1120
|
-
Repository.loadRootNodes(1);
|
|
1121
|
-
}
|
|
1122
|
-
|
|
1123
|
-
async function rebuildTree() {
|
|
1124
|
-
setIsReady(false);
|
|
1125
|
-
await buildAndSetTreeNodeData();
|
|
1136
|
+
(async () => {
|
|
1137
|
+
await reloadTree();
|
|
1126
1138
|
setIsReady(true);
|
|
1127
|
-
}
|
|
1139
|
+
})();
|
|
1140
|
+
|
|
1128
1141
|
|
|
1129
1142
|
// set up @onehat/data repository
|
|
1130
1143
|
const
|
|
@@ -1134,8 +1147,8 @@ function TreeComponent(props) {
|
|
|
1134
1147
|
Repository.on('beforeLoad', setTrue);
|
|
1135
1148
|
Repository.on('load', setFalse);
|
|
1136
1149
|
Repository.on('loadRootNodes', setFalse);
|
|
1137
|
-
Repository.on('loadRootNodes',
|
|
1138
|
-
Repository.on('add',
|
|
1150
|
+
Repository.on('loadRootNodes', buildAndSetTreeNodeData);
|
|
1151
|
+
Repository.on('add', buildAndSetTreeNodeData);
|
|
1139
1152
|
Repository.on('changeFilters', reloadTree);
|
|
1140
1153
|
Repository.on('changeSorters', reloadTree);
|
|
1141
1154
|
|
|
@@ -1143,8 +1156,8 @@ function TreeComponent(props) {
|
|
|
1143
1156
|
Repository.off('beforeLoad', setTrue);
|
|
1144
1157
|
Repository.off('load', setFalse);
|
|
1145
1158
|
Repository.off('loadRootNodes', setFalse);
|
|
1146
|
-
Repository.off('loadRootNodes',
|
|
1147
|
-
Repository.off('add',
|
|
1159
|
+
Repository.off('loadRootNodes', buildAndSetTreeNodeData);
|
|
1160
|
+
Repository.off('add', buildAndSetTreeNodeData);
|
|
1148
1161
|
Repository.off('changeFilters', reloadTree);
|
|
1149
1162
|
Repository.off('changeSorters', reloadTree);
|
|
1150
1163
|
};
|
|
@@ -1174,6 +1187,13 @@ function TreeComponent(props) {
|
|
|
1174
1187
|
onAfterDelete,
|
|
1175
1188
|
});
|
|
1176
1189
|
}
|
|
1190
|
+
|
|
1191
|
+
// update self with methods
|
|
1192
|
+
if (self) {
|
|
1193
|
+
self.reloadTree = reloadTree;
|
|
1194
|
+
self.expandPath = expandPath;
|
|
1195
|
+
self.scrollToNode = scrollToNode;
|
|
1196
|
+
}
|
|
1177
1197
|
|
|
1178
1198
|
const
|
|
1179
1199
|
headerToolbarItemComponents = useMemo(() => getHeaderToolbarItems(), [Repository?.hash, treeSearchValue, isDragMode, getTreeNodeData()]),
|
|
@@ -1252,38 +1272,42 @@ function TreeComponent(props) {
|
|
|
1252
1272
|
>
|
|
1253
1273
|
<Column bg="#fff" w={300}>
|
|
1254
1274
|
<FormPanel
|
|
1255
|
-
|
|
1275
|
+
_panel={{
|
|
1276
|
+
title: 'Choose Tree Node',
|
|
1277
|
+
}}
|
|
1256
1278
|
instructions="Multiple tree nodes matched your search. Please select which one to show."
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1279
|
+
_form={{
|
|
1280
|
+
flex: 1,
|
|
1281
|
+
items: [
|
|
1282
|
+
{
|
|
1283
|
+
type: 'Column',
|
|
1284
|
+
flex: 1,
|
|
1285
|
+
items: [
|
|
1286
|
+
{
|
|
1287
|
+
key: 'node_id',
|
|
1288
|
+
name: 'node_id',
|
|
1289
|
+
type: 'Combo',
|
|
1290
|
+
label: 'Tree Node',
|
|
1291
|
+
data: searchFormData,
|
|
1292
|
+
}
|
|
1293
|
+
],
|
|
1294
|
+
},
|
|
1295
|
+
],
|
|
1296
|
+
onCancel: (e) => {
|
|
1297
|
+
setHighlitedDatum(null);
|
|
1298
|
+
setIsModalShown(false);
|
|
1299
|
+
},
|
|
1300
|
+
onSave: (data, e) => {
|
|
1301
|
+
const
|
|
1302
|
+
treeNode = _.find(searchResults, (item) => {
|
|
1303
|
+
return item.id === data.node_id;
|
|
1304
|
+
}),
|
|
1305
|
+
cPath = treeNode.cPath;
|
|
1306
|
+
expandPath(cPath);
|
|
1307
|
+
|
|
1308
|
+
// Close the modal
|
|
1309
|
+
setIsModalShown(false);
|
|
1271
1310
|
},
|
|
1272
|
-
]}
|
|
1273
|
-
onCancel={(e) => {
|
|
1274
|
-
setHighlitedDatum(null);
|
|
1275
|
-
setIsModalShown(false);
|
|
1276
|
-
}}
|
|
1277
|
-
onSave={(data, e) => {
|
|
1278
|
-
const
|
|
1279
|
-
treeNode = _.find(searchResults, (item) => {
|
|
1280
|
-
return item.id === data.node_id;
|
|
1281
|
-
}),
|
|
1282
|
-
cPath = treeNode.cPath;
|
|
1283
|
-
expandPath(cPath);
|
|
1284
|
-
|
|
1285
|
-
// Close the modal
|
|
1286
|
-
setIsModalShown(false);
|
|
1287
1311
|
}}
|
|
1288
1312
|
/>
|
|
1289
1313
|
</Column>
|
|
@@ -734,7 +734,7 @@ export function runClosureTreeManagerScreenCrudTests(model, schema, newData, edi
|
|
|
734
734
|
|
|
735
735
|
const
|
|
736
736
|
managerSelector = '/' + Models + 'Manager',
|
|
737
|
-
treeSelector = '/' + Models + '
|
|
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 + '
|
|
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
|
|
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(
|
|
24
|
+
Repository = oneHatData.getRepository(model),
|
|
24
25
|
entities = [];
|
|
25
26
|
let i, data, entity;
|
|
26
27
|
if (_.isArray(value)) {
|