@teselagen/ui 0.7.31 → 0.7.33-beta.1

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 (164) hide show
  1. package/DataTable/utils/filterLocalEntitiesToHasura.d.ts +5 -0
  2. package/DataTable/utils/initializeHasuraWhereAndFilter.d.ts +2 -0
  3. package/DataTable/utils/queryParams.d.ts +8 -12
  4. package/DataTable/utils/simplifyHasuraWhere.d.ts +1 -0
  5. package/DataTable/utils/tableQueryParamsToHasuraClauses.d.ts +14 -0
  6. package/{src/DataTable/FilterAndSortMenu.js → FilterAndSortMenu.js} +27 -30
  7. package/filterLocalEntitiesToHasura.js +216 -0
  8. package/index.cjs.js +695 -968
  9. package/index.d.ts +1 -0
  10. package/index.es.js +695 -968
  11. package/initializeHasuraWhereAndFilter.js +27 -0
  12. package/{src/utils/isBeingCalledExcessively.js → isBeingCalledExcessively.js} +0 -1
  13. package/package.json +1 -1
  14. package/queryParams.js +336 -0
  15. package/simplifyHasuraWhere.js +80 -0
  16. package/tableQueryParamsToHasuraClauses.js +113 -0
  17. package/{src/DataTable/utils/withTableParams.js → withTableParams.js} +1 -14
  18. package/src/AdvancedOptions.spec.js +0 -26
  19. package/src/AsyncValidateFieldSpinner/index.js +0 -12
  20. package/src/BlueprintError/index.js +0 -14
  21. package/src/BounceLoader/index.js +0 -16
  22. package/src/BounceLoader/style.css +0 -45
  23. package/src/CollapsibleCard/index.js +0 -68
  24. package/src/CollapsibleCard/style.css +0 -23
  25. package/src/DNALoader/index.js +0 -20
  26. package/src/DNALoader/style.css +0 -251
  27. package/src/DataTable/index.js +0 -3214
  28. package/src/DataTable/style.css +0 -608
  29. package/src/DataTable/utils/index.js +0 -55
  30. package/src/DataTable/utils/queryParams.js +0 -1058
  31. package/src/DialogFooter/index.js +0 -86
  32. package/src/DialogFooter/style.css +0 -9
  33. package/src/FormComponents/index.js +0 -1266
  34. package/src/FormComponents/style.css +0 -275
  35. package/src/FormComponents/utils.js +0 -6
  36. package/src/HotkeysDialog/index.js +0 -79
  37. package/src/HotkeysDialog/style.css +0 -54
  38. package/src/InfoHelper/index.js +0 -78
  39. package/src/InfoHelper/style.css +0 -7
  40. package/src/IntentText/index.js +0 -18
  41. package/src/Loading/index.js +0 -70
  42. package/src/Loading/style.css +0 -4
  43. package/src/MenuBar/index.js +0 -423
  44. package/src/MenuBar/style.css +0 -45
  45. package/src/PromptUnsavedChanges/index.js +0 -38
  46. package/src/ResizableDraggableDialog/index.js +0 -141
  47. package/src/ResizableDraggableDialog/style.css +0 -42
  48. package/src/ScrollToTop/index.js +0 -72
  49. package/src/TagSelect/index.js +0 -69
  50. package/src/TagSelect/style.css +0 -13
  51. package/src/TgHtmlSelect/index.js +0 -20
  52. package/src/TgSelect/index.js +0 -537
  53. package/src/TgSelect/style.css +0 -61
  54. package/src/TgSuggest/index.js +0 -124
  55. package/src/Timeline/index.js +0 -15
  56. package/src/enhancers/withDialog/index.js +0 -196
  57. package/src/index.js +0 -87
  58. package/src/showConfirmationDialog/index.js +0 -148
  59. package/src/style.css +0 -265
  60. /package/{src/AdvancedOptions.js → AdvancedOptions.js} +0 -0
  61. /package/{src/AssignDefaultsModeContext.js → AssignDefaultsModeContext.js} +0 -0
  62. /package/{src/DataTable/CellDragHandle.js → CellDragHandle.js} +0 -0
  63. /package/{src/DataTable/ColumnFilterMenu.js → ColumnFilterMenu.js} +0 -0
  64. /package/{src/DataTable/Columns.js → Columns.js} +0 -0
  65. /package/{src/DataTable/DisabledLoadingComponent.js → DisabledLoadingComponent.js} +0 -0
  66. /package/{src/DataTable/DisplayOptions.js → DisplayOptions.js} +0 -0
  67. /package/{src/DropdownButton.js → DropdownButton.js} +0 -0
  68. /package/{src/DataTable/DropdownCell.js → DropdownCell.js} +0 -0
  69. /package/{src/DataTable/EditableCell.js → EditableCell.js} +0 -0
  70. /package/{src/FillWindow.css → FillWindow.css} +0 -0
  71. /package/{src/FillWindow.js → FillWindow.js} +0 -0
  72. /package/{src/FormComponents/FormSeparator.js → FormSeparator.js} +0 -0
  73. /package/{src/FormComponents/LoadingDots.js → LoadingDots.js} +0 -0
  74. /package/{src/MatchHeaders.js → MatchHeaders.js} +0 -0
  75. /package/{src/DataTable/PagingTool.js → PagingTool.js} +0 -0
  76. /package/{src/DataTable/RenderCell.js → RenderCell.js} +0 -0
  77. /package/{src/DataTable/SearchBar.js → SearchBar.js} +0 -0
  78. /package/{src/SimpleStepViz.js → SimpleStepViz.js} +0 -0
  79. /package/{src/DataTable/SortableColumns.js → SortableColumns.js} +0 -0
  80. /package/{src/DataTable/TableFormTrackerContext.js → TableFormTrackerContext.js} +0 -0
  81. /package/{src/Tag.js → Tag.js} +0 -0
  82. /package/{src/DataTable/ThComponent.js → ThComponent.js} +0 -0
  83. /package/{src/Timeline/TimelineEvent.js → TimelineEvent.js} +0 -0
  84. /package/{src/UploadCsvWizard.css → UploadCsvWizard.css} +0 -0
  85. /package/{src/UploadCsvWizard.js → UploadCsvWizard.js} +0 -0
  86. /package/{src/FormComponents/Uploader.js → Uploader.js} +0 -0
  87. /package/{src/utils/adHoc.js → adHoc.js} +0 -0
  88. /package/{src/autoTooltip.js → autoTooltip.js} +0 -0
  89. /package/{src/utils/basicHandleActionsWithFullState.js → basicHandleActionsWithFullState.js} +0 -0
  90. /package/{src/utils/browserUtils.js → browserUtils.js} +0 -0
  91. /package/{src/utils/combineReducersWithFullState.js → combineReducersWithFullState.js} +0 -0
  92. /package/{src/utils/commandControls.js → commandControls.js} +0 -0
  93. /package/{src/utils/commandUtils.js → commandUtils.js} +0 -0
  94. /package/{src/constants.js → constants.js} +0 -0
  95. /package/{src/DataTable/utils/convertSchema.js → convertSchema.js} +0 -0
  96. /package/{src/customIcons.js → customIcons.js} +0 -0
  97. /package/{src/DataTable/dataTableEnhancer.js → dataTableEnhancer.js} +0 -0
  98. /package/{src/DataTable/defaultFormatters.js → defaultFormatters.js} +0 -0
  99. /package/{src/DataTable/defaultValidators.js → defaultValidators.js} +0 -0
  100. /package/{src/utils/determineBlackOrWhiteTextColor.js → determineBlackOrWhiteTextColor.js} +0 -0
  101. /package/{src/DataTable/editCellHelper.js → editCellHelper.js} +0 -0
  102. /package/{src/DataTable/utils/formatPasteData.js → formatPasteData.js} +0 -0
  103. /package/{src/DataTable/utils/getAllRows.js → getAllRows.js} +0 -0
  104. /package/{src/DataTable/utils/getCellCopyText.js → getCellCopyText.js} +0 -0
  105. /package/{src/DataTable/utils/getCellInfo.js → getCellInfo.js} +0 -0
  106. /package/{src/DataTable/getCellVal.js → getCellVal.js} +0 -0
  107. /package/{src/utils/getDayjsFormatter.js → getDayjsFormatter.js} +0 -0
  108. /package/{src/DataTable/utils/getFieldPathToField.js → getFieldPathToField.js} +0 -0
  109. /package/{src/DataTable/utils/getIdOrCodeOrIndex.js → getIdOrCodeOrIndex.js} +0 -0
  110. /package/{src/DataTable/utils/getLastSelectedEntity.js → getLastSelectedEntity.js} +0 -0
  111. /package/{src/DataTable/utils/getNewEntToSelect.js → getNewEntToSelect.js} +0 -0
  112. /package/{src/FormComponents/getNewName.js → getNewName.js} +0 -0
  113. /package/{src/DataTable/utils/getRowCopyText.js → getRowCopyText.js} +0 -0
  114. /package/{src/DataTable/utils/getTableConfigFromStorage.js → getTableConfigFromStorage.js} +0 -0
  115. /package/{src/utils/getTextFromEl.js → getTextFromEl.js} +0 -0
  116. /package/{src/DataTable/getVals.js → getVals.js} +0 -0
  117. /package/{src/DataTable/utils/handleCopyColumn.js → handleCopyColumn.js} +0 -0
  118. /package/{src/DataTable/utils/handleCopyHelper.js → handleCopyHelper.js} +0 -0
  119. /package/{src/DataTable/utils/handleCopyRows.js → handleCopyRows.js} +0 -0
  120. /package/{src/DataTable/utils/handleCopyTable.js → handleCopyTable.js} +0 -0
  121. /package/{src/utils/handlerHelpers.js → handlerHelpers.js} +0 -0
  122. /package/{src/utils/hotkeyUtils.js → hotkeyUtils.js} +0 -0
  123. /package/{src/utils/hooks/index.js → index.js} +0 -0
  124. /package/{src/DataTable/utils/isBottomRightCornerOfRectangle.js → isBottomRightCornerOfRectangle.js} +0 -0
  125. /package/{src/DataTable/utils/isEntityClean.js → isEntityClean.js} +0 -0
  126. /package/{src/DataTable/isTruthy.js → isTruthy.js} +0 -0
  127. /package/{src/DataTable/isValueEmpty.js → isValueEmpty.js} +0 -0
  128. /package/{src/FormComponents/itemUpload.js → itemUpload.js} +0 -0
  129. /package/{src/utils/menuUtils.js → menuUtils.js} +0 -0
  130. /package/{src/utils/popoverOverflowModifiers.js → popoverOverflowModifiers.js} +0 -0
  131. /package/{src/DataTable/utils/primarySelectedValue.js → primarySelectedValue.js} +0 -0
  132. /package/{src/utils/pureNoFunc.js → pureNoFunc.js} +0 -0
  133. /package/{src/DataTable/utils/removeCleanRows.js → removeCleanRows.js} +0 -0
  134. /package/{src/utils/renderOnDoc.js → renderOnDoc.js} +0 -0
  135. /package/{src/rerenderOnWindowResize.js → rerenderOnWindowResize.js} +0 -0
  136. /package/{src/DataTable/utils/rowClick.js → rowClick.js} +0 -0
  137. /package/{src/DataTable/utils/selection.js → selection.js} +0 -0
  138. /package/{src/showAppSpinner.js → showAppSpinner.js} +0 -0
  139. /package/{src/showDialogOnDocBody.js → showDialogOnDocBody.js} +0 -0
  140. /package/{src/utils/showProgressToast.js → showProgressToast.js} +0 -0
  141. /package/{src/FormComponents/sortify.js → sortify.js} +0 -0
  142. /package/{src/Timeline/style.css → style.css} +0 -0
  143. /package/{src/utils/tagUtils.js → tagUtils.js} +0 -0
  144. /package/{src/utils/tgFormValues.js → tgFormValues.js} +0 -0
  145. /package/{src/enhancers/withDialog/tg_modalState.js → tg_modalState.js} +0 -0
  146. /package/{src/throwFormError.js → throwFormError.js} +0 -0
  147. /package/{src/toastr.js → toastr.js} +0 -0
  148. /package/{src/FormComponents/tryToMatchSchemas.js → tryToMatchSchemas.js} +0 -0
  149. /package/{src/typeToCommonType.js → typeToCommonType.js} +0 -0
  150. /package/{src/utils/hooks/useDeepEqualMemo.js → useDeepEqualMemo.js} +0 -0
  151. /package/{src/useDialog.js → useDialog.js} +0 -0
  152. /package/{src/utils/hooks/useStableReference.js → useStableReference.js} +0 -0
  153. /package/{src/DataTable/utils/useTableEntities.js → useTableEntities.js} +0 -0
  154. /package/{src/utils/useTraceUpdate.js → useTraceUpdate.js} +0 -0
  155. /package/{src/DataTable/utils/utils.js → utils.js} +0 -0
  156. /package/{src/DataTable/validateTableWideErrors.js → validateTableWideErrors.js} +0 -0
  157. /package/{src/DataTable/viewColumn.js → viewColumn.js} +0 -0
  158. /package/{src/enhancers/withField.js → withField.js} +0 -0
  159. /package/{src/enhancers/withFields.js → withFields.js} +0 -0
  160. /package/{src/enhancers/withLocalStorage.js → withLocalStorage.js} +0 -0
  161. /package/{src/utils/withSelectTableRecords.js → withSelectTableRecords.js} +0 -0
  162. /package/{src/DataTable/utils/withSelectedEntities.js → withSelectedEntities.js} +0 -0
  163. /package/{src/utils/withStore.js → withStore.js} +0 -0
  164. /package/{src/wrapDialog.js → wrapDialog.js} +0 -0
