@onehat/ui 0.3.272 → 0.3.274

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.272",
3
+ "version": "0.3.274",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -18,7 +18,9 @@ function Editor(props) {
18
18
  onEditMode,
19
19
  verifyCanEdit,
20
20
  _viewer = {},
21
- _form = {},
21
+ _form = {
22
+ containerProps: {}
23
+ },
22
24
 
23
25
  // withComponent
24
26
  self,
@@ -46,7 +48,6 @@ function Editor(props) {
46
48
  return null;
47
49
  }
48
50
  return <Viewer
49
- {...testProps(self)}
50
51
  {...propsToPass}
51
52
  {..._viewer}
52
53
  record={record}
@@ -59,7 +60,6 @@ function Editor(props) {
59
60
  }
60
61
 
61
62
  return <Form
62
- {...testProps(self)}
63
63
  {...propsToPass}
64
64
  {..._form}
65
65
  record={selection}
@@ -58,6 +58,7 @@ export function ComboComponent(props) {
58
58
  onGridSave, // to hook into when menu saves (ComboEditor only)
59
59
  onGridDelete, // to hook into when menu deletes (ComboEditor only)
60
60
  newEntityDisplayProperty,
61
+ testID,
61
62
 
62
63
  // withComponent
63
64
  self,
@@ -361,7 +362,7 @@ export function ComboComponent(props) {
361
362
  menuRef.current === relatedTarget ||
362
363
  menuRef.current?.contains(relatedTarget);
363
364
  },
364
- getFilterName = () => {
365
+ getFilterName = (isId) => {
365
366
  // Only used for remote repositories
366
367
  // Gets the filter name of the query, which becomes the condition sent to server
367
368
  let filterName = FILTER_NAME;
@@ -372,7 +373,10 @@ export function ComboComponent(props) {
372
373
  displayFieldDef = schema.getPropertyDefinition(displayFieldName);
373
374
 
374
375
  // Verify displayField is a real field
375
- if (!displayFieldDef.isVirtual) {
376
+ if (isId) {
377
+ const idFieldName = schema.model.idProperty;
378
+ filterName = idFieldName;
379
+ } else if (!displayFieldDef.isVirtual) {
376
380
  filterName = displayFieldName + ' LIKE';
377
381
  }
378
382
  }
@@ -418,10 +422,13 @@ export function ComboComponent(props) {
418
422
  }
419
423
 
420
424
  // Set filter
421
- const filterName = getFilterName();
425
+ const
426
+ idRegex = /^id:(.*)$/,
427
+ isId = _.isString(value) && !!value.match(idRegex),
428
+ filterName = getFilterName(isId);
422
429
  if (Repository.isRemote) {
423
430
  // remote
424
- const filterValue = _.isEmpty(value) ? null : value + '%';
431
+ const filterValue = _.isEmpty(value) ? null : (isId ? value.match(idRegex)[1] : value + '%');
425
432
  await Repository.filter(filterName, filterValue);
426
433
  if (!Repository.isAutoLoad) {
427
434
  await Repository.reload();
@@ -958,7 +965,7 @@ export function ComboComponent(props) {
958
965
  if (isRendered && additionalButtons?.length && containerWidth < 500) {
959
966
  // be responsive for small screen sizes and bump additionalButtons to the next line
960
967
  assembledComponents =
961
- <Column>
968
+ <Column testID={testID}>
962
969
  <Row {...refProps} justifyContent="center" alignItems="center" flex={1} h="100%">
963
970
  {xButton}
964
971
  {eyeButton}
@@ -971,7 +978,7 @@ export function ComboComponent(props) {
971
978
  </Column>;
972
979
  } else {
973
980
  assembledComponents =
974
- <Row {...refProps} justifyContent="center" alignItems="center" flex={1} h="100%" onLayout={onLayout}>
981
+ <Row testID={testID} {...refProps} justifyContent="center" alignItems="center" flex={1} h="100%" onLayout={onLayout}>
975
982
  {xButton}
976
983
  {eyeButton}
977
984
  {inputAndTrigger}
@@ -899,7 +899,7 @@ function Form(props) {
899
899
  >Back</Button>}
900
900
  {isSingle && editorMode === EDITOR_MODE__EDIT && onViewMode && !disableView &&
901
901
  <Button
902
- {...testProps('viewBtn')}
902
+ {...testProps('toViewBtn')}
903
903
  key="viewBtn"
904
904
  onPress={onViewMode}
905
905
  leftIcon={<Icon as={Eye} color="#fff" size="sm" />}
@@ -968,7 +968,7 @@ function Form(props) {
968
968
  }
969
969
  }
970
970
 
971
- return <Column {...sizeProps} {...containerProps} onLayout={onLayoutDecorated} ref={formRef} testID="form">
971
+ return <Column {...testProps(self)} {...sizeProps} {...containerProps} onLayout={onLayoutDecorated} ref={formRef}>
972
972
  {!!containerWidth && <>
973
973
  {editorType === EDITOR_TYPE__INLINE &&
974
974
  <Row
@@ -506,6 +506,7 @@ function GridComponent(props) {
506
506
  fields={fields}
507
507
  rowProps={rowProps}
508
508
  hideNavColumn={hideNavColumn}
509
+ isSelected={isSelected}
509
510
  bg={bg}
510
511
  item={item}
511
512
  isInlineEditorShown={isInlineEditorShown}
@@ -24,6 +24,7 @@ function GridRow(props) {
24
24
  fields,
25
25
  rowProps,
26
26
  hideNavColumn,
27
+ isSelected,
27
28
  bg,
28
29
  item,
29
30
  isInlineEditorShown,
@@ -126,7 +127,7 @@ function GridRow(props) {
126
127
  elementProps.isViewOnly = true; // TODO: this won't work for InlineGridEditor, bc that Grid can't use isViewOnly when actually editing
127
128
  }
128
129
  return <Element
129
- {...testProps('fieldname-' + config.fieldName)}
130
+ {...testProps('cell-' + config.fieldName)}
130
131
  value={value}
131
132
  key={key}
132
133
  overflow="hidden"
@@ -167,7 +168,7 @@ function GridRow(props) {
167
168
  elementProps.textOverflow = 'ellipsis';
168
169
  }
169
170
  return <Text
170
- {...testProps('fieldname-' + config.fieldName)}
171
+ {...testProps('cell-' + config.fieldName)}
171
172
  key={key}
172
173
  overflow="hidden"
173
174
  alignSelf="center"
@@ -219,6 +220,7 @@ function GridRow(props) {
219
220
  }
220
221
 
221
222
  return <Row
223
+ {...testProps('row' + (isSelected ? '-selected' : ''))}
222
224
  alignItems="center"
223
225
  flexGrow={1}
224
226
  {...rowProps}
@@ -124,6 +124,7 @@ export default function withAlert(WrappedComponent) {
124
124
  let buttons = [];
125
125
  if (includeCancel) {
126
126
  buttons.push(<Button
127
+ {...testProps('cancelBtn')}
127
128
  key="cancelBtn"
128
129
  onPress={onCancel}
129
130
  color="#fff"
@@ -136,6 +137,7 @@ export default function withAlert(WrappedComponent) {
136
137
  case ALERT_MODE_OK:
137
138
  case ALERT_MODE_INFO:
138
139
  buttons.push(<Button
140
+ {...testProps('okBtn')}
139
141
  key="okBtn"
140
142
  ref={autoFocusRef}
141
143
  onPress={onOk}
@@ -144,6 +146,7 @@ export default function withAlert(WrappedComponent) {
144
146
  break;
145
147
  case ALERT_MODE_YES:
146
148
  buttons.push(<Button
149
+ {...testProps('yesBtn')}
147
150
  key="yesBtn"
148
151
  ref={autoFocusRef}
149
152
  onPress={onYes}
@@ -154,6 +157,7 @@ export default function withAlert(WrappedComponent) {
154
157
  case ALERT_MODE_YES_NO:
155
158
  // TODO: need to create a new colorScheme so this can be black with blank background
156
159
  buttons.push(<Button
160
+ {...testProps('noBtn')}
157
161
  key="noBtn"
158
162
  onPress={onNo}
159
163
  color="trueGray.800"
@@ -162,6 +166,7 @@ export default function withAlert(WrappedComponent) {
162
166
  mr={2}
163
167
  >No</Button>);
164
168
  buttons.push(<Button
169
+ {...testProps('yesBtn')}
165
170
  key="yesBtn"
166
171
  ref={autoFocusRef}
167
172
  onPress={onYes}
@@ -191,11 +196,13 @@ export default function withAlert(WrappedComponent) {
191
196
  isOpen={isAlertShown}
192
197
  onClose={() => setIsAlertShown(false)}
193
198
  >
194
- <AlertDialog.Content>
199
+ <AlertDialog.Content
200
+ {...testProps('AlertDialog')}
201
+ >
195
202
  {canClose && <AlertDialog.CloseButton />}
196
203
  <AlertDialog.Header>{title}</AlertDialog.Header>
197
204
  <AlertDialog.Body>
198
- <Row alignItems="center" {...testProps('AlertDialog')}>
205
+ <Row alignItems="center">
199
206
  <Column w="40px" p={0} mr={5}>
200
207
  <Icon as={mode === ALERT_MODE_INFO ? CircleInfo : TriangleExclamation} size={10} color={mode === ALERT_MODE_INFO ? '#000' : '#f00'} />
201
208
  </Column>
@@ -249,14 +249,14 @@ function Viewer(props) {
249
249
  canEdit = false;
250
250
  }
251
251
 
252
- return <Column flex={flex} {...props} onLayout={onLayout}>
252
+ return <Column flex={flex} {...testProps(self)} {...props} onLayout={onLayout}>
253
253
  {containerWidth && <>
254
254
 
255
255
  <ScrollView _web={{ height: 1 }} width="100%" pb={1} ref={scrollViewRef}>
256
256
  {canEdit && onEditMode &&
257
257
  <Row px={4} pt={4} alignItems="center" justifyContent="flex-end">
258
258
  <Button
259
- {...testProps('editBtn')}
259
+ {...testProps('toEditBtn')}
260
260
  key="editBtn"
261
261
  onPress={onEditMode}
262
262
  leftIcon={<Icon as={Pencil} color="#fff" size="sm" />}
@@ -7,11 +7,15 @@ export default function testProps(id) {
7
7
  if (typeof __DEV__ === 'undefined' || !__DEV__) {
8
8
  return {}; // don't add test props in production
9
9
  }
10
- if (id?.reference) {
11
- // id is actually 'self' object
10
+ if (id?.path) { // id is actually 'self' object
11
+ id = id.path;
12
+ } else if (id?.reference) { // id is actually 'self' object
12
13
  id = id.reference;
13
14
  }
14
- if (id?.match(/\s/g)) {
15
+ if (!id) {
16
+ return {};
17
+ }
18
+ if (id.match(/\s/g)) {
15
19
  id = id.replace(/\s/g, '_'); // convert any spaces to underscores
16
20
  }
17
21
  if (!window && Platform.OS === 'android') {