@teselagen/ui 0.7.34 → 0.7.36

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.
Files changed (161) hide show
  1. package/isBeingCalledExcessively.js +2 -0
  2. package/package.json +1 -1
  3. package/style.css +26 -10
  4. package/DataTable/utils/filterLocalEntitiesToHasura.d.ts +0 -5
  5. package/DataTable/utils/initializeHasuraWhereAndFilter.d.ts +0 -2
  6. package/DataTable/utils/tableQueryParamsToHasuraClauses.d.ts +0 -26
  7. package/src/AdvancedOptions.js +0 -33
  8. package/src/AdvancedOptions.spec.js +0 -26
  9. package/src/AssignDefaultsModeContext.js +0 -22
  10. package/src/AsyncValidateFieldSpinner/index.js +0 -12
  11. package/src/BlueprintError/index.js +0 -14
  12. package/src/BounceLoader/index.js +0 -16
  13. package/src/BounceLoader/style.css +0 -45
  14. package/src/CollapsibleCard/index.js +0 -68
  15. package/src/CollapsibleCard/style.css +0 -23
  16. package/src/DNALoader/index.js +0 -20
  17. package/src/DNALoader/style.css +0 -251
  18. package/src/DataTable/CellDragHandle.js +0 -132
  19. package/src/DataTable/ColumnFilterMenu.js +0 -62
  20. package/src/DataTable/Columns.js +0 -979
  21. package/src/DataTable/DisabledLoadingComponent.js +0 -15
  22. package/src/DataTable/DisplayOptions.js +0 -199
  23. package/src/DataTable/DropdownCell.js +0 -61
  24. package/src/DataTable/EditableCell.js +0 -44
  25. package/src/DataTable/FilterAndSortMenu.js +0 -388
  26. package/src/DataTable/PagingTool.js +0 -225
  27. package/src/DataTable/RenderCell.js +0 -191
  28. package/src/DataTable/SearchBar.js +0 -69
  29. package/src/DataTable/SortableColumns.js +0 -100
  30. package/src/DataTable/TableFormTrackerContext.js +0 -10
  31. package/src/DataTable/ThComponent.js +0 -44
  32. package/src/DataTable/dataTableEnhancer.js +0 -41
  33. package/src/DataTable/defaultFormatters.js +0 -32
  34. package/src/DataTable/defaultValidators.js +0 -40
  35. package/src/DataTable/editCellHelper.js +0 -44
  36. package/src/DataTable/getCellVal.js +0 -20
  37. package/src/DataTable/getVals.js +0 -8
  38. package/src/DataTable/index.js +0 -3209
  39. package/src/DataTable/isTruthy.js +0 -12
  40. package/src/DataTable/isValueEmpty.js +0 -3
  41. package/src/DataTable/style.css +0 -608
  42. package/src/DataTable/utils/convertSchema.js +0 -69
  43. package/src/DataTable/utils/filterLocalEntitiesToHasura.js +0 -236
  44. package/src/DataTable/utils/filterLocalEntitiesToHasura.test.js +0 -587
  45. package/src/DataTable/utils/formatPasteData.js +0 -16
  46. package/src/DataTable/utils/getAllRows.js +0 -11
  47. package/src/DataTable/utils/getCellCopyText.js +0 -7
  48. package/src/DataTable/utils/getCellInfo.js +0 -36
  49. package/src/DataTable/utils/getFieldPathToField.js +0 -7
  50. package/src/DataTable/utils/getIdOrCodeOrIndex.js +0 -9
  51. package/src/DataTable/utils/getLastSelectedEntity.js +0 -11
  52. package/src/DataTable/utils/getNewEntToSelect.js +0 -25
  53. package/src/DataTable/utils/getRowCopyText.js +0 -28
  54. package/src/DataTable/utils/getTableConfigFromStorage.js +0 -5
  55. package/src/DataTable/utils/handleCopyColumn.js +0 -21
  56. package/src/DataTable/utils/handleCopyHelper.js +0 -15
  57. package/src/DataTable/utils/handleCopyRows.js +0 -23
  58. package/src/DataTable/utils/handleCopyTable.js +0 -16
  59. package/src/DataTable/utils/index.js +0 -55
  60. package/src/DataTable/utils/initializeHasuraWhereAndFilter.js +0 -26
  61. package/src/DataTable/utils/isBottomRightCornerOfRectangle.js +0 -20
  62. package/src/DataTable/utils/isEntityClean.js +0 -15
  63. package/src/DataTable/utils/primarySelectedValue.js +0 -1
  64. package/src/DataTable/utils/queryParams.js +0 -350
  65. package/src/DataTable/utils/removeCleanRows.js +0 -22
  66. package/src/DataTable/utils/rowClick.js +0 -181
  67. package/src/DataTable/utils/selection.js +0 -8
  68. package/src/DataTable/utils/tableQueryParamsToHasuraClauses.js +0 -253
  69. package/src/DataTable/utils/tableQueryParamsToHasuraClauses.test.js +0 -206
  70. package/src/DataTable/utils/useTableEntities.js +0 -38
  71. package/src/DataTable/utils/utils.js +0 -37
  72. package/src/DataTable/utils/withSelectedEntities.js +0 -65
  73. package/src/DataTable/utils/withTableParams.js +0 -288
  74. package/src/DataTable/validateTableWideErrors.js +0 -160
  75. package/src/DataTable/viewColumn.js +0 -97
  76. package/src/DialogFooter/index.js +0 -86
  77. package/src/DialogFooter/style.css +0 -9
  78. package/src/DropdownButton.js +0 -36
  79. package/src/FillWindow.css +0 -6
  80. package/src/FillWindow.js +0 -69
  81. package/src/FormComponents/FormSeparator.js +0 -9
  82. package/src/FormComponents/LoadingDots.js +0 -14
  83. package/src/FormComponents/Uploader.js +0 -1278
  84. package/src/FormComponents/getNewName.js +0 -31
  85. package/src/FormComponents/index.js +0 -1266
  86. package/src/FormComponents/itemUpload.js +0 -84
  87. package/src/FormComponents/sortify.js +0 -73
  88. package/src/FormComponents/style.css +0 -275
  89. package/src/FormComponents/tryToMatchSchemas.js +0 -264
  90. package/src/FormComponents/utils.js +0 -6
  91. package/src/HotkeysDialog/index.js +0 -79
  92. package/src/HotkeysDialog/style.css +0 -54
  93. package/src/InfoHelper/index.js +0 -78
  94. package/src/InfoHelper/style.css +0 -7
  95. package/src/IntentText/index.js +0 -18
  96. package/src/Loading/index.js +0 -70
  97. package/src/Loading/style.css +0 -4
  98. package/src/MatchHeaders.js +0 -234
  99. package/src/MenuBar/index.js +0 -423
  100. package/src/MenuBar/style.css +0 -45
  101. package/src/PromptUnsavedChanges/index.js +0 -38
  102. package/src/ResizableDraggableDialog/index.js +0 -141
  103. package/src/ResizableDraggableDialog/style.css +0 -42
  104. package/src/ScrollToTop/index.js +0 -72
  105. package/src/SimpleStepViz.js +0 -22
  106. package/src/Tag.js +0 -112
  107. package/src/TagSelect/index.js +0 -69
  108. package/src/TagSelect/style.css +0 -13
  109. package/src/TgHtmlSelect/index.js +0 -20
  110. package/src/TgSelect/index.js +0 -537
  111. package/src/TgSelect/style.css +0 -61
  112. package/src/TgSuggest/index.js +0 -124
  113. package/src/Timeline/TimelineEvent.js +0 -31
  114. package/src/Timeline/index.js +0 -15
  115. package/src/Timeline/style.css +0 -29
  116. package/src/UploadCsvWizard.css +0 -4
  117. package/src/UploadCsvWizard.js +0 -719
  118. package/src/autoTooltip.js +0 -201
  119. package/src/constants.js +0 -1
  120. package/src/customIcons.js +0 -361
  121. package/src/enhancers/withDialog/index.js +0 -196
  122. package/src/enhancers/withDialog/tg_modalState.js +0 -47
  123. package/src/enhancers/withField.js +0 -20
  124. package/src/enhancers/withFields.js +0 -11
  125. package/src/enhancers/withLocalStorage.js +0 -11
  126. package/src/index.js +0 -88
  127. package/src/rerenderOnWindowResize.js +0 -26
  128. package/src/showAppSpinner.js +0 -12
  129. package/src/showConfirmationDialog/index.js +0 -148
  130. package/src/showDialogOnDocBody.js +0 -33
  131. package/src/style.css +0 -265
  132. package/src/throwFormError.js +0 -16
  133. package/src/toastr.js +0 -148
  134. package/src/typeToCommonType.js +0 -6
  135. package/src/useDialog.js +0 -63
  136. package/src/utils/adHoc.js +0 -10
  137. package/src/utils/basicHandleActionsWithFullState.js +0 -14
  138. package/src/utils/browserUtils.js +0 -3
  139. package/src/utils/combineReducersWithFullState.js +0 -14
  140. package/src/utils/commandControls.js +0 -82
  141. package/src/utils/commandUtils.js +0 -112
  142. package/src/utils/determineBlackOrWhiteTextColor.js +0 -4
  143. package/src/utils/getDayjsFormatter.js +0 -35
  144. package/src/utils/getTextFromEl.js +0 -28
  145. package/src/utils/handlerHelpers.js +0 -24
  146. package/src/utils/hooks/index.js +0 -1
  147. package/src/utils/hooks/useDeepEqualMemo.js +0 -15
  148. package/src/utils/hooks/useStableReference.js +0 -9
  149. package/src/utils/hotkeyUtils.js +0 -131
  150. package/src/utils/isBeingCalledExcessively.js +0 -24
  151. package/src/utils/menuUtils.js +0 -433
  152. package/src/utils/popoverOverflowModifiers.js +0 -11
  153. package/src/utils/pureNoFunc.js +0 -31
  154. package/src/utils/renderOnDoc.js +0 -32
  155. package/src/utils/showProgressToast.js +0 -22
  156. package/src/utils/tagUtils.js +0 -45
  157. package/src/utils/tgFormValues.js +0 -35
  158. package/src/utils/useTraceUpdate.js +0 -19
  159. package/src/utils/withSelectTableRecords.js +0 -43
  160. package/src/utils/withStore.js +0 -10
  161. package/src/wrapDialog.js +0 -116
