@teselagen/ui 0.5.23-beta.1 → 0.5.23-beta.2

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
@@ -33239,20 +33239,6 @@ const SortableColumns = /* @__PURE__ */ __name(({ className, style, children, mo
33239
33239
  children
33240
33240
  );
33241
33241
  }, "SortableColumns");
33242
- const isEq = /* @__PURE__ */ __name((o1, o2) => {
33243
- const isEq2 = isEqualWith(o1, o2, function(val1, val2) {
33244
- if (isFunction$4(val1) && isFunction$4(val2)) {
33245
- return val1 === val2 || val1.toString() === val2.toString();
33246
- }
33247
- if (val1 && val1.constructor && val1.constructor.name === "FiberNode")
33248
- return true;
33249
- });
33250
- return isEq2;
33251
- }, "isEq");
33252
- const pure = /* @__PURE__ */ __name((BaseComponent) => {
33253
- const hoc = shouldUpdate((props, nextProps) => !isEq(props, nextProps));
33254
- return hoc(BaseComponent);
33255
- }, "pure");
33256
33242
  var warning = /* @__PURE__ */ __name(function() {
33257
33243
  }, "warning");
33258
33244
  var warning_1 = warning;
@@ -34131,9 +34117,6 @@ var withRouter = /* @__PURE__ */ __name(function withRouter2(Component) {
34131
34117
  return hoistStatics(C, Component);
34132
34118
  }, "withRouter");
34133
34119
  const dataTableEnhancer = compose(
34134
- // Function to make sure we don't rerender unless there are changes
34135
- // in the params
34136
- branch((props) => !props.alwaysRerender, pure),
34137
34120
  // form prop is needed for redux-form, but we are giving this prop as
34138
34121
  // formName, so we need to rename it. Previously it was done in the withTableParams, but now
34139
34122
  // it doesn't have it by default.
@@ -64358,6 +64341,20 @@ const withStore = /* @__PURE__ */ __name((Component) => {
64358
64341
  return /* @__PURE__ */ React$1.createElement(Component, __spreadProps(__spreadValues({}, props), { store }));
64359
64342
  };
64360
64343
  }, "withStore");
