@onehat/ui 0.3.247 → 0.3.249

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.247",
3
+ "version": "0.3.249",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -302,7 +302,8 @@ export default function withSecondaryEditor(WrappedComponent, isTree = false) {
302
302
  return;
303
303
  }
304
304
  if (secondaryUseRemoteDuplicate) {
305
- return onRemoteDuplicate();
305
+ const results = await onRemoteDuplicate();
306
+ return results;
306
307
  }
307
308
  const
308
309
  entity = secondarySelection[0],
@@ -112,6 +112,22 @@ export default function withSelection(WrappedComponent) {
112
112
  secondarySetSelection([]);
113
113
  }
114
114
  },
115
+ secondaryRefreshSelection = () => {
116
+ // When Repository reloads, the entities get destroyed.
117
+ // Loop through these destroyed entities and see if new ones exist with same ids.
118
+ // If so, select these new ones.
119
+ // That way, after a load event, we'll keep the same selection, if possible.
120
+ const
121
+ newSelection = [],
122
+ ids = _.map(secondaryLocalSelection, (item) => item.id);
123
+ _.each(ids, (id) => {
124
+ const found = SecondaryRepository.getById(id);
125
+ if (found) {
126
+ newSelection.push(found);
127
+ }
128
+ });
129
+ secondarySetSelection(newSelection);
130
+ },
115
131
  getMaxMinSelectionIndices = () => {
116
132
  let items,
117
133
  currentlySelectedRowIndices = [];
@@ -283,6 +299,15 @@ export default function withSelection(WrappedComponent) {
283
299
  }
284
300
  };
285
301
 
302
+ if (SecondaryRepository) {
303
+ useEffect(() => {
304
+ SecondaryRepository.on('load', secondaryRefreshSelection);
305
+ return () => {
306
+ SecondaryRepository.off('load', secondaryRefreshSelection);
307
+ };
308
+ }, []);
309
+ }
310
+
286
311
  useEffect(() => {
287
312
 
288
313
  (async () => {
@@ -301,7 +301,8 @@ export default function withEditor(WrappedComponent, isTree = false) {
301
301
  return;
302
302
  }
303
303
  if (useRemoteDuplicate) {
304
- return onRemoteDuplicate();
304
+ const results = await onRemoteDuplicate();
305
+ return results;
305
306
  }
306
307
  const
307
308
  entity = selection[0],
@@ -110,6 +110,22 @@ export default function withSelection(WrappedComponent) {
110
110
  deselectAll = () => {
111
111
  setSelection([]);
112
112
  },
113
+ refreshSelection = () => {
114
+ // When Repository reloads, the entities get destroyed.
115
+ // Loop through these destroyed entities and see if new ones exist with same ids.
116
+ // If so, select these new ones.
117
+ // That way, after a load event, we'll keep the same selection, if possible.
118
+ const
119
+ newSelection = [],
120
+ ids = _.map(localSelection.current, (item) => item.id);
121
+ _.each(ids, (id) => {
122
+ const found = Repository.getById(id);
123
+ if (found) {
124
+ newSelection.push(found);
125
+ }
126
+ });
127
+ setSelection(newSelection);
128
+ },
113
129
  getMaxMinSelectionIndices = () => {
114
130
  let items,
115
131
  currentlySelectedRowIndices = [];
@@ -283,10 +299,9 @@ export default function withSelection(WrappedComponent) {
283
299
 
284
300
  if (Repository) {
285
301
  useEffect(() => {
286
- // clear the selection when Repository loads
287
- Repository.on('load', deselectAll);
302
+ Repository.on('load', refreshSelection);
288
303
  return () => {
289
- Repository.off('load', deselectAll);
304
+ Repository.off('load', refreshSelection);
290
305
  };
291
306
  }, []);
292
307
  }