@onehat/ui 0.3.138 → 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
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
UI_MODE_REACT_NATIVE,
|
|
28
28
|
CURRENT_MODE,
|
|
29
29
|
} from '../../Constants/UiModes.js';
|
|
30
|
-
import * as colourMixer from '@k-renwick/colour-mixer'
|
|
30
|
+
import * as colourMixer from '@k-renwick/colour-mixer';
|
|
31
31
|
import UiGlobals from '../../UiGlobals.js';
|
|
32
32
|
import useForceUpdate from '../../Hooks/useForceUpdate.js';
|
|
33
33
|
import withContextMenu from '../Hoc/withContextMenu.js';
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
EDITOR_MODE__ADD,
|
|
8
8
|
EDITOR_MODE__EDIT,
|
|
9
9
|
} from '../../../Constants/Editor.js';
|
|
10
|
+
import UiGlobals from '../../../UiGlobals.js';
|
|
10
11
|
import _ from 'lodash';
|
|
11
12
|
|
|
12
13
|
// NOTE: This is a modified version of @onehat/ui/src/Hoc/withEditor
|
|
@@ -40,6 +41,7 @@ export default function withSecondaryEditor(WrappedComponent, isTree = false) {
|
|
|
40
41
|
secondaryOnChange,
|
|
41
42
|
secondaryOnSave,
|
|
42
43
|
secondaryNewEntityDisplayValue,
|
|
44
|
+
secondaryDefaultValues,
|
|
43
45
|
|
|
44
46
|
// withComponent
|
|
45
47
|
self,
|
|
@@ -68,6 +70,7 @@ export default function withSecondaryEditor(WrappedComponent, isTree = false) {
|
|
|
68
70
|
[secondaryIsSaving, setIsSaving] = useState(false),
|
|
69
71
|
[secondaryIsEditorShown, secondarySetIsEditorShown] = useState(false),
|
|
70
72
|
[secondaryIsEditorViewOnly, setIsEditorViewOnly] = useState(secondaryCanEditorViewOnly), // current state of whether editor is in view-only mode
|
|
73
|
+
[secondaryIsIgnoreNextSelectionChange, setSecondaryIsIgnoreNextSelectionChange] = useState(false),
|
|
71
74
|
[secondaryLastSelection, setLastSelection] = useState(),
|
|
72
75
|
secondarySetSelectionDecorated = (newSelection) => {
|
|
73
76
|
function doIt() {
|
|
@@ -91,8 +94,19 @@ export default function withSecondaryEditor(WrappedComponent, isTree = false) {
|
|
|
91
94
|
return secondaryNewEntityDisplayValueRef.current;
|
|
92
95
|
},
|
|
93
96
|
secondaryOnAdd = async (e, values) => {
|
|
94
|
-
|
|
95
|
-
|
|
97
|
+
let addValues = values;
|
|
98
|
+
|
|
99
|
+
if (!values) {
|
|
100
|
+
// you can either:
|
|
101
|
+
// 1. directlty submit 'values' to use in onAdd(), or
|
|
102
|
+
// 2. Use the repository's default values (defined on each property as 'defaultValue'), or
|
|
103
|
+
// 3. Individually override the repository's default values with submitted 'defaultValues' (given as a prop to this HOC)
|
|
104
|
+
let defaultValuesToUse = Repository.getSchema().getDefaultValues();
|
|
105
|
+
if (secondaryDefaultValues) {
|
|
106
|
+
_.merge(defaultValuesToUse, secondaryDefaultValues);
|
|
107
|
+
}
|
|
108
|
+
addValues = _.clone(defaultValuesToUse);
|
|
109
|
+
}
|
|
96
110
|
|
|
97
111
|
if (secondarySelectorId && !_.isEmpty(secondarySelectorSelected)) {
|
|
98
112
|
addValues[secondarySelectorId] = secondarySelectorSelected.id;
|
|
@@ -135,6 +149,7 @@ export default function withSecondaryEditor(WrappedComponent, isTree = false) {
|
|
|
135
149
|
setIsSaving(true);
|
|
136
150
|
const entity = await SecondaryRepository.add(addValues, false, true);
|
|
137
151
|
setIsSaving(false);
|
|
152
|
+
setSecondaryIsIgnoreNextSelectionChange(true);
|
|
138
153
|
secondarySetSelection([entity]);
|
|
139
154
|
setIsEditorViewOnly(false);
|
|
140
155
|
secondarySetEditorMode(EDITOR_MODE__ADD);
|
|
@@ -263,6 +278,7 @@ export default function withSecondaryEditor(WrappedComponent, isTree = false) {
|
|
|
263
278
|
idProperty = SecondaryRepository.getSchema().model.idProperty,
|
|
264
279
|
rawValues = _.omit(entity.rawValues, idProperty),
|
|
265
280
|
duplicate = await SecondaryRepository.add(rawValues, false, true);
|
|
281
|
+
setSecondaryIsIgnoreNextSelectionChange(true);
|
|
266
282
|
secondarySetSelection([duplicate]);
|
|
267
283
|
secondarySetEditorMode(EDITOR_MODE__EDIT);
|
|
268
284
|
secondarySetIsEditorShown(true);
|
|
@@ -272,6 +288,7 @@ export default function withSecondaryEditor(WrappedComponent, isTree = false) {
|
|
|
272
288
|
entity = secondarySelection[0],
|
|
273
289
|
duplicateEntity = await SecondaryRepository.remoteDuplicate(entity);
|
|
274
290
|
|
|
291
|
+
setSecondaryIsIgnoreNextSelectionChange(true);
|
|
275
292
|
secondarySetSelection([duplicateEntity]);
|
|
276
293
|
secondaryOnEdit();
|
|
277
294
|
},
|
|
@@ -307,6 +324,7 @@ export default function withSecondaryEditor(WrappedComponent, isTree = false) {
|
|
|
307
324
|
await SecondaryRepository.save();
|
|
308
325
|
success = true;
|
|
309
326
|
} catch (e) {
|
|
327
|
+
alert(e.context);
|
|
310
328
|
success = false;
|
|
311
329
|
}
|
|
312
330
|
setIsSaving(false);
|
|
@@ -394,13 +412,21 @@ export default function withSecondaryEditor(WrappedComponent, isTree = false) {
|
|
|
394
412
|
};
|
|
395
413
|
|
|
396
414
|
useEffect(() => {
|
|
397
|
-
// When
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
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();
|
|
420
|
+
} else {
|
|
421
|
+
// Most of the time, if selection changed, put the Editor in "view" mode
|
|
422
|
+
mode = EDITOR_MODE__VIEW;
|
|
423
|
+
}
|
|
424
|
+
setEditorMode(mode);
|
|
425
|
+
|
|
426
|
+
setSecondaryIsIgnoreNextSelectionChange(false);
|
|
427
|
+
setLastSelection(selection);
|
|
428
|
+
}, [selection]);
|
|
429
|
+
|
|
404
430
|
if (self) {
|
|
405
431
|
self.secondaryAdd = secondaryOnAdd;
|
|
406
432
|
self.secondaryEdit = secondaryOnEdit;
|
|
@@ -412,9 +438,14 @@ export default function withSecondaryEditor(WrappedComponent, isTree = false) {
|
|
|
412
438
|
secondaryNewEntityDisplayValueRef.current = secondaryNewEntityDisplayValue;
|
|
413
439
|
|
|
414
440
|
if (secondaryLastSelection !== secondarySelection) {
|
|
415
|
-
// 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,
|
|
416
442
|
// we see a flash of the previous state, since useEffect hasn't yet run.
|
|
417
|
-
|
|
443
|
+
// (basically redo what's in the useEffect, above)
|
|
444
|
+
if (secondaryIsIgnoreNextSelectionChange) {
|
|
445
|
+
editorMode = calculateEditorMode();
|
|
446
|
+
} else {
|
|
447
|
+
editorMode = EDITOR_MODE__VIEW;
|
|
448
|
+
}
|
|
418
449
|
}
|
|
419
450
|
|
|
420
451
|
return <WrappedComponent
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
EDITOR_MODE__ADD,
|
|
8
8
|
EDITOR_MODE__EDIT,
|
|
9
9
|
} from '../../Constants/Editor.js';
|
|
10
|
+
import UiGlobals from '../../UiGlobals.js';
|
|
10
11
|
import _ from 'lodash';
|
|
11
12
|
|
|
12
13
|
export default function withEditor(WrappedComponent, isTree = false) {
|
|
@@ -66,6 +67,7 @@ export default function withEditor(WrappedComponent, isTree = false) {
|
|
|
66
67
|
[isSaving, setIsSaving] = useState(false),
|
|
67
68
|
[isEditorShown, setIsEditorShown] = useState(false),
|
|
68
69
|
[isEditorViewOnly, setIsEditorViewOnly] = useState(canEditorViewOnly), // current state of whether editor is in view-only mode
|
|
70
|
+
[isIgnoreNextSelectionChange, setIsIgnoreNextSelectionChange] = useState(false),
|
|
69
71
|
[lastSelection, setLastSelection] = useState(),
|
|
70
72
|
setSelectionDecorated = (newSelection) => {
|
|
71
73
|
function doIt() {
|
|
@@ -144,6 +146,7 @@ export default function withEditor(WrappedComponent, isTree = false) {
|
|
|
144
146
|
setIsSaving(true);
|
|
145
147
|
const entity = await Repository.add(addValues, false, true);
|
|
146
148
|
setIsSaving(false);
|
|
149
|
+
setIsIgnoreNextSelectionChange(true);
|
|
147
150
|
setSelection([entity]);
|
|
148
151
|
setIsEditorViewOnly(false);
|
|
149
152
|
setEditorMode(EDITOR_MODE__ADD);
|
|
@@ -272,6 +275,7 @@ export default function withEditor(WrappedComponent, isTree = false) {
|
|
|
272
275
|
idProperty = Repository.getSchema().model.idProperty,
|
|
273
276
|
rawValues = _.omit(entity.rawValues, idProperty),
|
|
274
277
|
duplicate = await Repository.add(rawValues, false, true);
|
|
278
|
+
setIsIgnoreNextSelectionChange(true);
|
|
275
279
|
setSelection([duplicate]);
|
|
276
280
|
setEditorMode(EDITOR_MODE__EDIT);
|
|
277
281
|
setIsEditorShown(true);
|
|
@@ -281,6 +285,7 @@ export default function withEditor(WrappedComponent, isTree = false) {
|
|
|
281
285
|
entity = selection[0],
|
|
282
286
|
duplicateEntity = await Repository.remoteDuplicate(entity);
|
|
283
287
|
|
|
288
|
+
setIsIgnoreNextSelectionChange(true);
|
|
284
289
|
setSelection([duplicateEntity]);
|
|
285
290
|
onEdit();
|
|
286
291
|
},
|
|
@@ -405,9 +410,17 @@ export default function withEditor(WrappedComponent, isTree = false) {
|
|
|
405
410
|
|
|
406
411
|
useEffect(() => {
|
|
407
412
|
// When selection changes, set the mode appropriately
|
|
408
|
-
|
|
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();
|
|
417
|
+
} else {
|
|
418
|
+
// Most of the time, if selection changed, put the Editor in "view" mode
|
|
419
|
+
mode = EDITOR_MODE__VIEW;
|
|
420
|
+
}
|
|
409
421
|
setEditorMode(mode);
|
|
410
422
|
|
|
423
|
+
setIsIgnoreNextSelectionChange(false);
|
|
411
424
|
setLastSelection(selection);
|
|
412
425
|
}, [selection]);
|
|
413
426
|
|
|
@@ -424,7 +437,12 @@ export default function withEditor(WrappedComponent, isTree = false) {
|
|
|
424
437
|
if (lastSelection !== selection) {
|
|
425
438
|
// NOTE: If I don't calculate this on the fly for selection changes,
|
|
426
439
|
// we see a flash of the previous state, since useEffect hasn't yet run.
|
|
427
|
-
|
|
440
|
+
// (basically redo what's in the useEffect, above)
|
|
441
|
+
if (isIgnoreNextSelectionChange) {
|
|
442
|
+
editorMode = calculateEditorMode();
|
|
443
|
+
} else {
|
|
444
|
+
editorMode = EDITOR_MODE__VIEW;
|
|
445
|
+
}
|
|
428
446
|
}
|
|
429
447
|
|
|
430
448
|
return <WrappedComponent
|
package/src/UiGlobals.js
CHANGED
|
@@ -5,6 +5,11 @@ import _ from 'lodash';
|
|
|
5
5
|
const Globals = {
|
|
6
6
|
mode: CURRENT_MODE,
|
|
7
7
|
customInflect: (str) => str,
|
|
8
|
+
|
|
9
|
+
// global defaults
|
|
10
|
+
paginationIsShowMoreOnly: false,
|
|
11
|
+
autoAdjustPageSizeToHeight: true,
|
|
12
|
+
editorStaysInEditModeOnChangeSelection: false,
|
|
8
13
|
};
|
|
9
14
|
|
|
10
15
|
export default Globals;
|