@onehat/ui 0.3.128 → 0.3.132

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.128",
3
+ "version": "0.3.132",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -30,6 +30,8 @@ function Editor(props) {
30
30
  return null; // hide the editor when no selection
31
31
  }
32
32
 
33
+ const propsToPass = _.omit(props, ['self', 'reference', 'parent']);
34
+
33
35
  // Repository?.isRemotePhantomMode && selection.length === 1 &&
34
36
  if (editorMode === EDITOR_MODE__VIEW || isEditorViewOnly) {
35
37
  const record = selection[0];
@@ -37,19 +39,20 @@ function Editor(props) {
37
39
  return null;
38
40
  }
39
41
  return <Viewer
40
- {...props}
42
+ {...propsToPass}
43
+ {..._viewer}
41
44
  record={record}
42
45
  onEditMode={isEditorViewOnly ? null : onEditMode}
43
46
  onClose={onClose}
44
47
  onDelete={onDelete}
45
48
  parent={self}
46
49
  reference="viewer"
47
- {..._viewer}
48
50
  />;
49
51
  }
50
52
 
51
53
  return <Form
52
- {...props}
54
+ {...propsToPass}
55
+ {..._form}
53
56
  record={selection}
54
57
  onCancel={onCancel}
55
58
  onSave={onSave}
@@ -57,7 +60,6 @@ function Editor(props) {
57
60
  onDelete={onDelete}
58
61
  parent={self}
59
62
  reference="form"
60
- {..._form}
61
63
  />;
62
64
  }
63
65
 
