@teselagen/ui 0.6.6 → 0.7.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 (98) hide show
  1. package/DataTable/ColumnFilterMenu.d.ts +2 -1
  2. package/DataTable/Columns.d.ts +51 -0
  3. package/DataTable/DisplayOptions.d.ts +14 -14
  4. package/DataTable/EditabelCell.d.ts +2 -5
  5. package/DataTable/EditableCell.d.ts +7 -0
  6. package/DataTable/FilterAndSortMenu.d.ts +9 -9
  7. package/DataTable/PagingTool.d.ts +25 -2
  8. package/DataTable/RenderCell.d.ts +18 -0
  9. package/DataTable/SearchBar.d.ts +4 -3
  10. package/DataTable/SortableColumns.d.ts +6 -9
  11. package/DataTable/ThComponent.d.ts +9 -0
  12. package/DataTable/index.d.ts +0 -5
  13. package/DataTable/utils/getIdOrCodeOrIndex.d.ts +1 -2
  14. package/DataTable/utils/handleCopyTable.d.ts +1 -0
  15. package/DataTable/utils/index.d.ts +4 -2
  16. package/DataTable/utils/primarySelectedValue.d.ts +1 -0
  17. package/DataTable/utils/queryParams.d.ts +13 -8
  18. package/DataTable/utils/removeCleanRows.d.ts +1 -1
  19. package/DataTable/utils/rowClick.d.ts +24 -3
  20. package/DataTable/utils/useDeepEqualMemo.d.ts +1 -0
  21. package/DataTable/utils/useTableEntities.d.ts +5 -0
  22. package/DataTable/utils/useTableParams.d.ts +49 -0
  23. package/DataTable/utils/withTableParams.d.ts +3 -16
  24. package/DataTable/viewColumn.d.ts +11 -4
  25. package/FormComponents/AbstractField.d.ts +1 -0
  26. package/FormComponents/Uploader.d.ts +34 -1
  27. package/FormComponents/index.d.ts +111 -60
  28. package/MatchHeaders.d.ts +9 -10
  29. package/SimpleStepViz.d.ts +2 -1
  30. package/TgSuggest/index.d.ts +1 -21
  31. package/UploadCsvWizard.d.ts +1 -1
  32. package/index.cjs.js +47861 -49125
  33. package/index.d.ts +6 -3
  34. package/index.es.js +47959 -49223
  35. package/package.json +6 -5
  36. package/src/DataTable/CellDragHandle.js +70 -69
  37. package/src/DataTable/ColumnFilterMenu.js +23 -21
  38. package/src/DataTable/Columns.js +948 -0
  39. package/src/DataTable/Columns.jsx +945 -0
  40. package/src/DataTable/DisplayOptions.js +173 -192
  41. package/src/DataTable/EditabelCell.js +7 -18
  42. package/src/DataTable/EditabelCell.jsx +44 -0
  43. package/src/DataTable/EditableCell.js +44 -0
  44. package/src/DataTable/FilterAndSortMenu.js +215 -234
  45. package/src/DataTable/PagingTool.js +47 -56
  46. package/src/DataTable/RenderCell.js +191 -0
  47. package/src/DataTable/RenderCell.jsx +191 -0
  48. package/src/DataTable/SearchBar.js +12 -5
  49. package/src/DataTable/SortableColumns.js +44 -39
  50. package/src/DataTable/ThComponent.js +44 -0
  51. package/src/DataTable/dataTableEnhancer.js +32 -295
  52. package/src/DataTable/index.js +2945 -3596
  53. package/src/DataTable/utils/getIdOrCodeOrIndex.js +1 -1
  54. package/src/DataTable/utils/handleCopyTable.js +16 -0
  55. package/src/DataTable/utils/index.js +7 -3
  56. package/src/DataTable/utils/primarySelectedValue.js +1 -0
  57. package/src/DataTable/utils/queryParams.js +110 -85
  58. package/src/DataTable/utils/removeCleanRows.js +3 -3
  59. package/src/DataTable/utils/rowClick.js +34 -9
  60. package/src/DataTable/utils/selection.js +1 -1
  61. package/src/DataTable/utils/useDeepEqualMemo.js +10 -0
  62. package/src/DataTable/utils/useTableEntities.js +38 -0
  63. package/src/DataTable/utils/useTableParams.js +362 -0
  64. package/src/DataTable/utils/withTableParams.js +244 -274
  65. package/src/DataTable/validateTableWideErrors.js +1 -1
  66. package/src/DataTable/viewColumn.js +5 -9
  67. package/src/DialogFooter/index.js +3 -3
  68. package/src/FillWindow.js +2 -3
  69. package/src/FormComponents/AbstractField.js +388 -0
  70. package/src/FormComponents/Uploader.js +674 -649
  71. package/src/FormComponents/index.js +505 -654
  72. package/src/FormComponents/tryToMatchSchemas.js +1 -6
  73. package/src/MatchHeaders.js +27 -22
  74. package/src/SimpleStepViz.js +19 -23
  75. package/src/TgSelect/index.js +1 -1
  76. package/src/TgSuggest/index.js +94 -106
  77. package/src/UploadCsvWizard.js +571 -577
  78. package/src/enhancers/withDialog/tg_modalState.js +1 -0
  79. package/src/index.js +10 -4
  80. package/src/showDialogOnDocBody.js +5 -9
  81. package/src/useDialog.js +25 -26
  82. package/src/utils/commandControls.js +2 -2
  83. package/src/utils/handlerHelpers.js +19 -25
  84. package/src/utils/hooks/index.js +1 -0
  85. package/src/utils/hooks/useDeepEqualMemo.js +10 -0
  86. package/src/utils/hooks/useStableReference.js +9 -0
  87. package/src/utils/renderOnDoc.js +8 -5
  88. package/src/utils/tagUtils.js +3 -3
  89. package/src/utils/useTraceUpdate.js +19 -0
  90. package/src/wrapDialog.js +0 -2
  91. package/style.css +251 -251
  92. package/useDialog.d.ts +2 -6
  93. package/utils/hooks/index.d.ts +1 -0
  94. package/utils/hooks/useDeepEqualMemo.d.ts +1 -0
  95. package/utils/hooks/useStableReference.d.ts +1 -0
  96. package/utils/renderOnDoc.d.ts +1 -1
  97. package/utils/tagUtils.d.ts +5 -1
  98. package/utils/useTraceUpdate.d.ts +1 -0
