@teselagen/ui 0.7.34 → 0.7.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/isBeingCalledExcessively.js +2 -0
  2. package/package.json +1 -1
  3. package/style.css +26 -10
  4. package/DataTable/utils/filterLocalEntitiesToHasura.d.ts +0 -5
  5. package/DataTable/utils/initializeHasuraWhereAndFilter.d.ts +0 -2
  6. package/DataTable/utils/tableQueryParamsToHasuraClauses.d.ts +0 -26
  7. package/src/AdvancedOptions.js +0 -33
  8. package/src/AdvancedOptions.spec.js +0 -26
  9. package/src/AssignDefaultsModeContext.js +0 -22
  10. package/src/AsyncValidateFieldSpinner/index.js +0 -12
  11. package/src/BlueprintError/index.js +0 -14
  12. package/src/BounceLoader/index.js +0 -16
  13. package/src/BounceLoader/style.css +0 -45
  14. package/src/CollapsibleCard/index.js +0 -68
  15. package/src/CollapsibleCard/style.css +0 -23
  16. package/src/DNALoader/index.js +0 -20
  17. package/src/DNALoader/style.css +0 -251
  18. package/src/DataTable/CellDragHandle.js +0 -132
  19. package/src/DataTable/ColumnFilterMenu.js +0 -62
  20. package/src/DataTable/Columns.js +0 -979
  21. package/src/DataTable/DisabledLoadingComponent.js +0 -15
  22. package/src/DataTable/DisplayOptions.js +0 -199
  23. package/src/DataTable/DropdownCell.js +0 -61
  24. package/src/DataTable/EditableCell.js +0 -44
  25. package/src/DataTable/FilterAndSortMenu.js +0 -388
  26. package/src/DataTable/PagingTool.js +0 -225
  27. package/src/DataTable/RenderCell.js +0 -191
  28. package/src/DataTable/SearchBar.js +0 -69
  29. package/src/DataTable/SortableColumns.js +0 -100
  30. package/src/DataTable/TableFormTrackerContext.js +0 -10
  31. package/src/DataTable/ThComponent.js +0 -44
  32. package/src/DataTable/dataTableEnhancer.js +0 -41
  33. package/src/DataTable/defaultFormatters.js +0 -32
  34. package/src/DataTable/defaultValidators.js +0 -40
  35. package/src/DataTable/editCellHelper.js +0 -44
  36. package/src/DataTable/getCellVal.js +0 -20
  37. package/src/DataTable/getVals.js +0 -8
  38. package/src/DataTable/index.js +0 -3209
  39. package/src/DataTable/isTruthy.js +0 -12
  40. package/src/DataTable/isValueEmpty.js +0 -3
  41. package/src/DataTable/style.css +0 -608
  42. package/src/DataTable/utils/convertSchema.js +0 -69
  43. package/src/DataTable/utils/filterLocalEntitiesToHasura.js +0 -236
  44. package/src/DataTable/utils/filterLocalEntitiesToHasura.test.js +0 -587
  45. package/src/DataTable/utils/formatPasteData.js +0 -16
  46. package/src/DataTable/utils/getAllRows.js +0 -11
  47. package/src/DataTable/utils/getCellCopyText.js +0 -7
  48. package/src/DataTable/utils/getCellInfo.js +0 -36
  49. package/src/DataTable/utils/getFieldPathToField.js +0 -7
  50. package/src/DataTable/utils/getIdOrCodeOrIndex.js +0 -9
  51. package/src/DataTable/utils/getLastSelectedEntity.js +0 -11
  52. package/src/DataTable/utils/getNewEntToSelect.js +0 -25
  53. package/src/DataTable/utils/getRowCopyText.js +0 -28
  54. package/src/DataTable/utils/getTableConfigFromStorage.js +0 -5
  55. package/src/DataTable/utils/handleCopyColumn.js +0 -21
  56. package/src/DataTable/utils/handleCopyHelper.js +0 -15
  57. package/src/DataTable/utils/handleCopyRows.js +0 -23
  58. package/src/DataTable/utils/handleCopyTable.js +0 -16
  59. package/src/DataTable/utils/index.js +0 -55
  60. package/src/DataTable/utils/initializeHasuraWhereAndFilter.js +0 -26
  61. package/src/DataTable/utils/isBottomRightCornerOfRectangle.js +0 -20
  62. package/src/DataTable/utils/isEntityClean.js +0 -15
  63. package/src/DataTable/utils/primarySelectedValue.js +0 -1
  64. package/src/DataTable/utils/queryParams.js +0 -350
  65. package/src/DataTable/utils/removeCleanRows.js +0 -22
  66. package/src/DataTable/utils/rowClick.js +0 -181
  67. package/src/DataTable/utils/selection.js +0 -8
  68. package/src/DataTable/utils/tableQueryParamsToHasuraClauses.js +0 -253
  69. package/src/DataTable/utils/tableQueryParamsToHasuraClauses.test.js +0 -206
  70. package/src/DataTable/utils/useTableEntities.js +0 -38
  71. package/src/DataTable/utils/utils.js +0 -37
  72. package/src/DataTable/utils/withSelectedEntities.js +0 -65
  73. package/src/DataTable/utils/withTableParams.js +0 -288
  74. package/src/DataTable/validateTableWideErrors.js +0 -160
  75. package/src/DataTable/viewColumn.js +0 -97
  76. package/src/DialogFooter/index.js +0 -86
  77. package/src/DialogFooter/style.css +0 -9
  78. package/src/DropdownButton.js +0 -36
  79. package/src/FillWindow.css +0 -6
  80. package/src/FillWindow.js +0 -69
  81. package/src/FormComponents/FormSeparator.js +0 -9
  82. package/src/FormComponents/LoadingDots.js +0 -14
  83. package/src/FormComponents/Uploader.js +0 -1278
  84. package/src/FormComponents/getNewName.js +0 -31
  85. package/src/FormComponents/index.js +0 -1266
  86. package/src/FormComponents/itemUpload.js +0 -84
  87. package/src/FormComponents/sortify.js +0 -73
  88. package/src/FormComponents/style.css +0 -275
  89. package/src/FormComponents/tryToMatchSchemas.js +0 -264
  90. package/src/FormComponents/utils.js +0 -6
  91. package/src/HotkeysDialog/index.js +0 -79
  92. package/src/HotkeysDialog/style.css +0 -54
  93. package/src/InfoHelper/index.js +0 -78
  94. package/src/InfoHelper/style.css +0 -7
  95. package/src/IntentText/index.js +0 -18
  96. package/src/Loading/index.js +0 -70
  97. package/src/Loading/style.css +0 -4
  98. package/src/MatchHeaders.js +0 -234
  99. package/src/MenuBar/index.js +0 -423
  100. package/src/MenuBar/style.css +0 -45
  101. package/src/PromptUnsavedChanges/index.js +0 -38
  102. package/src/ResizableDraggableDialog/index.js +0 -141
  103. package/src/ResizableDraggableDialog/style.css +0 -42
  104. package/src/ScrollToTop/index.js +0 -72
  105. package/src/SimpleStepViz.js +0 -22
  106. package/src/Tag.js +0 -112
  107. package/src/TagSelect/index.js +0 -69
  108. package/src/TagSelect/style.css +0 -13
  109. package/src/TgHtmlSelect/index.js +0 -20
  110. package/src/TgSelect/index.js +0 -537
  111. package/src/TgSelect/style.css +0 -61
  112. package/src/TgSuggest/index.js +0 -124
  113. package/src/Timeline/TimelineEvent.js +0 -31
  114. package/src/Timeline/index.js +0 -15
  115. package/src/Timeline/style.css +0 -29
  116. package/src/UploadCsvWizard.css +0 -4
  117. package/src/UploadCsvWizard.js +0 -719
  118. package/src/autoTooltip.js +0 -201
  119. package/src/constants.js +0 -1
  120. package/src/customIcons.js +0 -361
  121. package/src/enhancers/withDialog/index.js +0 -196
  122. package/src/enhancers/withDialog/tg_modalState.js +0 -47
  123. package/src/enhancers/withField.js +0 -20
  124. package/src/enhancers/withFields.js +0 -11
  125. package/src/enhancers/withLocalStorage.js +0 -11
  126. package/src/index.js +0 -88
  127. package/src/rerenderOnWindowResize.js +0 -26
  128. package/src/showAppSpinner.js +0 -12
  129. package/src/showConfirmationDialog/index.js +0 -148
  130. package/src/showDialogOnDocBody.js +0 -33
  131. package/src/style.css +0 -265
  132. package/src/throwFormError.js +0 -16
  133. package/src/toastr.js +0 -148
  134. package/src/typeToCommonType.js +0 -6
  135. package/src/useDialog.js +0 -63
  136. package/src/utils/adHoc.js +0 -10
  137. package/src/utils/basicHandleActionsWithFullState.js +0 -14
  138. package/src/utils/browserUtils.js +0 -3
  139. package/src/utils/combineReducersWithFullState.js +0 -14
  140. package/src/utils/commandControls.js +0 -82
  141. package/src/utils/commandUtils.js +0 -112
  142. package/src/utils/determineBlackOrWhiteTextColor.js +0 -4
  143. package/src/utils/getDayjsFormatter.js +0 -35
  144. package/src/utils/getTextFromEl.js +0 -28
  145. package/src/utils/handlerHelpers.js +0 -24
  146. package/src/utils/hooks/index.js +0 -1
  147. package/src/utils/hooks/useDeepEqualMemo.js +0 -15
  148. package/src/utils/hooks/useStableReference.js +0 -9
  149. package/src/utils/hotkeyUtils.js +0 -131
  150. package/src/utils/isBeingCalledExcessively.js +0 -24
  151. package/src/utils/menuUtils.js +0 -433
  152. package/src/utils/popoverOverflowModifiers.js +0 -11
  153. package/src/utils/pureNoFunc.js +0 -31
  154. package/src/utils/renderOnDoc.js +0 -32
  155. package/src/utils/showProgressToast.js +0 -22
  156. package/src/utils/tagUtils.js +0 -45
  157. package/src/utils/tgFormValues.js +0 -35
  158. package/src/utils/useTraceUpdate.js +0 -19
  159. package/src/utils/withSelectTableRecords.js +0 -43
  160. package/src/utils/withStore.js +0 -10
  161. package/src/wrapDialog.js +0 -116
