@onehat/ui 0.3.139 → 0.3.140
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
|
@@ -70,6 +70,7 @@ export default function withSecondaryEditor(WrappedComponent, isTree = false) {
|
|
|
70
70
|
[secondaryIsSaving, setIsSaving] = useState(false),
|
|
71
71
|
[secondaryIsEditorShown, secondarySetIsEditorShown] = useState(false),
|
|
72
72
|
[secondaryIsEditorViewOnly, setIsEditorViewOnly] = useState(secondaryCanEditorViewOnly), // current state of whether editor is in view-only mode
|
|
73
|
+
[secondaryIsIgnoreNextSelectionChange, setSecondaryIsIgnoreNextSelectionChange] = useState(false),
|
|
73
74
|
[secondaryLastSelection, setLastSelection] = useState(),
|
|
74
75
|
secondarySetSelectionDecorated = (newSelection) => {
|
|
75
76
|
function doIt() {
|
|
@@ -148,6 +149,7 @@ export default function withSecondaryEditor(WrappedComponent, isTree = false) {
|
|
|
148
149
|
setIsSaving(true);
|
|
149
150
|
const entity = await SecondaryRepository.add(addValues, false, true);
|
|
150
151
|
setIsSaving(false);
|
|
152
|
+
setSecondaryIsIgnoreNextSelectionChange(true);
|
|
151
153
|
secondarySetSelection([entity]);
|
|
152
154
|
setIsEditorViewOnly(false);
|
|
153
155
|
secondarySetEditorMode(EDITOR_MODE__ADD);
|
|
@@ -276,6 +278,7 @@ export default function withSecondaryEditor(WrappedComponent, isTree = false) {
|
|
|
276
278
|
idProperty = SecondaryRepository.getSchema().model.idProperty,
|
|
277
279
|
rawValues = _.omit(entity.rawValues, idProperty),
|
|
278
280
|
duplicate = await SecondaryRepository.add(rawValues, false, true);
|
|
281
|
+
setSecondaryIsIgnoreNextSelectionChange(true);
|
|
279
282
|
secondarySetSelection([duplicate]);
|
|
280
283
|
secondarySetEditorMode(EDITOR_MODE__EDIT);
|
|
281
284
|
secondarySetIsEditorShown(true);
|
|
@@ -285,6 +288,7 @@ export default function withSecondaryEditor(WrappedComponent, isTree = false) {
|
|
|
285
288
|
entity = secondarySelection[0],
|
|
286
289
|
duplicateEntity = await SecondaryRepository.remoteDuplicate(entity);
|
|
287
290
|
|
|
291
|
+
setSecondaryIsIgnoreNextSelectionChange(true);
|
|
288
292
|
secondarySetSelection([duplicateEntity]);
|
|
289
293
|
secondaryOnEdit();
|
|
290
294
|
},
|
|
@@ -408,17 +412,21 @@ export default function withSecondaryEditor(WrappedComponent, isTree = false) {
|
|
|
408
412
|
};
|
|
409
413
|
|
|
410
414
|
useEffect(() => {
|
|
411
|
-
// When
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
+
// When selection changes, set the mode appropriately
|
|
416
|
+
let mode;
|
|
417
|
+
if (secondaryIsIgnoreNextSelectionChange) {
|
|
418
|
+
// on selection change from onAdd/onDuplicate/etc, calculate whether to put Editor in "add" or "edit" mode
|
|
419
|
+
mode = calculateEditorMode();
|
|
415
420
|
} else {
|
|
416
|
-
|
|
421
|
+
// Most of the time, if selection changed, put the Editor in "view" mode
|
|
422
|
+
mode = EDITOR_MODE__VIEW;
|
|
417
423
|
}
|
|
424
|
+
setEditorMode(mode);
|
|
418
425
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
426
|
+
setSecondaryIsIgnoreNextSelectionChange(false);
|
|
427
|
+
setLastSelection(selection);
|
|
428
|
+
}, [selection]);
|
|
429
|
+
|
|
422
430
|
if (self) {
|
|
423
431
|
self.secondaryAdd = secondaryOnAdd;
|
|
424
432
|
self.secondaryEdit = secondaryOnEdit;
|
|
@@ -430,9 +438,14 @@ export default function withSecondaryEditor(WrappedComponent, isTree = false) {
|
|
|
430
438
|
secondaryNewEntityDisplayValueRef.current = secondaryNewEntityDisplayValue;
|
|
431
439
|
|
|
432
440
|
if (secondaryLastSelection !== secondarySelection) {
|
|
433
|
-
// NOTE: If I don't calculate this on the fly for
|
|
441
|
+
// NOTE: If I don't calculate this on the fly for selection changes,
|
|
434
442
|
// we see a flash of the previous state, since useEffect hasn't yet run.
|
|
435
|
-
|
|
443
|
+
// (basically redo what's in the useEffect, above)
|
|
444
|
+
if (secondaryIsIgnoreNextSelectionChange) {
|
|
445
|
+
editorMode = calculateEditorMode();
|
|
446
|
+
} else {
|
|
447
|
+
editorMode = EDITOR_MODE__VIEW;
|
|
448
|
+
}
|
|
436
449
|
}
|
|
437
450
|
|
|
438
451
|
return <WrappedComponent
|
|
@@ -67,6 +67,7 @@ export default function withEditor(WrappedComponent, isTree = false) {
|
|
|
67
67
|
[isSaving, setIsSaving] = useState(false),
|
|
68
68
|
[isEditorShown, setIsEditorShown] = useState(false),
|
|
69
69
|
[isEditorViewOnly, setIsEditorViewOnly] = useState(canEditorViewOnly), // current state of whether editor is in view-only mode
|
|
70
|
+
[isIgnoreNextSelectionChange, setIsIgnoreNextSelectionChange] = useState(false),
|
|
70
71
|
[lastSelection, setLastSelection] = useState(),
|
|
71
72
|
setSelectionDecorated = (newSelection) => {
|
|
72
73
|
function doIt() {
|
|
@@ -145,6 +146,7 @@ export default function withEditor(WrappedComponent, isTree = false) {
|
|
|
145
146
|
setIsSaving(true);
|
|
146
147
|
const entity = await Repository.add(addValues, false, true);
|
|
147
148
|
setIsSaving(false);
|
|
149
|
+
setIsIgnoreNextSelectionChange(true);
|
|
148
150
|
setSelection([entity]);
|
|
149
151
|
setIsEditorViewOnly(false);
|
|
150
152
|
setEditorMode(EDITOR_MODE__ADD);
|
|
@@ -273,6 +275,7 @@ export default function withEditor(WrappedComponent, isTree = false) {
|
|
|
273
275
|
idProperty = Repository.getSchema().model.idProperty,
|
|
274
276
|
rawValues = _.omit(entity.rawValues, idProperty),
|
|
275
277
|
duplicate = await Repository.add(rawValues, false, true);
|
|
278
|
+
setIsIgnoreNextSelectionChange(true);
|
|
276
279
|
setSelection([duplicate]);
|
|
277
280
|
setEditorMode(EDITOR_MODE__EDIT);
|
|
278
281
|
setIsEditorShown(true);
|
|
@@ -282,6 +285,7 @@ export default function withEditor(WrappedComponent, isTree = false) {
|
|
|
282
285
|
entity = selection[0],
|
|
283
286
|
duplicateEntity = await Repository.remoteDuplicate(entity);
|
|
284
287
|
|
|
288
|
+
setIsIgnoreNextSelectionChange(true);
|
|
285
289
|
setSelection([duplicateEntity]);
|
|
286
290
|
onEdit();
|
|
287
291
|
},
|
|
@@ -406,13 +410,17 @@ export default function withEditor(WrappedComponent, isTree = false) {
|
|
|
406
410
|
|
|
407
411
|
useEffect(() => {
|
|
408
412
|
// When selection changes, set the mode appropriately
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
413
|
+
let mode;
|
|
414
|
+
if (isIgnoreNextSelectionChange) {
|
|
415
|
+
// on selection change from onAdd/onDuplicate/etc, calculate whether to put Editor in "add" or "edit" mode
|
|
416
|
+
mode = calculateEditorMode();
|
|
412
417
|
} else {
|
|
413
|
-
|
|
418
|
+
// Most of the time, if selection changed, put the Editor in "view" mode
|
|
419
|
+
mode = EDITOR_MODE__VIEW;
|
|
414
420
|
}
|
|
421
|
+
setEditorMode(mode);
|
|
415
422
|
|
|
423
|
+
setIsIgnoreNextSelectionChange(false);
|
|
416
424
|
setLastSelection(selection);
|
|
417
425
|
}, [selection]);
|
|
418
426
|
|
|
@@ -429,7 +437,12 @@ export default function withEditor(WrappedComponent, isTree = false) {
|
|
|
429
437
|
if (lastSelection !== selection) {
|
|
430
438
|
// NOTE: If I don't calculate this on the fly for selection changes,
|
|
431
439
|
// we see a flash of the previous state, since useEffect hasn't yet run.
|
|
432
|
-
|
|
440
|
+
// (basically redo what's in the useEffect, above)
|
|
441
|
+
if (isIgnoreNextSelectionChange) {
|
|
442
|
+
editorMode = calculateEditorMode();
|
|
443
|
+
} else {
|
|
444
|
+
editorMode = EDITOR_MODE__VIEW;
|
|
445
|
+
}
|
|
433
446
|
}
|
|
434
447
|
|
|
435
448
|
return <WrappedComponent
|