@teselagen/ui 0.5.23-beta.31 → 0.5.23-beta.32

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.
@@ -18,7 +18,6 @@ import { isBottomRightCornerOfRectangle } from './isBottomRightCornerOfRectangle
18
18
  import { isEntityClean } from './isEntityClean';
19
19
  import { PRIMARY_SELECTED_VAL } from './primarySelectedValue';
20
20
  import { removeCleanRows } from './removeCleanRows';
21
- import { useDeepEqualMemo } from './useDeepEqualMemo';
22
21
  import { useTableEntities } from './useTableEntities';
23
22
 
24
- export { defaultParsePaste, formatPasteData, getAllRows, getCellCopyText, getCellInfo, getEntityIdToEntity, getFieldPathToIndex, getFieldPathToField, getIdOrCodeOrIndex, getLastSelectedEntity, getNewEntToSelect, getNumberStrAtEnd, getRecordsFromIdMap, getRowCopyText, getSelectedRowsFromEntities, handleCopyColumn, handleCopyHelper, handleCopyRows, handleCopyTable, isBottomRightCornerOfRectangle, isEntityClean, PRIMARY_SELECTED_VAL, removeCleanRows, stripNumberAtEnd, useDeepEqualMemo, useTableEntities };
23
+ export { defaultParsePaste, formatPasteData, getAllRows, getCellCopyText, getCellInfo, getEntityIdToEntity, getFieldPathToIndex, getFieldPathToField, getIdOrCodeOrIndex, getLastSelectedEntity, getNewEntToSelect, getNumberStrAtEnd, getRecordsFromIdMap, getRowCopyText, getSelectedRowsFromEntities, handleCopyColumn, handleCopyHelper, handleCopyRows, handleCopyTable, isBottomRightCornerOfRectangle, isEntityClean, PRIMARY_SELECTED_VAL, removeCleanRows, stripNumberAtEnd, useTableEntities };
package/index.cjs.js CHANGED
@@ -17147,13 +17147,6 @@ const handleCopyTable = /* @__PURE__ */ __name((e2, opts) => {
17147
17147
  }
17148
17148
  }, "handleCopyTable");
17149
17149
  const PRIMARY_SELECTED_VAL = "main_cell";