@@ -1,84 +0,0 @@
1
- import React from "react";
2
- import {
3
- ProgressBar,
4
- Intent,
5
- Button,
6
- Tooltip,
7
- Position,
8
- Icon
9
- } from "@blueprintjs/core";
10
-
11
- const itemUpload = props => {
12
- const item = props.item;
13
- const name = nameShortener(item.name);
14
-
15
- return (
16
- <div className="item-upload-container" key={item.id}>
17
- <div className="item-upload">
18
- <div>
19
- {!props.saved ? (
20
- <Tooltip
21
- content={
22
- <span>
23
- {`Click to
24
- ${props.active ? "abort this uploading" : "remove this file"}`}
25
- </span>
26
- }
27
- position={Position.LEFT}
28
- usePortal={true}
29
- >
30
- <Button
31
- intent={Intent.DANGER}
32
- minimal
33
- icon="delete"
34
- onClick={props.onCancel}
35
- />
36
- </Tooltip>
37
- ) : null}
38
- </div>
39
- <div>
40
- <span>{name}</span>
41
- </div>
42
- <div>
43
- {props.active ? `${props.value}%` : null}
44
- {props.error ? (
45
- <Tooltip content={props.error} usePortal={true}>
46
- <Icon icon="error" intent={Intent.DANGER} />
47
- </Tooltip>
48
- ) : null}
49
- {props.saved ? (
50
- <Tooltip content={"File Saved"} usePortal={true}>
51
- <Icon icon="saved" intent={Intent.SUCCESS} />
52
- </Tooltip>
53
- ) : null}
54
- </div>
55
- </div>
56
- {props.active ? (
57
- <ProgressBar intent={Intent.PRIMARY} value={props.value / 100} />
58
- ) : null}
59
- </div>
60
- );
61
- };
62
-
63
- /**
64
- * Short file names length to display
65
- * @param {*} itemName
66
- */
67
- const nameShortener = itemName => {
68
- if (itemName.length > 40) {
69
- let name = "";
70
- const arr = itemName.split(".");
71
- name += `${arr[0].substring(0, 20)}...`;
72
- if (arr.length >= 2) {
73
- name += `${arr[arr.length - 2].substring(
74
- arr[arr.length - 2].length - 5,
75
- arr[arr.length - 2].length
76
- )}`;
77
- name += `.${arr[arr.length - 1]}`;
78
- }
79
- return name;
80
- }
81
- return itemName;
82
- };
83
-
84
- export default itemUpload;
@@ -1,73 +0,0 @@
1
- /*!
2
- * Copyright 2015-2016 Thomas Rosenau
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
-
17
- /**
18
- * Create a “sorted” version of an object.
19
- *
20
- * JS engines internally keep track of an object's keys in the order of
21
- * creation time, i.e. {a:1,b:2} is treated differently from {b:2,a:1}.
22
- * That difference can be seen when JSON.stringify is called on that object.
23
- * This function normalizes any kind of object by rearranging the keys in
24
- * alphabetical order (numerical keys first, since v8 does so, and there's
25
- * nothing we can do about it).
26
- * @param {*} o The object to be sorted
27
- */
28
-
29
- /* eslint-disable */
30
- const sortKeys = o => {
31
- if (Array.isArray(o)) {
32
- return o.map(sortKeys);
33
- } else if (o instanceof Object) {
34
- // put numeric keys first
35
- let numeric = [];
36
- let nonNumeric = [];
37
- Object.keys(o).forEach(key => {
38
- if (/^(0|[1-9][0-9]*)$/.test(key)) {
39
- numeric.push(+key);
40
- } else {
41
- nonNumeric.push(key);
42
- }
43
- });
44
- // do the rearrangement
45
- return numeric
46
- .sort(function (a, b) {
47
- return a - b;
48
- })
49
- .concat(nonNumeric.sort())
50
- .reduce((result, key) => {
51
- result[key] = sortKeys(o[key]); // recurse!
52
- return result;
53
- }, {});
54
- }
55
- return o;
56
- };
57
-
58
- const jsonStringify = JSON.stringify.bind(JSON);
59
-
60
- const sortify = (value, replacer, space) => {
61
- // replacer, toJSON(), cyclic references and other stuff is better handled by native stringifier.
62
- // So we do JSON.stringify(sortKeys( JSON.parse(JSON.stringify()) )).
63
- // This approach is slightly slower but much safer than a manual stringification.
64
- let nativeJson = jsonStringify(value, replacer, 0);
65
- if (!nativeJson || (nativeJson[0] !== "{" && nativeJson[0] !== "[")) {
66
- // if value is not an Object or Array
67
- return nativeJson;
68
- }
69
- let cleanObj = JSON.parse(nativeJson);
70
- return jsonStringify(sortKeys(cleanObj), null, space);
71
- };
72
-
73
- export default sortify;
@@ -1,275 +0,0 @@
1
- .tg-flex-form-content .bp3-form-content {
2
- display: flex;
3
- }
4
-
5
- .error-popover {
6
- margin: 5px;
7
- color: red;
8
- }
9
-
10
- .te-file-upload-input {
11
- min-width: 140px;
12
- }
13
-
14
- .ant-upload.ant-upload-drag {
15
- border-width: 2px;
16
- }
17
-
18
- .tg-upload-inner {
19
- margin: 10px;
20
- display: flex;
21
- flex-direction: column;
22
- align-items: center;
23
- font-size: 16px;
24
- }
25
- .tg-dropzone.tg-dropzone-minimal {
26
- height: 30px !important;
27
- width: fit-content !important;
28
- }
29
- .tg-dropzone-minimal .tg-upload-inner {
30
- flex-direction: row;
31
- margin: 4px;
32
- }
33
- .tg-dropzone-minimal .bp3-icon {
34
- flex-direction: row;
35
- margin-right: 5px;
36
- }
37
-
38
- .tg-hide-drop-target .ant-upload.ant-upload-drag {
39
- display: none;
40
- }
41
-
42
- .tg-dropzone {
43
- width: 100% !important;
44
- height: 100% !important;
45
- border-width: 2px;
46
- border-color: #d9d9d9;
47
- border-style: dashed;
48
- border-radius: 5px;
49
- cursor: pointer;
50
- transition: all 1s;
51
- }
52
- .tg-dropzone:hover {
53
- border-color: rgb(91, 157, 211);
54
- }
55
- .tg-dropzone-active {
56
- border-color: rgb(91, 157, 211);
57
- }
58
- .tg-dropzone-accept {
59
- border-color: rgb(123, 214, 150);
60
- }
61
- .tg-dropzone-reject {
62
- border-color: rgb(91, 157, 211);
63
- }
64
- .tg-dropzone-disabled {
65
- cursor: not-allowed;
66
- border-color: rgb(136, 133, 132) !important;
67
- opacity: 0.8;
68
- }
69
- .tg-upload-file-list-item {
70
- display: flex;
71
- justify-content: space-between;
72
- margin: 2px;
73
- border-radius: 3px;
74
- padding: 2px;
75
- }
76
- .tg-upload-file-list-item:hover {
77
- background: rgb(215, 238, 255);
78
- }
79
- .clickableIcon {
80
- cursor: pointer;
81
- }
82
- .clickableIcon:hover {
83
- opacity: 0.7;
84
- }
85
-
86
- .tg-upload-file-list-item a {
87
- display: block;
88
- white-space: nowrap;
89
- overflow: hidden;
90
- text-overflow: ellipsis;
91
- }
92
-
93
- .tg-upload-file-list-item-overflow {
94
- overflow: auto;
95
- height: 150px;
96
- }
97
-
98
- .tg-upload-file-list-counter {
99
- position: absolute;
100
- padding: 5px;
101
- }
102
-
103
- .tg-spin {
104
- animation-name: spin;
105
- animation-duration: 1500ms;
106
- animation-iteration-count: infinite;
107
- animation-timing-function: linear;
108
- }
109
- @keyframes spin {
110
- from {
111
- transform: rotate(0deg);
112
- }
113
- to {
114
- transform: rotate(360deg);
115
- }
116
- }
117
-
118
- /* .Select-multi-value-wrapper {
119
- max-height: 100px;
120
- overflow: scroll;
121
- } */
122
-
123
- /* dark styles */
124
- .bp3-dark .Select.is-open > .Select-control,
125
- .bp3-dark .Select-control,
126
- .bp3-dark .Select.is-disabled > .Select-control {
127
- background: rgba(16, 22, 26, 0.3);
128
- box-shadow:
129
- 0 0 0 0 rgba(19, 124, 189, 0),
130
- 0 0 0 0 rgba(19, 124, 189, 0),
131
- 0 0 0 0 rgba(19, 124, 189, 0),
132
- inset 0 0 0 1px rgba(16, 22, 26, 0.3),
133
- inset 0 1px 1px rgba(16, 22, 26, 0.4);
134
- background: rgba(16, 22, 26, 0.3);
135
- color: #f5f8fa;
136
- }
137
-
138
- .bp3-dark .Select.is-focused:not(.is-open) > .Select-control {
139
- background: rgba(16, 22, 26, 0.3);
140
- color: #f5f8fa;
141
- }
142
-
143
- .bp3-dark .Select-placeholder,
144
- .bp3-dark .Select--single > .Select-control .Select-value {
145
- color: rgb(191, 204, 214, 0.5); /*#bfccd6*/
146
- }
147
-
148
- .bp3-dark .Select-control {
149
- border: none !important;
150
- }
151
-
152
- .bp3-dark
153
- .Select.has-value.Select--single
154
- > .Select-control
155
- .Select-value
156
- .Select-value-label,
157
- .bp3-dark
158
- .Select.has-value.is-pseudo-focused.Select--single
159
- > .Select-control
160
- .Select-value
161
- .Select-value-label,
162
- .bp3-dark .Select-option.is-selected {
163
- color: #f5f8fa;
164
- }
165
-
166
- .bp3-dark .Select-option {
167
- background: #30404d;
168
- color: #f5f8fa;
169
- }
170
-
171
- .bp3-dark .Select-menu-outer {
172
- border: 1px solid #26738cb0;
173
- background: #202b33;
174
- }
175
-
176
- .bp3-dark .Select-option.is-focused {
177
- background: rgba(0, 126, 255, 0.08);
178
- color: #f5f8fa;
179
- }
180
-
181
- .bp3-dark .tg-upload-file-list-item:hover {
182
- background: #26738cb0;
183
- }
184
-
185
- .tg-tooltipError .bp3-popover-wrapper {
186
- width: 100%;
187
- }
188
-
189
- .tg-no-fill-field {
190
- display: table !important;
191
- }
192
-
193
- .item-upload-container {
194
- padding: 5px;
195
- width: 290px;
196
- }
197
-
198
- .item-upload {
199
- display: flex;
200
- justify-content: space-between;
201
- align-items: center;
202
- }
203
-
204
- /* .bp3-control {
205
- display: flex;
206
- align-items: center;
207
- } */
208
-
209
- .bp3-form-group.bp3-inline .bp3-form-content {
210
- flex: 1;
211
- }
212
-
213
- .bp3-dark input {
214
- color: #f5f8fa;
215
- }
216
-
217
- .tg-no-fill-field .bp3-checkbox {
218
- display: flex;
219
- align-items: center;
220
- }
221
-
222
- .bp3-form-group .info-helper-wrapper:not(.info-helper-wrapper-noMarginTop) {
223
- margin-top: -9px !important;
224
- }
225
-
226
- .generateDefaultDot {
227
- cursor: pointer;
228
- border-radius: 50%;
229
- background: #ffca00;
230
- box-shadow: 0px 0px 2px black;
231
- height: 8px;
232
- width: 8px;
233
- }
234
- .bp3-dark .generateDefaultDot {
235
- background: yellow;
236
- }
237
-
238
- .bp3-label {
239
- font-size: 13px;
240
- font-weight: 600;
241
- }
242
-
243
- :not(.no-inline-label-margins).bp3-inline .bp3-label {
244
- /* text-align: right; */
245
- padding-right: 20px;
246
- min-width: 100px;
247
- }
248
-
249
- .bp3-dark .tg-color-picker-selector input {
250
- color: #222222;
251
- }
252
-
253
- .form-separator {
254
- p {
255
- display: flex;
256
- align-items: center;
257
- width: 100%;
258
- }
259
- p::before {
260
- content: "";
261
- display: block;
262
- width: 100%;
263
- height: 1px;
264
- background-color: #e1e4e8;
265
- margin-right: 16px;
266
- }
267
- p::after {
268
- content: "";
269
- display: block;
270
- width: 100%;
271
- height: 1px;
272
- background-color: #e1e4e8;
273
- margin-left: 16px;
274
- }
275
- }
@@ -1,264 +0,0 @@
1
- import { forEach, isArray, isPlainObject, map, snakeCase } from "lodash-es";
2
- import { nanoid } from "nanoid";
3
- import Fuse from "fuse.js";
4
- import { editCellHelper } from "../DataTable/editCellHelper";
5
- import { validateTableWideErrors } from "../DataTable/validateTableWideErrors";
6
- import { isEmpty } from "lodash-es";
7
- import getTextFromEl from "../utils/getTextFromEl";
8
- import { min } from "lodash-es";
9
- import { camelCase } from "lodash-es";
10
- import { startCase } from "lodash-es";
11
-
12
- const getSchema = data => ({
13
- fields: map(data[0], (val, path) => {
14
- return { path, type: "string" };
15
- }),
16
- userData: data
17
- });
18
-
19
- export default async function tryToMatchSchemas({
20
- incomingData,
21
- validateAgainstSchema
22
- }) {
23
- await resolveValidateAgainstSchema(validateAgainstSchema);
24
- const userSchema = getSchema(incomingData);
25
-
26
- const { searchResults, csvValidationIssue, ignoredHeadersMsg } =
27
- await matchSchemas({
28
- userSchema,
29
- officialSchema: validateAgainstSchema
30
- });
31
-
32
- const incomingHeadersToScores = {};
33
-
34
- searchResults.forEach(r => {
35
- r.matches.forEach(match => {
36
- incomingHeadersToScores[match.item.path] =
37
- incomingHeadersToScores[match.item.path] || [];
38
- incomingHeadersToScores[match.item.path].push(match.score);
39
- });
40
- });
41
-
42
- searchResults.forEach(r => {
43
- for (const match of r.matches) {
44
- if (!incomingHeadersToScores[match.item.path]) continue;
45
- const minScore = min(incomingHeadersToScores[match.item.path]);
46
- if (minScore === match.score) {
47
- r.topMatch = match.item.path;
48
- r.matches.forEach(match => {
49
- if (!incomingHeadersToScores[match.item.path]) return;
50
- const arr = incomingHeadersToScores[match.item.path];
51
- arr.splice(arr.indexOf(match.score), 1);
52
- });
53
- delete incomingHeadersToScores[match.item.path];
54
- break;
55
- }
56
- }
57
- });
58
- const matchedHeaders = {};
59
- searchResults.forEach(r => {
60
- if (r.topMatch) {
61
- matchedHeaders[r.path] = r.topMatch;
62
- }
63
- });
64
-
65
- return {
66
- ignoredHeadersMsg,
67
- csvValidationIssue,
68
- matchedHeaders,
69
- userSchema,
70
- searchResults
71
- };
72
- }
73
-
74
- async function matchSchemas({ userSchema, officialSchema }) {
75
- const options = {
76
- includeScore: true,
77
- keys: ["path", "displayName"]
78
- };
79
- let csvValidationIssue = false;
80
- const fuse = new Fuse(userSchema.fields, options);
81
-
82
- const matchedAltPaths = [];
83
- officialSchema.fields.forEach(h => {
84
- let hasMatch = false;
85
- //run fuse search for results
86
- let result = fuse.search(h.path) || [];
87
-
88
- const hadNormalPathMatch = userSchema.fields.some(
89
- uh => norm(uh.path) === norm(h.path)
90
- );
91
- //if there are any exact matches, push them onto the results array
92
- userSchema.fields.forEach((uh, i) => {
93
- const pathMatch = norm(uh.path) === norm(h.path);
94
- const displayNameMatch =
95
- h.displayName && norm(uh.path) === norm(getTextFromEl(h.displayName));
96
- const hasAlternatePathMatch =
97
- !hadNormalPathMatch &&
98
- h.alternatePathMatch &&
99
- (isArray(h.alternatePathMatch)
100
- ? h.alternatePathMatch
101
- : [h.alternatePathMatch]
102
- ).find(alternatePathMatch => {
103
- let altPath = alternatePathMatch;
104
- if (isPlainObject(alternatePathMatch)) {
105
- altPath = alternatePathMatch.path;
106
- }
107
- return norm(uh.path) === norm(altPath);
108
- });
109
-
110
- if (hasAlternatePathMatch) {
111
- matchedAltPaths.push(
112
- hasAlternatePathMatch.path || hasAlternatePathMatch
113
- );
114
- if (hasAlternatePathMatch.format) {
115
- h.format = hasAlternatePathMatch.format;
116
- }
117
- }
118
- if (pathMatch || displayNameMatch || hasAlternatePathMatch) {
119
- result = result.filter(({ path }) => path === uh.path);
120
- //add a fake perfect match result to make sure we get the match
121
- result.unshift({
122
- item: {
123
- path: uh.path,
124
- type: h.type
125
- },
126
- refIndex: i,
127
- score: 0
128
- });
129
- hasMatch = true;
130
- }
131
- });
132
- h.hasMatch = hasMatch;
133
- h.matches = result;
134
-
135
- if (!hasMatch && h.isRequired) {
136
- csvValidationIssue =
137
- "It looks like some of the headers in your uploaded file(s) do not match the expected headers. Please look over and correct any issues with the mappings below.";
138
- }
139
- });
140
- const ignoredUserSchemaFields = [];
141
- userSchema.fields.forEach(uh => {
142
- if (
143
- !officialSchema.fields.find(
144
- h =>
145
- norm(h.path) === norm(uh.path) ||
146
- norm(h.displayName) === norm(uh.path) ||
147
- matchedAltPaths.includes(uh.path)
148
- )
149
- ) {
150
- // check that the column does contain data (if it doesn't, it's probably a blank column)
151
- if (userSchema.userData.some(e => e[uh.path])) {
152
- ignoredUserSchemaFields.push(uh);
153
- }
154
- }
155
- });
156
-
157
- if (officialSchema.coerceUserSchema) {
158
- officialSchema.coerceUserSchema({ userSchema, officialSchema });
159
- }
160
-
161
- userSchema.userData = map(userSchema.userData, e => {
162
- if (!e.id) {
163
- return {
164
- ...e,
165
- id: "__generated__" + nanoid()
166
- };
167
- }
168
- return e;
169
- });
170
- const editableFields = officialSchema.fields.filter(f => !f.isNotEditable);
171
- let hasErr;
172
- if (!csvValidationIssue) {
173
- userSchema.userData.some(e => {
174
- return editableFields.some(columnSchema => {
175
- //mutative
176
- const { error } = editCellHelper({
177
- entity: e,
178
- columnSchema,
179
- newVal: columnSchema.hasMatch
180
- ? e[columnSchema.matches[0]?.item?.path]
181
- : undefined
182
- });
183
- if (error) {
184
- hasErr = `${
185
- columnSchema.displayName || startCase(camelCase(columnSchema.path))
186
- }: ${error}`;
187
- return true;
188
- }
189
-
190
- return false;
191
- });
192
- });
193
- if (!hasErr) {
194
- hasErr = Object.values(
195
- validateTableWideErrors({
196
- entities: userSchema.userData,
197
- schema: officialSchema,
198
- optionalUserSchema: userSchema,
199
- newCellValidate: {}
200
- })
201
- )[0];
202
- }
203
- }
204
-
205
- if (officialSchema.tableWideAsyncValidation) {
206
- //do the table wide validation
207
- const res = await officialSchema.tableWideAsyncValidation({
208
- entities: userSchema.userData
209
- });
210
- if (!isEmpty(res)) {
211
- csvValidationIssue = addSpecialPropToAsyncErrs(res);
212
- }
213
- //return errors on the tables
214
- }
215
-
216
- if (hasErr && !csvValidationIssue) {
217
- if (hasErr.message) {
218
- csvValidationIssue = hasErr;
219
- } else {
220
- csvValidationIssue = {
221
- message: hasErr
222
- };
223
- // csvValidationIssue = ` Some of the data doesn't look quite right. Do these header mappings look correct?`;
224
- }
225
- // csvValidationIssue = `Some of the data doesn't look quite right. Do these header mappings look correct?`;
226
- }
227
- let ignoredHeadersMsg;
228
- if (ignoredUserSchemaFields.length) {
229
- ignoredHeadersMsg = `It looks like the following headers in your file didn't map to any of the accepted headers: ${ignoredUserSchemaFields
230
- .map(f => f.displayName || f.path)
231
- .join(", ")}`;
232
- }
233
- return {
234
- searchResults: officialSchema.fields,
235
- csvValidationIssue,
236
- ignoredHeadersMsg
237
- };
238
- }
239
-
240
- export const addSpecialPropToAsyncErrs = res => {
241
- forEach(res, (v, k) => {
242
- res[k] = {
243
- message: v,
244
- _isTableAsyncWideError: true
245
- };
246
- });
247
- return res;
248
- };
249
-
250
- async function resolveValidateAgainstSchema() {
251
- //tnw: wip!
252
- // mapSeries(validateAgainstSchema.fields, async f => {
253
- // if (f.type === "dropdown") {
254
- // console.log(`type:`, f.type)
255
- // if (f.getValues) {
256
- // f.values = await f.getValues(props);
257
- // }
258
- // }
259
- // })
260
- }
261
-
262
- function norm(h) {
263
- return snakeCase(h).toLowerCase().replace(/ /g, "");
264
- }
@@ -1,6 +0,0 @@
1
- export const REQUIRED_ERROR = "This field is required.";
2
-
3
- export const fieldRequired = value =>
4
- !value || (Array.isArray(value) && !value.length)
5
- ? REQUIRED_ERROR
6
- : undefined;