@onehat/ui 0.3.136 → 0.3.138

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/ui",
3
- "version": "0.3.136",
3
+ "version": "0.3.138",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -37,6 +37,7 @@ export default function withEditor(WrappedComponent, isTree = false) {
37
37
  onChange,
38
38
  onSave,
39
39
  newEntityDisplayValue,
40
+ defaultValues,
40
41
 
41
42
  // withComponent
42
43
  self,
@@ -88,8 +89,19 @@ export default function withEditor(WrappedComponent, isTree = false) {
88
89
  return newEntityDisplayValueRef.current;
89
90
  },
90
91
  onAdd = async (e, values) => {
91
- const defaultValues = Repository.getSchema().getDefaultValues();
92
- let addValues = values || _.clone(defaultValues);
92
+ let addValues = values;
93
+
94
+ if (!values) {
95
+ // you can either:
96
+ // 1. directlty submit 'values' to use in onAdd(), or
97
+ // 2. Use the repository's default values (defined on each property as 'defaultValue'), or
98
+ // 3. Individually override the repository's default values with submitted 'defaultValues' (given as a prop to this HOC)
99
+ let defaultValuesToUse = Repository.getSchema().getDefaultValues();
100
+ if (defaultValues) {
101
+ _.merge(defaultValuesToUse, defaultValues);
102
+ }
103
+ addValues = _.clone(defaultValuesToUse);
104
+ }
93
105
 
94
106
  if (selectorId && !_.isEmpty(selectorSelected)) {
95
107
  addValues[selectorId] = selectorSelected.id;
@@ -304,6 +316,7 @@ export default function withEditor(WrappedComponent, isTree = false) {
304
316
  await Repository.save();
305
317
  success = true;
306
318
  } catch (e) {
319
+ alert(e.context);
307
320
  success = false;
308
321
  }
309
322
  setIsSaving(false);