@onehat/ui 0.3.138 → 0.3.139
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,
|
|
@@ -91,8 +93,19 @@ export default function withSecondaryEditor(WrappedComponent, isTree = false) {
|
|
|
91
93
|
return secondaryNewEntityDisplayValueRef.current;
|
|
92
94
|
},
|
|
93
95
|
secondaryOnAdd = async (e, values) => {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
+
let addValues = values;
|
|
97
|
+
|
|
98
|
+
if (!values) {
|
|
99
|
+
// you can either:
|
|
100
|
+
// 1. directlty submit 'values' to use in onAdd(), or
|
|
101
|
+
// 2. Use the repository's default values (defined on each property as 'defaultValue'), or
|
|
102
|
+
// 3. Individually override the repository's default values with submitted 'defaultValues' (given as a prop to this HOC)
|
|
103
|
+
let defaultValuesToUse = Repository.getSchema().getDefaultValues();
|
|
104
|
+
if (secondaryDefaultValues) {
|
|
105
|
+
_.merge(defaultValuesToUse, secondaryDefaultValues);
|
|
106
|
+
}
|
|
107
|
+
addValues = _.clone(defaultValuesToUse);
|
|
108
|
+
}
|
|
96
109
|
|
|
97
110
|
if (secondarySelectorId && !_.isEmpty(secondarySelectorSelected)) {
|
|
98
111
|
addValues[secondarySelectorId] = secondarySelectorSelected.id;
|
|
@@ -307,6 +320,7 @@ export default function withSecondaryEditor(WrappedComponent, isTree = false) {
|
|
|
307
320
|
await SecondaryRepository.save();
|
|
308
321
|
success = true;
|
|
309
322
|
} catch (e) {
|
|
323
|
+
alert(e.context);
|
|
310
324
|
success = false;
|
|
311
325
|
}
|
|
312
326
|
setIsSaving(false);
|
|
@@ -395,8 +409,12 @@ export default function withSecondaryEditor(WrappedComponent, isTree = false) {
|
|
|
395
409
|
|
|
396
410
|
useEffect(() => {
|
|
397
411
|
// When secondarySelection changes, set the mode appropriately
|
|
398
|
-
|
|
399
|
-
|
|
412
|
+
if (UiGlobals.editorStaysInEditModeOnChangeSelection) {
|
|
413
|
+
const mode = calculateEditorMode();
|
|
414
|
+
secondarySetEditorMode(mode);
|
|
415
|
+
} else {
|
|
416
|
+
secondarySetEditorMode(EDITOR_MODE__VIEW);
|
|
417
|
+
}
|
|
400
418
|
|
|
401
419
|
setLastSelection(secondarySelection);
|
|
402
420
|
}, [secondarySelection]);
|
|
@@ -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) {
|
|
@@ -405,8 +406,12 @@ export default function withEditor(WrappedComponent, isTree = false) {
|
|
|
405
406
|
|
|
406
407
|
useEffect(() => {
|
|
407
408
|
// When selection changes, set the mode appropriately
|
|
408
|
-
|
|
409
|
-
|
|
409
|
+
if (UiGlobals.editorStaysInEditModeOnChangeSelection) {
|
|
410
|
+
const mode = calculateEditorMode();
|
|
411
|
+
setEditorMode(mode);
|
|
412
|
+
} else {
|
|
413
|
+
setEditorMode(EDITOR_MODE__VIEW);
|
|
414
|
+
}
|
|
410
415
|
|
|
411
416
|
setLastSelection(selection);
|
|
412
417
|
}, [selection]);
|
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;
|