@teselagen/ui 0.5.23-beta.7 → 0.5.23-beta.8

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.
@@ -0,0 +1 @@
1
+ export function withAbstractWrapper(ComponentToWrap: any, opts?: {}): (props: any) => import("react/jsx-runtime").JSX.Element;
package/index.cjs.js CHANGED
@@ -48408,12 +48408,7 @@ const DataTable = /* @__PURE__ */ __name((_G) => {
48408
48408
  const tmp = (urlConnected ? getCurrentParamsFromUrl(history.location) : reduxFormQueryParams) || {};
48409
48409
  tmp.searchTerm = reduxFormSearchInput;
48410
48410
  return tmp;
48411
- }, [
48412
- history.location,
48413
- reduxFormQueryParams,
48414
- reduxFormSearchInput,
48415
- urlConnected
48416
- ]);
48411
+ }, [history, reduxFormQueryParams, reduxFormSearchInput, urlConnected]);
48417
48412
  const tableParams = React$1.useMemo(() => {
48418
48413
  if (!isTableParamsConnected) {
48419
48414
  const updateSearch = /* @__PURE__ */ __name((val) => {
@@ -48450,7 +48445,7 @@ const DataTable = /* @__PURE__ */ __name((_G) => {
48450
48445
  _tableParams,
48451
48446
  change,
48452
48447
  currentParams,
48453
- history.replace,
48448
+ history,
48454
48449
  isTableParamsConnected,
48455
48450
  props,
48456
48451
  selectedEntities,
package/index.es.js CHANGED
@@ -48390,12 +48390,7 @@ const DataTable = /* @__PURE__ */ __name((_G) => {
48390
48390
  const tmp = (urlConnected ? getCurrentParamsFromUrl(history.location) : reduxFormQueryParams) || {};
48391
48391
  tmp.searchTerm = reduxFormSearchInput;
48392
48392
  return tmp;
48393
- }, [
48394
- history.location,
48395
- reduxFormQueryParams,
48396
- reduxFormSearchInput,
48397
- urlConnected
48398
- ]);
48393
+ }, [history, reduxFormQueryParams, reduxFormSearchInput, urlConnected]);
48399
48394
  const tableParams = useMemo(() => {
48400
48395
  if (!isTableParamsConnected) {
48401
48396
  const updateSearch = /* @__PURE__ */ __name((val) => {
@@ -48432,7 +48427,7 @@ const DataTable = /* @__PURE__ */ __name((_G) => {
48432
48427
  _tableParams,
48433
48428
  change2,
48434
48429
  currentParams,
48435
- history.replace,
48430
+ history,
48436
48431
  isTableParamsConnected,
48437
48432
  props,
48438
48433
  selectedEntities,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teselagen/ui",
3
- "version": "0.5.23-beta.7",
3
+ "version": "0.5.23-beta.8",
4
4
  "main": "./src/index.js",
5
5
  "exports": {
6
6
  ".": {
@@ -14,6 +14,7 @@
14
14
  "@teselagen/bounce-loader": "0.3.11",
15
15
  "@blueprintjs/core": "3.52.0",
16
16
  "@blueprintjs/datetime": "3.23.19",
17
+ "@blueprintjs/icons": "3.33.0",
17
18
  "@blueprintjs/select": "3.18.11",
18
19
  "@dnd-kit/core": "^6.1.0",
19
20
  "@dnd-kit/modifiers": "^7.0.0",
@@ -274,12 +274,7 @@ const DataTable = ({
274
274
 
275
275
  tmp.searchTerm = reduxFormSearchInput;
276
276
  return tmp;
277
- }, [
278
- history.location,
279
- reduxFormQueryParams,
280
- reduxFormSearchInput,
281
- urlConnected
282
- ]);
277
+ }, [history, reduxFormQueryParams, reduxFormSearchInput, urlConnected]);
283
278
 
284
279
  const tableParams = useMemo(() => {
285
280
  if (!isTableParamsConnected) {
@@ -324,7 +319,7 @@ const DataTable = ({
324
319
  _tableParams,
325
320
  change,
326
321
  currentParams,
327
- history.replace,
322
+ history,
328
323
  isTableParamsConnected,
329
324
  props,
330
325
  selectedEntities,
@@ -352,6 +352,7 @@ export default function useTableParams(
352
352
  reduxFormSearchInput,
353
353
  onlyShowRowsWErrors,
354
354
  reduxFormCellValidation,
355
+ reduxFormEntities,
355
356
  reduxFormSelectedCells,
356
357
  reduxFormSelectedEntityIdMap,
357
358
  reduxFormQueryParams,
@@ -0,0 +1,388 @@
1
+ import { Button, FormGroup, Position, Tooltip } from "@blueprintjs/core";
2
+ import { useCallback, useContext, useEffect, useRef, useState } from "react";
3
+ import {
4
+ AssignDefaultsModeContext,
5
+ WorkflowDefaultParamsContext,
6
+ workflowDefaultParamsObj
7
+ } from "../AssignDefaultsModeContext";
8
+ import { difference, isEqual, kebabCase } from "lodash-es";
9
+ import {
10
+ fakeWait,
11
+ getIntent,
12
+ getIntentClass,
13
+ LabelWithTooltipInfo
14
+ } from "./utils";
15
+ import useDeepCompareEffect from "use-deep-compare-effect";
16
+ import { change } from "redux-form";
17
+ import popoverOverflowModifiers from "../utils/popoverOverflowModifiers";
18
+ import classNames from "classnames";
19
+
20
+ const AbstractInput = props => {
21
+ const {
22
+ defaultValue,
23
+ meta: { dispatch, form, touched, error, warning },
24
+ onDefaultValChanged,
25
+ onFieldSubmit,
26
+ children,
27
+ tooltipProps,
28
+ tooltipError,
29
+ disabled,
30
+ intent,
31
+ tooltipInfo,
32
+ label,
33
+ inlineLabel,
34
+ isLabelTooltip,
35
+ secondaryLabel,
36
+ className,
37
+ showErrorIfUntouched,
38
+ asyncValidating,
39
+ containerStyle,
40
+ leftEl,
41
+ rightEl,
42
+ labelStyle,
43
+ noOuterLabel,
44
+ fileLimit,
45
+ noMarginBottom,
46
+ assignDefaultButton,
47
+ showGenerateDefaultDot,
48
+ setAssignDefaultsMode,
49
+ startAssigningDefault,
50
+ input,
51
+ noFillField,
52
+ isRequired,
53
+ isLoadingDefaultValue,
54
+ enableReinitialize,
55
+ defaultValCount
56
+ } = props;
57
+
58
+ const prevProps = useRef({ defaultValue, defaultValCount });
59
+
60
+ const updateDefaultValue = useCallback(() => {
61
+ dispatch(change(form, input.name, defaultValue));
62
+ onDefaultValChanged &&
63
+ onDefaultValChanged(defaultValue, input.name, form, props);
64
+ onFieldSubmit && onFieldSubmit(defaultValue);
65
+ }, [
66
+ defaultValue,
67
+ dispatch,
68
+ form,
69
+ input.name,
70
+ onDefaultValChanged,
71
+ onFieldSubmit,
72
+ props
73
+ ]);
74
+
75
+ useEffect(() => {
76
+ if (
77
+ ((input.value !== false && !input.value) || enableReinitialize) &&
78
+ defaultValue !== undefined
79
+ ) {
80
+ updateDefaultValue();
81
+ }
82
+ }, [defaultValue, enableReinitialize, input.value, updateDefaultValue]);
83
+
84
+ useEffect(() => {
85
+ const {
86
+ defaultValue: oldDefaultValue,
87
+ defaultValCount: oldDefaultValCount
88
+ } = prevProps.current;
89
+
90
+ if (
91
+ ((input.value !== false && !input.value) ||
92
+ enableReinitialize ||
93
+ defaultValCount !== oldDefaultValCount) &&
94
+ !isEqual(defaultValue, oldDefaultValue)
95
+ ) {
96
+ updateDefaultValue();
97
+ }
98
+
99
+ prevProps.current = { defaultValue, defaultValCount };
100
+ }, [
101
+ defaultValue,
102
+ defaultValCount,
103
+ enableReinitialize,
104
+ input.value,
105
+ updateDefaultValue
106
+ ]);
107
+
108
+ // if our custom field level validation is happening then we don't want to show the error visually
109
+ const showError =
110
+ (touched || showErrorIfUntouched) && error && !asyncValidating;
111
+ const showWarning = (touched || showErrorIfUntouched) && warning;
112
+ let componentToWrap =
113
+ isLabelTooltip || tooltipError ? (
114
+ <Tooltip
115
+ disabled={isLabelTooltip ? false : !showError}
116
+ intent={isLabelTooltip ? "none" : error ? "danger" : "warning"}
117
+ content={isLabelTooltip ? label : error || warning}
118
+ position={Position.TOP}
119
+ modifiers={popoverOverflowModifiers}
120
+ {...tooltipProps}
121
+ >
122
+ {children}
123
+ </Tooltip>
124
+ ) : (
125
+ children
126
+ );
127
+ const testClassName = "tg-test-" + kebabCase(input.name);
128
+ if (noFillField) {
129
+ componentToWrap = <div className="tg-no-fill-field">{componentToWrap}</div>;
130
+ }
131
+
132
+ let helperText;
133
+ if (!tooltipError) {
134
+ if (showError) {
135
+ helperText = error;
136
+ } else if (showWarning) {
137
+ helperText = warning;
138
+ }
139
+ }
140
+
141
+ // if in a cypress test show message so that inputs will not be interactable
142
+ if (window.Cypress && isLoadingDefaultValue) {
143
+ return "Loading default value...";
144
+ }
145
+
146
+ let labelInfo = secondaryLabel;
147
+
148
+ const hasOuterLabel = !noOuterLabel && !isLabelTooltip;
149
+ function getFileLimitInfo() {
150
+ if (!fileLimit) return "";
151
+ return `max ${fileLimit} file${fileLimit === 1 ? "" : "s"}`;
152
+ }
153
+
154
+ if (isRequired && hasOuterLabel && label && !labelInfo) {
155
+ labelInfo = `(required${fileLimit ? `, ${getFileLimitInfo()}` : ""})`;
156
+ } else if (!labelInfo && fileLimit) {
157
+ labelInfo = `(${getFileLimitInfo()})`;
158
+ }
159
+
160
+ return (
161
+ <FormGroup
162
+ className={classNames(className, testClassName, {
163
+ "tg-flex-form-content": leftEl || rightEl,
164
+ "tg-tooltipError": tooltipError,
165
+ "tg-has-error": showError && error
166
+ })}
167
+ disabled={disabled}
168
+ helperText={helperText}
169
+ intent={intent}
170
+ label={
171
+ hasOuterLabel && (
172
+ <LabelWithTooltipInfo
173
+ labelStyle={labelStyle}
174
+ label={label}
175
+ tooltipInfo={tooltipInfo}
176
+ />
177
+ )
178
+ }
179
+ inline={inlineLabel}
180
+ labelInfo={labelInfo}
181
+ style={{
182
+ ...(noMarginBottom && { marginBottom: 0 }),
183
+ ...containerStyle
184
+ }}
185
+ >
186
+ {showGenerateDefaultDot && (
187
+ <div style={{ zIndex: 10, position: "relative", height: 0, width: 0 }}>
188
+ <div style={{ position: "absolute", left: "0px", top: "0px" }}>
189
+ <Tooltip
190
+ modifiers={popoverOverflowModifiers}
191
+ content="Allows a Default to be Set. Click to Enter Set Default Mode (or press Shift+D when outside the input field)"
192
+ >
193
+ <div
194
+ onClick={() => {
195
+ setAssignDefaultsMode(true);
196
+ startAssigningDefault();
197
+ }}
198
+ className="generateDefaultDot"
199
+ ></div>
200
+ </Tooltip>
201
+ </div>
202
+ </div>
203
+ )}
204
+ {assignDefaultButton}
205
+ {leftEl} {componentToWrap} {rightEl}
206
+ </FormGroup>
207
+ );
208
+ };
209
+
210
+ export const withAbstractWrapper = (ComponentToWrap, opts = {}) => {
211
+ return props => {
212
+ const {
213
+ massageDefaultIdValue,
214
+ generateDefaultValue,
215
+ defaultValueByIdOverride,
216
+ defaultValue: defaultValueFromProps,
217
+ isRequired,
218
+ ...rest
219
+ } = props;
220
+
221
+ //get is assign defaults mode
222
+ //if assign default value mode then add on to the component
223
+ const [defaultValCount, setDefaultValCount] = useState(0);
224
+ const [defaultValueFromBackend, setDefault] = useState();
225
+ const [allowUserOverride, setUserOverride] = useState(true);
226
+ const [isLoadingDefaultValue, setLoadingDefaultValue] = useState(false);
227
+ const { inAssignDefaultsMode, setAssignDefaultsMode } = useContext(
228
+ AssignDefaultsModeContext
229
+ );
230
+ // tnr: we might want to grab this context object off the window in the future and have it live in lims by default
231
+ // there is no reason for those vals to live in TRC. Example code below:
232
+ // const workflowParams = useContext(window.__tgDefaultValParamsContext || defaultNullContext);
233
+ const workflowParams = useContext(WorkflowDefaultParamsContext);
234
+
235
+ const caresAboutToolContext = generateDefaultValue?.params?.toolName;
236
+
237
+ const customParamsToUse = {
238
+ ...(caresAboutToolContext
239
+ ? { ...workflowDefaultParamsObj, ...workflowParams }
240
+ : {}),
241
+ ...(generateDefaultValue ? generateDefaultValue.customParams : {})
242
+ };
243
+
244
+ async function triggerGetDefault() {
245
+ if (!defaultValueByIdOverride) {
246
+ //if defaultValueByIdOverride is passed, we can skip over getting the value from the backend straight to massaging the default value
247
+ if (!window.__triggerGetDefaultValueRequest) return;
248
+ if (!generateDefaultValue) return;
249
+ setLoadingDefaultValue(true);
250
+ //custom params should match params keys. if not throw an error
251
+ const doParamsMatch = isEqual(
252
+ Object.keys({
253
+ ...(caresAboutToolContext ? workflowDefaultParamsObj : {}), //we don't want to compare these keys so we just spread them here
254
+ ...(generateDefaultValue.params || {})
255
+ }).sort(),
256
+ Object.keys(customParamsToUse).sort()
257
+ );
258
+ if (!doParamsMatch) {
259
+ console.warn(
260
+ `Issue with generateDefaultValue. customParams don't match params`
261
+ );
262
+ console.warn(
263
+ `generateDefaultValue.params:`,
264
+ generateDefaultValue.params
265
+ );
266
+ console.warn(`generateDefaultValue.customParams:`, customParamsToUse);
267
+ throw new Error(
268
+ `Issue with generateDefaultValue code=${
269
+ generateDefaultValue.code
270
+ }: Difference detected with: ${difference(
271
+ Object.keys(generateDefaultValue.params || {}),
272
+ Object.keys(customParamsToUse || {})
273
+ ).join(
274
+ ", "
275
+ )}. customParams passed into the field should match params (as defined in defaultValueConstants.js). See console for more details.`
276
+ );
277
+ }
278
+ }
279
+
280
+ try {
281
+ let { defaultValue, allowUserOverride } = defaultValueByIdOverride
282
+ ? { defaultValue: defaultValueByIdOverride }
283
+ : await window.__triggerGetDefaultValueRequest(
284
+ generateDefaultValue.code,
285
+ customParamsToUse
286
+ );
287
+ if (massageDefaultIdValue) {
288
+ const massagedRes = await massageDefaultIdValue({
289
+ defaultValueById: defaultValue
290
+ });
291
+ if (massagedRes.defaultValue) {
292
+ defaultValue = massagedRes.defaultValue;
293
+ }
294
+ if (massagedRes.preventUserOverrideFromBeingDisabled) {
295
+ allowUserOverride = true;
296
+ }
297
+ }
298
+
299
+ // TODO:Add ths back in when we have a better way to determine if a field is a checkbox or switch
300
+ // if (
301
+ // "false" === false
302
+ // // ComponentToWrap === renderBlueprintCheckbox ||
303
+ // // ComponentToWrap === renderBlueprintSwitch
304
+ // ) {
305
+ // setDefault(defaultValue === "true");
306
+ // } else {
307
+ if (typeof defaultValue === "string") {
308
+ // remove double spaces and leading/trailing
309
+ defaultValue = defaultValue.replace(/\s+/g, " ").trim();
310
+ }
311
+ setDefault(defaultValue);
312
+ // }
313
+ setUserOverride(allowUserOverride);
314
+ setDefaultValCount(defaultValCount + 1);
315
+ } catch (error) {
316
+ console.error(`error aswf298f:`, error);
317
+ }
318
+ if (window.Cypress && window.Cypress.addFakeDefaultValueWait) {
319
+ await fakeWait();
320
+ }
321
+ setLoadingDefaultValue(false);
322
+ }
323
+ // if generateDefaultValue, hit the backend for that value
324
+ useDeepCompareEffect(() => {
325
+ // if the input already has a value we don't want to override with the default value request
326
+ if (rest.input.value) return;
327
+ triggerGetDefault();
328
+ }, [generateDefaultValue || {}]);
329
+ // const asyncValidating = props.asyncValidating;
330
+ const defaultProps = {
331
+ ...rest,
332
+ defaultValue: defaultValueFromBackend || defaultValueFromProps,
333
+ disabled: props.disabled || allowUserOverride === false,
334
+ readOnly: props.readOnly || isLoadingDefaultValue,
335
+ intent: getIntent(props),
336
+ intentClass: getIntentClass(props)
337
+ };
338
+
339
+ // don't show intent while async validating
340
+ // if (asyncValidating) {
341
+ // delete defaultProps.intent;
342
+ // delete defaultProps.intentClass;
343
+ // }
344
+
345
+ const startAssigningDefault = () =>
346
+ window.__showAssignDefaultValueModal &&
347
+ window.__showAssignDefaultValueModal({
348
+ ...props,
349
+ generateDefaultValue: {
350
+ ...props.generateDefaultValue,
351
+ customParams: customParamsToUse
352
+ },
353
+ onFinish: () => {
354
+ triggerGetDefault();
355
+ }
356
+ });
357
+
358
+ return (
359
+ <AbstractInput
360
+ {...{
361
+ ...opts,
362
+ defaultValCount,
363
+ isRequired,
364
+ ...defaultProps,
365
+ isLoadingDefaultValue,
366
+ showGenerateDefaultDot:
367
+ !inAssignDefaultsMode &&
368
+ window.__showGenerateDefaultDot &&
369
+ window.__showGenerateDefaultDot() &&
370
+ !!generateDefaultValue,
371
+ setAssignDefaultsMode,
372
+ startAssigningDefault,
373
+ assignDefaultButton: inAssignDefaultsMode && generateDefaultValue && (
374
+ <Button
375
+ onClick={startAssigningDefault}
376
+ small
377
+ style={{ background: "yellow", color: "black" }}
378
+ >
379
+ Assign Default
380
+ </Button>
381
+ )
382
+ }}
383
+ >
384
+ <ComponentToWrap {...defaultProps} />
385
+ </AbstractInput>
386
+ );
387
+ };
388
+ };