@onehat/ui 0.3.66 → 0.3.68

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.66",
3
+ "version": "0.3.68",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -61,7 +61,7 @@ export function ComboComponent(props) {
61
61
  inputRef = useRef(),
62
62
  triggerRef = useRef(),
63
63
  menuRef = useRef(),
64
- displayValueRef = useRef(null),
64
+ displayValueRef = useRef(),
65
65
  typingTimeout = useRef(),
66
66
  [isMenuShown, setIsMenuShown] = useState(false),
67
67
  [isRendered, setIsRendered] = useState(false),
@@ -118,6 +118,58 @@ export function ComboComponent(props) {
118
118
  toggleMenu = () => {
119
119
  setIsMenuShown(!isMenuShown);
120
120
  },
121
+ getDisplayValue = () => {
122
+ return displayValueRef.current;
123
+ },
124
+ setDisplayValue = async (value) => {
125
+ let displayValue = '';
126
+ if (_.isNil(value)) {
127
+ // do nothing
128
+ } else if (_.isArray(value)) {
129
+ displayValue = [];
130
+ if (Repository) {
131
+ if (!Repository.isLoaded) {
132
+ throw Error('Not yet implemented'); // Would a Combo ever have multiple remote selections? Shouldn't that be a Tag field??
133
+ }
134
+ if (Repository.isLoading) {
135
+ await Repository.waitUntilDoneLoading();
136
+ }
137
+ displayValue = _.each(value, (id) => {
138
+ const entity = Repository.getById(id);
139
+ if (entity) {
140
+ displayValue.push(entity.displayValue)
141
+ }
142
+ });
143
+ } else {
144
+ displayValue = _.each(value, (id) => {
145
+ const item = _.find(data, (datum) => datum[idIx] === id);
146
+ if (item) {
147
+ displayValue.push(item[displayIx]);
148
+ }
149
+ });
150
+ }
151
+ displayValue = displayValue.join(', ');
152
+ } else {
153
+ if (Repository) {
154
+ let entity;
155
+ if (!Repository.isLoaded) {
156
+ entity = await Repository.getSingleEntityFromServer(value);
157
+ } else {
158
+ if (Repository.isLoading) {
159
+ await Repository.waitUntilDoneLoading();
160
+ }
161
+ entity = Repository.getById(value);
162
+ }
163
+ displayValue = entity?.displayValue || '';
164
+ } else {
165
+ const item = _.find(data, (datum) => datum[idIx] === value);
166
+ displayValue = (item && item[displayIx]) || '';
167
+ }
168
+ }
169
+
170
+ displayValueRef.current = displayValue;
171
+ resetInputTextValue();
172
+ },
121
173
  resetInputTextValue = () => {
122
174
  setTextInputValue(getDisplayValue());
123
175
  },
@@ -344,57 +396,6 @@ export function ComboComponent(props) {
344
396
  // setTextInputValue(newTextValue);
345
397
  // }
346
398
  }
347
- },
348
- getDisplayValue = () => {
349
- return displayValueRef.current;
350
- },
351
- setDisplayValue = async (value) => {
352
- let displayValue = '';
353
- if (_.isNil(value)) {
354
- // do nothing
355
- } else if (_.isArray(value)) {
356
- displayValue = [];
357
- if (Repository) {
358
- if (!Repository.isLoaded) {
359
- throw Error('Not yet implemented'); // Would a Combo ever have multiple remote selections? Shouldn't that be a Tag field??
360
- }
361
- if (Repository.isLoading) {
362
- await Repository.waitUntilDoneLoading();
363
- }
364
- displayValue = _.each(value, (id) => {
365
- const entity = Repository.getById(id);
366
- if (entity) {
367
- displayValue.push(entity.displayValue)
368
- }
369
- });
370
- } else {
371
- displayValue = _.each(value, (id) => {
372
- const item = _.find(data, (datum) => datum[idIx] === id);
373
- if (item) {
374
- displayValue.push(item[displayIx]);
375
- }
376
- });
377
- }
378
- displayValue = displayValue.join(', ');
379
- } else {
380
- if (Repository) {
381
- let entity;
382
- if (!Repository.isLoaded) {
383
- entity = await Repository.getSingleEntityFromServer(value);
384
- } else {
385
- if (Repository.isLoading) {
386
- await Repository.waitUntilDoneLoading();
387
- }
388
- entity = Repository.getById(value);
389
- }
390
- displayValue = entity?.displayValue || '';
391
- } else {
392
- const item = _.find(data, (datum) => datum[idIx] === value);
393
- displayValue = (item && item[displayIx]) || '';
394
- }
395
- }
396
-
397
- displayValueRef.current = displayValue;
398
399
  };
399
400
 
400
401
  useEffect(() => {
@@ -412,7 +413,6 @@ export function ComboComponent(props) {
412
413
  (async () => {
413
414
  setIsSearchMode(false);
414
415
  await setDisplayValue(value);
415
- resetInputTextValue();
416
416
  if (!isReady) {
417
417
  setIsReady(true);
418
418
  }
@@ -1,4 +1,7 @@
1
1
  import React, { useState, useRef, useEffect, } from 'react';
2
+ import {
3
+ v4 as uuid,
4
+ } from 'uuid';
2
5
  import _ from 'lodash';
3
6
 
4
7
  // This HOC establishes a parent-child relationship between components.
@@ -7,13 +10,14 @@ import _ from 'lodash';
7
10
 
8
11
  export default function withComponent(WrappedComponent) {
9
12
  return (props) => {
13
+
10
14
  const {
11
15
  // self: parent,
12
16
  parent,
13
17
  componentMethods,
14
18
  ...propsToPass
15
19
  } = props,
16
- { reference } = props,
20
+ reference = !_.isEmpty(props.reference) ? props.reference : uuid(),
17
21
  childrenRef = useRef({}),
18
22
  selfRef = useRef({
19
23
  parent,
@@ -66,6 +70,7 @@ export default function withComponent(WrappedComponent) {
66
70
  // parent={parent}
67
71
  self={selfRef.current}
68
72
  {...propsToPass}
73
+ reference={reference}
69
74
  />;
70
75
 
71
76
  };
@@ -187,7 +187,7 @@ export default function withPdfButton(WrappedComponent) {
187
187
  startingValues={startingValues}
188
188
  validator={validator}
189
189
  checkIsEditingDisabled={false}
190
- onCancel={(e) => {
190
+ onClose={(e) => {
191
191
  setIsModalShown(false);
192
192
  }}
193
193
  onSubmit={(data, e) => {