@onehat/ui 0.2.63 → 0.2.65

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.63",
3
+ "version": "0.2.65",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "license": "UNLICENSED",
27
27
  "dependencies": {
28
- "@onehat/data": "^1.18.0",
28
+ "@onehat/data": "^1.18.1",
29
29
  "@hookform/resolvers": "^3.1.1",
30
30
  "@k-renwick/colour-mixer": "^1.2.1",
31
31
  "js-cookie": "^3.0.5",
@@ -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
@@ -493,7 +493,13 @@ function Form(props) {
493
493
  {isSingle && editorMode === EDITOR_MODE__EDIT && onViewMode &&
494
494
  <Button
495
495
  key="viewBtn"
496
- onPress={onViewMode}
496
+ onPress={() => {
497
+ if (!_.isEmpty(formState.dirtyFields)) {
498
+ confirm('This record has unsaved changes. Are you sure you want to switch to "View" mode? Changes will be lost.', onViewMode);
499
+ } else {
500
+ onViewMode();
501
+ }
502
+ }}
497
503
  leftIcon={<Icon as={Eye} color="#fff" size="sm" />}
498
504
  color="#fff"
499
505
  >To View</Button>}
@@ -521,7 +527,7 @@ function Form(props) {
521
527
  key="cancelBtn"
522
528
  variant="ghost"
523
529
  onPress={() => {
524
- if (formState.isDirty) {
530
+ if (!_.isEmpty(formState.dirtyFields)) {
525
531
  confirm('This record has unsaved changes. Are you sure you want to cancel editing? Changes will be lost.', onCancel);
526
532
  } else {
527
533
  onCancel();
@@ -532,7 +538,7 @@ function Form(props) {
532
538
  {!isViewOnly && onSave && <Button
533
539
  key="saveBtn"
534
540
  onPress={(e) => handleSubmit(onSave, onSubmitError)(e)}
535
- isDisabled={!_.isEmpty(formState.errors) || (!isSingle && !record?.isPhantom && !formState.isDirty)}
541
+ isDisabled={!_.isEmpty(formState.errors) || (!isSingle && !record?.isPhantom && !_.isEmpty(formState.dirtyFields))}
536
542
  color="#fff"
537
543
  >{editorMode === EDITOR_MODE__ADD ? 'Add' : 'Save'}</Button>}
538
544
  {isViewOnly && onClose && <Button
@@ -155,16 +155,16 @@ export default function withAlert(WrappedComponent) {
155
155
  <Panel
156
156
  title={title}
157
157
  isCollapsible={false}
158
- p={5}
158
+ p={0}
159
159
  footer={<Footer justifyContent="flex-end" >
160
160
  <Button.Group space={2}>
161
161
  {buttons}
162
162
  </Button.Group>
163
163
  </Footer>}
164
164
  >
165
- <Row flex={1}>
166
- <Column w={50} p={0} mr={5}>
167
- <Icon as={TriangleExclamation} size={10}/>
165
+ <Row flex={1} p={5}>
166
+ <Column w="40px" p={0} mr={5}>
167
+ <Icon as={TriangleExclamation} size={10} color="#f00" />
168
168
  </Column>
169
169
  <Text>{message}</Text>
170
170
  </Row>
@@ -23,7 +23,7 @@ export default function withEditor(WrappedComponent) {
23
23
  if (selection.length > 1) {
24
24
  return 'records?';
25
25
  }
26
- return 'record?';
26
+ return 'record' + (selection[0].displayValue ? ' ' + selection[0].displayValue : '') + '?';
27
27
  },
28
28
  record,
29
29
 
@@ -49,9 +49,8 @@ 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;
@@ -67,8 +66,11 @@ export default function withEditor(WrappedComponent) {
67
66
  await Repository.reload();
68
67
  }
69
68
 
69
+ // Unmap the values, so we can input true originalData
70
+ addValues = Repository.unmapData(addValues);
71
+
70
72
  const entity = await Repository.add(addValues, false, true, true);
71
- setSelection([entity]);
73
+ setSelection([entity]);
72
74
  setIsEditorViewOnly(false);
73
75
  setEditorMode(EDITOR_MODE__ADD);
74
76
  setIsEditorShown(true);
@@ -97,8 +99,10 @@ export default function withEditor(WrappedComponent) {
97
99
  }
98
100
  },
99
101
  onDelete = async () => {
100
- Repository.delete(selection);
101
- await Repository.save();
102
+ await Repository.delete(selection);
103
+ if (!Repository.isAutoSave) {
104
+ await Repository.save();
105
+ }
102
106
  },
103
107
  viewRecord = () => {
104
108
  if (!userCanView) {