@onehat/ui 0.2.62 → 0.2.64

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.2.62",
3
+ "version": "0.2.64",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -25,12 +25,12 @@
25
25
  },
26
26
  "license": "UNLICENSED",
27
27
  "dependencies": {
28
- "@onehat/data": "^1.17.3",
29
- "@hookform/resolvers": "^3.1.0",
28
+ "@onehat/data": "^1.18.1",
29
+ "@hookform/resolvers": "^3.1.1",
30
30
  "@k-renwick/colour-mixer": "^1.2.1",
31
31
  "js-cookie": "^3.0.5",
32
32
  "native-base": "^3.4.28",
33
- "react-hook-form": "^7.44.3",
33
+ "react-hook-form": "^7.45.0",
34
34
  "yup": "^1.2.0"
35
35
  },
36
36
  "peerDependencies": {
@@ -121,7 +121,7 @@ function Form(props) {
121
121
  mode: 'onChange', // onChange | onBlur | onSubmit | onTouched | all
122
122
  // reValidateMode: 'onChange', // onChange | onBlur | onSubmit
123
123
  defaultValues,
124
- values: defaultValues,
124
+ // values: defaultValues, // NOTE: This will cause a looping re-render if not used carefully!
125
125
  // resetOptions: {
126
126
  // keepDirtyValues: false, // user-interacted input will be retained
127
127
  // keepErrors: false, // input errors will be retained with value update
@@ -49,20 +49,25 @@ export default function withEditor(WrappedComponent) {
49
49
  if (!userCanEdit || disableAdd) {
50
50
  return;
51
51
  }
52
- const
53
- defaultValues = Repository.getSchema().model.defaultValues,
54
- addValues = _.clone(defaultValues);
52
+ const defaultValues = Repository.getSchema().model.defaultValues;
53
+ let addValues = _.clone(defaultValues);
55
54
 
56
55
  if (selectorId && !_.isEmpty(selectorSelected)) {
57
56
  addValues[selectorId] = selectorSelected.id;
58
57
  }
59
58
 
60
59
  // Set repository to sort by id DESC and switch to page 1, so this new entity is guaranteed to show up on the current page, even after saving
61
- Repository.pauseEvents();
62
- Repository.sort(Repository.schema.model.idProperty, 'DESC');
63
- Repository.setPage(1);
64
- Repository.resumeEvents();
65
- await Repository.reload();
60
+ const currentSorter = Repository.sorters[0];
61
+ if (currentSorter.name !== Repository.schema.model.idProperty || currentSorter.direction !== 'DESC') {
62
+ Repository.pauseEvents();
63
+ Repository.sort(Repository.schema.model.idProperty, 'DESC');
64
+ Repository.setPage(1);
65
+ Repository.resumeEvents();
66
+ await Repository.reload();
67
+ }
68
+
69
+ // Unmap the values, so we can input true originalData
70
+ addValues = Repository.unmapData(addValues);
66
71
 
67
72
  const entity = await Repository.add(addValues, false, true, true);
68
73
  setSelection([entity]);
@@ -95,7 +100,9 @@ export default function withEditor(WrappedComponent) {
95
100
  },
96
101
  onDelete = async () => {
97
102
  Repository.delete(selection);
98
- await Repository.save();
103
+ if (!Repository.isAutoSave) {
104
+ await Repository.save();
105
+ }
99
106
  },
100
107
  viewRecord = () => {
101
108
  if (!userCanView) {