@onehat/ui 0.4.40 → 0.4.42

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.
Files changed (32) hide show
  1. package/package.json +1 -1
  2. package/src/Components/Buttons/Button.js +6 -13
  3. package/src/Components/Buttons/ReloadButton.js +0 -1
  4. package/src/Components/Filter/DateRange.js +3 -1
  5. package/src/Components/Filter/NumberRange.js +4 -1
  6. package/src/Components/Form/Field/Checkbox/CheckboxGroup.js +11 -9
  7. package/src/Components/Form/Field/Combo/Combo.js +118 -83
  8. package/src/Components/Form/Field/Combo/PageSizeCombo.js +1 -0
  9. package/src/Components/Form/Field/Date.js +15 -2
  10. package/src/Components/Form/Field/Number.js +5 -6
  11. package/src/Components/Form/Field/RadioGroup/RadioGroup.js +11 -9
  12. package/src/Components/Form/Field/Select/PageSizeSelect.js +2 -1
  13. package/src/Components/Form/Field/Slider.js +186 -191
  14. package/src/Components/Form/Field/Tag/Tag.js +12 -10
  15. package/src/Components/Form/Field/TextArea.js +96 -98
  16. package/src/Components/Form/Form.js +12 -9
  17. package/src/Components/Grid/Grid.js +21 -22
  18. package/src/Components/Grid/GridRow.js +11 -12
  19. package/src/Components/Hoc/Secondary/withSecondarySelection.js +22 -7
  20. package/src/Components/Hoc/withEditor.js +60 -21
  21. package/src/Components/Hoc/withFilters.js +1 -1
  22. package/src/Components/Hoc/withMultiSelection.js +1 -2
  23. package/src/Components/Hoc/withPdfButtons.js +3 -0
  24. package/src/Components/Hoc/withSelection.js +63 -35
  25. package/src/Components/Hoc/withTooltip.js +7 -1
  26. package/src/Components/Toolbar/Pagination.js +56 -56
  27. package/src/Components/Toolbar/PaginationToolbar.js +18 -15
  28. package/src/Components/Toolbar/Toolbar.js +4 -7
  29. package/src/Components/Tooltip/Tooltip.js +13 -10
  30. package/src/Components/Tree/Tree.js +14 -10
  31. package/src/Components/Viewer/MeterTypeText.js +3 -3
  32. package/src/Constants/Styles.js +2 -0
@@ -608,12 +608,15 @@ function Form(props) {
608
608
  }
609
609
 
