@onehat/ui 0.3.207 → 0.3.209

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.207",
3
+ "version": "0.3.209",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -552,19 +552,21 @@ function Form(props) {
552
552
 
553
553
  let isRequired = false,
554
554
  requiredIndicator = null;
555
- if (getIsRequired) {
556
- isRequired = getIsRequired(formGetValues, formState);
557
- } else if (validatorToUse?.fields && validatorToUse.fields[name]?.exclusiveTests?.required) {
558
- // submitted validator
559
- isRequired = true;
560
- } else if ((propertyDef?.validator?.spec && !propertyDef.validator.spec.optional) ||
561
- (propertyDef?.requiredIfPhantom && isPhantom) ||
562
- (propertyDef?.requiredIfNotPhantom && !isPhantom)) {
563
- // property definition
564
- isRequired = true;
565
- }
566
- if (isRequired) {
567
- requiredIndicator = <Text color="#f00" fontSize="30px" pr={1}>*</Text>;
555
+ if (!isMultiple) { // Don't require fields if editing multiple records
556
+ if (getIsRequired) {
557
+ isRequired = getIsRequired(formGetValues, formState);
558
+ } else if (validatorToUse?.fields && validatorToUse.fields[name]?.exclusiveTests?.required) {
559
+ // submitted validator
560
+ isRequired = true;
561
+ } else if ((propertyDef?.validator?.spec && !propertyDef.validator.spec.optional) ||
562
+ (propertyDef?.requiredIfPhantom && isPhantom) ||
563
+ (propertyDef?.requiredIfNotPhantom && !isPhantom)) {
564
+ // property definition
565
+ isRequired = true;
566
+ }
567
+ if (isRequired) {
568
+ requiredIndicator = <Text color="#f00" fontSize="30px" pr={1}>*</Text>;
569
+ }
568
570
  }
569
571
  if (!disableLabels && label && editorType !== EDITOR_TYPE__INLINE) {
570
572
  const labelProps = {};
@@ -37,6 +37,7 @@ export default function withEditor(WrappedComponent, isTree = false) {
37
37
  onChange, // any kind of crud change
38
38
  onDelete,
39
39
  onSave, // this could also be called 'onEdit'
40
+ onEditorClose,
40
41
  newEntityDisplayValue,
41
42
  newEntityDisplayProperty, // in case the field to set for newEntityDisplayValue is different from model
42
43
  defaultValues,
@@ -66,10 +67,16 @@ export default function withEditor(WrappedComponent, isTree = false) {
66
67
  [currentRecord, setCurrentRecord] = useState(null),
67
68
  [isAdding, setIsAdding] = useState(false),
68
69
  [isSaving, setIsSaving] = useState(false),
69
- [isEditorShown, setIsEditorShown] = useState(false),
70
+ [isEditorShown, setIsEditorShownRaw] = useState(false),
70
71
  [isEditorViewOnly, setIsEditorViewOnly] = useState(canEditorViewOnly), // current state of whether editor is in view-only mode
71
72
  [isIgnoreNextSelectionChange, setIsIgnoreNextSelectionChange] = useState(false),
72
73
  [lastSelection, setLastSelection] = useState(),
74
+ setIsEditorShown = (bool) => {
75
+ setIsEditorShownRaw(bool);
76
+ if (!bool && onEditorClose) {
77
+ onEditorClose();
78
+ }
79
+ },
73
80
  setSelectionDecorated = (newSelection) => {
74
81
  function doIt() {
75
82
  setSelection(newSelection);
@@ -407,20 +414,26 @@ export default function withEditor(WrappedComponent, isTree = false) {
407
414
  setIsEditorShown(false);
408
415
  });
409
416
  },
410
- calculateEditorMode = () => {
411
- let mode = editorMode;
412
- if (!canEditorViewOnly && userCanEdit) {
413
- if (selection.length > 1) {
414
- if (!disableEdit) {
415
- // For multiple entities selected, change it to edit multiple mode
416
- mode = EDITOR_MODE__EDIT;
417
- }
418
- } else if (selection.length === 1 && !selection[0].isDestroyed && selection[0].isPhantom) {
419
- if (!disableAdd) {
420
- // When a phantom entity is selected, change it to add mode.
421
- mode = EDITOR_MODE__ADD;
417
+ calculateEditorMode = (isIgnoreNextSelectionChange = false) => {
418
+ // calculateEditorMode gets called only on selection changes
419
+ let mode;
420
+ if (isIgnoreNextSelectionChange) {
421
+ mode = editorMode;
422
+ if (!canEditorViewOnly && userCanEdit) {
423
+ if (selection.length > 1) {
424
+ if (!disableEdit) {
425
+ // For multiple entities selected, change it to edit multiple mode
426
+ mode = EDITOR_MODE__EDIT;
427
+ }
428
+ } else if (selection.length === 1 && !selection[0].isDestroyed && selection[0].isPhantom) {
429
+ if (!disableAdd) {
430
+ // When a phantom entity is selected, change it to add mode.
431
+ mode = EDITOR_MODE__ADD;
432
+ }
422
433
  }
423
434
  }
435
+ } else {
436
+ mode = selection.length > 1 ? EDITOR_MODE__EDIT : EDITOR_MODE__VIEW;
424
437
  }
425
438
  return mode;
426
439
  },
@@ -455,16 +468,7 @@ export default function withEditor(WrappedComponent, isTree = false) {
455
468
  }, []);
456
469
 
457
470
  useEffect(() => {
458
- // When selection changes, set the mode appropriately
459
- let mode;
460
- if (isIgnoreNextSelectionChange) {
461
- // on selection change from doAdd/doDuplicate/etc, calculate whether to put Editor in "add" or "edit" mode
462
- mode = calculateEditorMode();
463
- } else {
464
- // Most of the time, if selection changed, put the Editor in "view" mode
465
- mode = EDITOR_MODE__VIEW;
466
- }
467
- setEditorMode(mode);
471
+ setEditorMode(calculateEditorMode(isIgnoreNextSelectionChange));
468
472
 
469
473
  setIsIgnoreNextSelectionChange(false);
470
474
  setLastSelection(selection);
@@ -485,11 +489,7 @@ export default function withEditor(WrappedComponent, isTree = false) {
485
489
  // NOTE: If I don't calculate this on the fly for selection changes,
486
490
  // we see a flash of the previous state, since useEffect hasn't yet run.
487
491
  // (basically redo what's in the useEffect, above)
488
- if (isIgnoreNextSelectionChange) {
489
- editorMode = calculateEditorMode();
490
- } else {
491
- editorMode = EDITOR_MODE__VIEW;
492
- }
492
+ editorMode = calculateEditorMode(isIgnoreNextSelectionChange);
493
493
  }
494
494
 
495
495
  return <WrappedComponent