17150
- const useDeepEqualMemo = /* @__PURE__ */ __name((value) => {
17151
- const ref2 = React$1.useRef();
17152
- if (!isEqual(value, ref2.current)) {
17153
- ref2.current = value;
17154
- }
17155
- return ref2.current;
17156
- }, "useDeepEqualMemo");
17157
17150
  const useTableEntities = /* @__PURE__ */ __name((tableFormName) => {
17158
17151
  const dispatch = reactRedux.useDispatch();
17159
17152
  const selectTableEntities = React$1.useCallback(
@@ -17189,6 +17182,13 @@ const useTableEntities = /* @__PURE__ */ __name((tableFormName) => {
17189
17182
  });
17190
17183
  return { selectTableEntities, allOrderedEntities, selectedEntities };
17191
17184
  }, "useTableEntities");
17185
+ const useDeepEqualMemo = /* @__PURE__ */ __name((value) => {
17186
+ const ref2 = React$1.useRef();
17187
+ if (!isEqual(value, ref2.current)) {
17188
+ ref2.current = value;
17189
+ }
17190
+ return ref2.current;
17191
+ }, "useDeepEqualMemo");
17192
17192
  function rowClick(e2, rowInfo, entities, {
17193
17193
  reduxFormSelectedEntityIdMap,
17194
17194
  isSingleSelect,
@@ -31783,6 +31783,13 @@ const sortify = /* @__PURE__ */ __name((value, replacer, space2) => {
31783
31783
  }, "sortify");
31784
31784
  const REQUIRED_ERROR = "This field is required.";
31785
31785
  const fieldRequired = /* @__PURE__ */ __name((value) => !value || Array.isArray(value) && !value.length ? REQUIRED_ERROR : void 0, "fieldRequired");
31786
+ const useStableReference = /* @__PURE__ */ __name((value) => {
31787
+ const ref2 = React$1.useRef();
31788
+ React$1.useEffect(() => {
31789
+ ref2.current = value;
31790
+ }, [value]);
31791
+ return ref2;
31792
+ }, "useStableReference");
31786
31793
  function getIntent({
31787
31794
  showErrorIfUntouched,
31788
31795
  meta: { touched, error, warning: warning2 }
@@ -31872,8 +31879,8 @@ const AbstractInput = /* @__PURE__ */ __name(({
31872
31879
  noFillField,
31873
31880
  noMarginBottom,
31874
31881
  noOuterLabel,
31875
- onDefaultValChanged,
31876
- onFieldSubmit,
31882
+ onDefaultValChanged: _onDefaultValChanged,
31883
+ onFieldSubmit: _onFieldSubmit,
31877
31884
  rightEl,
31878
31885
  secondaryLabel,
31879
31886
  setAssignDefaultsMode,
@@ -31885,11 +31892,13 @@ const AbstractInput = /* @__PURE__ */ __name(({
31885
31892
  tooltipProps
31886
31893
  }) => {
31887
31894
  const dispatch = reactRedux.useDispatch();
31895
+ const onDefaultValChanged = useStableReference(_onDefaultValChanged);
31896
+ const onFieldSubmit = useStableReference(_onFieldSubmit);
31888
31897
  React$1.useEffect(() => {
31889
31898
  if (defaultValue2 !== void 0) {
31890
31899
  dispatch(reduxForm.change(form, name, defaultValue2));
31891
- onDefaultValChanged && onDefaultValChanged(defaultValue2, name, form);
31892
- onFieldSubmit && onFieldSubmit(defaultValue2);
31900
+ onDefaultValChanged.current && onDefaultValChanged.current(defaultValue2, name, form);
31901
+ onFieldSubmit.current && onFieldSubmit.current(defaultValue2);
31893
31902
  }
31894
31903
  }, [defaultValue2, dispatch, form, name, onDefaultValChanged, onFieldSubmit]);
31895
31904
  const showError = (touched || showErrorIfUntouched) && error && !asyncValidating;
package/index.d.ts CHANGED
@@ -15,6 +15,7 @@ export * from './utils/commandUtils';
15
15
  export * from './utils/commandControls';
16
16
  export * from './utils/useTraceUpdate';
17
17
  export { default as Uploader } from './FormComponents/Uploader';
18
+ export { useDeepEqualMemo } from './utils/hooks';
18
19
  export { default as Loading } from './Loading';
19
20
  export { throwFormError } from './throwFormError';
20
21
  export { default as AdvancedOptions } from './AdvancedOptions';
@@ -57,6 +58,6 @@ export { mergeSchemas, default as convertSchema } from './DataTable/utils/conver
57
58
  export { getCurrentParamsFromUrl, setCurrentParamsOnUrl } from './DataTable/utils/queryParams';
58
59
  export { default as withSelectedEntities, getSelectedEntities } from './DataTable/utils/withSelectedEntities';
59
60
  export { default as DataTable, ConnectedPagingTool as PagingTool } from './DataTable';
60
- export { removeCleanRows, useTableEntities, getIdOrCodeOrIndex, useDeepEqualMemo } from './DataTable/utils';
61
+ export { removeCleanRows, useTableEntities, getIdOrCodeOrIndex } from './DataTable/utils';
61
62
  export { default as withTableParams, useTableParams } from './DataTable/utils/withTableParams';
62
63
  export { default as Timeline, TimelineEvent } from './Timeline';
package/index.es.js CHANGED
@@ -17129,13 +17129,6 @@ const handleCopyTable = /* @__PURE__ */ __name((e2, opts) => {
17129
17129
  }
17130
17130
  }, "handleCopyTable");
17131
17131
  const PRIMARY_SELECTED_VAL = "main_cell";
17132
- const useDeepEqualMemo = /* @__PURE__ */ __name((value) => {
17133
- const ref2 = useRef();
17134
- if (!isEqual(value, ref2.current)) {
17135
- ref2.current = value;
17136
- }
17137
- return ref2.current;
17138
- }, "useDeepEqualMemo");
17139
17132
  const useTableEntities = /* @__PURE__ */ __name((tableFormName) => {
17140
17133
  const dispatch = useDispatch();
17141
17134
  const selectTableEntities = useCallback(
@@ -17171,6 +17164,13 @@ const useTableEntities = /* @__PURE__ */ __name((tableFormName) => {
17171
17164
  });
17172
17165
  return { selectTableEntities, allOrderedEntities, selectedEntities };
17173
17166
  }, "useTableEntities");
17167
+ const useDeepEqualMemo = /* @__PURE__ */ __name((value) => {
17168
+ const ref2 = useRef();
17169
+ if (!isEqual(value, ref2.current)) {
17170
+ ref2.current = value;
17171
+ }
17172
+ return ref2.current;
17173
+ }, "useDeepEqualMemo");
17174
17174
  function rowClick(e2, rowInfo, entities, {
17175
17175
  reduxFormSelectedEntityIdMap,
17176
17176
  isSingleSelect,
@@ -31765,6 +31765,13 @@ const sortify = /* @__PURE__ */ __name((value, replacer, space2) => {
31765
31765
  }, "sortify");
31766
31766
  const REQUIRED_ERROR = "This field is required.";
31767
31767
  const fieldRequired = /* @__PURE__ */ __name((value) => !value || Array.isArray(value) && !value.length ? REQUIRED_ERROR : void 0, "fieldRequired");
31768
+ const useStableReference = /* @__PURE__ */ __name((value) => {
31769
+ const ref2 = useRef();
31770
+ useEffect(() => {
31771
+ ref2.current = value;
31772
+ }, [value]);
31773
+ return ref2;
31774
+ }, "useStableReference");
31768
31775
  function getIntent({
31769
31776
  showErrorIfUntouched,
31770
31777
  meta: { touched, error, warning: warning2 }
@@ -31854,8 +31861,8 @@ const AbstractInput = /* @__PURE__ */ __name(({
31854
31861
  noFillField,
31855
31862
  noMarginBottom,
31856
31863
  noOuterLabel,
31857
- onDefaultValChanged,
31858
- onFieldSubmit,
31864
+ onDefaultValChanged: _onDefaultValChanged,
31865
+ onFieldSubmit: _onFieldSubmit,
31859
31866
  rightEl,
31860
31867
  secondaryLabel,
31861
31868
  setAssignDefaultsMode,
@@ -31867,11 +31874,13 @@ const AbstractInput = /* @__PURE__ */ __name(({
31867
31874
  tooltipProps
31868
31875
  }) => {
31869
31876
  const dispatch = useDispatch();
31877
+ const onDefaultValChanged = useStableReference(_onDefaultValChanged);
31878
+ const onFieldSubmit = useStableReference(_onFieldSubmit);
31870
31879
  useEffect(() => {
31871
31880
  if (defaultValue2 !== void 0) {
31872
31881
  dispatch(change(form, name, defaultValue2));
31873
- onDefaultValChanged && onDefaultValChanged(defaultValue2, name, form);
31874
- onFieldSubmit && onFieldSubmit(defaultValue2);
31882
+ onDefaultValChanged.current && onDefaultValChanged.current(defaultValue2, name, form);
31883
+ onFieldSubmit.current && onFieldSubmit.current(defaultValue2);
31875
31884
  }
31876
31885
  }, [defaultValue2, dispatch, form, name, onDefaultValChanged, onFieldSubmit]);
31877
31886
  const showError = (touched || showErrorIfUntouched) && error && !asyncValidating;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teselagen/ui",
3
- "version": "0.5.23-beta.31",
3
+ "version": "0.5.23-beta.32",
4
4
  "main": "./src/index.js",
5
5
  "exports": {
6
6
  ".": {
@@ -1,13 +1,13 @@
1
- import React, { useEffect, useRef } from "react";
1
+ import React, { useEffect, useRef, useState } from "react";
2
2
 
3
3
  export const EditableCell = ({
4
- value,
5
- setValue,
6
4
  cancelEdit,
7
5
  dataTest,
8
6
  finishEdit,
9
- isNumeric
7
+ isNumeric,
8
+ initialValue
10
9
  }) => {
10
+ const [value, setValue] = useState(initialValue);
11
11
  const inputRef = useRef(null);
12
12
 
13
13
  useEffect(() => {
@@ -67,9 +67,9 @@ import {
67
67
  handleCopyTable,
68
68
  isEntityClean,
69
69
  PRIMARY_SELECTED_VAL,
70
- removeCleanRows,
71
- useDeepEqualMemo
70
+ removeCleanRows
72
71
  } from "./utils";
72
+ import { useDeepEqualMemo } from "../utils/hooks";
73
73
  import rowClick, {
74
74
  changeSelectedEntities,
75
75
  finalizeSelection
@@ -24,7 +24,6 @@ import { handleCopyColumn } from "./handleCopyColumn";
24
24
  import { isBottomRightCornerOfRectangle } from "./isBottomRightCornerOfRectangle";
25
25
  import { handleCopyTable } from "./handleCopyTable";
26
26
  import { PRIMARY_SELECTED_VAL } from "./primarySelectedValue";
27
- import { useDeepEqualMemo } from "./useDeepEqualMemo";
28
27
  import { useTableEntities } from "./useTableEntities";
29
28
 
30
29
  export {
@@ -52,6 +51,5 @@ export {
52
51
  PRIMARY_SELECTED_VAL,
53
52
  removeCleanRows,
54
53
  stripNumberAtEnd,
55
- useDeepEqualMemo,
56
54
  useTableEntities
57
55
  };
@@ -352,7 +352,6 @@ export default function useTableParams(
352
352
  reduxFormSearchInput,
353
353
  onlyShowRowsWErrors,
354
354
  reduxFormCellValidation,
355
- reduxFormEntities,
356
355
  reduxFormSelectedCells,
357
356
  reduxFormSelectedEntityIdMap,
358
357
  reduxFormQueryParams,
@@ -11,7 +11,7 @@ import {
11
11
  } from "./queryParams";
12
12
  import { withRouter } from "react-router-dom";
13
13
  import getTableConfigFromStorage from "./getTableConfigFromStorage";
14
- import { useDeepEqualMemo } from "./useDeepEqualMemo";
14
+ import { useDeepEqualMemo } from "../../utils/hooks/useDeepEqualMemo";
15
15
  import { branch, compose } from "recompose";
16
16
 
17
17
  /**
@@ -46,6 +46,7 @@ import Uploader from "./Uploader";
46
46
  import sortify from "./sortify";
47
47
  import { fieldRequired } from "./utils";
48
48
  import { useDispatch } from "react-redux";
49
+ import { useStableReference } from "../utils/hooks/useStableReference";
49
50
 
50
51
  export { fieldRequired };
51
52
 
@@ -147,8 +148,8 @@ const AbstractInput = ({
147
148
  noFillField,
148
149
  noMarginBottom,
149
150
  noOuterLabel,
150
- onDefaultValChanged,
151
- onFieldSubmit,
151
+ onDefaultValChanged: _onDefaultValChanged,
152
+ onFieldSubmit: _onFieldSubmit,
152
153
  rightEl,
153
154
  secondaryLabel,
154
155
  setAssignDefaultsMode,
@@ -160,13 +161,16 @@ const AbstractInput = ({
160
161
  tooltipProps
161
162
  }) => {
162
163
  const dispatch = useDispatch();
164
+ const onDefaultValChanged = useStableReference(_onDefaultValChanged);
165
+ const onFieldSubmit = useStableReference(_onFieldSubmit);
163
166
 
164
167
  // This only takes care that the default Value is changed when it is changed in the parent component
165
168
  useEffect(() => {
166
169
  if (defaultValue !== undefined) {
167
170
  dispatch(change(form, name, defaultValue));
168
- onDefaultValChanged && onDefaultValChanged(defaultValue, name, form);
169
- onFieldSubmit && onFieldSubmit(defaultValue);
171
+ onDefaultValChanged.current &&
172
+ onDefaultValChanged.current(defaultValue, name, form);
173
+ onFieldSubmit.current && onFieldSubmit.current(defaultValue);
170
174
  }
171
175
  }, [defaultValue, dispatch, form, name, onDefaultValChanged, onFieldSubmit]);
172
176
 
@@ -11,7 +11,8 @@ import { some } from "lodash-es";
11
11
  import { times } from "lodash-es";
12
12
  import DialogFooter from "./DialogFooter";
13
13
  import DataTable from "./DataTable";
14
- import { removeCleanRows, useDeepEqualMemo } from "./DataTable/utils";
14
+ import { useDeepEqualMemo } from "./utils/hooks";
15
+ import { removeCleanRows } from "./DataTable/utils";
15
16
  import wrapDialog from "./wrapDialog";
16
17
  import { omit } from "lodash-es";
17
18
  import { useDispatch, useSelector } from "react-redux";
package/src/index.js CHANGED
@@ -22,7 +22,8 @@ export {
22
22
  } from "./DataTable";
23
23
  export { removeCleanRows, useTableEntities } from "./DataTable/utils";
24
24
 
25
- export { getIdOrCodeOrIndex, useDeepEqualMemo } from "./DataTable/utils";
25
+ export { useDeepEqualMemo } from "./utils/hooks";
26
+ export { getIdOrCodeOrIndex } from "./DataTable/utils";
26
27
  export { default as convertSchema } from "./DataTable/utils/convertSchema";
27
28
  export { default as Loading } from "./Loading";
28
29
  export { throwFormError } from "./throwFormError";
@@ -0,0 +1 @@
1
+ export { useDeepEqualMemo } from "./useDeepEqualMemo";
@@ -0,0 +1,10 @@
1
+ import { isEqual } from "lodash-es";
2
+ import { useRef } from "react";
3
+
4
+ export const useDeepEqualMemo = value => {
5
+ const ref = useRef();
6
+ if (!isEqual(value, ref.current)) {
7
+ ref.current = value;
8
+ }
9
+ return ref.current;
10
+ };
@@ -0,0 +1,9 @@
1
+ import { useEffect, useRef } from "react";
2
+
3
+ export const useStableReference = value => {
4
+ const ref = useRef();
5
+ useEffect(() => {
6
+ ref.current = value;
7
+ }, [value]);
8
+ return ref;
9
+ };
@@ -0,0 +1 @@
1
+ export { useDeepEqualMemo } from './useDeepEqualMemo';
@@ -0,0 +1 @@
1
+ export function useDeepEqualMemo(value: any): undefined;
@@ -0,0 +1 @@
1
+ export function useStableReference(value: any): import('../../../../../node_modules/react').MutableRefObject<undefined>;
@@ -1 +0,0 @@
1
- export function withAbstractWrapper(ComponentToWrap: any, opts?: {}): (props: any) => import("react/jsx-runtime").JSX.Element;
@@ -1,388 +0,0 @@
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
- };