610
610
  if (isEditorViewOnly || !isEditable) {
611
- let value = record?.properties[name]?.displayValue || null;
612
- if (_.isNil(value) && record && record[name]) {
613
- value = record[name];
614
- }
615
- if (_.isNil(value) && startingValues && startingValues[name]) {
616
- value = startingValues[name];
611
+ let value = null;
612
+ if (isSingle) {
613
+ value = record?.properties[name]?.displayValue || null;
614
+ if (_.isNil(value) && record && record[name]) {
615
+ value = record[name];
616
+ }
617
+ if (_.isNil(value) && startingValues && startingValues[name]) {
618
+ value = startingValues[name];
619
+ }
617
620
  }
618
621
 
619
622
  let elementClassName = 'field-' + name;
@@ -963,7 +966,7 @@ function Form(props) {
963
966
  doReset = (values) => {
964
967
  reset(values);
965
968
  if (onReset) {
966
- onReset(values, formSetValue, formGetValues);
969
+ onReset(values, formSetValue, formGetValues, trigger);
967
970
  }
968
971
  },
969
972
  onSaveDecorated = async (data, e) => {
@@ -995,14 +998,14 @@ function Form(props) {
995
998
  }
996
999
  if (record === previousRecord) {
997
1000
  if (onInit) {
998
- onInit(initialValues, formSetValue, formGetValues);
1001
+ onInit(initialValues, formSetValue, formGetValues, trigger);
999
1002
  }
1000
1003
  } else {
1001
1004
  setPreviousRecord(record);
1002
1005
  doReset(defaultValues);
1003
1006
  }
1004
1007
  if (formSetup) {
1005
- formSetup(formSetValue, formGetValues, formState);
1008
+ formSetup(formSetValue, formGetValues, formState, trigger);
1006
1009
  }
1007
1010
  }, [record]);
1008
1011
 
@@ -146,6 +146,7 @@ function GridComponent(props) {
146
146
  disableBottomToolbar = false,
147
147
  disablePagination = false,
148
148
  bottomToolbar = 'pagination',
149
+ _paginationToolbarProps = {},
149
150
  topToolbar = null,
150
151
  additionalToolbarButtons = [],
151
152
  bg = '#fff',
@@ -455,17 +456,20 @@ function GridComponent(props) {
455
456
  if (isHeaderRow || isReorderMode) {
456
457
  return
457
458
  }
459
+ if (selection && selection[0] && selection[0].isRemotePhantom) {
460
+ return; // block context menu or changing selection when a remote phantom is already selected
461
+ }
458
462
 
459
463
  // context menu
460
- const selection = [item];
464
+ const newSelection = [item];
461
465
  if (!disableWithSelection) {
462
- setSelection(selection);
466
+ setSelection(newSelection);
463
467
  }
464
468
  if (onEditorRowClick) { // e.g. inline editor
465
469
  onEditorRowClick(item, index, e);
466
470
  }
467
471
  if (onContextMenu) {
468
- onContextMenu(item, e, selection);
472
+ onContextMenu(item, e, newSelection);
469
473
  }
470
474
  }}
471
475
  className="Pressable Row flex-row grow">
@@ -741,10 +745,12 @@ function GridComponent(props) {
741
745
  let dragRecord,
742
746
  dropRecord;
743
747
  if (Repository) {
744
- dragRecord = Repository.getByIx(dragIx);
745
- dropRecord = Repository.getByIx(dropIx);
746
- if (dropRecord) {
747
- Repository.reorder(dragRecord, dropRecord, useBottom ? DROP_POSITION_AFTER : DROP_POSITION_BEFORE);
748
+ if (!Repository.isDestroyed) {
749
+ dragRecord = Repository.getByIx(dragIx);
750
+ dropRecord = Repository.getByIx(dropIx);
751
+ if (dropRecord) {
752
+ Repository.reorder(dragRecord, dropRecord, useBottom ? DROP_POSITION_AFTER : DROP_POSITION_BEFORE);
753
+ }
748
754
  }
749
755
  } else {
750
756
  function arrayMove(arr, fromIndex, toIndex) {
@@ -763,21 +769,13 @@ function GridComponent(props) {
763
769
  const
764
770
  headerHeight = showHeaders ? 50 : 0,
765
771
  footerHeight = !disablePagination ? 50 : 0,
766
- height = containerHeight - headerHeight - footerHeight;
767
-
768
- const rowsPerContainer = Math.floor(height / defaultRowHeight);
769
-
770
- // // Get the total height of all rows
771
- // const rows = gridRef.current._listRef._scrollRef.childNodes[0].childNodes;
772
- // let totalRowHeight = 0;
773
- // rows.forEach((row) => {
774
- // totalRowHeight += row.getBoundingClientRect().height;
775
- // });
776
- // const rowsPerContainer = Math.floor(height / (totalRowHeight / rows.length));
777
-
778
- let pageSize = rowsPerContainer;
779
- if (showHeaders) {
780
- pageSize--;
772
+ availableHeight = containerHeight - headerHeight - footerHeight,
773
+ maxClassNormal = styles.GRID_ROW_MAX_HEIGHT_NORMAL, // e.g. max-h-[40px]
774
+ rowNormalHeight = parseInt(maxClassNormal.match(/\d+/)[0]);
775
+
776
+ let pageSize = Math.floor(availableHeight / rowNormalHeight);
777
+ if (pageSize < 1) {
778
+ pageSize = 1;
781
779
  }
782
780
  return pageSize;
783
781
  },
@@ -1159,6 +1157,7 @@ function GridComponent(props) {
1159
1157
  toolbarItems={footerToolbarItemComponents}
1160
1158
  disablePageSize={disablePageSize}
1161
1159
  showMoreOnly={showMoreOnly}
1160
+ {..._paginationToolbarProps}
1162
1161
  />;
1163
1162
  } else if (footerToolbarItemComponents.length) {
1164
1163
  listFooterComponent = <Toolbar>
@@ -92,8 +92,8 @@ function GridRow(props) {
92
92
  justify-center
93
93
  border-r-black-100
94
94
  block
95
- max-h-[40px]
96
- overflow-scroll
95
+ overflow-auto
96
+ ${styles.GRID_ROW_MAX_HEIGHT_EXTRA}
97
97
  `;
98
98
  if (isOnlyOneVisibleColumn) {
99
99
  colClassName = ' w-full';
@@ -167,8 +167,9 @@ function GridRow(props) {
167
167
  if (type.match(/(Tag|TagEditor|Json)$/)) {
168
168
  elementProps.isViewOnly = true; // TODO: this won't work for InlineGridEditor, bc that Grid can't use isViewOnly when actually editing
169
169
  }
170
+ let cellProps = {};
170
171
  if (config.getCellProps) {
171
- _.assign(elementProps, config.getCellProps(item));
172
+ _.assign(cellProps, config.getCellProps(item));
172
173
  }
173
174
  let elementClassName = `
174
175
  GridRow-Element
@@ -177,16 +178,19 @@ function GridRow(props) {
177
178
  px-2
178
179
  py-3
179
180
  block
180
- max-h-[40px]
181
181
  overflow-scroll
182
182
  ${colClassName}
183
183
  ${styles.GRID_CELL_CLASSNAME}
184
+ ${styles.GRID_ROW_MAX_HEIGHT_NORMAL}
184
185
  `;
185
186
  if (config.className) {
186
187
  elementClassName += ' ' + config.className;
187
188
  }
189
+ if (cellProps.className) {
190
+ elementClassName += ' ' + cellProps.className;
191
+ }
188
192
  if (type.match(/(Tag|TagEditor)$/)) {
189
- elementClassName += ' max-h-[80px]';
193
+ elementClassName += ' ' + styles.GRID_ROW_MAX_HEIGHT_EXTRA;
190
194
  }
191
195
  return <Element
192
196
  {...testProps('cell-' + config.fieldName)}
@@ -232,14 +236,9 @@ function GridRow(props) {
232
236
  GridRow-TextNative
233
237
  self-center
234
238
  overflow-hidden
235
- text-ellipsis
236
- truncate
237
- whitespace-nowrap
238
- overflow-hidden
239
239
  ${colClassName}
240
- ${styles.GRID_CELL_CLASSNAME}
241
- ${styles.GRID_CELL_PX}
242
- ${styles.GRID_CELL_PY}
240
+ ${styles.GRID_CELL_CLASSNAME}
241
+ ${styles.GRID_ROW_MAX_HEIGHT_EXTRA}
243
242
  `;
244
243
  if (config.className) {
245
244
  textClassName += ' ' + config.className;
@@ -50,6 +50,7 @@ export default function withSelection(WrappedComponent) {
50
50
  initialSelection = secondarySelection || secondaryDefaultSelection || [],
51
51
  forceUpdate = useForceUpdate(),
52
52
  secondarySelectionRef = useRef(initialSelection),
53
+ SecondaryRepositoryRef = useRef(SecondaryRepository),
53
54
  [isReady, setIsReady] = useState(secondarySelection || false), // if secondarySelection is already defined, or secondaryValue is not null and we don't need to load repository, it's ready
54
55
  secondarySetSelection = (secondarySelection) => {
55
56
  if (_.isEqual(secondarySelection, secondaryGetSelection())) {
@@ -68,6 +69,9 @@ export default function withSelection(WrappedComponent) {
68
69
  secondaryGetSelection = () => {
69
70
  return secondarySelectionRef.current;
70
71
  },
72
+ secondaryGetRepository = () => {
73
+ return SecondaryRepositoryRef.current;
74
+ },
71
75
  secondarySelectPrev = () => {
72
76
  secondarySelectDirection(SELECT_UP);
73
77
  },
@@ -112,6 +116,7 @@ export default function withSelection(WrappedComponent) {
112
116
  secondarySetSelection(newSelection);
113
117
  },
114
118
  secondaryRemoveFromSelection = (item) => {
119
+ const SecondaryRepository = secondaryGetRepository();
115
120
  let newSelection = [];
116
121
  if (SecondaryRepository) {
117
122
  newSelection = _.remove(secondaryGetSelection(), (sel) => sel !== item);
@@ -132,7 +137,8 @@ export default function withSelection(WrappedComponent) {
132
137
  // That way, after a load event, we'll keep the same selection, if possible.
133
138
  const
134
139
  newSelection = [],
135
- ids = _.map(secondaryGetSelection(), (item) => item.id);
140
+ ids = _.map(secondaryGetSelection(), (item) => item.id),
141
+ SecondaryRepository = secondaryGetRepository();
136
142
  _.each(ids, (id) => {
137
143
  const found = SecondaryRepository.getById(id);
138
144
  if (found) {
@@ -144,6 +150,7 @@ export default function withSelection(WrappedComponent) {
144
150
  getMaxMinSelectionIndices = () => {
145
151
  let items,
146
152
  currentlySelectedRowIndices = [];
153
+ const SecondaryRepository = secondaryGetRepository();
147
154
  if (SecondaryRepository) {
148
155
  items = SecondaryRepository.getEntitiesOnPage();
149
156
  } else {
@@ -194,6 +201,7 @@ export default function withSelection(WrappedComponent) {
194
201
  secondarySetSelection(newSelection);
195
202
  },
196
203
  secondaryIsInSelection = (item) => {
204
+ const SecondaryRepository = secondaryGetRepository();
197
205
  if (SecondaryRepository) {
198
206
  return inArray(item, secondaryGetSelection());
199
207
  }
@@ -204,6 +212,8 @@ export default function withSelection(WrappedComponent) {
204
212
  return !!found;
205
213
  },
206
214
  getIndexOfSelectedItem = (item) => {
215
+ const SecondaryRepository = secondaryGetRepository();
216
+
207
217
  // Gets ix of entity on page, or element in secondaryData array
208
218
  if (SecondaryRepository) {
209
219
  const entities = SecondaryRepository.getEntitiesOnPage();
@@ -223,12 +233,14 @@ export default function withSelection(WrappedComponent) {
223
233
  if (!secondaryGetSelection()[0]) {
224
234
  return null;
225
235
  }
226
- const secondaryValues = _.map(secondaryGetSelection(), (item) => {
227
- if (SecondaryRepository) {
228
- return item.id;
229
- }
230
- return item[secondaryIdIx];
231
- });
236
+ const
237
+ SecondaryRepository = secondaryGetRepository(),
238
+ secondaryValues = _.map(secondaryGetSelection(), (item) => {
239
+ if (SecondaryRepository) {
240
+ return item.id;
241
+ }
242
+ return item[secondaryIdIx];
243
+ });
232
244
  if (secondaryValues.length === 1) {
233
245
  return secondaryValues[0];
234
246
  }
@@ -239,6 +251,7 @@ export default function withSelection(WrappedComponent) {
239
251
  return '';
240
252
  }
241
253
 
254
+ const SecondaryRepository = secondaryGetRepository();
242
255
  return _.map(secondarySelection, (item) => {
243
256
  if (SecondaryRepository) {
244
257
  return item.displayValue;
@@ -258,6 +271,7 @@ export default function withSelection(WrappedComponent) {
258
271
  }
259
272
  },
260
273
  conformSelectionToValue = async () => {
274
+ const SecondaryRepository = secondaryGetRepository();
261
275
  let newSelection = [];
262
276
  if (SecondaryRepository) {
263
277
  if (SecondaryRepository.isLoading) {
@@ -325,6 +339,7 @@ export default function withSelection(WrappedComponent) {
325
339
 
326
340
  (async () => {
327
341
 
342
+ const SecondaryRepository = secondaryGetRepository();
328
343
  if (usesWithValue && SecondaryRepository?.isRemote
329
344
  && !SecondaryRepository.isAutoLoad && !SecondaryRepository.isLoaded && !SecondaryRepository.isLoading && (!_.isNil(secondaryValue) || !_.isEmpty(secondarySelection)) || secondaryAutoSelectFirstItem) {
330
345
  // on initialization, we can't conformSelectionToValue if the repository is not yet loaded,
@@ -101,6 +101,15 @@ export default function withEditor(WrappedComponent, isTree = false) {
101
101
  onEditorClose();
102
102
  }
103
103
  },
104
+ setIsWaitModalShown = (bool) => {
105
+ const
106
+ dispatch = UiGlobals.redux?.dispatch,
107
+ setIsWaitModalShownAction = UiGlobals.debugReducer?.setIsWaitModalShownAction;
108
+ if (setIsWaitModalShownAction) {
109
+ console.log('withEditor:setIsWaitModalShownAction', bool);
110
+ dispatch(setIsWaitModalShownAction(bool));
111
+ }
112
+ },
104
113
  setSelectionDecorated = (newSelection) => {
105
114
  function doIt() {
106
115
  setSelection(newSelection);
@@ -386,36 +395,66 @@ export default function withEditor(WrappedComponent, isTree = false) {
386
395
  return;
387
396
  }
388
397
 
389
- // check permissions for duplicate
390
-
391
398
  const selection = getSelection();
392
399
  if (selection.length !== 1) {
393
400
  return;
394
401
  }
402
+
395
403
  if (useRemoteDuplicate) {
396
- const results = await onRemoteDuplicate();
397
- return results;
404
+ return await onRemoteDuplicate();
405
+ }
406
+
407
+ let isSuccess = false,
408
+ duplicateEntity;
409
+ try {
410
+ const
411
+ entity = selection[0],
412
+ idProperty = Repository.getSchema().model.idProperty,
413
+ rawValues = _.omit(entity.getOriginalData(), idProperty);
414
+ rawValues.id = null; // unset the id of the duplicate
415
+
416
+ setIsWaitModalShown(true);
417
+
418
+ duplicateEntity = await Repository.add(rawValues, false, true);
419
+ isSuccess = true;
420
+
421
+ } catch(err) {
422
+ // do nothing
423
+ } finally {
424
+ setIsWaitModalShown(false);
425
+ }
426
+
427
+ if (isSuccess) {
428
+ setIsIgnoreNextSelectionChange(true);
429
+ setSelection([duplicateEntity]);
430
+ setEditorMode(EDITOR_MODE__EDIT);
431
+ setIsEditorShown(true);
398
432
  }
399
- const
400
- entity = selection[0],
401
- idProperty = Repository.getSchema().model.idProperty,
402
- rawValues = _.omit(entity.getOriginalData(), idProperty);
403
- rawValues.id = null; // unset the id of the duplicate
404
- const duplicate = await Repository.add(rawValues, false, true);
405
- setIsIgnoreNextSelectionChange(true);
406
- setSelection([duplicate]);
407
- setEditorMode(EDITOR_MODE__EDIT);
408
- setIsEditorShown(true);
409
433
  },
410
434
  onRemoteDuplicate = async () => {
411
- const
412
- selection = getSelection(),
413
- entity = selection[0],
414
- duplicateEntity = await Repository.remoteDuplicate(entity);
435
+ let isSuccess = false,
436
+ duplicateEntity;
437
+ try {
438
+ const
439
+ selection = getSelection(),
440
+ entity = selection[0];
441
+
442
+ setIsWaitModalShown(true);
415
443
 
416
- setIsIgnoreNextSelectionChange(true);
417
- setSelection([duplicateEntity]);
418
- doEdit();
444
+ duplicateEntity = await Repository.remoteDuplicate(entity);
445
+ isSuccess = true;
446
+
447
+ } catch(err) {
448
+ // do nothing
449
+ } finally {
450
+ setIsWaitModalShown(false);
451
+ }
452
+ if (isSuccess) {
453
+ setIsIgnoreNextSelectionChange(true);
454
+ setSelection([duplicateEntity]);
455
+ doEdit();
456
+ return duplicateEntity;
457
+ }
419
458
  },
420
459
  doEditorSave = async (data, e) => {
421
460
  let mode = getEditorMode() === EDITOR_MODE__ADD ? ADD : EDIT;
@@ -654,7 +654,7 @@ export default function withFilters(WrappedComponent) {
654
654
  <HStack className="withFilters-scrollViewContainer flex-1 items-center">
655
655
  <ScrollView
656
656
  ref={scrollViewRef}
657
- className={`withFilters-ScrollView ${scrollViewClass}`}
657
+ className={`withFilters-ScrollView ${scrollViewClass} pb-1`}
658
658
  horizontal={true}
659
659
  contentContainerStyle={{ alignItems: 'center' }}
660
660
  onContentSizeChange={onContentSizeChange}
@@ -5,8 +5,7 @@ import {
5
5
 
6
6
  export default function withMultiSelection(WrappedComponent) {
7
7
  return forwardRef((props, ref) => {
8
- const
9
- {
8
+ const {
10
9
  selectionMode = SELECTION_MODE_MULTI,
11
10
  } = props;
12
11
  return <WrappedComponent
@@ -141,6 +141,9 @@ export default function withPdfButtons(WrappedComponent) {
141
141
  if (!_.isEmpty(items)) {
142
142
  const defaults = item.defaults;
143
143
  item.items = _.map(items, (item, ix) => {
144
+ if (!item){
145
+ return null;
146
+ }
144
147
  return buildNextLayer(item, ix, defaults);
145
148
  });
146
149
  }
@@ -48,6 +48,7 @@ export default function withSelection(WrappedComponent) {
48
48
  initialSelection = selection || defaultSelection || [],
49
49
  forceUpdate = useForceUpdate(),
50
50
  selectionRef = useRef(initialSelection),
51
+ RepositoryRef = useRef(Repository),
51
52
  [isReady, setIsReady] = useState(selection || false), // if selection is already defined, or value is not null and we don't need to load repository, it's ready
52
53
  setSelection = (selection) => {
53
54
  if (_.isEqual(selection, getSelection())) {
@@ -65,7 +66,10 @@ export default function withSelection(WrappedComponent) {
65
66
  },
66
67
  getSelection = () => {
67
68
  return selectionRef.current;
68
- }
69
+ },
70
+ getRepository = () => {
71
+ return RepositoryRef.current;
72
+ },
69
73
  selectPrev = () => {
70
74
  selectDirection(SELECT_UP);
71
75
  },
@@ -110,6 +114,7 @@ export default function withSelection(WrappedComponent) {
110
114
  setSelection(newSelection);
111
115
  },
112
116
  removeFromSelection = (item) => {
117
+ const Repository = getRepository();
113
118
  let newSelection = [];
114
119
  if (Repository) {
115
120
  newSelection = _.remove(getSelection(), (sel) => sel !== item);
@@ -130,7 +135,8 @@ export default function withSelection(WrappedComponent) {
130
135
  // That way, after a load event, we'll keep the same selection, if possible.
131
136
  const
132
137
  newSelection = [],
133
- ids = _.map(getSelection(), (item) => item.id);
138
+ ids = _.map(getSelection(), (item) => item.id),
139
+ Repository = getRepository();
134
140
  _.each(ids, (id) => {
135
141
  const found = Repository.getById(id);
136
142
  if (found) {
@@ -142,8 +148,11 @@ export default function withSelection(WrappedComponent) {
142
148
  getMaxMinSelectionIndices = () => {
143
149
  let items,
144
150
  currentlySelectedRowIndices = [];
151
+ const Repository = getRepository();
145
152
  if (Repository) {
146
- items = Repository.getEntitiesOnPage();
153
+ if (!Repository.isDestroyed) {
154
+ items = Repository.getEntitiesOnPage();
155
+ }
147
156
  } else {
148
157
  items = data;
149
158
  }
@@ -192,6 +201,7 @@ export default function withSelection(WrappedComponent) {
192
201
  setSelection(newSelection);
193
202
  },
194
203
  isInSelection = (item) => {
204
+ const Repository = getRepository();
195
205
  if (Repository) {
196
206
  return inArray(item, getSelection());
197
207
  }
@@ -202,10 +212,16 @@ export default function withSelection(WrappedComponent) {
202
212
  return !!found;
203
213
  },
204
214
  getIndexOfSelectedItem = (item) => {
215
+ const Repository = getRepository();
216
+
205
217
  // Gets ix of entity on page, or element in data array
206
218
  if (Repository) {
207
- const entities = Repository.getEntitiesOnPage();
208
- return entities.indexOf(item);
219
+ if (!Repository.isDestroyed) {
220
+ const entities = Repository.getEntitiesOnPage();
221
+ return entities.indexOf(item);
222
+ } else {
223
+ return -1;
224
+ }
209
225
  }
210
226
 
211
227
  let found;
@@ -221,12 +237,14 @@ export default function withSelection(WrappedComponent) {
221
237
  if (!getSelection()[0]) {
222
238
  return null;
223
239
  }
224
- const values = _.map(getSelection(), (item) => {
225
- if (Repository) {
226
- return item.id;
227
- }
228
- return item[idIx];
229
- });
240
+ const
241
+ Repository = getRepository(),
242
+ values = _.map(getSelection(), (item) => {
243
+ if (Repository) {
244
+ return item.id;
245
+ }
246
+ return item[idIx];
247
+ });
230
248
  if (values.length === 1) {
231
249
  return values[0];
232
250
  }
@@ -237,6 +255,7 @@ export default function withSelection(WrappedComponent) {
237
255
  return '';
238
256
  }
239
257
 
258
+ const Repository = getRepository();
240
259
  return _.map(selection, (item) => {
241
260
  if (Repository) {
242
261
  return item.displayValue;
@@ -256,30 +275,33 @@ export default function withSelection(WrappedComponent) {
256
275
  }
257
276
  },
258
277
  conformSelectionToValue = async () => {
278
+ const Repository = getRepository();
259
279
  let newSelection = [];
260
280
  if (Repository) {
261
- if (Repository.isLoading) {
262
- await Repository.waitUntilDoneLoading();
263
- }
264
- // Get entity or entities that match value
265
- if ((_.isArray(value) && !_.isEmpty(value)) || !!value) {
266
- if (_.isArray(value)) {
267
- newSelection = Repository.getBy((entity) => inArray(entity.id, value));
268
- } else {
269
- let found = Repository.getById(value);
270
- if (found) {
271
- newSelection.push(found);
272
- // } else if (Repository?.isRemote && Repository?.entities.length) {
273
-
274
- // // Value cannot be found in Repository, but actually exists on server
275
- // // Try to get this value from the server directly
276
- // Repository.filter(Repository.schema.model.idProperty, value);
277
- // await Repository.load();
278
- // found = Repository.getById(value);
279
- // if (found) {
280
- // newSelection.push(found);
281
- // }
282
-
281
+ if (!Repository.isDestroyed) {
282
+ if (Repository.isLoading) {
283
+ await Repository.waitUntilDoneLoading();
284
+ }
285
+ // Get entity or entities that match value
286
+ if ((_.isArray(value) && !_.isEmpty(value)) || !!value) {
287
+ if (_.isArray(value)) {
288
+ newSelection = Repository.getBy((entity) => inArray(entity.id, value));
289
+ } else {
290
+ let found = Repository.getById(value);
291
+ if (found) {
292
+ newSelection.push(found);
293
+ // } else if (Repository?.isRemote && Repository?.entities.length) {
294
+
295
+ // // Value cannot be found in Repository, but actually exists on server
296
+ // // Try to get this value from the server directly
297
+ // Repository.filter(Repository.schema.model.idProperty, value);
298
+ // await Repository.load();
299
+ // found = Repository.getById(value);
300
+ // if (found) {
301
+ // newSelection.push(found);
302
+ // }
303
+
304
+ }
283
305
  }
284
306
  }
285
307
  }
@@ -312,6 +334,9 @@ export default function withSelection(WrappedComponent) {
312
334
 
313
335
  if (Repository) {
314
336
  useEffect(() => {
337
+ if (Repository.isDestroyed) {
338
+ return null;
339
+ }
315
340
  Repository.on('load', refreshSelection);
316
341
  return () => {
317
342
  Repository.off('load', refreshSelection);
@@ -323,6 +348,7 @@ export default function withSelection(WrappedComponent) {
323
348
 
324
349
  (async () => {
325
350
 
351
+ const Repository = getRepository();
326
352
  if (usesWithValue && Repository?.isRemote
327
353
  && !Repository.isAutoLoad && !Repository.isLoaded && !Repository.isLoading && (!_.isNil(value) || !_.isEmpty(selection)) || autoSelectFirstItem) {
328
354
  // on initialization, we can't conformSelectionToValue if the repository is not yet loaded,
@@ -341,8 +367,10 @@ export default function withSelection(WrappedComponent) {
341
367
  } else if (autoSelectFirstItem) {
342
368
  let newSelection = [];
343
369
  if (Repository) {
344
- const entitiesOnPage = Repository.getEntitiesOnPage();
345
- newSelection = entitiesOnPage[0] ? [entitiesOnPage[0]] : [];
370
+ if (!Repository.isDestroyed) {
371
+ const entitiesOnPage = Repository.getEntitiesOnPage();
372
+ newSelection = entitiesOnPage[0] ? [entitiesOnPage[0]] : [];
373
+ }
346
374
  } else {
347
375
  newSelection = data[0] ? [data[0]] : [];
348
376
  }
@@ -10,6 +10,7 @@ export default function withTooltip(WrappedComponent) {
10
10
  const {
11
11
  tooltip,
12
12
  tooltipPlacement = 'bottom',
13
+ tooltipClassName,
13
14
  _tooltip = {},
14
15
  ...propsToPass
15
16
  } = props;
@@ -17,7 +18,12 @@ export default function withTooltip(WrappedComponent) {
17
18
  let component = <WrappedComponent {...propsToPass} ref={ref} />;
18
19
 
19
20
  if (tooltip || !_.isEmpty(_tooltip)) {
20
- component = <Tooltip label={tooltip} placement={tooltipPlacement} {..._tooltip}>
21
+ component = <Tooltip
22
+ label={tooltip}
23
+ placement={tooltipPlacement}
24
+ className={tooltipClassName}
25
+ {..._tooltip}
26
+ >
21
27
  {component}
22
28
  </Tooltip>;
23
29
  }