64344
+ const isEq = /* @__PURE__ */ __name((o1, o2) => {
64345
+ const isEq2 = isEqualWith(o1, o2, function(val1, val2) {
64346
+ if (isFunction$4(val1) && isFunction$4(val2)) {
64347
+ return val1 === val2 || val1.toString() === val2.toString();
64348
+ }
64349
+ if (val1 && val1.constructor && val1.constructor.name === "FiberNode")
64350
+ return true;
64351
+ });
64352
+ return isEq2;
64353
+ }, "isEq");
64354
+ const pure = /* @__PURE__ */ __name((BaseComponent) => {
64355
+ const hoc = shouldUpdate((props, nextProps) => !isEq(props, nextProps));
64356
+ return hoc(BaseComponent);
64357
+ }, "pure");
64361
64358
  function withTableParams(compOrOpts, pTopLevelOpts) {
64362
64359
  let topLevelOptions;
64363
64360
  let Component;
package/index.es.js CHANGED
@@ -33221,20 +33221,6 @@ const SortableColumns = /* @__PURE__ */ __name(({ className, style, children, mo
33221
33221
  children
33222
33222
  );
33223
33223
  }, "SortableColumns");
33224
- const isEq = /* @__PURE__ */ __name((o1, o2) => {
33225
- const isEq2 = isEqualWith(o1, o2, function(val1, val2) {
33226
- if (isFunction$4(val1) && isFunction$4(val2)) {
33227
- return val1 === val2 || val1.toString() === val2.toString();
33228
- }
33229
- if (val1 && val1.constructor && val1.constructor.name === "FiberNode")
33230
- return true;
33231
- });
33232
- return isEq2;
33233
- }, "isEq");
33234
- const pure = /* @__PURE__ */ __name((BaseComponent) => {
33235
- const hoc = shouldUpdate((props, nextProps) => !isEq(props, nextProps));
33236
- return hoc(BaseComponent);
33237
- }, "pure");
33238
33224
  var warning = /* @__PURE__ */ __name(function() {
33239
33225
  }, "warning");
33240
33226
  var warning_1 = warning;
@@ -34113,9 +34099,6 @@ var withRouter = /* @__PURE__ */ __name(function withRouter2(Component2) {
34113
34099
  return hoistStatics(C, Component2);
34114
34100
  }, "withRouter");
34115
34101
  const dataTableEnhancer = compose(
34116
- // Function to make sure we don't rerender unless there are changes
34117
- // in the params
34118
- branch((props) => !props.alwaysRerender, pure),
34119
34102
  // form prop is needed for redux-form, but we are giving this prop as
34120
34103
  // formName, so we need to rename it. Previously it was done in the withTableParams, but now
34121
34104
  // it doesn't have it by default.
@@ -64340,6 +64323,20 @@ const withStore = /* @__PURE__ */ __name((Component2) => {
64340
64323
  return /* @__PURE__ */ React__default.createElement(Component2, __spreadProps(__spreadValues({}, props), { store }));
64341
64324
  };
64342
64325
  }, "withStore");
64326
+ const isEq = /* @__PURE__ */ __name((o1, o2) => {
64327
+ const isEq2 = isEqualWith(o1, o2, function(val1, val2) {
64328
+ if (isFunction$4(val1) && isFunction$4(val2)) {
64329
+ return val1 === val2 || val1.toString() === val2.toString();
64330
+ }
64331
+ if (val1 && val1.constructor && val1.constructor.name === "FiberNode")
64332
+ return true;
64333
+ });
64334
+ return isEq2;
64335
+ }, "isEq");
64336
+ const pure = /* @__PURE__ */ __name((BaseComponent) => {
64337
+ const hoc = shouldUpdate((props, nextProps) => !isEq(props, nextProps));
64338
+ return hoc(BaseComponent);
64339
+ }, "pure");
64343
64340
  function withTableParams(compOrOpts, pTopLevelOpts) {
64344
64341
  let topLevelOptions;
64345
64342
  let Component2;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teselagen/ui",
3
- "version": "0.5.23-beta.1",
3
+ "version": "0.5.23-beta.2",
4
4
  "main": "./src/index.js",
5
5
  "exports": {
6
6
  ".": {
@@ -12,6 +12,10 @@
12
12
  "dependencies": {
13
13
  "@teselagen/file-utils": "0.3.16",
14
14
  "@teselagen/bounce-loader": "0.3.11",
15
+ "@blueprintjs/core": "3.52.0",
16
+ "@blueprintjs/datetime": "3.23.19",
17
+ "@blueprintjs/icons": "3.33.0",
18
+ "@blueprintjs/select": "3.18.11",
15
19
  "@dnd-kit/core": "^6.1.0",
16
20
  "@dnd-kit/modifiers": "^7.0.0",
17
21
  "@dnd-kit/sortable": "^8.0.0",
@@ -6,7 +6,6 @@
6
6
  */
7
7
  import { reduxForm } from "redux-form";
8
8
  import { branch, compose, withProps } from "recompose";
9
- import pureNoFunc from "../utils/pureNoFunc";
10
9
  import { withRouter } from "react-router-dom";
11
10
 
12
11
  /*
@@ -31,9 +30,6 @@ import { withRouter } from "react-router-dom";
31
30
  understanding if it's possible.
32
31
  */
33
32
  export default compose(
34
- // Function to make sure we don't rerender unless there are changes
35
- // in the params
36
- branch(props => !props.alwaysRerender, pureNoFunc),
37
33
  // form prop is needed for redux-form, but we are giving this prop as
38
34
  // formName, so we need to rename it. Previously it was done in the withTableParams, but now
39
35
  // it doesn't have it by default.
@@ -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
+ };