@@ -1,37 +0,0 @@
1
- import { getIdOrCodeOrIndex } from "./getIdOrCodeOrIndex";
2
-
3
- export const getFieldPathToIndex = schema => {
4
- const fieldToIndex = {};
5
- schema.fields.forEach((f, i) => {
6
- fieldToIndex[f.path] = i;
7
- });
8
- return fieldToIndex;
9
- };
10
-
11
- export const defaultParsePaste = str => {
12
- return str.split(/\r\n|\n|\r/).map(row => row.split("\t"));
13
- };
14
-
15
- export const getEntityIdToEntity = entities => {
16
- const entityIdToEntity = {};
17
- entities.forEach((e, i) => {
18
- entityIdToEntity[getIdOrCodeOrIndex(e, i)] = { e, i };
19
- });
20
- return entityIdToEntity;
21
- };
22
-
23
- const endsWithNumber = str => {
24
- return /[0-9]+$/.test(str);
25
- };
26
-
27
- export const getNumberStrAtEnd = str => {
28
- if (endsWithNumber(str)) {
29
- return str.match(/[0-9]+$/)[0];
30
- }
31
-
32
- return null;
33
- };
34
-
35
- export const stripNumberAtEnd = str => {
36
- return str?.replace?.(getNumberStrAtEnd(str), "");
37
- };
@@ -1,65 +0,0 @@
1
- import { formValueSelector } from "redux-form";
2
- import { reduce } from "lodash-es";
3
- import { connect } from "react-redux";
4
- /**
5
- * @param {*string} formName
6
- * @param {*string} formName
7
- * @param {*string} formName
8
- * @param {*string} ...etc
9
- * adds a new prop `${formName}SelectedEntities` eg sequenceTableSelectedEntities
10
- */
11
- export default function withSelectedEntities(...formNames) {
12
- if (!formNames.length) {
13
- throw new Error(
14
- "You need to pass at least one arg to withSelectedEntities"
15
- );
16
- }
17
- if (typeof formNames[0] === "string") {
18
- //NEW WAY
19
- return connect(state => {
20
- return formNames.reduce((acc, formName) => {
21
- acc[formName + "SelectedEntities"] = getRecordsFromReduxForm(
22
- state,
23
- formName
24
- );
25
- return acc;
26
- }, {});
27
- });
28
- } else {
29
- //OLD WAY:
30
- const { formName, name } = formNames[0];
31
- if (!formName) {
32
- throw new Error(
33
- "Please pass a {formName} option when using withSelectedEntities"
34
- );
35
- }
36
- return connect(state => {
37
- return {
38
- [name || "selectedEntities"]: getRecordsFromReduxForm(state, formName)
39
- };
40
- });
41
- }
42
- }
43
-
44
- export function getRecordsFromReduxForm(state, formName) {
45
- const selector = formValueSelector(formName);
46
- return getRecordsFromIdMap(selector(state, "reduxFormSelectedEntityIdMap"));
47
- }
48
-
49
- export function getRecordsFromIdMap(idMap = {}) {
50
- return reduce(
51
- idMap,
52
- (acc, item) => {
53
- if (item && item.entity) acc.push(item);
54
- return acc;
55
- },
56
- []
57
- )
58
- .sort((a, b) => a.rowIndex - b.rowIndex)
59
- .map(item => item.entity);
60
- }
61
-
62
- export function getSelectedEntities(storeOrState, formName) {
63
- const state = storeOrState.getState ? storeOrState.getState() : storeOrState;
64
- return getRecordsFromReduxForm(state, formName);
65
- }
@@ -1,288 +0,0 @@
1
- import React, { useCallback, useMemo } from "react";
2
- import { change as _change, formValueSelector } from "redux-form";
3
- import { useDispatch, useSelector } from "react-redux";
4
- import convertSchema from "./convertSchema";
5
- import {
6
- makeDataTableHandlers,
7
- getQueryParams,
8
- setCurrentParamsOnUrl,
9
- getCurrentParamsFromUrl
10
- } from "./queryParams";
11
- import { withRouter } from "react-router-dom";
12
- import getTableConfigFromStorage from "./getTableConfigFromStorage";
13
- import { useDeepEqualMemo } from "../../utils/hooks/useDeepEqualMemo";
14
- import { branch, compose } from "recompose";
15
- import { getCCDisplayName } from "./tableQueryParamsToHasuraClauses";
16
-
17
- /**
18
- * Note all these options can be passed at Design Time or at Runtime (like reduxForm())
19
- *
20
- * @export
21
- *
22
- * @param {compOrOpts} compOrOpts
23
- * @typedef {object} compOrOpts
24
- * @property {*string} formName - required unique identifier for the table
25
- * @property {Object | Function} schema - The data table schema or a function returning it. The function wll be called with props as the argument.
26
- * @property {boolean} urlConnected - whether the table should connect to/update the URL
27
- * @property {boolean} withSelectedEntities - whether or not to pass the selected entities
28
- * @property {boolean} isCodeModel - whether the model is keyed by code instead of id in the db
29
- * @property {object} defaults - tableParam defaults such as pageSize, filter, etc
30
- * @property {boolean} noOrderError - won't console an error if an order is not found on schema
31
- */
32
- export const useTableParams = props => {
33
- const {
34
- additionalFilter,
35
- controlled_pageSize,
36
- defaults: _defaults,
37
- doNotCoercePageSize,
38
- entities,
39
- formName = "tgDataTable",
40
- history,
41
- initialValues,
42
- isCodeModel,
43
- isInfinite,
44
- isLocalCall = false,
45
- isSimple,
46
- noForm,
47
- noOrderError,
48
- onlyOneFilter,
49
- orderByFirstColumn,
50
- pageSize,
51
- schema,
52
- syncDisplayOptionsToDb,
53
- tableParams: _tableParams,
54
- urlConnected,
55
- withDisplayOptions,
56
- withPaging,
57
- withSelectedEntities
58
- } = props;
59
-
60
- const defaults = useMemo(
61
- () => ({
62
- pageSize: controlled_pageSize || 25,
63
- order: [], //[-name, statusCode] //an array of camelCase display names with - sign to denote reverse
64
- searchTerm: "",
65
- page: 1,
66
- filters: [
67
- //filters look like this:
68
- // {
69
- // selectedFilter: 'textContains', //camel case
70
- // filterOn: ccDisplayName, //camel case display name if available and string, otherwise path
71
- // filterValue: 'thomas',
72
- // }
73
- ],
74
- ..._defaults
75
- }),
76
- [_defaults, controlled_pageSize]
77
- );
78
-
79
- const convertedSchema = useMemo(() => convertSchema(schema), [schema]);
80
-
81
- if (isLocalCall) {
82
- if (!noForm && (!formName || formName === "tgDataTable")) {
83
- console.error(
84
- "Please pass a unique 'formName' prop to the locally connected <DataTable/> component with schema: ",
85
- schema
86
- );
87
- }
88
- if (orderByFirstColumn && !defaults?.order?.length) {
89
- defaults.order = [getCCDisplayName(convertedSchema.fields[0])];
90
- }
91
- } else {
92
- //in user instantiated withTableParams() call
93
- if (!formName || formName === "tgDataTable") {
94
- console.error(
95
- "Please pass a unique 'formName' prop to the withTableParams() with schema: ",
96
- schema
97
- );
98
- }
99
- }
100
-
101
- const {
102
- reduxFormQueryParams: _reduxFormQueryParams = {},
103
- reduxFormSelectedEntityIdMap: _reduxFormSelectedEntityIdMap = {}
104
- } = useSelector(state =>
105
- formValueSelector(formName)(
106
- state,
107
- "reduxFormQueryParams",
108
- "reduxFormSelectedEntityIdMap"
109
- )
110
- );
111
-
112
- // We want to make sure we don't rerender everything unnecessary
113
- // with redux-forms we tend to do unnecessary renders
114
- const reduxFormQueryParams = useDeepEqualMemo(_reduxFormQueryParams);
115
- const reduxFormSelectedEntityIdMap = useDeepEqualMemo(
116
- _reduxFormSelectedEntityIdMap
117
- );
118
-
119
- const _currentParams = useMemo(() => {
120
- const tmp =
121
- (urlConnected
122
- ? getCurrentParamsFromUrl(history?.location) //important to use history location and not ownProps.location because for some reason the location path lags one render behind!!
123
- : reduxFormQueryParams) || {};
124
-
125
- return tmp;
126
- }, [history?.location, reduxFormQueryParams, urlConnected]);
127
-
128
- const selectedEntities = useMemo(
129
- () =>
130
- withSelectedEntities
131
- ? Object.values(reduxFormSelectedEntityIdMap)
132
- .sort((a, b) => a.rowIndex - b.rowIndex)
133
- .map(item => item.entity)
134
- : undefined,
135
- [reduxFormSelectedEntityIdMap, withSelectedEntities]
136
- );
137
-
138
- const currentParams = useDeepEqualMemo(_currentParams);
139
-
140
- const defaultsToUse = useMemo(() => {
141
- const _tableConfig = getTableConfigFromStorage(formName);
142
- const userSetPageSize =
143
- _tableConfig?.userSetPageSize &&
144
- parseInt(_tableConfig.userSetPageSize, 10);
145
- let _defaultsToUse = defaults;
146
- if (!syncDisplayOptionsToDb && userSetPageSize) {
147
- _defaultsToUse = _defaultsToUse || {};
148
- _defaultsToUse.pageSize = userSetPageSize;
149
- }
150
-
151
- return _defaultsToUse;
152
- }, [defaults, formName, syncDisplayOptionsToDb]);
153
-
154
- const passingProps = useMemo(
155
- () => ({
156
- formName: "tgDataTable",
157
- ...props,
158
- pageSize: controlled_pageSize || pageSize,
159
- defaults: defaultsToUse,
160
- location: history?.location
161
- }),
162
- // We don't want to rerender this every time a prop changes
163
- // eslint-disable-next-line react-hooks/exhaustive-deps
164
- [controlled_pageSize, defaultsToUse, pageSize, history?.location]
165
- );
166
-
167
- const queryParams = useMemo(() => {
168
- return getQueryParams({
169
- doNotCoercePageSize,
170
- currentParams,
171
- entities, // for local table
172
- urlConnected,
173
- defaults: defaultsToUse,
174
- schema: convertedSchema,
175
- isInfinite: isInfinite || (isSimple && !withPaging),
176
- isLocalCall,
177
- additionalFilter,
178
- noOrderError,
179
- isCodeModel,
180
- ownProps: passingProps
181
- });
182
- }, [
183
- additionalFilter,
184
- passingProps,
185
- doNotCoercePageSize,
186
- currentParams,
187
- entities,
188
- urlConnected,
189
- defaultsToUse,
190
- convertedSchema,
191
- isInfinite,
192
- isSimple,
193
- withPaging,
194
- isLocalCall,
195
- noOrderError,
196
- isCodeModel
197
- ]);
198
-
199
- const dispatch = useDispatch();
200
- const change = useCallback(
201
- (...args) => dispatch(_change(formName, ...args)),
202
- [dispatch, formName]
203
- );
204
-
205
- const setNewParams = useCallback(
206
- newParams => {
207
- // we always will update the redux params as a workaround for withRouter not always working
208
- // if inside a redux-connected container https://github.com/ReactTraining/react-router/issues/5037
209
- change("reduxFormQueryParams", prev => {
210
- let tmp = newParams;
211
- if (typeof tmp === "function") tmp = newParams(prev);
212
- urlConnected && setCurrentParamsOnUrl(tmp, history?.replace);
213
- return tmp;
214
- });
215
- },
216
- [change, history?.replace, urlConnected]
217
- );
218
-
219
- const dispatchProps = useMemo(
220
- () =>
221
- makeDataTableHandlers({
222
- setNewParams,
223
- defaults,
224
- onlyOneFilter
225
- }),
226
- [defaults, onlyOneFilter, setNewParams]
227
- );
228
-
229
- const tableParams = useMemo(
230
- () => ({
231
- changeFormValue: (...args) => change(...args),
232
- selectedEntities,
233
- ..._tableParams,
234
- formName,
235
- initialValues,
236
- isLocalCall,
237
- schema,
238
- currentParams,
239
- withDisplayOptions,
240
- ...queryParams,
241
- ...dispatchProps,
242
- form: formName, //this will override the default redux form name
243
- isTableParamsConnected: true //let the table know not to do local sorting/filtering etc.
244
- }),
245
- [
246
- _tableParams,
247
- change,
248
- currentParams,
249
- dispatchProps,
250
- formName,
251
- initialValues,
252
- isLocalCall,
253
- queryParams,
254
- schema,
255
- selectedEntities,
256
- withDisplayOptions
257
- ]
258
- );
259
-
260
- return {
261
- isLocalCall,
262
- schema,
263
- ...queryParams,
264
- ...(withSelectedEntities &&
265
- typeof withSelectedEntities === "string" && {
266
- [withSelectedEntities]: selectedEntities
267
- }),
268
- currentParams,
269
- selectedEntities,
270
- tableParams,
271
- urlConnected
272
- };
273
- };
274
-
275
- const withTableParams = topLevelOptions =>
276
- compose(
277
- //don't use withRouter if noRouter is passed!
278
- branch(({ noRouter }) => !noRouter, withRouter),
279
- Comp => props => {
280
- const tableParams = useTableParams({
281
- ...topLevelOptions,
282
- ...props
283
- });
284
- return <Comp {...props} {...tableParams} />;
285
- }
286
- );
287
-
288
- export default withTableParams;
@@ -1,160 +0,0 @@
1
- import { getIdOrCodeOrIndex } from "./utils";
2
- import { getCellVal } from "./getCellVal";
3
- import { forEach, isArray } from "lodash-es";
4
- import { startCase } from "lodash-es";
5
- import { camelCase } from "lodash-es";
6
-
7
- const uniqueMsg = "This value must be unique";
8
- export function validateTableWideErrors({
9
- entities,
10
- schema,
11
- optionalUserSchema,
12
- newCellValidate
13
- }) {
14
- forEach(newCellValidate, (err, cellId) => {
15
- if (err && err._isTableWideError) {
16
- delete newCellValidate[cellId];
17
- }
18
- });
19
- if (schema.tableWideValidation) {
20
- const newErrs = schema.tableWideValidation({
21
- entities
22
- });
23
- forEach(newErrs, (err, cellId) => {
24
- newCellValidate[cellId] = {
25
- message: err,
26
- _isTableWideError: true
27
- };
28
- });
29
- }
30
- const displayNameMap = {};
31
- const fieldUpperToPath = {};
32
-
33
- forEach(schema.fields, f => {
34
- fieldUpperToPath[f.path.toUpperCase()] = f.path;
35
- displayNameMap[f.path] = f.displayName || startCase(camelCase(f.path));
36
- });
37
- function getDisplayName(path) {
38
- return displayNameMap[path] || startCase(camelCase(path));
39
- }
40
-
41
- if (schema.requireAtLeastOneOf) {
42
- //make sure at least one of the required fields is present
43
- (isArray(schema.requireAtLeastOneOf[0])
44
- ? schema.requireAtLeastOneOf
45
- : [schema.requireAtLeastOneOf]
46
- ).forEach(alo => {
47
- entities.forEach(entity => {
48
- if (!alo.some(path => getCellVal(entity, path))) {
49
- alo.forEach(path => {
50
- const cellId = `${getIdOrCodeOrIndex(entity)}:${path}`;
51
- newCellValidate[cellId] = {
52
- message: `At least one of these fields must be present - ${alo
53
- .map(getDisplayName)
54
- .join(", ")}`,
55
- _isTableWideError: true
56
- };
57
- });
58
- }
59
- });
60
- });
61
- }
62
- if (schema.requireExactlyOneOf) {
63
- (isArray(schema.requireExactlyOneOf[0])
64
- ? schema.requireExactlyOneOf
65
- : [schema.requireExactlyOneOf]
66
- ).forEach(reqs => {
67
- entities.forEach(entity => {
68
- const present = reqs.filter(path => getCellVal(entity, path));
69
- if (present.length !== 1) {
70
- reqs.forEach(path => {
71
- const cellId = `${getIdOrCodeOrIndex(entity)}:${path}`;
72
- const fields = reqs.map(getDisplayName).join(", ");
73
- const err = {
74
- message:
75
- present.length === 0
76
- ? `One of these fields is required - ${fields}`
77
- : `Cannot have more than one of these fields - ${fields}`,
78
- _isTableWideError: true
79
- };
80
- newCellValidate[cellId] = err;
81
- });
82
- }
83
- });
84
- });
85
- }
86
-
87
- const requireIfs = [];
88
- schema.fields.forEach(col => {
89
- const { path, requireIf } = col;
90
- if (requireIf) {
91
- const requireIfPath = fieldUpperToPath[requireIf.toUpperCase()];
92
- requireIfs.push([requireIfPath, path]);
93
- }
94
- });
95
- requireIfs.forEach(([requireIfPath, path]) => {
96
- entities.forEach(entity => {
97
- const requireIfVal = getCellVal(entity, requireIfPath);
98
- const pathVal = getCellVal(entity, path);
99
- if (requireIfVal && !pathVal) {
100
- const cellId = `${getIdOrCodeOrIndex(entity)}:${path}`;
101
- newCellValidate[cellId] = {
102
- message: `This field is required if ${displayNameMap[requireIfPath]} is present`,
103
- _isTableWideError: true
104
- };
105
- }
106
- });
107
- });
108
- if (schema.requireAllOrNone) {
109
- (isArray(schema.requireAllOrNone[0])
110
- ? schema.requireAllOrNone
111
- : [schema.requireAllOrNone]
112
- ).forEach(reqs => {
113
- entities.forEach(entity => {
114
- const present = reqs.filter(path => getCellVal(entity, path));
115
- if (present.length && present.length !== reqs.length) {
116
- reqs.forEach(path => {
117
- const cellId = `${getIdOrCodeOrIndex(entity)}:${path}`;
118
- const fields = reqs.map(getDisplayName).join(", ");
119
- const err = {
120
- message: `Please specify either ALL of the following fields or NONE of them - ${fields}`,
121
- _isTableWideError: true
122
- };
123
- newCellValidate[cellId] = err;
124
- });
125
- }
126
- });
127
- });
128
- }
129
-
130
- schema.fields.forEach(col => {
131
- let { path, isUnique } = col;
132
- if (isUnique) {
133
- if (optionalUserSchema) {
134
- path = col.matches[0].item.path;
135
- }
136
- const existingVals = {};
137
- entities.forEach(entity => {
138
- const val = getCellVal(entity, path, col);
139
- if (!val) return;
140
- const cellId = `${getIdOrCodeOrIndex(entity)}:${path}`;
141
- if (existingVals[val]) {
142
- newCellValidate[cellId] = {
143
- message: uniqueMsg,
144
- _isTableWideError: true
145
- };
146
- newCellValidate[existingVals[val]] = {
147
- message: uniqueMsg,
148
- _isTableWideError: true
149
- };
150
- } else {
151
- if (newCellValidate[cellId] === uniqueMsg) {
152
- delete newCellValidate[cellId];
153
- }
154
- existingVals[val] = cellId;
155
- }
156
- });
157
- }
158
- });
159
- return newCellValidate;
160
- }
@@ -1,97 +0,0 @@
1
- import React from "react";
2
- import { Icon, Button, Tooltip } from "@blueprintjs/core";
3
- import { reduce } from "lodash-es";
4
-
5
- export const viewColumn = {
6
- width: 35,
7
- noEllipsis: true,
8
- hideInMenu: true,
9
- immovable: true,
10
- type: "action",
11
- render: () => {
12
- return <Icon className="dt-eyeIcon" icon="eye-open" />;
13
- }
14
- };
15
-
16
- export const openColumn = ({ onDoubleClick, history }) => ({
17
- ...viewColumn,
18
- render: (val, record, rowInfo) => {
19
- return (
20
- <Tooltip content="Open">
21
- <Button
22
- onClick={e => {
23
- e.stopPropagation();
24
- onDoubleClick &&
25
- onDoubleClick(rowInfo.original, rowInfo.index, history);
26
- }}
27
- minimal
28
- small
29
- className="dt-eyeIcon"
30
- icon="document-open"
31
- />
32
- </Tooltip>
33
- );
34
- }
35
- });
36
-
37
- export const multiViewColumn = {
38
- ...viewColumn,
39
- columnHeader: ({ recordIdToIsVisibleMap, setRecordIdToIsVisibleMap }) => {
40
- const allVisible = reduce(
41
- recordIdToIsVisibleMap,
42
- (acc, val) => acc && val,
43
- true
44
- );
45
- return (
46
- <Tooltip content={allVisible ? "Hide All" : "Show All"}>
47
- <Button
48
- className={`showHideAllButton-${allVisible ? "visible" : "hidden"}`}
49
- minimal
50
- onClick={() => {
51
- setRecordIdToIsVisibleMap(
52
- reduce(
53
- recordIdToIsVisibleMap,
54
- (acc, val, key) => {
55
- acc[key] = !allVisible;
56
- return acc;
57
- },
58
- {}
59
- )
60
- );
61
- }}
62
- icon={allVisible ? "eye-open" : "eye-off"}
63
- />
64
- </Tooltip>
65
- );
66
- },
67
- render: (
68
- val,
69
- record,
70
- row,
71
- { recordIdToIsVisibleMap, setRecordIdToIsVisibleMap }
72
- ) => {
73
- if (!recordIdToIsVisibleMap) {
74
- return null;
75
- }
76
- const isVisible = recordIdToIsVisibleMap[record.id];
77
- return (
78
- <Tooltip content={isVisible ? "Hide" : "Show"}>
79
- <Button
80
- onClick={e => {
81
- e.stopPropagation();
82
- e.preventDefault();
83
- setRecordIdToIsVisibleMap(
84
- Object.assign({}, recordIdToIsVisibleMap, {
85
- [record.id]: !isVisible
86
- })
87
- );
88
- }}
89
- minimal
90
- small
91
- className={`showHideButton-${isVisible ? "visible" : "hidden"}-${record.id}`}
92
- icon={isVisible ? "eye-open" : "eye-off"}
93
- />
94
- </Tooltip>
95
- );
96
- }
97
- };