@onehat/ui 0.3.23 → 0.3.25

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.23",
3
+ "version": "0.3.25",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -26,7 +26,7 @@
26
26
  "license": "UNLICENSED",
27
27
  "dependencies": {
28
28
  "@gluestack-style/react": "^0.2.38",
29
- "@gluestack-ui/themed": "^0.1.21",
29
+ "@gluestack-ui/themed": "^0.1.53",
30
30
  "@hookform/resolvers": "^3.3.1",
31
31
  "@k-renwick/colour-mixer": "^1.2.1",
32
32
  "@onehat/data": "^1.19.0",
@@ -1,16 +1,12 @@
1
- import {
2
- Box,
3
- } from 'native-base';
4
1
  import {
5
2
  EDITOR_MODE__VIEW,
6
3
  } from '../../Constants/Editor.js';
4
+ import Form from '../Form/Form.js';
5
+ import Viewer from '../Viewer/Viewer.js';
7
6
  import _ from 'lodash';
8
7
 
9
-
10
8
  export default function Editor(props) {
11
9
  const {
12
- Form,
13
- Viewer,
14
10
  isEditorViewOnly,
15
11
  onEditorCancel: onCancel,
16
12
  onEditorSave: onSave,
@@ -19,9 +15,6 @@ export default function Editor(props) {
19
15
  editorMode,
20
16
  onEditMode,
21
17
 
22
- // withData
23
- Repository,
24
-
25
18
  // withSelection
26
19
  selection,
27
20
 
@@ -46,9 +39,6 @@ export default function Editor(props) {
46
39
  />;
47
40
  }
48
41
 
49
- // NOTE: Ideally, this form should use multiple columns when screen is wide enough,
50
- // and only show in one column when it's not.
51
-
52
42
  return <Form
53
43
  {...props}
54
44
  record={selection}
@@ -29,7 +29,7 @@ export default function FieldSet(props) {
29
29
  borderWidth={1}
30
30
  borderColor="trueGray.400"
31
31
  bg={styles.FORM_FIELDSET_BG}
32
- m={2}
32
+ mb={4}
33
33
  pb={1}
34
34
  {...propsToPass}
35
35
  >
@@ -96,7 +96,6 @@ function Form(props) {
96
96
 
97
97
  // withAlert
98
98
  alert,
99
- confirm,
100
99
  } = props,
101
100
  styles = UiGlobals.styles,
102
101
  record = props.record?.length === 1 ? props.record[0] : props.record,
@@ -269,14 +268,14 @@ function Form(props) {
269
268
  onChange: onEditorChange,
270
269
  useSelectorId = false,
271
270
  ...propsToPass
272
- } = item;
273
- let editorTypeProps = {};
271
+ } = item,
272
+ editorTypeProps = {};
274
273
 
275
274
  const propertyDef = name && Repository?.getSchema().getPropertyDefinition(name);
276
275
  if (propertyDef?.isEditingDisabled) {
277
276
  isEditable = false;
278
277
  }
279
- if (!type && Repository) {
278
+ if (!type) {
280
279
  if (isEditable) {
281
280
  const
282
281
  {
@@ -553,15 +552,15 @@ function Form(props) {
553
552
  formComponents = buildFromItems();
554
553
  const formAncillaryComponents = buildAncillary();
555
554
  editor = <>
556
- <Row>{formComponents}</Row>
555
+ <Column p={4}>{formComponents}</Column>
557
556
  <Column pt={4}>{formAncillaryComponents}</Column>
558
557
  </>;
559
558
  } else {
560
559
  formComponents = buildFromItems();
561
560
  const formAncillaryComponents = buildAncillary();
562
561
  editor = <ScrollView _web={{ height: 1 }} width="100%" pb={1}>
563
- <Row>{formComponents}</Row>
564
- <Column pt={4}>{formAncillaryComponents}</Column>
562
+ <Column p={4}>{formComponents}</Column>
563
+ <Column m={2} pt={4}>{formAncillaryComponents}</Column>
565
564
  </ScrollView>;
566
565
  }
567
566
 
@@ -617,7 +616,7 @@ function Form(props) {
617
616
  </Row>}
618
617
 
619
618
  {editor}
620
-
619
+
621
620
  <Footer justifyContent="flex-end" {...footerProps} {...savingProps}>
622
621
  {onDelete && editorMode === EDITOR_MODE__EDIT && isSingle &&
623
622
  <Row flex={1} justifyContent="flex-start">
@@ -195,7 +195,8 @@ function GridComponent(props) {
195
195
  let newSelection = selection;
196
196
  if (isInSelection(item)) {
197
197
  // Already selected
198
- if (allowToggle) {
198
+ const isSingle = selection.length === 1;
199
+ if (allowToggle || isSingle) {
199
200
  // Create empty selection
200
201
  newSelection = [];
201
202
  } else {
@@ -10,37 +10,115 @@ import {
10
10
  EDITOR_TYPE__SIDE,
11
11
  } from '../../Constants/Editor.js';
12
12
  import UiGlobals from '../../UiGlobals.js';
13
+ import inArray from '../../Functions/inArray.js';
13
14
  import getComponentFromType from '../../Functions/getComponentFromType.js';
14
15
  import Label from '../Form/Label.js';
15
16
  import Pencil from '../Icons/Pencil.js';
16
17
  import Footer from '../Layout/Footer.js';
17
18
  import _ from 'lodash';
18
19
 
19
- // This is a wrapper for the Viewer subcomponent passed to props,
20
- // that adds buttons and a footer
21
-
22
20
  export default function Viewer(props) {
23
21
  const {
24
- additionalViewButtons = [],
25
- ancillaryItems = [],
26
22
  viewerCanDelete = false,
27
-
28
- // withData
23
+ items = [], // Columns, FieldSets, Fields, etc to define the form
24
+ ancillaryItems = [], // additional items which are not controllable form elements, but should appear in the form
25
+ columnDefaults = {}, // defaults for each Column defined in items (above)
29
26
  record,
27
+ additionalViewButtons = [],
30
28
 
31
- // parent container
32
- selectorSelected,
29
+ // withData
30
+ Repository,
33
31
 
34
32
  // withEditor
35
33
  editorType,
36
34
  onEditMode,
37
35
  onClose,
38
36
  onDelete,
37
+
38
+ // parent container
39
+ selectorId,
40
+ selectorSelected,
41
+
39
42
  } = props,
40
43
  isMultiple = _.isArray(record),
41
44
  isSideEditor = editorType === EDITOR_TYPE__SIDE,
42
45
  styles = UiGlobals.styles,
43
46
  flex = props.flex || 1,
47
+ buildFromItems = () => {
48
+ return _.map(items, (item, ix) => buildNextLayer(item, ix, columnDefaults));
49
+ },
50
+ buildNextLayer = (item, ix, defaults) => {
51
+ let {
52
+ type,
53
+ title,
54
+ name,
55
+ label,
56
+ items,
57
+ // onChange: onEditorChange,
58
+ useSelectorId = false,
59
+ ...propsToPass
60
+ } = item,
61
+ editorTypeProps = {};
62
+
63
+ const propertyDef = name && Repository?.getSchema().getPropertyDefinition(name);
64
+ if (!type) {
65
+ if (propertyDef.viewerType) {
66
+ const
67
+ {
68
+ type: t,
69
+ ...p
70
+ } = propertyDef.viewerType;
71
+ type = t
72
+ } else {
73
+ type = 'Text';
74
+ }
75
+ }
76
+ if (type?.match && type.match(/Combo$/) && Repository?.isRemote && !Repository?.isLoaded) {
77
+ editorTypeProps.autoLoad = true;
78
+ }
79
+ const Element = getComponentFromType(type);
80
+ let children;
81
+
82
+ if (inArray(type, ['Column', 'FieldSet'])) {
83
+ if (_.isEmpty(items)) {
84
+ return null;
85
+ }
86
+ const defaults = item.defaults;
87
+ children = _.map(items, (item, ix) => {
88
+ return buildNextLayer(item, ix, defaults);
89
+ });
90
+ return <Element key={ix} title={title} {...defaults} {...propsToPass} {...editorTypeProps}>{children}</Element>;
91
+ }
92
+
93
+ if (!label && Repository && propertyDef.title) {
94
+ label = propertyDef.title;
95
+ }
96
+
97
+ let value = record?.properties[name]?.displayValue || null;
98
+ const
99
+ schema = record?.repository.getSchema(),
100
+ propertyDefinition = schema?.getPropertyDefinition(name);
101
+ if (propertyDefinition?.isFk) {
102
+ // value above is the id, get the actual display value
103
+ const fkDisplayField = propertyDefinition.fkDisplayField;
104
+ if (record.properties[fkDisplayField]) {
105
+ value = record.properties[fkDisplayField].displayValue;
106
+ }
107
+ }
108
+
109
+ let element = <Element
110
+ value={value}
111
+ {...propsToPass}
112
+ />;
113
+ if (label) {
114
+ const labelProps = {};
115
+ if (defaults?.labelWidth) {
116
+ labelProps.w = defaults.labelWidth;
117
+ }
118
+ element = <><Label {...labelProps}>{label}</Label>{element}</>;
119
+ }
120
+ return <Row key={ix}>{element}</Row>;
121
+ },
44
122
  buildAncillary = () => {
45
123
  const components = [];
46
124
  if (ancillaryItems.length) {
@@ -86,7 +164,7 @@ export default function Viewer(props) {
86
164
 
87
165
  return <Column flex={flex} {...props}>
88
166
  <ScrollView width="100%" _web={{ height: 1 }}>
89
- <Column m={2}>
167
+ <Column p={4}>
90
168
  {onEditMode && <Row mb={4} justifyContent="flex-end">
91
169
  <Button
92
170
  key="editBtn"
@@ -101,7 +179,7 @@ export default function Viewer(props) {
101
179
  {additionalViewButtons}
102
180
  </Row>}
103
181
 
104
- {props.children}
182
+ {buildFromItems()}
105
183
 
106
184
  {buildAncillary()}
107
185