@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 +1 -1
- package/src/Components/Form/Form.js +15 -13
- package/src/Components/Hoc/withEditor.js +28 -28
package/package.json
CHANGED
|
@@ -552,19 +552,21 @@ function Form(props) {
|
|
|
552
552
|
|
|
553
553
|
let isRequired = false,
|
|
554
554
|
requiredIndicator = null;
|
|
555
|
-
if (
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
(propertyDef?.
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
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,
|
|
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
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
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
|
-
|
|
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
|
-
|
|
489
|
-
editorMode = calculateEditorMode();
|
|
490
|
-
} else {
|
|
491
|
-
editorMode = EDITOR_MODE__VIEW;
|
|
492
|
-
}
|
|
492
|
+
editorMode = calculateEditorMode(isIgnoreNextSelectionChange);
|
|
493
493
|
}
|
|
494
494
|
|
|
495
495
|
return <WrappedComponent
|