@@ -5,300 +5,37 @@
5
5
  * @property {string} queryName What the props come back on ( by default = modelName + 'Query')
6
6
  */
7
7
  import { reduxForm } from "redux-form";
8
-
9
- import { arrayMove } from "@dnd-kit/sortable";
10
- import { toArray, keyBy, get } from "lodash-es";
11
- import { withProps, withState, branch, compose } from "recompose";
12
- import withTableParams from "../DataTable/utils/withTableParams";
13
- import convertSchema from "../DataTable/utils/convertSchema";
14
- import { viewColumn, openColumn } from "../DataTable/viewColumn";
15
- import pureNoFunc from "../utils/pureNoFunc";
16
- import tgFormValues from "../utils/tgFormValues";
17
- import getTableConfigFromStorage from "./utils/getTableConfigFromStorage";
18
-
8
+ import { branch, compose, withProps } from "recompose";
9
+ import { withRouter } from "react-router-dom";
10
+
11
+ /*
12
+ Right now DataTable is doing the same as withTableParams, so the logic is being
13
+ run twice. We need to refactor this to make it more DRY.
14
+ We could do two possible refactorings:
15
+ - remove withTableParams and just give all the appropiate props to DataTable. This would
16
+ make the component simpler.
17
+ - remove the logic from DataTable and just use withTableParams and a new hook called
18
+ useTableParams. This would be more flexible in the case we want to be able to use
19
+ pagination in a different component.
20
+ We should avoid having the component handle all the different
21
+ cases of input because of the next reasons:
22
+ 1. It makes the component more complex and harder to understand.
23
+ 2. It makes the component harder to test.
24
+ 3. It makes the component harder to reuse.
25
+ 4. Maintaining the the logic in the component is harder.
26
+ Keeping the logic and uses simple makes maintaining easier.
27
+
28
+ In my opinion, reduxForm could be replaced here with regular redux or even just be taken down.
29
+ Could be a major simplification, but this needs to be analized with lims for better
30
+ understanding if it's possible.
31
+ */
19
32
  export default compose(
20
- // maybe we need this in some cases?
21
- // tgFormValues("reduxFormEntities"),
22
- // withProps(props => {
23
- // const entities = props.reduxFormEntities || props.entities;
24
- // return {
25
- // _origEntities: props.entities,
26
- // entities
27
- // };
28
- // }),
29
- //connect to withTableParams here in the dataTable component so that, in the case that the table is not manually connected,
30
- withTableParams({
31
- isLocalCall: true
32
- }),
33
- branch(
34
- props => props.showEmptyColumnsByDefault,
35
- withState("showForcedHiddenColumns", "setShowForcedHidden", true),
36
- withState("showForcedHiddenColumns", "setShowForcedHidden", false)
37
- ),
38
- withProps(ownProps => {
39
- let propsToUse = ownProps;
40
- if (!ownProps.isTableParamsConnected) {
41
- //this is the case where we're hooking up to withTableParams locally, so we need to take the tableParams off the props
42
- propsToUse = {
43
- ...ownProps,
44
- ...ownProps.tableParams
45
- };
46
- }
47
-
48
- const {
49
- schema,
50
- withDisplayOptions,
51
- syncDisplayOptionsToDb,
52
- formName,
53
- tableConfigurations,
54
- deleteTableConfiguration,
55
- upsertTableConfiguration,
56
- upsertFieldOption,
57
- currentUser,
58
- isViewable,
59
- isOpenable,
60
- entities = [],
61
- cellRenderer = {},
62
- showForcedHiddenColumns,
63
- isSimple,
64
- isInfinite,
65
- compact = true,
66
- extraCompact
67
- } = propsToUse;
68
- let schemaToUse = convertSchema(schema);
69
- let fieldOptsByPath = {};
70
- let tableConfig = {};
71
- let resetDefaultVisibility;
72
- let updateColumnVisibility;
73
- let persistPageSize;
74
- let moveColumnPersist;
75
- let resizePersist;
76
- let updateTableDisplayDensity;
77
- let compactToUse = !!compact;
78
- let extraCompactToUse = !!extraCompact;
79
-
80
- if (isViewable) {
81
- schemaToUse.fields = [viewColumn, ...schemaToUse.fields];
82
- }
83
- if (isOpenable) {
84
- schemaToUse.fields = [openColumn, ...schemaToUse.fields];
85
- }
86
- // this must come before handling orderings.
87
- schemaToUse.fields = schemaToUse.fields.map(field => {
88
- if (field.placementPath) {
89
- return {
90
- ...field,
91
- sortDisabled:
92
- field.sortDisabled ||
93
- (typeof field.path === "string" && field.path.includes(".")),
94
- path: field.placementPath
95
- };
96
- } else {
97
- return field;
98
- }
99
- });
100
- const hasOptionForForcedHidden =
101
- withDisplayOptions && (isSimple || isInfinite);
102
- if (withDisplayOptions) {
103
- if (syncDisplayOptionsToDb) {
104
- tableConfig = tableConfigurations && tableConfigurations[0];
105
- } else {
106
- tableConfig = getTableConfigFromStorage(formName);
107
- }
108
- if (!tableConfig) {
109
- tableConfig = {
110
- fieldOptions: []
111
- };
112
- }
113
- if (tableConfig.density) {
114
- compactToUse = tableConfig.density === "compact";
115
- }
116
- if (tableConfig.density) {
117
- extraCompactToUse = tableConfig.density === "extraCompact";
118
- }
119
- const columnOrderings = tableConfig.columnOrderings;
120
- fieldOptsByPath = keyBy(tableConfig.fieldOptions, "path");
121
- schemaToUse = {
122
- ...schemaToUse,
123
- fields: schemaToUse.fields.map(field => {
124
- const fieldOpt = fieldOptsByPath[field.path];
125
- let noValsForField = false;
126
- // only add this hidden column ability if no paging
127
- if (!showForcedHiddenColumns && hasOptionForForcedHidden) {
128
- noValsForField = entities.every(e => {
129
- const val = get(e, field.path);
130
- return field.render
131
- ? !field.render(val, e)
132
- : cellRenderer[field.path]
133
- ? !cellRenderer[field.path](val, e)
134
- : !val;
135
- });
136
- }
137
- if (noValsForField) {
138
- return {
139
- ...field,
140
- isHidden: true,
141
- isForcedHidden: true
142
- };
143
- } else if (fieldOpt) {
144
- return {
145
- ...field,
146
- isHidden: fieldOpt.isHidden
147
- };
148
- } else {
149
- return field;
150
- }
151
- })
152
- };
153
-
154
- if (columnOrderings) {
155
- const fieldsWithOrders = [];
156
- const fieldsWithoutOrder = [];
157
- // if a new field has been added since the orderings were set then we want
158
- // it to be at the end instead of the beginning
159
- schemaToUse.fields.forEach(field => {
160
- if (columnOrderings.indexOf(field.path) > -1) {
161
- fieldsWithOrders.push(field);
162
- } else {
163
- fieldsWithoutOrder.push(field);
164
- }
165
- });
166
- schemaToUse.fields = fieldsWithOrders
167
- .sort(({ path: path1 }, { path: path2 }) => {
168
- return (
169
- columnOrderings.indexOf(path1) - columnOrderings.indexOf(path2)
170
- );
171
- })
172
- .concat(fieldsWithoutOrder);
173
- tableConfig.columnOrderings = schemaToUse.fields.map(f => f.path);
174
- }
175
-
176
- if (syncDisplayOptionsToDb) {
177
- //sync up to db
178
- let tableConfigurationId;
179
- resetDefaultVisibility = function () {
180
- tableConfigurationId = tableConfig.id;
181
-
182
- if (tableConfigurationId) {
183
- deleteTableConfiguration(tableConfigurationId);
184
- }
185
- };
186
- updateColumnVisibility = function ({ shouldShow, path }) {
187
- if (tableConfigurationId) {
188
- const existingFieldOpt = fieldOptsByPath[path] || {};
189
- upsertFieldOption({
190
- id: existingFieldOpt.id,
191
- path,
192
- isHidden: !shouldShow,
193
- tableConfigurationId
194
- });
195
- } else {
196
- upsertTableConfiguration({
197
- userId: currentUser.user.id,
198
- formName,
199
- fieldOptions: [
200
- {
201
- path,
202
- isHidden: !shouldShow
203
- }
204
- ]
205
- });
206
- }
207
- };
208
- } else {
209
- const syncStorage = () => {
210
- window.localStorage.setItem(formName, JSON.stringify(tableConfig));
211
- };
212
-
213
- //sync display options with localstorage
214
- resetDefaultVisibility = function () {
215
- window.localStorage.removeItem(formName);
216
- };
217
- updateColumnVisibility = function ({ path, paths, shouldShow }) {
218
- const newFieldOpts = {
219
- ...fieldOptsByPath
220
- };
221
- const pathsToUse = paths ? paths : [path];
222
- pathsToUse.forEach(path => {
223
- newFieldOpts[path] = { path, isHidden: !shouldShow };
224
- });
225
- tableConfig.fieldOptions = toArray(newFieldOpts);
226
- syncStorage();
227
- };
228
- updateTableDisplayDensity = function (density) {
229
- tableConfig.density = density;
230
- syncStorage();
231
- };
232
- persistPageSize = function (pageSize) {
233
- tableConfig.userSetPageSize = pageSize;
234
- syncStorage();
235
- };
236
- moveColumnPersist = function ({ oldIndex, newIndex }) {
237
- // we might already have an array of the fields [path1, path2, ..etc]
238
- const columnOrderings =
239
- tableConfig.columnOrderings ||
240
- schemaToUse.fields.map(({ path }) => path); // columnOrderings is [path1, path2, ..etc]
241
-
242
- tableConfig.columnOrderings = arrayMove(
243
- columnOrderings,
244
- oldIndex,
245
- newIndex
246
- );
247
- syncStorage();
248
- };
249
- resizePersist = function (newResized) {
250
- tableConfig.resized = newResized;
251
- syncStorage();
252
- };
253
- }
254
- }
255
- const resized = tableConfig.resized;
256
- return {
257
- ...propsToUse,
258
- schema: schemaToUse,
259
- compact: compactToUse,
260
- extraCompact: extraCompactToUse,
261
- resized,
262
- resetDefaultVisibility,
263
- updateColumnVisibility,
264
- persistPageSize,
265
- updateTableDisplayDensity,
266
- resizePersist,
267
- moveColumnPersist,
268
- hasOptionForForcedHidden
269
- };
270
- }),
271
- branch(props => !props.noForm, reduxForm({})), //the formName is passed via withTableParams and is often user overridden
272
- tgFormValues(
273
- "localStorageForceUpdate",
274
- "reduxFormQueryParams",
275
- "reduxFormSearchInput",
276
- "onlyShowRowsWErrors",
277
- "reduxFormSelectedEntityIdMap",
278
- "reduxFormExpandedEntityIdMap",
279
- "reduxFormSelectedCells",
280
- "reduxFormEditingCell",
281
- "reduxFormEditingCellSelectAll",
282
- "reduxFormCellIdToEditValue",
283
- "reduxFormEntities",
284
- "reduxFormCellValidation",
285
- "reduxFormEntitiesUndoRedoStack"
286
- ),
287
- withProps(props => {
288
- const entities = props.reduxFormEntities || props.entities;
289
- return {
290
- _origEntities: props.entities,
291
- entities
292
- };
293
- }),
294
- // withFields({
295
- // names: [
296
- // "localStorageForceUpdate",
297
- // "reduxFormQueryParams",
298
- // "reduxFormSearchInput",
299
- // "reduxFormSelectedEntityIdMap",
300
- // "reduxFormExpandedEntityIdMap"
301
- // ]
302
- // }),
303
- branch(props => !props.alwaysRerender, pureNoFunc)
33
+ // form prop is needed for redux-form, but we are giving this prop as
34
+ // formName, so we need to rename it. Previously it was done in the withTableParams, but now
35
+ // it doesn't have it by default.
36
+ withProps(({ formName }) => ({ form: formName })),
37
+ // the formName is passed via withTableParams and is often user overridden
38
+ branch(props => !props.noForm, reduxForm({})),
39
+ // don't use withRouter if noRouter is passed!
40
+ branch(props => !props.noRouter, withRouter)
304
41
  );