@@ -51,6 +51,7 @@ export function ComboComponent(props) {
51
51
  onRowPress,
52
52
  icon,
53
53
  Editor, // only used for the eyeButton
54
+ onSave, // to hook into when menu saves (ComboEditor only)
54
55
 
55
56
  // withComponent
56
57
  self,
@@ -81,6 +82,7 @@ export function ComboComponent(props) {
81
82
  [isRendered, setIsRendered] = useState(false),
82
83
  [isReady, setIsReady] = useState(false),
83
84
  [isSearchMode, setIsSearchMode] = useState(false),
85
+ [containerWidth, setContainerWidth] = useState(),
84
86
  [gridSelection, setGridSelection] = useState(null),
85
87
  [textInputValue, setTextInputValue] = useState(''),
86
88
  [newEntityDisplayValue, setNewEntityDisplayValue] = useState(null),
@@ -88,6 +90,10 @@ export function ComboComponent(props) {
88
90
  [width, setWidth] = useState(0),
89
91
  [top, setTop] = useState(0),
90
92
  [left, setLeft] = useState(0),
93
+ onLayout = (e) => {
94
+ setIsRendered(true);
95
+ setContainerWidth(e.nativeEvent.layout.width);
96
+ },
91
97
  showMenu = async () => {
92
98
  if (isMenuShown) {
93
99
  return;
@@ -120,7 +126,7 @@ export function ComboComponent(props) {
120
126
  }
121
127
  }
122
128
  if (Repository && !Repository.isLoaded) {
123
- await Repository.load();
129
+ // await Repository.load(); // this breaks when the menu (Grid) has selectorSelected
124
130
  }
125
131
  setIsMenuShown(true);
126
132
  },
@@ -738,6 +744,9 @@ export function ComboComponent(props) {
738
744
  const id = entity.id;
739
745
  setValue(id);
740
746
  }
747
+ if (onSave) {
748
+ onSave(selection);
749
+ }
741
750
  }}
742
751
  onRowPress={(item, e) => {
743
752
  if (onRowPress) {
@@ -896,15 +905,49 @@ export function ComboComponent(props) {
896
905
  if (tooltipRef) {
897
906
  refProps.ref = tooltipRef;
898
907
  }
899
- assembledComponents = <Row {...refProps} justifyContent="center" alignItems="center" h={styles.FORM_COMBO_HEIGHT} flex={1} onLayout={() => setIsRendered(true)}>
900
- {xButton}
901
- {eyeButton}
902
- {inputAndTrigger}
903
- {additionalButtons}
904
- {dropdownMenu}
905
- </Row>;
908
+
909
+ if (isRendered && additionalButtons?.length && containerWidth < 500) {
910
+ // be responsive for small screen sizes and bump additionalButtons to the next line
911
+ assembledComponents =
912
+ <Column>
913
+ <Row {...refProps} justifyContent="center" alignItems="center" h={styles.FORM_COMBO_HEIGHT} flex={1}>
914
+ {xButton}
915
+ {eyeButton}
916
+ {inputAndTrigger}
917
+ {dropdownMenu}
918
+ </Row>
919
+ <Row mt={2}>
920
+ {additionalButtons}
921
+ </Row>
922
+ </Column>;
923
+ } else {
924
+ assembledComponents =
925
+ <Row {...refProps} justifyContent="center" alignItems="center" h={styles.FORM_COMBO_HEIGHT} flex={1} onLayout={onLayout}>
926
+ {xButton}
927
+ {eyeButton}
928
+ {inputAndTrigger}
929
+ {additionalButtons}
930
+ {dropdownMenu}
931
+ </Row>;
932
+ }
906
933
 
907
934
  if (isViewerShown && Editor) {
935
+ const propsForViewer = _.pick(props, [
936
+ 'disableCopy',
937
+ 'disableDuplicate',
938
+ 'disablePrint',
939
+ 'disableView',
940
+ 'value',
941
+ 'Repository',
942
+ 'data',
943
+ 'displayField',
944
+ 'displayIx',
945
+ 'fields',
946
+ 'idField',
947
+ 'idIx',
948
+ 'model',
949
+ 'name',
950
+ ]);
908
951
  assembledComponents =
909
952
  <>
910
953
  {assembledComponents}
@@ -913,7 +956,7 @@ export function ComboComponent(props) {
913
956
  onClose={onViewerClose}
914
957
  >
915
958
  <Editor
916
- {...props}
959
+ {...propsForViewer}
917
960
  editorType={EDITOR_TYPE__WINDOWED}
918
961
  px={0}
919
962
  py={0}
@@ -227,7 +227,7 @@ function Form(props) {
227
227
  let editorProps = {};
228
228
  if (!editor) {
229
229
  const propertyDef = fieldName && Repository?.getSchema().getPropertyDefinition(fieldName);
230
- editor = propertyDef[fieldName].editorType;
230
+ editor = propertyDef && propertyDef[fieldName].editorType;
231
231
  if (_.isPlainObject(editor)) {
232
232
  const {
233
233
  type,
@@ -323,15 +323,15 @@ function Form(props) {
323
323
  {
324
324
  type: t,
325
325
  ...p
326
- } = propertyDef.editorType;
326
+ } = propertyDef?.editorType;
327
327
  type = t;
328
328
  editorTypeProps = p;
329
- } else if (propertyDef.viewerType) {
329
+ } else if (propertyDef?.viewerType) {
330
330
  const
331
331
  {
332
332
  type: t,
333
333
  ...p
334
- } = propertyDef.viewerType;
334
+ } = propertyDef?.viewerType;
335
335
  type = t;
336
336
  } else {
337
337
  type = 'Text';
@@ -521,10 +521,20 @@ function Form(props) {
521
521
  }
522
522
 
523
523
  if (item.additionalEditButtons) {
524
- element = <Row flex={1} flexWrap="wrap">
524
+ const buttons = buildAdditionalButtons(item.additionalEditButtons, self, { fieldState, formSetValue, formGetValues, formState });
525
+ if (containerWidth > 400) {
526
+ element = <Row flex={1} flexWrap="wrap">
527
+ {element}
528
+ {buttons}
529
+ </Row>;
530
+ } else {
531
+ element = <Column flex={1} w="100%">
525
532
  {element}
526
- {buildAdditionalButtons(item.additionalEditButtons, self, { fieldState, formSetValue, formGetValues, formState })}
527
- </Row>;
533
+ <Row flex={1} w="100%" mt={2} flexWrap="wrap">
534
+ {buttons}
535
+ </Row>
536
+ </Column>;
537
+ }
528
538
  }
529
539
 
530
540
  let isRequired = false,
@@ -693,6 +703,8 @@ function Form(props) {
693
703
  if (self) {
694
704
  self.ref = formRef;
695
705
  self.formState = formState;
706
+ self.formSetValue = formSetValue;
707
+ self.formGetValues = formGetValues;
696
708
  }
697
709
 
698
710
  const sizeProps = {};
@@ -483,7 +483,7 @@ export default function withFilters(WrappedComponent) {
483
483
 
484
484
  // basic property filter
485
485
  const propertyDef = Repository.getSchema().getPropertyDefinition(filterField);
486
- data.push([ filterField, propertyDef.title ]);
486
+ data.push([ filterField, propertyDef?.title ]);
487
487
  });
488
488
 
489
489
  // sort by title
@@ -108,7 +108,7 @@ export default function withPdfButton(WrappedComponent) {
108
108
 
109
109
  if (!item.title) {
110
110
  const propertyDef = name && Repository?.getSchema().getPropertyDefinition(name);
111
- if (propertyDef.title) {
111
+ if (propertyDef?.title) {
112
112
  item.title = propertyDef.title;
113
113
  }
114
114
  }
@@ -0,0 +1,14 @@
1
+ // Font Awesome Pro 6.2.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2022 Fonticons, Inc.
2
+ import * as React from "react"
3
+ import Svg, { Path } from "react-native-svg"
4
+ import { Icon } from 'native-base';
5
+
6
+ function SvgComponent(props) {
7
+ return (
8
+ <Icon xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" {...props}>
9
+ <Path d="M32 96h320V32c0-12.9 7.8-24.6 19.8-29.6s25.7-2.2 34.9 6.9l96 96c6 6 9.4 14.1 9.4 22.6s-3.4 16.6-9.4 22.6l-96 96c-9.2 9.2-22.9 11.9-34.9 6.9S352 236.8 352 223.8V160H32c-17.7 0-32-14.3-32-32s14.3-32 32-32zm448 256c17.7 0 32 14.3 32 32s-14.3 32-32 32H160v64c0 12.9-7.8 24.6-19.8 29.6s-25.7 2.2-34.9-6.9l-96-96c-6-6-9.4-14.1-9.4-22.6s3.4-16.6 9.4-22.6l96-96c9.2-9.2 22.9-11.9 34.9-6.9s19.8 16.6 19.8 29.6v64h320z" />
10
+ </Icon>
11
+ )
12
+ }
13
+
14
+ export default SvgComponent
@@ -73,12 +73,12 @@ function Viewer(props) {
73
73
 
74
74
  const propertyDef = name && Repository?.getSchema().getPropertyDefinition(name);
75
75
  if (!type) {
76
- if (propertyDef.viewerType) {
76
+ if (propertyDef?.viewerType) {
77
77
  const
78
78
  {
79
79
  type: t,
80
80
  ...p
81
- } = propertyDef.viewerType;
81
+ } = propertyDef.viewerType;
82
82
  type = t
83
83
  } else {
84
84
  type = 'Text';
@@ -121,7 +121,7 @@ function Viewer(props) {
121
121
  return <Element key={ix} title={title} {...defaults} {...propsToPass} {...editorTypeProps}>{children}</Element>;
122
122
  }
123
123
 
124
- if (!label && Repository && propertyDef.title) {
124
+ if (!label && Repository && propertyDef?.title) {
125
125
  label = propertyDef.title;
126
126
  }
127
127
 
@@ -144,6 +144,7 @@ import RectangleXmark from '../Components/Icons/RectangleXmark.js';
144
144
  import RectangleXmarkRegular from '../Components/Icons/RectangleXmarkRegular.js';
145
145
  import ReorderRows from '../Components/Icons/ReorderRows.js';
146
146
  import RightFromBracket from '../Components/Icons/RightFromBracket.js';
147
+ import RightLeft from '../Components/Icons/RightLeft.js';
147
148
  import RightToBracket from '../Components/Icons/RightToBracket.js';
148
149
  import Rotate from '../Components/Icons/Rotate.js';
149
150
  import RotateLeft from '../Components/Icons/RotateLeft.js';
@@ -374,6 +375,7 @@ const components = {
374
375
  RectangleXmarkRegular,
375
376
  ReorderRows,
376
377
  RightFromBracket,
378
+ RightLeft,
377
379
  RightToBracket,
378
380
  Rotate,
379
381
  RotateLeft,