@@ -1,3214 +0,0 @@
1
- import React, {
2
- useEffect,
3
- useRef,
4
- useMemo,
5
- useState,
6
- useCallback,
7
- useContext
8
- } from "react";
9
- import {
10
- invert,
11
- toNumber,
12
- isEmpty,
13
- min,
14
- max,
15
- camelCase,
16
- startCase,
17
- noop,
18
- cloneDeep,
19
- keyBy,
20
- omit,
21
- forEach,
22
- lowerCase,
23
- get,
24
- omitBy,
25
- times,
26
- toArray,
27
- isFunction,
28
- isEqual,
29
- every,
30
- some
31
- } from "lodash-es";
32
- import {
33
- Button,
34
- Menu,
35
- MenuItem,
36
- ContextMenu,
37
- Icon,
38
- Intent,
39
- Callout,
40
- Tooltip,
41
- useHotkeys
42
- } from "@blueprintjs/core";
43
- import { arrayMove } from "@dnd-kit/sortable";
44
- import classNames from "classnames";
45
- import scrollIntoView from "dom-scroll-into-view";
46
- import ReactTable from "@teselagen/react-table";
47
- import immer, { produceWithPatches, enablePatches, applyPatches } from "immer";
48
- import papaparse from "papaparse";
49
- import { useDispatch, useSelector } from "react-redux";
50
- import { ThComponent } from "./ThComponent";
51
- import {
52
- defaultParsePaste,
53
- formatPasteData,
54
- getAllRows,
55
- getCellCopyText,
56
- getCellInfo,
57
- getEntityIdToEntity,
58
- getFieldPathToIndex,
59
- getIdOrCodeOrIndex,
60
- getLastSelectedEntity,
61
- getNewEntToSelect,
62
- getRecordsFromIdMap,
63
- getRowCopyText,
64
- handleCopyColumn,
65
- handleCopyHelper,
66
- handleCopyRows,
67
- handleCopyTable,
68
- isEntityClean,
69
- PRIMARY_SELECTED_VAL,
70
- removeCleanRows
71
- } from "./utils";
72
- import { useDeepEqualMemo } from "../utils/hooks";
73
- import rowClick, {
74
- changeSelectedEntities,
75
- finalizeSelection
76
- } from "./utils/rowClick";
77
- import PagingTool from "./PagingTool";
78
- import SearchBar from "./SearchBar";
79
- import DisplayOptions from "./DisplayOptions";
80
- import DisabledLoadingComponent from "./DisabledLoadingComponent";
81
- import SortableColumns from "./SortableColumns";
82
- import dataTableEnhancer from "./dataTableEnhancer";
83
- import "../toastr";
84
- import "@teselagen/react-table/react-table.css";
85
- import "./style.css";
86
- import { nanoid } from "nanoid";
87
- import { SwitchField } from "../FormComponents";
88
- import { validateTableWideErrors } from "./validateTableWideErrors";
89
- import { editCellHelper } from "./editCellHelper";
90
- import getTableConfigFromStorage from "./utils/getTableConfigFromStorage";
91
- import { viewColumn, openColumn, multiViewColumn } from "./viewColumn";
92
- import convertSchema from "./utils/convertSchema";
93
- import TableFormTrackerContext from "./TableFormTrackerContext";
94
- import {
95
- getCCDisplayName,
96
- getCurrentParamsFromUrl,
97
- getQueryParams,
98
- makeDataTableHandlers,
99
- setCurrentParamsOnUrl
100
- } from "./utils/queryParams";
101
- import { useColumns } from "./Columns";
102
- import { formValueSelector, change as _change } from "redux-form";
103
- import { throwFormError } from "../throwFormError";
104
- import { isObservableArray, toJS } from "mobx";
105
- import { isBeingCalledExcessively } from "../utils/isBeingCalledExcessively";
106
-
107
- enablePatches();
108
- const IS_LINUX = window.navigator.platform.toLowerCase().search("linux") > -1;
109
-
110
- const itemSizeEstimators = {
111
- compact: () => 25.34,
112
- normal: () => 33.34,
113
- comfortable: () => 41.34
114
- };
115
-
116
- const DataTable = ({
117
- controlled_pageSize,
118
- formName = "tgDataTable",
119
- history,
120
- isSimple,
121
- isLocalCall = true,
122
- isTableParamsConnected,
123
- noForm,
124
- orderByFirstColumn,
125
- schema: _schema,
126
- showEmptyColumnsByDefault,
127
- tableParams: _tableParams,
128
- anyTouched,
129
- blur,
130
- ...ownProps
131
- }) => {
132
- if (isTableParamsConnected && _tableParams && !_tableParams.entities) {
133
- throw new Error(
134
- `No entities array detected in tableParams object (<DataTable {...tableParams}/>). You need to call withQuery() after withTableParams() like: compose(withTableParams(), withQuery(something)).`
135
- );
136
- }
137
- const dispatch = useDispatch();
138
- const change = useCallback(
139
- (...args) => dispatch(_change(formName, ...args)),
140
- [dispatch, formName]
141
- );
142
- const tableRef = useRef();
143
- const alreadySelected = useRef(false);
144
- const [onlyShowRowsWErrors, setOnlyShowRowsWErrors] = useState(false);
145
- const [entitiesUndoRedoStack, setEntitiesUndoRedoStack] = useState({
146
- currentVersion: 0
147
- });
148
- const [selectedCells, setSelectedCells] = useState({});
149
- const _tableConfig = getTableConfigFromStorage(formName);
150
- // make user set page size persist
151
- const userSetPageSize =
152
- _tableConfig?.userSetPageSize && parseInt(_tableConfig.userSetPageSize, 10);
153
-
154
- const formTracker = useContext(TableFormTrackerContext);
155
- useEffect(() => {
156
- if (formTracker.isActive && !formTracker.formNames.includes(formName)) {
157
- formTracker.pushFormName(formName);
158
- }
159
- }, [formTracker, formName]);
160
-
161
- const [showForcedHiddenColumns, setShowForcedHidden] = useState(() => {
162
- if (showEmptyColumnsByDefault) {
163
- return true;
164
- }
165
- return false;
166
- });
167
-
168
- const {
169
- reduxFormCellValidation: _reduxFormCellValidation,
170
- reduxFormEditingCell,
171
- reduxFormEntities,
172
- reduxFormQueryParams: _reduxFormQueryParams = {},
173
- reduxFormSelectedEntityIdMap: _reduxFormSelectedEntityIdMap = {}
174
- } = useSelector(state =>
175
- formValueSelector(formName)(
176
- state,
177
- "reduxFormCellValidation",
178
- "reduxFormEntities",
179
- "reduxFormQueryParams",
180
- "reduxFormSelectedEntityIdMap"
181
- )
182
- );
183
-
184
- // We want to make sure we don't rerender everything unnecessary
185
- // with redux-forms we tend to do unnecessary renders
186
- const reduxFormCellValidation = useDeepEqualMemo(_reduxFormCellValidation);
187
- const reduxFormQueryParams = useDeepEqualMemo(_reduxFormQueryParams);
188
- const reduxFormSelectedEntityIdMap = useDeepEqualMemo(
189
- _reduxFormSelectedEntityIdMap
190
- );
191
-
192
- let props = ownProps;
193
- if (!isTableParamsConnected) {
194
- // When using mobx values we need to transform it to a js array instead of a proxy so the next hooks get the right values
195
- const normalizedEntities = isObservableArray(ownProps.entities)
196
- ? toJS(ownProps.entities)
197
- : ownProps.entities;
198
- //this is the case where we're hooking up to withTableParams locally, so we need to take the tableParams off the props
199
- props = {
200
- ...ownProps,
201
- ..._tableParams,
202
- entities: normalizedEntities
203
- };
204
- }
205
-
206
- const convertedSchema = useMemo(() => convertSchema(_schema), [_schema]);
207
-
208
- if (isLocalCall) {
209
- if (!noForm && (!formName || formName === "tgDataTable")) {
210
- throw new Error(
211
- "Please pass a unique 'formName' prop to the locally connected <DataTable/> component with schema: ",
212
- _schema
213
- );
214
- }
215
- } else {
216
- //in user instantiated withTableParams() call
217
- if (!formName || formName === "tgDataTable") {
218
- throw new Error(
219
- "Please pass a unique 'formName' prop to the withTableParams() with schema: ",
220
- _schema
221
- );
222
- }
223
- }
224
-
225
- const { withPaging = !isSimple } = props;
226
- const {
227
- doNotCoercePageSize,
228
- isInfinite = isSimple && !withPaging,
229
- syncDisplayOptionsToDb,
230
- urlConnected,
231
- withSelectedEntities
232
- } = props;
233
-
234
- const defaults = useMemo(() => {
235
- const _defaults = {
236
- pageSize: controlled_pageSize || 25,
237
- order: [], // ["-name", "statusCode"] //an array of camelCase display names with - sign to denote reverse
238
- searchTerm: "",
239
- page: 1,
240
- filters: [
241
- // filters look like this:
242
- // {
243
- // selectedFilter: 'textContains', //camel case
244
- // filterOn: ccDisplayName, //camel case display name
245
- // filterValue: 'thomas',
246
- // }
247
- ],
248
- ...(props.defaults || {})
249
- };
250
- if (isLocalCall && orderByFirstColumn && !_defaults?.order?.length) {
251
- const r = [getCCDisplayName(convertedSchema.fields[0])];
252
- _defaults.order = r;
253
- }
254
-
255
- if (!syncDisplayOptionsToDb && userSetPageSize) {
256
- _defaults.pageSize = userSetPageSize;
257
- }
258
-
259
- return _defaults;
260
- }, [
261
- controlled_pageSize,
262
- convertedSchema.fields,
263
- isLocalCall,
264
- orderByFirstColumn,
265
- props.defaults,
266
- syncDisplayOptionsToDb,
267
- userSetPageSize
268
- ]);
269
-
270
- const selectedEntities = withSelectedEntities
271
- ? getRecordsFromIdMap(reduxFormSelectedEntityIdMap)
272
- : undefined;
273
-
274
- props = {
275
- ...props,
276
- ...(withSelectedEntities &&
277
- typeof withSelectedEntities === "string" && {
278
- [withSelectedEntities]: selectedEntities
279
- })
280
- };
281
-
282
- const _currentParams = useMemo(() => {
283
- const tmp =
284
- (urlConnected
285
- ? getCurrentParamsFromUrl(history.location) //important to use history location and not ownProps.location because for some reason the location path lags one render behind!!
286
- : reduxFormQueryParams) || {};
287
- return tmp;
288
- }, [history, reduxFormQueryParams, urlConnected]);
289
-
290
- const currentParams = useDeepEqualMemo(_currentParams);
291
-
292
- const tableParams = useMemo(() => {
293
- if (!isTableParamsConnected) {
294
- const setNewParams = newParams => {
295
- // we always will update the redux params as a workaround for withRouter not always working
296
- // if inside a redux-connected container https://github.com/ReactTraining/react-router/issues/5037
297
- change("reduxFormQueryParams", prev => {
298
- let tmp = newParams;
299
- if (typeof tmp === "function") tmp = newParams(prev);
300
- urlConnected && setCurrentParamsOnUrl(tmp, history?.replace);
301
- return tmp;
302
- });
303
- };
304
-
305
- const dispatchProps = makeDataTableHandlers({
306
- setNewParams,
307
- defaults,
308
- onlyOneFilter: props.onlyOneFilter
309
- });
310
-
311
- const changeFormValue = (...args) => change(...args);
312
-
313
- return {
314
- changeFormValue,
315
- selectedEntities,
316
- ..._tableParams,
317
- ...dispatchProps,
318
- isTableParamsConnected: true //let the table know not to do local sorting/filtering etc.
319
- };
320
- }
321
- return _tableParams;
322
- }, [
323
- _tableParams,
324
- change,
325
- defaults,
326
- history?.replace,
327
- isTableParamsConnected,
328
- props.onlyOneFilter,
329
- selectedEntities,
330
- urlConnected
331
- ]);
332
-
333
- props = {
334
- ...props,
335
- ...tableParams
336
- };
337
-
338
- const queryParams = useMemo(() => {
339
- if (!isTableParamsConnected) {
340
- const additionalFilterToUse =
341
- typeof props.additionalFilter === "function"
342
- ? props.additionalFilter
343
- : () => props.additionalFilter;
344
-
345
- const additionalOrFilterToUse =
346
- typeof props.additionalOrFilter === "function"
347
- ? props.additionalOrFilter
348
- : () => props.additionalOrFilter;
349
-
350
- return getQueryParams({
351
- doNotCoercePageSize,
352
- currentParams,
353
- entities: props.entities, // for local table
354
- urlConnected,
355
- defaults,
356
- schema: convertedSchema,
357
- isInfinite,
358
- isLocalCall,
359
- additionalFilter: additionalFilterToUse,
360
- additionalOrFilter: additionalOrFilterToUse,
361
- noOrderError: props.noOrderError,
362
- isCodeModel: props.isCodeModel,
363
- ownProps: props
364
- });
365
- }
366
- return {};
367
- // eslint-disable-next-line react-hooks/exhaustive-deps
368
- }, [
369
- props.entities,
370
- props.noOrderError,
371
- props.isCodeModel,
372
- convertedSchema,
373
- currentParams,
374
- doNotCoercePageSize,
375
- isInfinite,
376
- isLocalCall,
377
- isTableParamsConnected,
378
- urlConnected
379
- ]);
380
-
381
- props = {
382
- ...props,
383
- ...queryParams
384
- };
385
-
386
- const {
387
- addFilters = noop,
388
- additionalFilters,
389
- additionalFooterButtons,
390
- autoFocusSearch,
391
- cellRenderer,
392
- children,
393
- className = "",
394
- clearFilters = noop,
395
- compact: _compact = true,
396
- compactPaging,
397
- contextMenu = noop,
398
- controlled_hasNextPage,
399
- controlled_onRefresh,
400
- controlled_page,
401
- controlled_setPage,
402
- controlled_setPageSize,
403
- controlled_total,
404
- currentUser,
405
- deleteTableConfiguration,
406
- disabled = false,
407
- disableSetPageSize,
408
- doNotShowEmptyRows,
409
- doNotValidateUntouchedRows,
410
- editingCellSelectAll,
411
- entities: _origEntities = [],
412
- entitiesAcrossPages: _entitiesAcrossPages,
413
- entityCount,
414
- errorParsingUrlString,
415
- expandAllByDefault,
416
- extraClasses = "",
417
- extraCompact: _extraCompact,
418
- filters = [],
419
- fragment,
420
- getCellHoverText,
421
- getRowClassName,
422
- helperProp,
423
- hideColumnHeader,
424
- hideDisplayOptionsIcon,
425
- hidePageSizeWhenPossible = isSimple ? !withPaging : false,
426
- hideSelectedCount = isSimple,
427
- hideSetPageSize,
428
- hideTotalPages,
429
- selectedIds,
430
- isCellEditable,
431
- isCopyable = true,
432
- isEntityDisabled = noop,
433
- isLoading = false,
434
- isOpenable,
435
- isSingleSelect = false,
436
- isViewable,
437
- recordIdToIsVisibleMap,
438
- setRecordIdToIsVisibleMap,
439
- keepSelectionOnPageChange,
440
- leftOfSearchBarItems,
441
- maxHeight = 600,
442
- minimalStyle,
443
- mustClickCheckboxToSelect,
444
- noDeselectAll,
445
- noFooter = isSimple ? !withPaging : false,
446
- noFullscreenButton = isSimple,
447
- noHeader = false,
448
- noPadding = isSimple,
449
- noRowsFoundMessage,
450
- noSelect = false,
451
- noUserSelect,
452
- onDeselect = noop,
453
- onDoubleClick,
454
- onMultiRowSelect = noop,
455
- onRefresh,
456
- onRowClick = noop,
457
- onRowSelect = noop,
458
- onSingleRowSelect = noop,
459
- order,
460
- page = 1,
461
- pageSize: _pageSize = 10,
462
- pagingDisabled,
463
- removeSingleFilter,
464
- ReactTableProps = {},
465
- safeQuery,
466
- searchMenuButton,
467
- searchTerm,
468
- selectAllByDefault,
469
- setNewParams,
470
- setOrder,
471
- setPage = noop,
472
- setPageSize = noop,
473
- setSearchTerm = noop,
474
- shouldShowSubComponent,
475
- showCount = false,
476
- style = {},
477
- SubComponent,
478
- subHeader,
479
- tableConfigurations,
480
- tableName,
481
- topLeftItems,
482
- upsertFieldOption,
483
- upsertTableConfiguration,
484
- variables,
485
- withCheckboxes = false,
486
- withDisplayOptions,
487
- withExpandAndCollapseAllButton,
488
- withFilter,
489
- withSearch = !isSimple,
490
- withSelectAll,
491
- withSort,
492
- withTitle = !isSimple,
493
- noExcessiveCheck
494
- } = props;
495
-
496
- const _entities = useMemo(
497
- () => (reduxFormEntities?.length ? reduxFormEntities : _origEntities) || [],
498
- [_origEntities, reduxFormEntities]
499
- );
500
-
501
- const entities = useDeepEqualMemo(_entities);
502
-
503
- const entitiesAcrossPages = useDeepEqualMemo(_entitiesAcrossPages);
504
-
505
- // This is because we need to maintain the reduxFormSelectedEntityIdMap and
506
- // allOrderedEntities updated
507
- useEffect(() => {
508
- console.log(`noExcessiveCheck:`,noExcessiveCheck)
509
- !noExcessiveCheck && isBeingCalledExcessively({ uniqName: `dt_entities_${formName}` });
510
- change("allOrderedEntities", entitiesAcrossPages);
511
- if (entities.length === 0 || isEmpty(reduxFormSelectedEntityIdMap)) return;
512
- changeSelectedEntities({
513
- idMap: reduxFormSelectedEntityIdMap,
514
- entities,
515
- change
516
- });
517
- // eslint-disable-next-line react-hooks/exhaustive-deps
518
- }, [entitiesAcrossPages, reduxFormSelectedEntityIdMap, change, noExcessiveCheck]);
519
-
520
- const [tableConfig, setTableConfig] = useState({ fieldOptions: [] });
521
-
522
- useEffect(() => {
523
- if (withDisplayOptions) {
524
- let newTableConfig = {};
525
- if (syncDisplayOptionsToDb) {
526
- newTableConfig = tableConfigurations && tableConfigurations[0];
527
- } else {
528
- newTableConfig = getTableConfigFromStorage(formName);
529
- }
530
- !noExcessiveCheck && isBeingCalledExcessively({ uniqName: `dt_setTableConfig_${formName}` });
531
- // if the tableConfig is the same as the newTableConfig, don't update
532
- setTableConfig(prev => {
533
- if (!newTableConfig) {
534
- newTableConfig = {
535
- fieldOptions: []
536
- };
537
- if (isEqual(prev, newTableConfig)) {
538
- return prev;
539
- } else {
540
- return newTableConfig;
541
- }
542
- } else {
543
- return newTableConfig;
544
- }
545
- });
546
- }
547
- }, [
548
- convertedSchema, // If the schema changes we want to take into account the synced tableConfig again
549
- formName,
550
- syncDisplayOptionsToDb,
551
- tableConfigurations,
552
- withDisplayOptions,
553
- noExcessiveCheck
554
- ]);
555
-
556
- const schema = useMemo(() => {
557
- const schema = { ...convertedSchema };
558
- if (isViewable) {
559
- schema.fields = [viewColumn, ...schema.fields];
560
- }
561
- if (recordIdToIsVisibleMap) {
562
- schema.fields = [multiViewColumn, ...schema.fields];
563
- }
564
- if (isOpenable) {
565
- schema.fields = [
566
- openColumn({ onDoubleClick, history }),
567
- ...schema.fields
568
- ];
569
- }
570
- // this must come before handling orderings.
571
- schema.fields = schema.fields.map(field => {
572
- if (field.placementPath) {
573
- return {
574
- ...field,
575
- sortDisabled:
576
- field.sortDisabled ||
577
- (typeof field.path === "string" && field.path.includes(".")),
578
- path: field.placementPath
579
- };
580
- } else {
581
- return field;
582
- }
583
- });
584
-
585
- if (withDisplayOptions) {
586
- const fieldOptsByPath = keyBy(tableConfig.fieldOptions, "path");
587
- schema.fields = schema.fields.map(field => {
588
- const fieldOpt = fieldOptsByPath[field.path];
589
- let noValsForField = false;
590
- // only add this hidden column ability if no paging
591
- if (
592
- !showForcedHiddenColumns &&
593
- withDisplayOptions &&
594
- (isSimple || isInfinite)
595
- ) {
596
- noValsForField = entities.every(e => {
597
- const val = get(e, field.path);
598
- return field.render
599
- ? !field.render(val, e, undefined, {
600
- currentParams,
601
- setNewParams
602
- })
603
- : cellRenderer?.[field.path]
604
- ? !cellRenderer[field.path](val, e, undefined, {
605
- currentParams,
606
- setNewParams
607
- })
608
- : !val;
609
- });
610
- }
611
- if (noValsForField) {
612
- return {
613
- ...field,
614
- isHidden: true,
615
- isForcedHidden: true
616
- };
617
- } else if (fieldOpt) {
618
- return {
619
- ...field,
620
- isHidden: fieldOpt.isHidden
621
- };
622
- } else {
623
- return field;
624
- }
625
- });
626
-
627
- const columnOrderings = tableConfig.columnOrderings;
628
- if (columnOrderings) {
629
- const fieldsWithOrders = [];
630
- const fieldsWithoutOrder = [];
631
- // if a new field has been added since the orderings were set then we want
632
- // it to be at the end instead of the beginning
633
- schema.fields.forEach(field => {
634
- if (columnOrderings.indexOf(field.path) > -1) {
635
- fieldsWithOrders.push(field);
636
- } else {
637
- fieldsWithoutOrder.push(field);
638
- }
639
- });
640
- schema.fields = fieldsWithOrders
641
- .sort(({ path: path1 }, { path: path2 }) => {
642
- return (
643
- columnOrderings.indexOf(path1) - columnOrderings.indexOf(path2)
644
- );
645
- })
646
- .concat(fieldsWithoutOrder);
647
- // We shouldn't need to update the columnOrderings here, this could lead
648
- // to unnecessary updates. TableConfig and schema have circular
649
- // dependencies, which is bad at the moment of updating.
650
- if (
651
- !isEqual(
652
- schema.fields.map(f => f.path),
653
- columnOrderings
654
- )
655
- ) {
656
- setTableConfig(prev => ({
657
- ...prev,
658
- columnOrderings: schema.fields.map(f => f.path)
659
- }));
660
- }
661
- }
662
- }
663
- return schema;
664
- }, [
665
- cellRenderer,
666
- convertedSchema,
667
- currentParams,
668
- entities,
669
- history,
670
- isInfinite,
671
- isOpenable,
672
- isSimple,
673
- isViewable,
674
- onDoubleClick,
675
- setNewParams,
676
- showForcedHiddenColumns,
677
- tableConfig.columnOrderings,
678
- tableConfig.fieldOptions,
679
- withDisplayOptions,
680
- recordIdToIsVisibleMap
681
- ]);
682
-
683
- const {
684
- moveColumnPersist,
685
- persistPageSize,
686
- resetDefaultVisibility,
687
- resizePersist,
688
- updateColumnVisibility,
689
- updateTableDisplayDensity
690
- } = useMemo(() => {
691
- let resetDefaultVisibility;
692
- let updateColumnVisibility;
693
- let updateTableDisplayDensity;
694
- let persistPageSize;
695
- let moveColumnPersist;
696
- let resizePersist = noop;
697
-
698
- if (withDisplayOptions) {
699
- const fieldOptsByPath = keyBy(tableConfig.fieldOptions, "path");
700
- if (syncDisplayOptionsToDb) {
701
- // sync up to db
702
- // There must be a better way to set this variable...
703
- let tableConfigurationId;
704
- resetDefaultVisibility = function () {
705
- tableConfigurationId = tableConfig.id;
706
- if (tableConfigurationId) {
707
- deleteTableConfiguration(tableConfigurationId);
708
- }
709
- };
710
- updateColumnVisibility = function ({ shouldShow, path }) {
711
- if (tableConfigurationId) {
712
- const existingFieldOpt = fieldOptsByPath[path] || {};
713
- upsertFieldOption({
714
- id: existingFieldOpt.id,
715
- path,
716
- isHidden: !shouldShow,
717
- tableConfigurationId
718
- });
719
- } else {
720
- upsertTableConfiguration({
721
- userId: currentUser.user.id,
722
- formName,
723
- fieldOptions: [
724
- {
725
- path,
726
- isHidden: !shouldShow
727
- }
728
- ]
729
- });
730
- }
731
- };
732
- } else {
733
- const syncStorage = newTableConfig => {
734
- setTableConfig(newTableConfig);
735
- window.localStorage.setItem(formName, JSON.stringify(newTableConfig));
736
- };
737
-
738
- //sync display options with localstorage
739
- resetDefaultVisibility = function () {
740
- setTableConfig({ fieldOptions: [] });
741
- window.localStorage.removeItem(formName);
742
- };
743
- updateColumnVisibility = function ({ path, paths, shouldShow }) {
744
- const newFieldOpts = {
745
- ...fieldOptsByPath
746
- };
747
- const pathsToUse = paths ? paths : [path];
748
- pathsToUse.forEach(path => {
749
- newFieldOpts[path] = { path, isHidden: !shouldShow };
750
- });
751
- syncStorage({ ...tableConfig, fieldOptions: toArray(newFieldOpts) });
752
- };
753
- updateTableDisplayDensity = function (density) {
754
- syncStorage({ ...tableConfig, density: density });
755
- };
756
- persistPageSize = function (pageSize) {
757
- syncStorage({ ...tableConfig, userSetPageSize: pageSize });
758
- };
759
- moveColumnPersist = function ({ oldIndex, newIndex }) {
760
- // we might already have an array of the fields [path1, path2, ..etc]
761
- const columnOrderings =
762
- tableConfig.columnOrderings ||
763
- schema.fields.map(({ path }) => path); // columnOrderings is [path1, path2, ..etc]
764
- syncStorage({
765
- ...tableConfig,
766
- columnOrderings: arrayMove(columnOrderings, oldIndex, newIndex)
767
- });
768
- };
769
- resizePersist = function (newResized) {
770
- syncStorage({ ...tableConfig, resized: newResized });
771
- };
772
- }
773
- }
774
- return {
775
- moveColumnPersist,
776
- persistPageSize,
777
- resetDefaultVisibility,
778
- resizePersist,
779
- updateColumnVisibility,
780
- updateTableDisplayDensity
781
- };
782
- }, [
783
- currentUser?.user?.id,
784
- deleteTableConfiguration,
785
- formName,
786
- schema.fields,
787
- syncDisplayOptionsToDb,
788
- tableConfig,
789
- upsertFieldOption,
790
- upsertTableConfiguration,
791
- withDisplayOptions
792
- ]);
793
-
794
- let compact = _compact;
795
- let extraCompact = _extraCompact;
796
-
797
- if (withDisplayOptions && tableConfig.density) {
798
- compact = tableConfig.density === "compact";
799
- extraCompact = tableConfig.density === "extraCompact";
800
- }
801
-
802
- const resized = useMemo(
803
- () => tableConfig.resized || [],
804
- [tableConfig?.resized]
805
- );
806
-
807
- const pageSize = controlled_pageSize || _pageSize;
808
-
809
- const [expandedEntityIdMap, setExpandedEntityIdMap] = useState(() => {
810
- const initialExpandedEntityIdMap = {};
811
- if (expandAllByDefault) {
812
- entities.forEach(entity => {
813
- initialExpandedEntityIdMap[entity.id || entity.code] = true;
814
- });
815
- }
816
- return initialExpandedEntityIdMap;
817
- });
818
-
819
- const updateValidation = useCallback(
820
- (entities, newCellValidate) => {
821
- const tableWideErr = validateTableWideErrors({
822
- entities,
823
- schema,
824
- newCellValidate
825
- });
826
- change("reduxFormCellValidation", tableWideErr);
827
- },
828
- [schema, change]
829
- );
830
-
831
- const updateEntitiesHelper = useCallback(
832
- (ents, fn) => {
833
- const [nextState, patches, inversePatches] = produceWithPatches(ents, fn);
834
- if (!inversePatches.length) return;
835
- const thatNewNew = [...nextState];
836
- thatNewNew.isDirty = true;
837
- change("reduxFormEntities", thatNewNew);
838
- setEntitiesUndoRedoStack(prev => ({
839
- ...omitBy(prev, (v, k) => {
840
- return toNumber(k) > prev.currentVersion + 1;
841
- }),
842
- currentVersion: prev.currentVersion + 1,
843
- [prev.currentVersion + 1]: {
844
- inversePatches,
845
- patches
846
- }
847
- }));
848
- },
849
- [change]
850
- );
851
-
852
- const formatAndValidateEntities = useCallback(
853
- (entities, { useDefaultValues, indexToStartAt } = {}) => {
854
- const editableFields = schema.fields.filter(f => !f.isNotEditable);
855
- const validationErrors = {};
856
-
857
- const newEnts = immer(entities, entities => {
858
- entities.forEach((e, index) => {
859
- editableFields.forEach(columnSchema => {
860
- if (useDefaultValues) {
861
- if (e[columnSchema.path] === undefined) {
862
- if (isFunction(columnSchema.defaultValue)) {
863
- e[columnSchema.path] = columnSchema.defaultValue(
864
- index + indexToStartAt,
865
- e
866
- );
867
- } else e[columnSchema.path] = columnSchema.defaultValue;
868
- }
869
- }
870
- //mutative
871
- const { error } = editCellHelper({
872
- entity: e,
873
- columnSchema,
874
- newVal: e[columnSchema.path]
875
- });
876
- if (error) {
877
- const rowId = getIdOrCodeOrIndex(e, index);
878
- validationErrors[`${rowId}:${columnSchema.path}`] = error;
879
- }
880
- });
881
- });
882
- });
883
- return {
884
- newEnts,
885
- validationErrors
886
- };
887
- },
888
- [schema.fields]
889
- );
890
-
891
- const updateValidationHelper = useCallback(() => {
892
- updateValidation(entities, reduxFormCellValidation);
893
- }, [entities, reduxFormCellValidation, updateValidation]);
894
-
895
- const addEditableTableEntities = useCallback(
896
- incomingEnts => {
897
- updateEntitiesHelper(entities, entities => {
898
- const newEntities = incomingEnts.map(e => ({
899
- ...e,
900
- id: e.id || nanoid(),
901
- _isClean: false
902
- }));
903
-
904
- const { newEnts, validationErrors } = formatAndValidateEntities(
905
- newEntities,
906
- {
907
- useDefaultValues: true,
908
- indexToStartAt: entities.length
909
- }
910
- );
911
- if (every(entities, "_isClean")) {
912
- forEach(newEnts, (e, i) => {
913
- entities[i] = e;
914
- });
915
- } else {
916
- entities.splice(entities.length, 0, ...newEnts);
917
- }
918
-
919
- updateValidation(entities, {
920
- ...reduxFormCellValidation,
921
- ...validationErrors
922
- });
923
- });
924
- },
925
- [
926
- entities,
927
- formatAndValidateEntities,
928
- reduxFormCellValidation,
929
- updateEntitiesHelper,
930
- updateValidation
931
- ]
932
- );
933
-
934
- const getEditableTableInfoAndThrowFormError = useCallback(() => {
935
- const { entsToUse, validationToUse } = removeCleanRows(
936
- reduxFormEntities,
937
- reduxFormCellValidation
938
- );
939
- const validationWTableErrs = validateTableWideErrors({
940
- entities: entsToUse,
941
- schema,
942
- newCellValidate: validationToUse
943
- });
944
-
945
- if (!entsToUse?.length) {
946
- throwFormError(
947
- "Please add at least one row to the table before submitting."
948
- );
949
- }
950
- const invalid =
951
- isEmpty(validationWTableErrs) || !some(validationWTableErrs, v => v)
952
- ? undefined
953
- : validationWTableErrs;
954
-
955
- if (invalid) {
956
- throwFormError("Please fix the errors in the table before submitting.");
957
- }
958
-
959
- return entsToUse;
960
- }, [reduxFormCellValidation, reduxFormEntities, schema]);
961
-
962
- useEffect(() => {
963
- // This is bad practice, we shouldn't be assigning value to an
964
- // external variable
965
- if (helperProp) {
966
- helperProp.updateValidationHelper = updateValidationHelper;
967
- helperProp.addEditableTableEntities = addEditableTableEntities;
968
- helperProp.getEditableTableInfoAndThrowFormError =
969
- getEditableTableInfoAndThrowFormError;
970
- }
971
- }, [
972
- addEditableTableEntities,
973
- getEditableTableInfoAndThrowFormError,
974
- helperProp,
975
- updateValidationHelper
976
- ]);
977
-
978
- const handleRowMove = useCallback(
979
- (type, shiftHeld) => e => {
980
- e.preventDefault();
981
- e.stopPropagation();
982
- let newIdMap = {};
983
- const lastSelectedEnt = getLastSelectedEntity(
984
- reduxFormSelectedEntityIdMap
985
- );
986
-
987
- if (noSelect) return;
988
- if (lastSelectedEnt) {
989
- let lastSelectedIndex = entities.findIndex(
990
- ent => ent === lastSelectedEnt
991
- );
992
- if (lastSelectedIndex === -1) {
993
- if (lastSelectedEnt.id !== undefined) {
994
- lastSelectedIndex = entities.findIndex(
995
- ent => ent.id === lastSelectedEnt.id
996
- );
997
- } else if (lastSelectedEnt.code !== undefined) {
998
- lastSelectedIndex = entities.findIndex(
999
- ent => ent.code === lastSelectedEnt.code
1000
- );
1001
- }
1002
- }
1003
- if (lastSelectedIndex === -1) {
1004
- return;
1005
- }
1006
- const newEntToSelect = getNewEntToSelect({
1007
- type,
1008
- lastSelectedIndex,
1009
- entities,
1010
- isEntityDisabled
1011
- });
1012
-
1013
- if (!newEntToSelect) return;
1014
- if (shiftHeld && !isSingleSelect) {
1015
- if (
1016
- reduxFormSelectedEntityIdMap[
1017
- newEntToSelect.id || newEntToSelect.code
1018
- ]
1019
- ) {
1020
- //the entity being moved to has already been selected
1021
- newIdMap = omit(reduxFormSelectedEntityIdMap, [
1022
- lastSelectedEnt.id || lastSelectedEnt.code
1023
- ]);
1024
- newIdMap[newEntToSelect.id || newEntToSelect.code].time =
1025
- Date.now() + 1;
1026
- } else {
1027
- //the entity being moved to has NOT been selected yet
1028
- newIdMap = {
1029
- ...reduxFormSelectedEntityIdMap,
1030
- [newEntToSelect.id || newEntToSelect.code]: {
1031
- entity: newEntToSelect,
1032
- time: Date.now()
1033
- }
1034
- };
1035
- }
1036
- } else {
1037
- //no shiftHeld
1038
- newIdMap[newEntToSelect.id || newEntToSelect.code] = {
1039
- entity: newEntToSelect,
1040
- time: Date.now()
1041
- };
1042
- }
1043
- }
1044
-
1045
- finalizeSelection({
1046
- idMap: newIdMap,
1047
- entities,
1048
- props: {
1049
- onDeselect,
1050
- onSingleRowSelect,
1051
- onMultiRowSelect,
1052
- noDeselectAll,
1053
- onRowSelect,
1054
- noSelect,
1055
- change
1056
- }
1057
- });
1058
- },
1059
- [
1060
- change,
1061
- entities,
1062
- isEntityDisabled,
1063
- isSingleSelect,
1064
- noDeselectAll,
1065
- noSelect,
1066
- onDeselect,
1067
- onMultiRowSelect,
1068
- onRowSelect,
1069
- onSingleRowSelect,
1070
- reduxFormSelectedEntityIdMap
1071
- ]
1072
- );
1073
-
1074
- const primarySelectedCellId = useMemo(() => {
1075
- for (const k of Object.keys(selectedCells)) {
1076
- if (selectedCells[k] === PRIMARY_SELECTED_VAL) {
1077
- return k;
1078
- }
1079
- }
1080
- }, [selectedCells]);
1081
-
1082
- const startCellEdit = useCallback(
1083
- (cellId, initialValue) => {
1084
- // This initial value is not needed if the event is propagated accordingly.
1085
- // This is directly connected to the RenderCell component, which does set
1086
- // the initial value.
1087
- change("reduxFormInitialValue", initialValue);
1088
- change("reduxFormEditingCell", prev => {
1089
- //check if the cell is already selected and editing and if so, don't change it
1090
- if (prev === cellId) return cellId;
1091
- setSelectedCells(prev => {
1092
- if (prev[cellId] === PRIMARY_SELECTED_VAL) {
1093
- return prev;
1094
- }
1095
- return { ...prev, [cellId]: PRIMARY_SELECTED_VAL };
1096
- });
1097
- return cellId;
1098
- });
1099
- },
1100
- [change]
1101
- );
1102
-
1103
- const handleEnterStartCellEdit = useCallback(
1104
- e => {
1105
- e.stopPropagation();
1106
- startCellEdit(primarySelectedCellId);
1107
- },
1108
- [primarySelectedCellId, startCellEdit]
1109
- );
1110
-
1111
- const handleDeleteCell = useCallback(() => {
1112
- const newCellValidate = {
1113
- ...reduxFormCellValidation
1114
- };
1115
- if (isEmpty(selectedCells)) return;
1116
- const rowIds = [];
1117
- updateEntitiesHelper(entities, entities => {
1118
- const entityIdToEntity = getEntityIdToEntity(entities);
1119
- Object.keys(selectedCells).forEach(cellId => {
1120
- const [rowId, path] = cellId.split(":");
1121
- rowIds.push(rowId);
1122
- const entity = entityIdToEntity[rowId].e;
1123
- delete entity._isClean;
1124
- const { error } = editCellHelper({
1125
- entity,
1126
- path,
1127
- schema,
1128
- newVal: ""
1129
- });
1130
- if (error) {
1131
- newCellValidate[cellId] = error;
1132
- } else {
1133
- delete newCellValidate[cellId];
1134
- }
1135
- });
1136
- updateValidation(entities, newCellValidate);
1137
- });
1138
- }, [
1139
- entities,
1140
- reduxFormCellValidation,
1141
- schema,
1142
- selectedCells,
1143
- updateEntitiesHelper,
1144
- updateValidation
1145
- ]);
1146
-
1147
- const handleCopySelectedCells = useCallback(
1148
- e => {
1149
- // if the current selection is consecutive cells then copy with
1150
- // tabs between. if not then just select primary selected cell
1151
- if (isEmpty(selectedCells)) return;
1152
- const pathToIndex = getFieldPathToIndex(schema);
1153
- const entityIdToEntity = getEntityIdToEntity(entities);
1154
- const selectionGrid = [];
1155
- let firstRowIndex;
1156
- let firstCellIndex;
1157
- Object.keys(selectedCells).forEach(key => {
1158
- const [rowId, path] = key.split(":");
1159
- const eInfo = entityIdToEntity[rowId];
1160
- if (eInfo) {
1161
- if (firstRowIndex === undefined || eInfo.i < firstRowIndex) {
1162
- firstRowIndex = eInfo.i;
1163
- }
1164
- if (!selectionGrid[eInfo.i]) {
1165
- selectionGrid[eInfo.i] = [];
1166
- }
1167
- const cellIndex = pathToIndex[path];
1168
- if (firstCellIndex === undefined || cellIndex < firstCellIndex) {
1169
- firstCellIndex = cellIndex;
1170
- }
1171
- selectionGrid[eInfo.i][cellIndex] = true;
1172
- }
1173
- });
1174
- if (firstRowIndex === undefined) return;
1175
- const allRows = getAllRows(e);
1176
- let fullCellText = "";
1177
- const fullJson = [];
1178
- times(selectionGrid.length, i => {
1179
- const row = selectionGrid[i];
1180
- if (fullCellText) {
1181
- fullCellText += "\n";
1182
- }
1183
- if (!row) {
1184
- return;
1185
- } else {
1186
- const jsonRow = [];
1187
- // ignore header
1188
- let [rowCopyText, json] = getRowCopyText(allRows[i + 1]);
1189
- rowCopyText = rowCopyText.split("\t");
1190
- times(row.length, i => {
1191
- const cell = row[i];
1192
- if (cell) {
1193
- fullCellText += rowCopyText[i];
1194
- jsonRow.push(json[i]);
1195
- }
1196
- if (i !== row.length - 1 && i >= firstCellIndex)
1197
- fullCellText += "\t";
1198
- });
1199
- fullJson.push(jsonRow);
1200
- }
1201
- });
1202
- if (!fullCellText) return window.toastr.warning("No text to copy");
1203
-
1204
- handleCopyHelper(fullCellText, fullJson, "Selected cells copied");
1205
- },
1206
- [entities, selectedCells, schema]
1207
- );
1208
-
1209
- const handleCopySelectedRows = useCallback(
1210
- (selectedRecords, e) => {
1211
- const idToIndex = entities.reduce((acc, e, i) => {
1212
- acc[e.id || e.code] = i;
1213
- return acc;
1214
- }, {});
1215
-
1216
- //index 0 of the table is the column titles
1217
- //must add 1 to rowNum
1218
- const rowNumbersToCopy = selectedRecords
1219
- .map(rec => idToIndex[rec.id || rec.code] + 1)
1220
- .sort();
1221
-
1222
- if (!rowNumbersToCopy.length) return;
1223
- rowNumbersToCopy.unshift(0); //add in the header row
1224
- try {
1225
- const allRowEls = getAllRows(e);
1226
- if (!allRowEls) return;
1227
- const rowEls = rowNumbersToCopy.map(i => allRowEls[i]);
1228
-
1229
- handleCopyRows(rowEls, {
1230
- onFinishMsg: "Selected rows copied"
1231
- });
1232
- } catch (error) {
1233
- console.error(`error:`, error);
1234
- window.toastr.error("Error copying rows.");
1235
- }
1236
- },
1237
- [entities]
1238
- );
1239
-
1240
- const handleCopyHotkey = useCallback(
1241
- e => {
1242
- if (isCellEditable) {
1243
- handleCopySelectedCells(e);
1244
- } else {
1245
- handleCopySelectedRows(
1246
- getRecordsFromIdMap(reduxFormSelectedEntityIdMap),
1247
- e
1248
- );
1249
- }
1250
- },
1251
- [
1252
- handleCopySelectedCells,
1253
- handleCopySelectedRows,
1254
- isCellEditable,
1255
- reduxFormSelectedEntityIdMap
1256
- ]
1257
- );
1258
-
1259
- const handleCut = useCallback(
1260
- e => {
1261
- handleDeleteCell();
1262
- handleCopyHotkey(e);
1263
- },
1264
- [handleCopyHotkey, handleDeleteCell]
1265
- );
1266
-
1267
- const flashTableBorder = () => {
1268
- try {
1269
- const table = tableRef.current.tableRef;
1270
- table.classList.add("tgBorderBlue");
1271
- setTimeout(() => {
1272
- table.classList.remove("tgBorderBlue");
1273
- }, 300);
1274
- } catch (e) {
1275
- console.error(`err when flashing table border:`, e);
1276
- }
1277
- };
1278
-
1279
- const handleUndo = useCallback(() => {
1280
- if (entitiesUndoRedoStack.currentVersion > 0) {
1281
- flashTableBorder();
1282
- const nextState = applyPatches(
1283
- entities,
1284
- entitiesUndoRedoStack[entitiesUndoRedoStack.currentVersion]
1285
- .inversePatches
1286
- );
1287
- const { newEnts, validationErrors } =
1288
- formatAndValidateEntities(nextState);
1289
- setEntitiesUndoRedoStack(prev => ({
1290
- ...prev,
1291
- currentVersion: prev.currentVersion - 1
1292
- }));
1293
- updateValidation(newEnts, validationErrors);
1294
- change("reduxFormEntities", newEnts);
1295
- }
1296
- }, [
1297
- change,
1298
- entities,
1299
- formatAndValidateEntities,
1300
- entitiesUndoRedoStack,
1301
- updateValidation
1302
- ]);
1303
-
1304
- const handleRedo = useCallback(() => {
1305
- const nextV = entitiesUndoRedoStack.currentVersion + 1;
1306
- if (entitiesUndoRedoStack[nextV]) {
1307
- flashTableBorder();
1308
- const nextState = applyPatches(
1309
- entities,
1310
- entitiesUndoRedoStack[nextV].patches
1311
- );
1312
- const { newEnts, validationErrors } =
1313
- formatAndValidateEntities(nextState);
1314
- change("reduxFormEntities", newEnts);
1315
- updateValidation(newEnts, validationErrors);
1316
- setEntitiesUndoRedoStack(prev => ({
1317
- ...prev,
1318
- currentVersion: nextV
1319
- }));
1320
- }
1321
- }, [
1322
- change,
1323
- entities,
1324
- formatAndValidateEntities,
1325
- entitiesUndoRedoStack,
1326
- updateValidation
1327
- ]);
1328
-
1329
- const handleSelectAllRows = useCallback(
1330
- e => {
1331
- if (isSingleSelect) return;
1332
- e.preventDefault();
1333
-
1334
- if (isCellEditable) {
1335
- const schemaPaths = schema.fields.map(f => f.path);
1336
- const newSelectedCells = {};
1337
- entities.forEach((entity, i) => {
1338
- if (isEntityDisabled(entity)) return;
1339
- const entityId = getIdOrCodeOrIndex(entity, i);
1340
- schemaPaths.forEach(p => {
1341
- newSelectedCells[`${entityId}:${p}`] = true;
1342
- });
1343
- });
1344
- setSelectedCells(newSelectedCells);
1345
- } else {
1346
- const newIdMap = {};
1347
-
1348
- entities.forEach((entity, i) => {
1349
- if (isEntityDisabled(entity)) return;
1350
- const entityId = getIdOrCodeOrIndex(entity, i);
1351
- newIdMap[entityId] = { entity };
1352
- });
1353
- finalizeSelection({
1354
- idMap: newIdMap,
1355
- entities,
1356
- props: {
1357
- onDeselect,
1358
- onSingleRowSelect,
1359
- onMultiRowSelect,
1360
- noDeselectAll,
1361
- onRowSelect,
1362
- noSelect,
1363
- change
1364
- }
1365
- });
1366
- }
1367
- },
1368
- [
1369
- change,
1370
- entities,
1371
- isCellEditable,
1372
- isEntityDisabled,
1373
- isSingleSelect,
1374
- noDeselectAll,
1375
- noSelect,
1376
- onDeselect,
1377
- onMultiRowSelect,
1378
- onRowSelect,
1379
- onSingleRowSelect,
1380
- schema.fields
1381
- ]
1382
- );
1383
-
1384
- const hotKeys = useMemo(
1385
- () => [
1386
- {
1387
- global: false,
1388
- combo: "up",
1389
- label: "Move Up a Row",
1390
- onKeyDown: handleRowMove("up")
1391
- },
1392
- {
1393
- global: false,
1394
- combo: "down",
1395
- label: "Move Down a Row",
1396
- onKeyDown: handleRowMove("down")
1397
- },
1398
- {
1399
- global: false,
1400
- combo: "up+shift",
1401
- label: "Move Up a Row",
1402
- onKeyDown: handleRowMove("up", true)
1403
- },
1404
- ...(isCellEditable
1405
- ? [
1406
- {
1407
- global: false,
1408
- combo: "enter",
1409
- label: "Enter -> Start Cell Edit",
1410
- onKeyDown: handleEnterStartCellEdit
1411
- },
1412
- {
1413
- global: false,
1414
- combo: "mod+x",
1415
- label: "Cut",
1416
- onKeyDown: handleCut
1417
- },
1418
- {
1419
- global: false,
1420
- combo: IS_LINUX ? "alt+z" : "mod+z",
1421
- label: "Undo",
1422
- onKeyDown: handleUndo
1423
- },
1424
- {
1425
- global: false,
1426
- combo: IS_LINUX ? "alt+shift+z" : "mod+shift+z",
1427
- label: "Redo",
1428
- onKeyDown: handleRedo
1429
- },
1430
- {
1431
- global: false,
1432
- combo: "backspace",
1433
- label: "Delete Cell",
1434
- onKeyDown: handleDeleteCell
1435
- }
1436
- ]
1437
- : []),
1438
- {
1439
- global: false,
1440
- combo: "down+shift",
1441
- label: "Move Down a Row",
1442
- onKeyDown: handleRowMove("down", true)
1443
- },
1444
- {
1445
- global: false,
1446
- combo: "mod + c",
1447
- label: "Copy rows",
1448
- onKeyDown: handleCopyHotkey
1449
- },
1450
- {
1451
- global: false,
1452
- combo: "mod + a",
1453
- label: "Select rows",
1454
- onKeyDown: handleSelectAllRows
1455
- }
1456
- ],
1457
- [
1458
- handleCopyHotkey,
1459
- handleCut,
1460
- handleDeleteCell,
1461
- handleEnterStartCellEdit,
1462
- handleRedo,
1463
- handleRowMove,
1464
- handleSelectAllRows,
1465
- handleUndo,
1466
- isCellEditable
1467
- ]
1468
- );
1469
-
1470
- const { handleKeyDown, handleKeyUp } = useHotkeys(hotKeys);
1471
- const [columns, setColumns] = useState([]);
1472
- const [fullscreen, setFullscreen] = useState(false);
1473
- const [selectingAll, setSelectingAll] = useState(false);
1474
-
1475
- // format in the schema shouldn't be something that changes the value
1476
- // everytime, it produces weird behavior since it keeps rerendering,
1477
- // we should make enforce the user set the format as something that
1478
- // "formats", not "changes".
1479
- useEffect(() => {
1480
- const formatAndValidateTableInitial = () => {
1481
- const { newEnts, validationErrors } = formatAndValidateEntities(entities);
1482
- const toKeep = {};
1483
- //on the initial load we want to keep any async table wide errors
1484
- forEach(reduxFormCellValidation, (v, k) => {
1485
- if (v && v._isTableAsyncWideError) {
1486
- toKeep[k] = v;
1487
- }
1488
- });
1489
- change("reduxFormEntities", prev => {
1490
- if (!isEqual(prev, newEnts)) {
1491
- return newEnts;
1492
- }
1493
- return prev;
1494
- });
1495
- updateValidation(newEnts, {
1496
- ...toKeep,
1497
- ...validationErrors
1498
- });
1499
- };
1500
- isCellEditable && formatAndValidateTableInitial();
1501
- }, [
1502
- change,
1503
- entities,
1504
- formatAndValidateEntities,
1505
- isCellEditable,
1506
- reduxFormCellValidation,
1507
- updateValidation
1508
- ]);
1509
-
1510
- const handlePaste = useCallback(
1511
- e => {
1512
- if (isCellEditable) {
1513
- if (isEmpty(selectedCells)) return;
1514
- try {
1515
- let pasteData = [];
1516
- let toPaste;
1517
- if (window.clipboardData && window.clipboardData.getData) {
1518
- // IE
1519
- toPaste = window.clipboardData.getData("Text");
1520
- } else if (e.clipboardData && e.clipboardData.getData) {
1521
- toPaste = e.clipboardData.getData("text/plain");
1522
- }
1523
- const jsonToPaste = e.clipboardData.getData("application/json");
1524
- try {
1525
- const pastedJson = [];
1526
- JSON.parse(jsonToPaste).forEach(row => {
1527
- const newRow = [];
1528
- Object.values(row).forEach(cell => {
1529
- const cellVal = JSON.parse(cell);
1530
- newRow.push(cellVal);
1531
- });
1532
- pastedJson.push(newRow);
1533
- });
1534
- pasteData = pastedJson;
1535
- // try to remove the header row if it exists
1536
- if (
1537
- pasteData[0] &&
1538
- pasteData[0][0] &&
1539
- pasteData[0][0].__isHeaderCell
1540
- ) {
1541
- pasteData = pasteData.slice(1);
1542
- }
1543
- } catch (e) {
1544
- if (toPaste.includes(",")) {
1545
- //try papaparsing it out as a csv if it contains commas
1546
- try {
1547
- const { data, errors } = papaparse.parse(toPaste, {
1548
- header: false
1549
- });
1550
- if (data?.length && !errors?.length) {
1551
- pasteData = data;
1552
- }
1553
- } catch (error) {
1554
- console.error(`error p982qhgpf9qh`, error);
1555
- }
1556
- }
1557
- }
1558
- pasteData = pasteData.length ? pasteData : defaultParsePaste(toPaste);
1559
-
1560
- if (!pasteData || !pasteData.length) return;
1561
-
1562
- if (pasteData.length === 1 && pasteData[0].length === 1) {
1563
- const newCellValidate = {
1564
- ...reduxFormCellValidation
1565
- };
1566
- // single paste value, fill all cells with value
1567
- const newVal = pasteData[0][0];
1568
- updateEntitiesHelper(entities, entities => {
1569
- const entityIdToEntity = getEntityIdToEntity(entities);
1570
- Object.keys(selectedCells).forEach(cellId => {
1571
- const [rowId, path] = cellId.split(":");
1572
-
1573
- const entity = entityIdToEntity[rowId].e;
1574
- delete entity._isClean;
1575
- const { error } = editCellHelper({
1576
- entity,
1577
- path,
1578
- schema,
1579
- newVal: formatPasteData({ newVal, path, schema })
1580
- });
1581
- if (error) {
1582
- newCellValidate[cellId] = error;
1583
- } else {
1584
- delete newCellValidate[cellId];
1585
- }
1586
- });
1587
- updateValidation(entities, newCellValidate);
1588
- });
1589
- } else {
1590
- // handle paste in same format
1591
- if (primarySelectedCellId) {
1592
- const newCellValidate = {
1593
- ...reduxFormCellValidation
1594
- };
1595
-
1596
- const newSelectedCells = { ...selectedCells };
1597
- updateEntitiesHelper(entities, entities => {
1598
- const entityIdToEntity = getEntityIdToEntity(entities);
1599
- const [rowId, primaryCellPath] =
1600
- primarySelectedCellId.split(":");
1601
- const primaryEntityInfo = entityIdToEntity[rowId];
1602
- const startIndex = primaryEntityInfo.i;
1603
- const endIndex = primaryEntityInfo.i + pasteData.length;
1604
- for (let i = startIndex; i < endIndex; i++) {
1605
- if (!entities[i]) {
1606
- entities[i] = { id: nanoid() };
1607
- }
1608
- }
1609
- const entitiesToManipulate = entities.slice(
1610
- startIndex,
1611
- endIndex
1612
- );
1613
- const pathToIndex = getFieldPathToIndex(schema);
1614
- const indexToPath = invert(pathToIndex);
1615
- const startCellIndex = pathToIndex[primaryCellPath];
1616
- pasteData.forEach((row, i) => {
1617
- row.forEach((newVal, j) => {
1618
- if (newVal) {
1619
- const cellIndexToChange = startCellIndex + j;
1620
- const entity = entitiesToManipulate[i];
1621
- if (entity) {
1622
- delete entity._isClean;
1623
- const path = indexToPath[cellIndexToChange];
1624
- if (path) {
1625
- const { error } = editCellHelper({
1626
- entity,
1627
- path,
1628
- schema,
1629
- newVal: formatPasteData({
1630
- newVal,
1631
- path,
1632
- schema
1633
- })
1634
- });
1635
- const cellId = `${getIdOrCodeOrIndex(entity)}:${path}`;
1636
- if (!newSelectedCells[cellId]) {
1637
- newSelectedCells[cellId] = true;
1638
- }
1639
- if (error) {
1640
- newCellValidate[cellId] = error;
1641
- } else {
1642
- delete newCellValidate[cellId];
1643
- }
1644
- }
1645
- }
1646
- }
1647
- });
1648
- });
1649
- updateValidation(entities, newCellValidate);
1650
- });
1651
- setSelectedCells(newSelectedCells);
1652
- }
1653
- }
1654
- } catch (error) {
1655
- console.error(`error:`, error);
1656
- }
1657
- }
1658
- },
1659
- [
1660
- entities,
1661
- isCellEditable,
1662
- primarySelectedCellId,
1663
- reduxFormCellValidation,
1664
- schema,
1665
- selectedCells,
1666
- updateEntitiesHelper,
1667
- updateValidation
1668
- ]
1669
- );
1670
-
1671
- useEffect(() => {
1672
- document.addEventListener("paste", handlePaste);
1673
- return () => {
1674
- document.removeEventListener("paste", handlePaste);
1675
- };
1676
- }, [handlePaste]);
1677
-
1678
- useEffect(() => {
1679
- addFilters(additionalFilters);
1680
- // eslint-disable-next-line react-hooks/exhaustive-deps
1681
- }, [additionalFilters]);
1682
-
1683
- useEffect(() => {
1684
- setColumns(
1685
- schema.fields
1686
- ? schema.fields.reduce((col, field, i) => {
1687
- if (field.isHidden) {
1688
- return col;
1689
- }
1690
- return col.concat({
1691
- ...field,
1692
- columnIndex: i
1693
- });
1694
- }, [])
1695
- : []
1696
- );
1697
- }, [schema?.fields]);
1698
-
1699
- const setSelectedIds = useCallback(
1700
- (selectedIds, scrollToFirst) => {
1701
- const idArray = Array.isArray(selectedIds) ? selectedIds : [selectedIds];
1702
- const selectedEntities = entities.filter(
1703
- e => idArray.indexOf(getIdOrCodeOrIndex(e)) > -1 && !isEntityDisabled(e)
1704
- );
1705
- const newIdMap = selectedEntities.reduce((acc, entity) => {
1706
- acc[getIdOrCodeOrIndex(entity)] = { entity };
1707
- return acc;
1708
- }, {});
1709
- setExpandedEntityIdMap(newIdMap);
1710
- finalizeSelection({
1711
- idMap: newIdMap,
1712
- entities,
1713
- props: {
1714
- onDeselect,
1715
- onSingleRowSelect,
1716
- onMultiRowSelect,
1717
- noDeselectAll,
1718
- onRowSelect,
1719
- noSelect,
1720
- change
1721
- }
1722
- });
1723
- // This option could be eliminated, keeping it because it was prior in the
1724
- // code, but it is a fuctionality not needed
1725
- if (scrollToFirst) {
1726
- const idToScrollTo = idArray[0];
1727
- if (!idToScrollTo && idToScrollTo !== 0) return;
1728
- const entityIndexToScrollTo = entities.findIndex(
1729
- e => e.id === idToScrollTo || e.code === idToScrollTo
1730
- );
1731
- if (entityIndexToScrollTo === -1 || !tableRef.current) return;
1732
- const tableBody = tableRef.current.tableRef.querySelector(".rt-tbody");
1733
- if (!tableBody) return;
1734
- const rowEl =
1735
- tableBody.getElementsByClassName("rt-tr-group")[
1736
- entityIndexToScrollTo
1737
- ];
1738
- if (!rowEl) return;
1739
- setTimeout(() => {
1740
- //we need to delay for a teeny bit to make sure the table has drawn
1741
- rowEl &&
1742
- tableBody &&
1743
- scrollIntoView(rowEl, tableBody, {
1744
- alignWithTop: true
1745
- });
1746
- }, 0);
1747
- }
1748
- },
1749
- [
1750
- change,
1751
- entities,
1752
- isEntityDisabled,
1753
- noDeselectAll,
1754
- noSelect,
1755
- onDeselect,
1756
- onMultiRowSelect,
1757
- onRowSelect,
1758
- onSingleRowSelect
1759
- ]
1760
- );
1761
-
1762
- // We need to make sure this only runs at the beggining
1763
- useEffect(() => {
1764
- if (selectedIds) {
1765
- setSelectedIds(selectedIds);
1766
- }
1767
- if (selectAllByDefault && entities && entities.length) {
1768
- if (alreadySelected.current) return;
1769
- setSelectedIds(entities.map(getIdOrCodeOrIndex));
1770
- alreadySelected.current = true;
1771
- }
1772
- }, [entities, selectedIds, selectAllByDefault, setSelectedIds]);
1773
-
1774
- const TheadComponent = useCallback(
1775
- ({ className, style, children }) => {
1776
- const moveColumn = ({ oldIndex, newIndex }) => {
1777
- let oldStateColumnIndex, newStateColumnIndex;
1778
- columns.forEach((column, i) => {
1779
- if (oldIndex === column.columnIndex) oldStateColumnIndex = i;
1780
- if (newIndex === column.columnIndex) newStateColumnIndex = i;
1781
- });
1782
- // because it is all handled in state we need
1783
- // to perform the move and update the columnIndices
1784
- // because they are used for the sortable columns
1785
- const newColumns = arrayMove(
1786
- columns,
1787
- oldStateColumnIndex,
1788
- newStateColumnIndex
1789
- ).map((column, i) => {
1790
- return {
1791
- ...column,
1792
- columnIndex: i
1793
- };
1794
- });
1795
- setColumns(newColumns);
1796
- };
1797
- return (
1798
- <SortableColumns
1799
- className={className}
1800
- style={style}
1801
- moveColumn={moveColumnPersist || moveColumn}
1802
- >
1803
- {children}
1804
- </SortableColumns>
1805
- );
1806
- },
1807
- [columns, moveColumnPersist]
1808
- );
1809
-
1810
- const addEntitiesToSelection = entities => {
1811
- const idMap = reduxFormSelectedEntityIdMap || {};
1812
- const newIdMap = cloneDeep(idMap) || {};
1813
- entities.forEach((entity, i) => {
1814
- if (isEntityDisabled(entity)) return;
1815
- const entityId = getIdOrCodeOrIndex(entity, i);
1816
- newIdMap[entityId] = { entity };
1817
- });
1818
- finalizeSelection({
1819
- idMap: newIdMap,
1820
- entities,
1821
- props: {
1822
- onDeselect,
1823
- onSingleRowSelect,
1824
- onMultiRowSelect,
1825
- noDeselectAll,
1826
- onRowSelect,
1827
- noSelect,
1828
- change
1829
- }
1830
- });
1831
- };
1832
-
1833
- const refocusTable = useCallback(() => {
1834
- const table = tableRef.current?.tableRef?.closest(
1835
- ".data-table-container>div"
1836
- );
1837
- table?.focus();
1838
- }, []);
1839
-
1840
- const isSelectionARectangle = useCallback(() => {
1841
- if (selectedCells && Object.keys(selectedCells).length > 1) {
1842
- const pathToIndex = getFieldPathToIndex(schema);
1843
- const entityMap = getEntityIdToEntity(entities);
1844
- let selectionGrid = [];
1845
- let firstCellIndex;
1846
- let lastCellIndex;
1847
- let lastRowIndex;
1848
- let firstRowIndex;
1849
- const selectedPaths = [];
1850
- Object.keys(selectedCells).forEach(key => {
1851
- // if (reduxFormSelectedCells[key] === PRIMARY_SELECTED_VAL) {
1852
- // primaryCellId = key;
1853
- // }
1854
- const [rowId, cellPath] = key.split(":");
1855
- if (!selectedPaths.includes(cellPath)) selectedPaths.push(cellPath);
1856
- const cellIndex = pathToIndex[cellPath];
1857
- const ent = entityMap[rowId];
1858
- if (!ent) return;
1859
- const { i } = ent;
1860
- if (firstRowIndex === undefined || i < firstRowIndex) {
1861
- firstRowIndex = i;
1862
- }
1863
- if (lastRowIndex === undefined || i > lastRowIndex) {
1864
- lastRowIndex = i;
1865
- }
1866
- if (!selectionGrid[i]) selectionGrid[i] = [];
1867
- selectionGrid[i][cellIndex] = { cellId: key, rowIndex: i, cellIndex };
1868
- if (firstCellIndex === undefined || cellIndex < firstCellIndex) {
1869
- firstCellIndex = cellIndex;
1870
- }
1871
- if (lastCellIndex === undefined || cellIndex > lastCellIndex) {
1872
- lastCellIndex = cellIndex;
1873
- }
1874
- });
1875
- selectionGrid = selectionGrid.slice(firstRowIndex);
1876
- let isRectangle = true;
1877
- for (let i = 0; i < selectionGrid.length; i++) {
1878
- const row = selectionGrid[i];
1879
- if (!row) {
1880
- isRectangle = false;
1881
- break;
1882
- } else {
1883
- for (let j = firstCellIndex; j < row.length; j++) {
1884
- if (!row[j]) {
1885
- isRectangle = false;
1886
- break;
1887
- }
1888
- }
1889
- }
1890
- }
1891
- if (isRectangle) {
1892
- return {
1893
- entityMap,
1894
- firstCellIndex,
1895
- firstRowIndex,
1896
- isRect: true,
1897
- lastCellIndex,
1898
- lastRowIndex,
1899
- selectedPaths,
1900
- selectionGrid,
1901
- pathToIndex
1902
- };
1903
- } else {
1904
- return {};
1905
- }
1906
- }
1907
- return {};
1908
- }, [entities, schema, selectedCells]);
1909
-
1910
- const handleCellClick = useCallback(
1911
- ({ event, cellId }) => {
1912
- if (!cellId) return;
1913
- const [rowId, cellPath] = cellId.split(":");
1914
- const entityMap = getEntityIdToEntity(entities);
1915
- const { e: entity, i: rowIndex } = entityMap[rowId];
1916
- const pathToIndex = getFieldPathToIndex(schema);
1917
- const columnIndex = pathToIndex[cellPath];
1918
- const rowDisabled = isEntityDisabled(entity);
1919
-
1920
- if (rowDisabled) return;
1921
- let newSelectedCells = {
1922
- ...selectedCells
1923
- };
1924
- if (newSelectedCells[cellId] && !event.shiftKey) {
1925
- // don't deselect if editing
1926
- if (reduxFormEditingCell === cellId) return;
1927
- if (event.metaKey) {
1928
- delete newSelectedCells[cellId];
1929
- } else {
1930
- newSelectedCells = {};
1931
- newSelectedCells[cellId] = PRIMARY_SELECTED_VAL;
1932
- }
1933
- } else {
1934
- if (event.metaKey) {
1935
- if (isEmpty(newSelectedCells)) {
1936
- newSelectedCells[cellId] = PRIMARY_SELECTED_VAL;
1937
- } else {
1938
- newSelectedCells[cellId] = PRIMARY_SELECTED_VAL;
1939
- if (primarySelectedCellId)
1940
- newSelectedCells[primarySelectedCellId] = true;
1941
- }
1942
- } else if (event.shiftKey) {
1943
- if (primarySelectedCellId) {
1944
- const [rowId, colPath] = primarySelectedCellId.split(":");
1945
- const primaryRowIndex = entities.findIndex((e, i) => {
1946
- return getIdOrCodeOrIndex(e, i) === rowId;
1947
- });
1948
- const fieldToIndex = getFieldPathToIndex(schema);
1949
- const primaryColIndex = fieldToIndex[colPath];
1950
-
1951
- if (primaryRowIndex === -1 || primaryColIndex === -1) {
1952
- newSelectedCells = {};
1953
- newSelectedCells[cellId] = PRIMARY_SELECTED_VAL;
1954
- } else {
1955
- const minRowIndex = min([primaryRowIndex, rowIndex]);
1956
- const minColIndex = min([primaryColIndex, columnIndex]);
1957
- const maxRowIndex = max([primaryRowIndex, rowIndex]);
1958
- const maxColIndex = max([primaryColIndex, columnIndex]);
1959
- const entitiesBetweenRows = entities.slice(
1960
- minRowIndex,
1961
- maxRowIndex + 1
1962
- );
1963
- const fieldsBetweenCols = schema.fields.slice(
1964
- minColIndex,
1965
- maxColIndex + 1
1966
- );
1967
- newSelectedCells = {
1968
- [primarySelectedCellId]: PRIMARY_SELECTED_VAL
1969
- };
1970
- entitiesBetweenRows.forEach(e => {
1971
- const rowId = getIdOrCodeOrIndex(e, entities.indexOf(e));
1972
- fieldsBetweenCols.forEach(f => {
1973
- const cellId = `${rowId}:${f.path}`;
1974
- if (!newSelectedCells[cellId])
1975
- newSelectedCells[cellId] = true;
1976
- });
1977
- });
1978
- // newSelectedCells[cellId] = PRIMARY_SELECTED_VAL;
1979
- // newSelectedCells[primarySelectedCellId] = true;
1980
- }
1981
- } else {
1982
- newSelectedCells = {};
1983
- newSelectedCells[cellId] = PRIMARY_SELECTED_VAL;
1984
- }
1985
- } else {
1986
- newSelectedCells = {};
1987
- newSelectedCells[cellId] = PRIMARY_SELECTED_VAL;
1988
- }
1989
- }
1990
-
1991
- setSelectedCells(newSelectedCells);
1992
- },
1993
- [
1994
- entities,
1995
- isEntityDisabled,
1996
- primarySelectedCellId,
1997
- reduxFormEditingCell,
1998
- schema,
1999
- selectedCells
2000
- ]
2001
- );
2002
-
2003
- const insertRows = useCallback(
2004
- ({ above, numRows = 1, appendToBottom } = {}) => {
2005
- const [rowId] = primarySelectedCellId?.split(":") || [];
2006
- updateEntitiesHelper(entities, entities => {
2007
- const newEntities = times(numRows).map(() => ({ id: nanoid() }));
2008
-
2009
- const indexToInsert = entities.findIndex((e, i) => {
2010
- return getIdOrCodeOrIndex(e, i) === rowId;
2011
- });
2012
- const insertIndex = above ? indexToInsert : indexToInsert + 1;
2013
- const insertIndexToUse = appendToBottom ? entities.length : insertIndex;
2014
- let { newEnts, validationErrors } = formatAndValidateEntities(
2015
- newEntities,
2016
- {
2017
- useDefaultValues: true,
2018
- indexToStartAt: insertIndexToUse
2019
- }
2020
- );
2021
-
2022
- newEnts = newEnts.map(e => ({
2023
- ...e,
2024
- _isClean: true
2025
- }));
2026
- updateValidation(entities, {
2027
- ...reduxFormCellValidation,
2028
- ...validationErrors
2029
- });
2030
-
2031
- entities.splice(insertIndexToUse, 0, ...newEnts);
2032
- });
2033
- refocusTable();
2034
- },
2035
- [
2036
- entities,
2037
- formatAndValidateEntities,
2038
- primarySelectedCellId,
2039
- reduxFormCellValidation,
2040
- refocusTable,
2041
- updateEntitiesHelper,
2042
- updateValidation
2043
- ]
2044
- );
2045
-
2046
- const showContextMenu = useCallback(
2047
- (e, { idMap, selectedCells } = {}) => {
2048
- let selectedRecords;
2049
- if (isCellEditable) {
2050
- const rowIds = {};
2051
- Object.keys(selectedCells).forEach(cellKey => {
2052
- const [rowId] = cellKey.split(":");
2053
- rowIds[rowId] = true;
2054
- });
2055
- selectedRecords = entities.filter(
2056
- ent => rowIds[getIdOrCodeOrIndex(ent)]
2057
- );
2058
- } else {
2059
- selectedRecords = getRecordsFromIdMap(idMap);
2060
- }
2061
-
2062
- const itemsToRender = contextMenu({
2063
- selectedRecords,
2064
- history
2065
- });
2066
- if (!itemsToRender && !isCopyable) return null;
2067
- const copyMenuItems = [];
2068
-
2069
- e.persist();
2070
- if (isCopyable) {
2071
- //compute the cellWrapper here so we don't lose access to it
2072
- const cellWrapper =
2073
- e.target.querySelector(".tg-cell-wrapper") ||
2074
- e.target.closest(".tg-cell-wrapper");
2075
- if (cellWrapper) {
2076
- copyMenuItems.push(
2077
- <MenuItem
2078
- key="copyCell"
2079
- onClick={() => {
2080
- //TODOCOPY: we need to make sure that the cell copy is being used by the row copy.. right now we have 2 different things going on
2081
- //do we need to be able to copy hidden cells? It seems like it should just copy what's on the page..?
2082
- const specificColumn = cellWrapper.getAttribute("data-test");
2083
- handleCopyRows([cellWrapper.closest(".rt-tr")], {
2084
- specificColumn,
2085
- onFinishMsg: "Cell copied"
2086
- });
2087
- const [text, jsonText] = getCellCopyText(cellWrapper);
2088
- handleCopyHelper(text, jsonText);
2089
- }}
2090
- text="Cell"
2091
- />
2092
- );
2093
-
2094
- copyMenuItems.push(
2095
- <MenuItem
2096
- key="copyColumn"
2097
- onClick={() => {
2098
- handleCopyColumn(e, cellWrapper);
2099
- }}
2100
- text="Column"
2101
- />
2102
- );
2103
- if (selectedRecords.length > 1) {
2104
- copyMenuItems.push(
2105
- <MenuItem
2106
- key="copyColumnSelected"
2107
- onClick={() => {
2108
- handleCopyColumn(e, cellWrapper, selectedRecords);
2109
- }}
2110
- text="Column (Selected)"
2111
- />
2112
- );
2113
- }
2114
- }
2115
- if (selectedRecords.length === 0 || selectedRecords.length === 1) {
2116
- //compute the row here so we don't lose access to it
2117
- const cell =
2118
- e.target.querySelector(".tg-cell-wrapper") ||
2119
- e.target.closest(".tg-cell-wrapper") ||
2120
- e.target.closest(".rt-td");
2121
- const row = cell.closest(".rt-tr");
2122
- copyMenuItems.push(
2123
- <MenuItem
2124
- key="copySelectedRows"
2125
- onClick={() => {
2126
- handleCopyRows([row]);
2127
- // loop through each cell in the row
2128
- }}
2129
- text="Row"
2130
- />
2131
- );
2132
- } else if (selectedRecords.length > 1) {
2133
- copyMenuItems.push(
2134
- <MenuItem
2135
- key="copySelectedRows"
2136
- onClick={() => {
2137
- handleCopySelectedRows(selectedRecords, e);
2138
- // loop through each cell in the row
2139
- }}
2140
- text="Rows"
2141
- />
2142
- );
2143
- }
2144
- copyMenuItems.push(
2145
- <MenuItem
2146
- key="copyFullTableRows"
2147
- onClick={() => {
2148
- handleCopyTable(e);
2149
- // loop through each cell in the row
2150
- }}
2151
- text="Table"
2152
- />
2153
- );
2154
- }
2155
- const selectedRowIds = Object.keys(selectedCells).map(cellId => {
2156
- const [rowId] = cellId.split(":");
2157
- return rowId;
2158
- });
2159
-
2160
- const menu = (
2161
- <Menu>
2162
- {itemsToRender}
2163
- {copyMenuItems.length && (
2164
- <MenuItem icon="clipboard" key="copyOpts" text="Copy">
2165
- {copyMenuItems}
2166
- </MenuItem>
2167
- )}
2168
- {isCellEditable && (
2169
- <>
2170
- <MenuItem
2171
- icon="add-row-top"
2172
- text="Add Row Above"
2173
- key="addRowAbove"
2174
- onClick={() => {
2175
- insertRows({ above: true });
2176
- }}
2177
- />
2178
- <MenuItem
2179
- icon="add-row-top"
2180
- text="Add Row Below"
2181
- key="addRowBelow"
2182
- onClick={() => {
2183
- insertRows({});
2184
- }}
2185
- />
2186
- <MenuItem
2187
- icon="remove"
2188
- text={`Remove Row${selectedRowIds.length > 1 ? "s" : ""}`}
2189
- key="removeRow"
2190
- onClick={() => {
2191
- const selectedRowIds = Object.keys(selectedCells).map(
2192
- cellId => {
2193
- const [rowId] = cellId.split(":");
2194
- return rowId;
2195
- }
2196
- );
2197
- updateEntitiesHelper(entities, entities => {
2198
- const ents = entities.filter(
2199
- (e, i) =>
2200
- !selectedRowIds.includes(getIdOrCodeOrIndex(e, i))
2201
- );
2202
- updateValidation(
2203
- ents,
2204
- omitBy(reduxFormCellValidation, (v, cellId) =>
2205
- selectedRowIds.includes(cellId.split(":")[0])
2206
- )
2207
- );
2208
- return ents;
2209
- });
2210
- refocusTable();
2211
- }}
2212
- />
2213
- </>
2214
- )}
2215
- </Menu>
2216
- );
2217
- ContextMenu.show(menu, { left: e.clientX, top: e.clientY });
2218
- },
2219
- [
2220
- contextMenu,
2221
- entities,
2222
- handleCopySelectedRows,
2223
- history,
2224
- insertRows,
2225
- isCellEditable,
2226
- isCopyable,
2227
- reduxFormCellValidation,
2228
- refocusTable,
2229
- updateEntitiesHelper,
2230
- updateValidation
2231
- ]
2232
- );
2233
-
2234
- const getTableRowProps = useCallback(
2235
- (state, rowInfo) => {
2236
- if (!rowInfo) {
2237
- return {
2238
- className: "no-row-data"
2239
- };
2240
- }
2241
- const entity = rowInfo.original;
2242
- const rowId = getIdOrCodeOrIndex(entity, rowInfo.index);
2243
- const rowSelected = reduxFormSelectedEntityIdMap[rowId];
2244
- const isExpanded = expandedEntityIdMap[rowId];
2245
- const rowDisabled = isEntityDisabled(entity);
2246
- const dataId = entity.id || entity.code;
2247
- return {
2248
- onClick: e => {
2249
- if (isCellEditable) return;
2250
- // if checkboxes are activated or row expander is clicked don't select row
2251
- if (e.target.matches(".tg-expander, .tg-expander *")) {
2252
- setExpandedEntityIdMap(prev => ({ ...prev, [rowId]: !isExpanded }));
2253
- return;
2254
- } else if (
2255
- e.target.closest(".tg-react-table-checkbox-cell-container")
2256
- ) {
2257
- return;
2258
- } else if (mustClickCheckboxToSelect) {
2259
- return;
2260
- }
2261
- if (e.detail > 1) {
2262
- return; //cancel multiple quick clicks
2263
- }
2264
- rowClick(e, rowInfo, entities, {
2265
- reduxFormSelectedEntityIdMap,
2266
- isSingleSelect,
2267
- noSelect,
2268
- onRowClick,
2269
- isEntityDisabled,
2270
- withCheckboxes,
2271
- onDeselect,
2272
- onSingleRowSelect,
2273
- onMultiRowSelect,
2274
- noDeselectAll,
2275
- onRowSelect,
2276
- change
2277
- });
2278
- },
2279
- //row right click
2280
- onContextMenu: e => {
2281
- e.preventDefault();
2282
- if (rowId === undefined || rowDisabled || isCellEditable) return;
2283
- const oldIdMap = cloneDeep(reduxFormSelectedEntityIdMap) || {};
2284
- let newIdMap;
2285
- if (withCheckboxes) {
2286
- newIdMap = oldIdMap;
2287
- } else {
2288
- // if we are not using checkboxes we need to make sure
2289
- // that the id of the record gets added to the id map
2290
- newIdMap = oldIdMap[rowId] ? oldIdMap : { [rowId]: { entity } };
2291
-
2292
- // tgreen: this will refresh the selection with fresh data. The entities in redux might not be up to date
2293
- const keyedEntities = keyBy(entities, getIdOrCodeOrIndex);
2294
- forEach(newIdMap, (val, key) => {
2295
- const freshEntity = keyedEntities[key];
2296
- if (freshEntity) {
2297
- newIdMap[key] = { ...newIdMap[key], entity: freshEntity };
2298
- }
2299
- });
2300
- finalizeSelection({
2301
- idMap: newIdMap,
2302
- entities,
2303
- props: {
2304
- onDeselect,
2305
- onSingleRowSelect,
2306
- onMultiRowSelect,
2307
- noDeselectAll,
2308
- onRowSelect,
2309
- noSelect,
2310
- change
2311
- }
2312
- });
2313
- }
2314
- showContextMenu(e, { idMap: newIdMap, selectedCells });
2315
- },
2316
- className: classNames(
2317
- "with-row-data",
2318
- getRowClassName && getRowClassName(rowInfo, state),
2319
- {
2320
- disabled: rowDisabled,
2321
- selected: rowSelected && !withCheckboxes,
2322
- "rt-tr-last-row": rowInfo.index === entities.length - 1
2323
- }
2324
- ),
2325
- "data-test-id": dataId === undefined ? rowInfo.index : dataId,
2326
- "data-index": rowInfo.index,
2327
- "data-tip": typeof rowDisabled === "string" ? rowDisabled : undefined,
2328
- onDoubleClick: e => {
2329
- if (rowDisabled) return;
2330
- onDoubleClick &&
2331
- onDoubleClick(rowInfo.original, rowInfo.index, history, e);
2332
- }
2333
- };
2334
- },
2335
- [
2336
- change,
2337
- entities,
2338
- expandedEntityIdMap,
2339
- getRowClassName,
2340
- history,
2341
- isCellEditable,
2342
- isEntityDisabled,
2343
- isSingleSelect,
2344
- mustClickCheckboxToSelect,
2345
- noDeselectAll,
2346
- noSelect,
2347
- onDeselect,
2348
- onDoubleClick,
2349
- onMultiRowSelect,
2350
- onRowClick,
2351
- onRowSelect,
2352
- onSingleRowSelect,
2353
- reduxFormSelectedEntityIdMap,
2354
- selectedCells,
2355
- showContextMenu,
2356
- withCheckboxes
2357
- ]
2358
- );
2359
-
2360
- const getTableCellProps = useCallback(
2361
- (state, rowInfo, column) => {
2362
- if (!isCellEditable) return {}; //only allow cell selection to do stuff here
2363
- if (!rowInfo) return {};
2364
- if (!reduxFormCellValidation) return {};
2365
- const entity = rowInfo.original;
2366
- const rowIndex = rowInfo.index;
2367
- const rowId = getIdOrCodeOrIndex(entity, rowIndex);
2368
- const {
2369
- cellId,
2370
- cellIdAbove,
2371
- cellIdToRight,
2372
- cellIdBelow,
2373
- cellIdToLeft,
2374
- rowDisabled,
2375
- columnIndex
2376
- } = getCellInfo({
2377
- columnIndex: column.index,
2378
- columnPath: column.path,
2379
- rowId,
2380
- schema,
2381
- entities,
2382
- rowIndex,
2383
- isEntityDisabled,
2384
- entity
2385
- });
2386
-
2387
- const _isClean =
2388
- (entity._isClean && doNotValidateUntouchedRows) ||
2389
- isEntityClean(entity);
2390
-
2391
- const err = !_isClean && reduxFormCellValidation[cellId];
2392
- let selectedTopBorder,
2393
- selectedRightBorder,
2394
- selectedBottomBorder,
2395
- selectedLeftBorder;
2396
- if (selectedCells[cellId]) {
2397
- selectedTopBorder = !selectedCells[cellIdAbove];
2398
- selectedRightBorder = !selectedCells[cellIdToRight];
2399
- selectedBottomBorder = !selectedCells[cellIdBelow];
2400
- selectedLeftBorder = !selectedCells[cellIdToLeft];
2401
- }
2402
- const isPrimarySelected = selectedCells[cellId] === PRIMARY_SELECTED_VAL;
2403
- const className = classNames({
2404
- isSelectedCell: selectedCells[cellId],
2405
- isPrimarySelected,
2406
- isSecondarySelected: selectedCells[cellId] === true,
2407
- noSelectedTopBorder: !selectedTopBorder,
2408
- isCleanRow: _isClean,
2409
- noSelectedRightBorder: !selectedRightBorder,
2410
- noSelectedBottomBorder: !selectedBottomBorder,
2411
- noSelectedLeftBorder: !selectedLeftBorder,
2412
- isDropdownCell: column.type === "dropdown",
2413
- isEditingCell: reduxFormEditingCell === cellId,
2414
- hasCellError: !!err,
2415
- "no-data-tip": selectedCells[cellId]
2416
- });
2417
- return {
2418
- onDoubleClick: () => {
2419
- // cell double click
2420
- if (rowDisabled) return;
2421
- startCellEdit(cellId);
2422
- },
2423
- ...(err && {
2424
- "data-tip": err?.message || err,
2425
- "data-no-child-data-tip": true
2426
- }),
2427
- onContextMenu: e => {
2428
- const newSelectedCells = { ...selectedCells };
2429
- if (!isPrimarySelected) {
2430
- if (primarySelectedCellId) {
2431
- newSelectedCells[primarySelectedCellId] = true;
2432
- }
2433
- newSelectedCells[cellId] = PRIMARY_SELECTED_VAL;
2434
- setSelectedCells(newSelectedCells);
2435
- }
2436
- showContextMenu(e, { selectedCells: newSelectedCells });
2437
- },
2438
- onClick: event => {
2439
- handleCellClick({
2440
- event,
2441
- cellId,
2442
- rowDisabled,
2443
- rowIndex,
2444
- columnIndex
2445
- });
2446
- },
2447
- className
2448
- };
2449
- },
2450
- [
2451
- doNotValidateUntouchedRows,
2452
- entities,
2453
- handleCellClick,
2454
- isCellEditable,
2455
- isEntityDisabled,
2456
- primarySelectedCellId,
2457
- reduxFormCellValidation,
2458
- reduxFormEditingCell,
2459
- schema,
2460
- selectedCells,
2461
- showContextMenu,
2462
- startCellEdit
2463
- ]
2464
- );
2465
-
2466
- if (withSelectAll && !safeQuery) {
2467
- throw new Error("safeQuery is needed for selecting all table records");
2468
- }
2469
-
2470
- let compactClassName = "";
2471
- if (compactPaging) {
2472
- compactClassName += " tg-compact-paging";
2473
- }
2474
- compactClassName += extraCompact
2475
- ? " tg-extra-compact-table"
2476
- : compact
2477
- ? " tg-compact-table"
2478
- : "";
2479
-
2480
- const hasFilters =
2481
- filters.length ||
2482
- searchTerm ||
2483
- schema.fields.some(
2484
- field => field.filterIsActive && field.filterIsActive(currentParams)
2485
- );
2486
-
2487
- const additionalFilterKeys = schema.fields.reduce((acc, field) => {
2488
- if (field.filterKey) acc.push(field.filterKey);
2489
- return acc;
2490
- }, []);
2491
-
2492
- const filtersOnNonDisplayedFields = useMemo(() => {
2493
- const _filtersOnNonDisplayedFields = [];
2494
- if (filters && filters.length) {
2495
- schema.fields.forEach(field => {
2496
- const ccDisplayName = getCCDisplayName(field);
2497
- if (field.isHidden) {
2498
- filters.forEach(filter => {
2499
- if (filter.filterOn === ccDisplayName) {
2500
- _filtersOnNonDisplayedFields.push({
2501
- ...filter,
2502
- displayName: field.displayName
2503
- });
2504
- }
2505
- });
2506
- }
2507
- });
2508
- }
2509
- return _filtersOnNonDisplayedFields;
2510
- }, [filters, schema.fields]);
2511
-
2512
- const numRows = isInfinite ? entities.length : pageSize;
2513
- const idMap = useMemo(
2514
- () => reduxFormSelectedEntityIdMap || {},
2515
- [reduxFormSelectedEntityIdMap]
2516
- );
2517
- const selectedRowCount = Object.keys(idMap).filter(key => idMap[key]).length;
2518
-
2519
- let rowsToShow = doNotShowEmptyRows
2520
- ? Math.min(numRows, entities.length)
2521
- : numRows;
2522
- // if there are no entities then provide enough space to show
2523
- // no rows found message
2524
- if (entities.length === 0 && rowsToShow < 3) rowsToShow = 3;
2525
- const expandedRows = entities.reduce((acc, row, index) => {
2526
- const rowId = getIdOrCodeOrIndex(row, index);
2527
- acc[index] = expandedEntityIdMap[rowId];
2528
- return acc;
2529
- }, {});
2530
-
2531
- const showHeader = (withTitle || withSearch || children) && !noHeader;
2532
- const toggleFullscreenButton = (
2533
- <Button
2534
- icon="fullscreen"
2535
- active={fullscreen}
2536
- minimal
2537
- onClick={() => setFullscreen(prev => !prev)}
2538
- />
2539
- );
2540
-
2541
- const { showSelectAll, showClearAll } = useMemo(() => {
2542
- let _showSelectAll = false;
2543
- let _showClearAll = false;
2544
- // we want to show select all if every row on the current page is selected
2545
- // and not every row across all pages are already selected.
2546
- if (!isInfinite) {
2547
- const canShowSelectAll =
2548
- withSelectAll ||
2549
- (entitiesAcrossPages && numRows < entitiesAcrossPages.length);
2550
- if (canShowSelectAll) {
2551
- // could all be disabled
2552
- let atLeastOneRowOnCurrentPageSelected = false;
2553
- const allRowsOnCurrentPageSelected = entities.every(e => {
2554
- const rowId = getIdOrCodeOrIndex(e);
2555
- const selected = idMap[rowId] || isEntityDisabled(e);
2556
- if (selected) atLeastOneRowOnCurrentPageSelected = true;
2557
- return selected;
2558
- });
2559
- if (
2560
- atLeastOneRowOnCurrentPageSelected &&
2561
- allRowsOnCurrentPageSelected
2562
- ) {
2563
- let everyEntitySelected;
2564
- if (isLocalCall) {
2565
- everyEntitySelected = entitiesAcrossPages.every(e => {
2566
- const rowId = getIdOrCodeOrIndex(e);
2567
- return idMap[rowId] || isEntityDisabled(e);
2568
- });
2569
- } else {
2570
- everyEntitySelected = entityCount <= selectedRowCount;
2571
- }
2572
- if (everyEntitySelected) {
2573
- _showClearAll = selectedRowCount;
2574
- }
2575
- // only show if not all selected
2576
- _showSelectAll = !everyEntitySelected;
2577
- }
2578
- }
2579
- }
2580
- return { showSelectAll: _showSelectAll, showClearAll: _showClearAll };
2581
- }, [
2582
- entities,
2583
- entitiesAcrossPages,
2584
- entityCount,
2585
- idMap,
2586
- isEntityDisabled,
2587
- isInfinite,
2588
- isLocalCall,
2589
- numRows,
2590
- selectedRowCount,
2591
- withSelectAll
2592
- ]);
2593
-
2594
- const showNumSelected = !noSelect && !isSingleSelect && !hideSelectedCount;
2595
- const selectedAndTotalMessage = useMemo(() => {
2596
- let _selectedAndTotalMessage = "";
2597
- if (showNumSelected) {
2598
- _selectedAndTotalMessage += `${selectedRowCount} Selected `;
2599
- }
2600
- if (showCount && showNumSelected) {
2601
- _selectedAndTotalMessage += `/ `;
2602
- }
2603
- if (showCount) {
2604
- _selectedAndTotalMessage += `${entityCount || 0} Total`;
2605
- }
2606
- if (_selectedAndTotalMessage) {
2607
- _selectedAndTotalMessage = <div>{_selectedAndTotalMessage}</div>;
2608
- }
2609
- return _selectedAndTotalMessage;
2610
- }, [entityCount, selectedRowCount, showCount, showNumSelected]);
2611
-
2612
- const shouldShowPaging =
2613
- !isInfinite &&
2614
- withPaging &&
2615
- (hidePageSizeWhenPossible ? entityCount > pageSize : true);
2616
-
2617
- const SubComponentToUse = useMemo(() => {
2618
- if (SubComponent) {
2619
- return row => {
2620
- let shouldShow = true;
2621
- if (shouldShowSubComponent) {
2622
- shouldShow = shouldShowSubComponent(row.original);
2623
- }
2624
- if (shouldShow) {
2625
- return SubComponent(row);
2626
- }
2627
- };
2628
- }
2629
- return;
2630
- }, [SubComponent, shouldShowSubComponent]);
2631
-
2632
- const nonDisplayedFilterComp = useMemo(() => {
2633
- if (filtersOnNonDisplayedFields.length) {
2634
- const content = filtersOnNonDisplayedFields.map(
2635
- ({ displayName, path, selectedFilter, filterValue }) => {
2636
- let filterValToDisplay = filterValue;
2637
- if (selectedFilter === "inList") {
2638
- filterValToDisplay = Array.isArray(filterValToDisplay)
2639
- ? filterValToDisplay
2640
- : filterValToDisplay && filterValToDisplay.split(";");
2641
- }
2642
- if (Array.isArray(filterValToDisplay)) {
2643
- filterValToDisplay = filterValToDisplay.join(", ");
2644
- }
2645
- return (
2646
- <div
2647
- key={displayName || startCase(camelCase(path))}
2648
- className="tg-filter-on-non-displayed-field"
2649
- >
2650
- {displayName || startCase(camelCase(path))}{" "}
2651
- {lowerCase(selectedFilter)} {filterValToDisplay}
2652
- </div>
2653
- );
2654
- }
2655
- );
2656
- return (
2657
- <div style={{ marginRight: 5, marginLeft: "auto" }}>
2658
- <Tooltip
2659
- content={
2660
- <div>
2661
- Active filters on hidden columns:
2662
- <br />
2663
- <br />
2664
- {content}
2665
- </div>
2666
- }
2667
- >
2668
- <Icon icon="filter-list" />
2669
- </Tooltip>
2670
- </div>
2671
- );
2672
- }
2673
- return null;
2674
- }, [filtersOnNonDisplayedFields]);
2675
-
2676
- const filteredEnts = useMemo(() => {
2677
- if (onlyShowRowsWErrors) {
2678
- const rowToErrorMap = {};
2679
- forEach(reduxFormCellValidation, (err, cellId) => {
2680
- if (err) {
2681
- const [rowId] = cellId.split(":");
2682
- rowToErrorMap[rowId] = true;
2683
- }
2684
- });
2685
- return entities.filter(e => {
2686
- return rowToErrorMap[e.id];
2687
- });
2688
- }
2689
- return entities;
2690
- }, [entities, onlyShowRowsWErrors, reduxFormCellValidation]);
2691
-
2692
- const renderColumns = useColumns({
2693
- addFilters,
2694
- cellRenderer,
2695
- columns,
2696
- currentParams,
2697
- compact,
2698
- editingCellSelectAll,
2699
- entities,
2700
- expandedEntityIdMap,
2701
- extraCompact,
2702
- filters,
2703
- formName,
2704
- getCellHoverText,
2705
- isCellEditable,
2706
- isEntityDisabled,
2707
- isLocalCall,
2708
- isSimple,
2709
- isSingleSelect,
2710
- isSelectionARectangle,
2711
- noDeselectAll,
2712
- noSelect,
2713
- noUserSelect,
2714
- onDeselect,
2715
- onMultiRowSelect,
2716
- onRowClick,
2717
- onRowSelect,
2718
- onSingleRowSelect,
2719
- order,
2720
- primarySelectedCellId,
2721
- reduxFormCellValidation,
2722
- reduxFormSelectedEntityIdMap,
2723
- refocusTable,
2724
- removeSingleFilter,
2725
- schema,
2726
- selectedCells,
2727
- setExpandedEntityIdMap,
2728
- setNewParams,
2729
- setOrder,
2730
- setSelectedCells,
2731
- shouldShowSubComponent,
2732
- startCellEdit,
2733
- SubComponent,
2734
- tableRef,
2735
- updateEntitiesHelper,
2736
- updateValidation,
2737
- withCheckboxes,
2738
- withExpandAndCollapseAllButton,
2739
- withFilter,
2740
- withSort,
2741
- recordIdToIsVisibleMap,
2742
- setRecordIdToIsVisibleMap
2743
- });
2744
-
2745
- const scrollToTop = useCallback(
2746
- () =>
2747
- tableRef.current?.tableRef?.children?.[0]?.children?.[0]?.scrollIntoView(),
2748
- []
2749
- );
2750
-
2751
- const reactTable = useMemo(
2752
- () => (
2753
- <ReactTable
2754
- data={filteredEnts}
2755
- ref={tableRef}
2756
- className={classNames({
2757
- isCellEditable,
2758
- "tg-table-loading": isLoading,
2759
- "tg-table-disabled": disabled
2760
- })}
2761
- itemSizeEstimator={
2762
- extraCompact
2763
- ? itemSizeEstimators.compact
2764
- : compact
2765
- ? itemSizeEstimators.normal
2766
- : itemSizeEstimators.comfortable
2767
- }
2768
- TfootComponent={() => {
2769
- return <button>hasdfasdf</button>;
2770
- }}
2771
- // We should try to not give all the props to the render column
2772
- columns={renderColumns}
2773
- pageSize={rowsToShow}
2774
- expanded={expandedRows}
2775
- showPagination={false}
2776
- sortable={false}
2777
- loading={isLoading || disabled}
2778
- defaultResized={resized}
2779
- onResizedChange={(newResized = []) => {
2780
- const resizedToUse = newResized.map(column => {
2781
- // have a min width of 50 so that columns don't disappear
2782
- if (column.value < 50) {
2783
- return {
2784
- ...column,
2785
- value: 50
2786
- };
2787
- } else {
2788
- return column;
2789
- }
2790
- });
2791
- resizePersist(resizedToUse);
2792
- }}
2793
- TheadComponent={TheadComponent}
2794
- ThComponent={ThComponent}
2795
- getTrGroupProps={getTableRowProps}
2796
- getTdProps={getTableCellProps}
2797
- NoDataComponent={({ children }) =>
2798
- isLoading ? null : (
2799
- <div className="rt-noData">{noRowsFoundMessage || children}</div>
2800
- )
2801
- }
2802
- LoadingComponent={({ loadingText, loading }) => (
2803
- <DisabledLoadingComponent
2804
- loading={loading}
2805
- loadingText={loadingText}
2806
- disabled={disabled}
2807
- />
2808
- )}
2809
- style={{
2810
- maxHeight,
2811
- minHeight: 150,
2812
- ...style
2813
- }}
2814
- SubComponent={SubComponentToUse}
2815
- {...ReactTableProps}
2816
- />
2817
- ),
2818
- [
2819
- ReactTableProps,
2820
- SubComponentToUse,
2821
- TheadComponent,
2822
- compact,
2823
- disabled,
2824
- expandedRows,
2825
- extraCompact,
2826
- filteredEnts,
2827
- getTableCellProps,
2828
- getTableRowProps,
2829
- isCellEditable,
2830
- isLoading,
2831
- maxHeight,
2832
- noRowsFoundMessage,
2833
- renderColumns,
2834
- resizePersist,
2835
- resized,
2836
- rowsToShow,
2837
- style
2838
- ]
2839
- );
2840
-
2841
- return (
2842
- <div tabIndex="1" onKeyDown={handleKeyDown} onKeyUp={handleKeyUp}>
2843
- <div
2844
- className={classNames(
2845
- "data-table-container",
2846
- extraClasses,
2847
- className,
2848
- compactClassName,
2849
- {
2850
- fullscreen,
2851
- in_cypress_test: window.Cypress, //tnr: this is a hack to make cypress be able to correctly click the table without the sticky header getting in the way. remove me once https://github.com/cypress-io/cypress/issues/871 is fixed
2852
- "dt-isViewable": isViewable,
2853
- "dt-minimalStyle": minimalStyle,
2854
- "no-padding": noPadding,
2855
- "hide-column-header": hideColumnHeader
2856
- }
2857
- )}
2858
- >
2859
- <div
2860
- className="data-table-container-inner"
2861
- {...(isCellEditable && {
2862
- tabIndex: -1,
2863
- onKeyDown: e => {
2864
- const isTabKey = e.key === "Tab";
2865
- const isArrowKey = e.key.startsWith("Arrow");
2866
- if ((isArrowKey && e.target?.tagName !== "INPUT") || isTabKey) {
2867
- const left = e.key === "ArrowLeft";
2868
- const up = e.key === "ArrowUp";
2869
- const down = e.key === "ArrowDown" || e.key === "Enter";
2870
- let cellIdToUse = primarySelectedCellId;
2871
- const pathToIndex = getFieldPathToIndex(schema);
2872
- const entityMap = getEntityIdToEntity(entities);
2873
- if (!cellIdToUse) return;
2874
- const {
2875
- isRect,
2876
- firstCellIndex,
2877
- lastCellIndex,
2878
- lastRowIndex,
2879
- firstRowIndex
2880
- } = isSelectionARectangle();
2881
-
2882
- if (isRect) {
2883
- const [rowId, columnPath] = cellIdToUse.split(":");
2884
-
2885
- const columnIndex = pathToIndex[columnPath];
2886
- const indexToPath = invert(pathToIndex);
2887
- // we want to grab the cell opposite to the primary selected cell
2888
- if (
2889
- firstCellIndex === columnIndex &&
2890
- firstRowIndex === entityMap[rowId]?.i
2891
- ) {
2892
- cellIdToUse = `${entities[lastRowIndex].id}:${indexToPath[lastCellIndex]}`;
2893
- } else if (
2894
- firstCellIndex === columnIndex &&
2895
- lastRowIndex === entityMap[rowId]?.i
2896
- ) {
2897
- cellIdToUse = `${entities[firstRowIndex].id}:${indexToPath[lastCellIndex]}`;
2898
- } else if (
2899
- lastCellIndex === columnIndex &&
2900
- firstRowIndex === entityMap[rowId]?.i
2901
- ) {
2902
- cellIdToUse = `${entities[lastRowIndex].id}:${indexToPath[firstCellIndex]}`;
2903
- } else {
2904
- cellIdToUse = `${entities[firstRowIndex].id}:${indexToPath[firstCellIndex]}`;
2905
- }
2906
- }
2907
- if (!cellIdToUse) return;
2908
- const [rowId, columnPath] = cellIdToUse.split(":");
2909
- const columnIndex = pathToIndex[columnPath];
2910
-
2911
- const { i: rowIndex } = entityMap[rowId];
2912
-
2913
- const {
2914
- cellIdAbove,
2915
- cellIdToRight,
2916
- cellIdBelow,
2917
- cellIdToLeft
2918
- } = getCellInfo({
2919
- columnIndex,
2920
- columnPath,
2921
- rowId,
2922
- schema,
2923
- entities,
2924
- rowIndex,
2925
- isEntityDisabled,
2926
- entity: entityMap[rowId].e
2927
- });
2928
- const nextCellId = up
2929
- ? cellIdAbove
2930
- : down
2931
- ? cellIdBelow
2932
- : left
2933
- ? cellIdToLeft
2934
- : cellIdToRight;
2935
-
2936
- e.stopPropagation();
2937
- e.preventDefault();
2938
- if (!nextCellId) return;
2939
- // this.handleCellBlur();
2940
- // this.finishCellEdit
2941
- if (
2942
- document.activeElement?.parentElement?.classList.contains(
2943
- "rt-td"
2944
- )
2945
- ) {
2946
- document.activeElement.blur();
2947
- }
2948
- handleCellClick({
2949
- event: e,
2950
- cellId: nextCellId
2951
- });
2952
- }
2953
- if (e.metaKey || e.ctrlKey || e.altKey) return;
2954
- if (!primarySelectedCellId) return;
2955
- const entityIdToEntity = getEntityIdToEntity(entities);
2956
- const [rowId] = primarySelectedCellId.split(":");
2957
- if (!rowId) return;
2958
- const entity = entityIdToEntity[rowId].e;
2959
- if (!entity) return;
2960
- const rowDisabled = isEntityDisabled(entity);
2961
- const isNum = e.code?.startsWith("Digit");
2962
- const isLetter = e.code?.startsWith("Key");
2963
- if (!isNum && !isLetter) {
2964
- return;
2965
- }
2966
- if (rowDisabled) return;
2967
- e.stopPropagation();
2968
- startCellEdit(primarySelectedCellId, e.key);
2969
- }
2970
- })}
2971
- >
2972
- {isCellEditable && entities.length > 50 && (
2973
- // test for this!!
2974
- <SwitchField
2975
- name="onlyShowRowsWErrors"
2976
- inlineLabel={true}
2977
- label="Only Show Rows With Errors"
2978
- onChange={e => {
2979
- setOnlyShowRowsWErrors(e.target.value);
2980
- }}
2981
- />
2982
- )}
2983
- {showHeader && (
2984
- <div className="data-table-header">
2985
- <div className="data-table-title-and-buttons">
2986
- {tableName && withTitle && (
2987
- <span className="data-table-title">{tableName}</span>
2988
- )}
2989
- {children}
2990
- {topLeftItems}
2991
- </div>
2992
- {errorParsingUrlString && (
2993
- <Callout
2994
- icon="error"
2995
- style={{
2996
- width: "unset"
2997
- }}
2998
- intent={Intent.WARNING}
2999
- >
3000
- Error parsing URL
3001
- </Callout>
3002
- )}
3003
- {nonDisplayedFilterComp}
3004
- {withSearch && (
3005
- <div className="data-table-search-and-clear-filter-container">
3006
- {leftOfSearchBarItems}
3007
- {hasFilters ? (
3008
- <Tooltip content="Clear Filters">
3009
- <Button
3010
- minimal
3011
- intent="danger"
3012
- icon="filter-remove"
3013
- disabled={disabled}
3014
- className="data-table-clear-filters"
3015
- onClick={() => {
3016
- clearFilters(additionalFilterKeys);
3017
- }}
3018
- />
3019
- </Tooltip>
3020
- ) : (
3021
- ""
3022
- )}
3023
- <SearchBar
3024
- noForm={noForm}
3025
- searchInput={currentParams.searchTerm}
3026
- setSearchTerm={setSearchTerm}
3027
- loading={isLoading}
3028
- searchMenuButton={searchMenuButton}
3029
- disabled={disabled}
3030
- autoFocusSearch={autoFocusSearch}
3031
- />
3032
- </div>
3033
- )}
3034
- </div>
3035
- )}
3036
- {subHeader}
3037
- {showSelectAll && !isSingleSelect && (
3038
- <div
3039
- style={{
3040
- marginTop: 5,
3041
- marginBottom: 5,
3042
- display: "flex",
3043
- alignItems: "center"
3044
- }}
3045
- >
3046
- All items on this page are selected.{" "}
3047
- <Button
3048
- small
3049
- minimal
3050
- intent="primary"
3051
- text={`Select all ${
3052
- entityCount || entitiesAcrossPages.length
3053
- } items`}
3054
- loading={selectingAll}
3055
- onClick={async () => {
3056
- if (withSelectAll) {
3057
- // this will be by querying for everything
3058
- setSelectingAll(true);
3059
- try {
3060
- const allEntities = await safeQuery(fragment, {
3061
- variables: {
3062
- filter: variables.filter,
3063
- sort: variables.sort
3064
- },
3065
- canCancel: true
3066
- });
3067
- addEntitiesToSelection(allEntities);
3068
- } catch (error) {
3069
- console.error(`error:`, error);
3070
- window.toastr.error("Error selecting all constructs");
3071
- }
3072
- setSelectingAll(false);
3073
- } else {
3074
- addEntitiesToSelection(entitiesAcrossPages);
3075
- }
3076
- }}
3077
- />
3078
- </div>
3079
- )}
3080
- {showClearAll > 0 && (
3081
- <div
3082
- style={{
3083
- marginTop: 5,
3084
- marginBottom: 5,
3085
- display: "flex",
3086
- alignItems: "center"
3087
- }}
3088
- >
3089
- All {showClearAll} items are selected.
3090
- <Button
3091
- small
3092
- minimal
3093
- intent="primary"
3094
- text="Clear Selection"
3095
- onClick={() => {
3096
- finalizeSelection({
3097
- idMap: {},
3098
- entities,
3099
- props: {
3100
- onDeselect,
3101
- onSingleRowSelect,
3102
- onMultiRowSelect,
3103
- noDeselectAll,
3104
- onRowSelect,
3105
- noSelect,
3106
- change
3107
- }
3108
- });
3109
- }}
3110
- />
3111
- </div>
3112
- )}
3113
- {reactTable}
3114
- {isCellEditable && (
3115
- <div style={{ display: "flex" }}>
3116
- <div
3117
- style={{
3118
- width: "100%",
3119
- display: "flex",
3120
- justifyContent: "center"
3121
- }}
3122
- >
3123
- {!onlyShowRowsWErrors && (
3124
- <Button
3125
- icon="add"
3126
- onClick={() => {
3127
- insertRows({ numRows: 10, appendToBottom: true });
3128
- }}
3129
- minimal
3130
- >
3131
- Add 10 Rows
3132
- </Button>
3133
- )}
3134
- </div>
3135
- <Button
3136
- onClick={e => {
3137
- handleCopyTable(e, { isDownload: true });
3138
- }}
3139
- data-tip="Download Table as CSV"
3140
- minimal
3141
- icon="download"
3142
- />
3143
- </div>
3144
- )}
3145
- {!noFooter && (
3146
- <div
3147
- className="data-table-footer"
3148
- style={{
3149
- justifyContent:
3150
- !showNumSelected && !showCount ? "flex-end" : "space-between"
3151
- }}
3152
- >
3153
- {selectedAndTotalMessage}
3154
- <div style={{ display: "flex", flexWrap: "wrap" }}>
3155
- {additionalFooterButtons}
3156
- {!noFullscreenButton && toggleFullscreenButton}
3157
- {withDisplayOptions && (
3158
- <DisplayOptions
3159
- compact={compact}
3160
- extraCompact={extraCompact}
3161
- disabled={disabled}
3162
- hideDisplayOptionsIcon={hideDisplayOptionsIcon}
3163
- resetDefaultVisibility={resetDefaultVisibility}
3164
- updateColumnVisibility={updateColumnVisibility}
3165
- updateTableDisplayDensity={updateTableDisplayDensity}
3166
- showForcedHiddenColumns={showForcedHiddenColumns}
3167
- setShowForcedHidden={setShowForcedHidden}
3168
- hasOptionForForcedHidden={
3169
- withDisplayOptions && (isSimple || isInfinite)
3170
- }
3171
- schema={schema}
3172
- />
3173
- )}
3174
- {shouldShowPaging && (
3175
- <PagingTool
3176
- controlled_hasNextPage={controlled_hasNextPage}
3177
- controlled_onRefresh={controlled_onRefresh}
3178
- controlled_page={controlled_page}
3179
- controlled_setPage={controlled_setPage}
3180
- controlled_setPageSize={controlled_setPageSize}
3181
- controlled_total={controlled_total}
3182
- disabled={disabled}
3183
- disableSetPageSize={disableSetPageSize}
3184
- entities={entities}
3185
- entityCount={entityCount}
3186
- hideSetPageSize={hideSetPageSize}
3187
- hideTotalPages={hideTotalPages}
3188
- keepSelectionOnPageChange={keepSelectionOnPageChange}
3189
- onRefresh={onRefresh}
3190
- page={page}
3191
- pageSize={pageSize}
3192
- pagingDisabled={pagingDisabled}
3193
- persistPageSize={persistPageSize}
3194
- setPage={setPage}
3195
- setPageSize={setPageSize}
3196
- setSelectedEntityIdMap={newIdMap => {
3197
- change("reduxFormSelectedEntityIdMap", newIdMap);
3198
- }}
3199
- scrollToTop={scrollToTop}
3200
- />
3201
- )}
3202
- </div>
3203
- </div>
3204
- )}
3205
- </div>
3206
- </div>
3207
- </div>
3208
- );
3209
- };
3210
-
3211
- const WrappedDT = dataTableEnhancer(DataTable);
3212
- export default WrappedDT;
3213
- const ConnectedPagingTool = dataTableEnhancer(PagingTool);
3214
- export { ConnectedPagingTool };