@onehat/ui 0.3.208 → 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 +20 -27
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 = {};
|
|
@@ -414,20 +414,26 @@ export default function withEditor(WrappedComponent, isTree = false) {
|
|
|
414
414
|
setIsEditorShown(false);
|
|
415
415
|
});
|
|
416
416
|
},
|
|
417
|
-
calculateEditorMode = () => {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
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
|
+
}
|
|
429
433
|
}
|
|
430
434
|
}
|
|
435
|
+
} else {
|
|
436
|
+
mode = selection.length > 1 ? EDITOR_MODE__EDIT : EDITOR_MODE__VIEW;
|
|
431
437
|
}
|
|
432
438
|
return mode;
|
|
433
439
|
},
|
|
@@ -462,16 +468,7 @@ export default function withEditor(WrappedComponent, isTree = false) {
|
|
|
462
468
|
}, []);
|
|
463
469
|
|
|
464
470
|
useEffect(() => {
|
|
465
|
-
|
|
466
|
-
let mode;
|
|
467
|
-
if (isIgnoreNextSelectionChange) {
|
|
468
|
-
// on selection change from doAdd/doDuplicate/etc, calculate whether to put Editor in "add" or "edit" mode
|
|
469
|
-
mode = calculateEditorMode();
|
|
470
|
-
} else {
|
|
471
|
-
// Most of the time, if selection changed, put the Editor in "view" mode
|
|
472
|
-
mode = EDITOR_MODE__VIEW;
|
|
473
|
-
}
|
|
474
|
-
setEditorMode(mode);
|
|
471
|
+
setEditorMode(calculateEditorMode(isIgnoreNextSelectionChange));
|
|
475
472
|
|
|
476
473
|
setIsIgnoreNextSelectionChange(false);
|
|
477
474
|
setLastSelection(selection);
|
|
@@ -492,11 +489,7 @@ export default function withEditor(WrappedComponent, isTree = false) {
|
|
|
492
489
|
// NOTE: If I don't calculate this on the fly for selection changes,
|
|
493
490
|
// we see a flash of the previous state, since useEffect hasn't yet run.
|
|
494
491
|
// (basically redo what's in the useEffect, above)
|
|
495
|
-
|
|
496
|
-
editorMode = calculateEditorMode();
|
|
497
|
-
} else {
|
|
498
|
-
editorMode = EDITOR_MODE__VIEW;
|
|
499
|
-
}
|
|
492
|
+
editorMode = calculateEditorMode(isIgnoreNextSelectionChange);
|
|
500
493
|
}
|
|
501
494
|
|
|
502
495
|
return <WrappedComponent
|