@gpa-gemstone/common-pages 0.0.131 → 0.0.132
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.
- package/lib/Pipelines/CSVPipeline.js +204 -110
- package/package.json +6 -6
@@ -44,6 +44,42 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
44
44
|
__setModuleDefault(result, mod);
|
45
45
|
return result;
|
46
46
|
};
|
47
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
48
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
49
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
50
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
51
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
52
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
53
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
54
|
+
});
|
55
|
+
};
|
56
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
57
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
58
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
59
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
60
|
+
function step(op) {
|
61
|
+
if (f) throw new TypeError("Generator is already executing.");
|
62
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
63
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
64
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
65
|
+
switch (op[0]) {
|
66
|
+
case 0: case 1: t = op; break;
|
67
|
+
case 4: _.label++; return { value: op[1], done: false };
|
68
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
69
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
70
|
+
default:
|
71
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
72
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
73
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
74
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
75
|
+
if (t[2]) _.ops.pop();
|
76
|
+
_.trys.pop(); continue;
|
77
|
+
}
|
78
|
+
op = body.call(thisArg, _);
|
79
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
80
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
81
|
+
}
|
82
|
+
};
|
47
83
|
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
48
84
|
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
49
85
|
if (ar || !(i in from)) {
|
@@ -53,6 +89,9 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
53
89
|
}
|
54
90
|
return to.concat(ar || Array.prototype.slice.call(from));
|
55
91
|
};
|
92
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
93
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
94
|
+
};
|
56
95
|
Object.defineProperty(exports, "__esModule", { value: true });
|
57
96
|
exports.useCSVPipeline = useCSVPipeline;
|
58
97
|
var React = __importStar(require("react"));
|
@@ -62,6 +101,7 @@ var react_forms_1 = require("@gpa-gemstone/react-forms");
|
|
62
101
|
var react_table_1 = require("@gpa-gemstone/react-table");
|
63
102
|
var gpa_symbols_1 = require("@gpa-gemstone/gpa-symbols");
|
64
103
|
var lodash_1 = require("lodash");
|
104
|
+
var ErrorBoundary_1 = __importDefault(require("../ErrorBoundary"));
|
65
105
|
var AdditionalUploadUI = function (props) {
|
66
106
|
return (React.createElement("div", { className: 'row justify-content-center' },
|
67
107
|
React.createElement("div", { className: 'col-6 p-0' },
|
@@ -98,13 +138,11 @@ function CsvPipelineEditStep(props) {
|
|
98
138
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
|
99
139
|
var rawDataRef = React.useRef();
|
100
140
|
var _z = React.useState([]), pagedData = _z[0], setPagedData = _z[1];
|
101
|
-
var _0 = React.useState(
|
102
|
-
var _1 = React.useState(
|
103
|
-
var _2 = React.useState(
|
104
|
-
var _3 = React.useState(0),
|
105
|
-
var _4 = React.useState(
|
106
|
-
var _5 = React.useState(true), showDataHeaderAlert = _5[0], setShowDataHeaderAlert = _5[1];
|
107
|
-
var _6 = React.useState(true), showDataOrHeaderAlert = _6[0], setShowDataOrHeaderAlert = _6[1];
|
141
|
+
var _0 = React.useState(0), page = _0[0], setPage = _0[1];
|
142
|
+
var _1 = React.useState(1), totalPages = _1[0], setTotalPages = _1[1];
|
143
|
+
var _2 = React.useState(true), isFileParseable = _2[0], setIsFileParseable = _2[1];
|
144
|
+
var _3 = React.useState(0), isCSVMissingHeadersCount = _3[0], setIsCSVMissingHeadersCount = _3[1];
|
145
|
+
var _4 = React.useState(0), isCSVMissingDataCellsCount = _4[0], setIsCSVMissingDataCellsCount = _4[1];
|
108
146
|
React.useEffect(function () {
|
109
147
|
var _a, _b, _c, _d, _e;
|
110
148
|
if (((_a = props.AdditionalProps) === null || _a === void 0 ? void 0 : _a.Data.length) === 0)
|
@@ -115,59 +153,115 @@ function CsvPipelineEditStep(props) {
|
|
115
153
|
setPagedData(Data.slice(page * 10, (page + 1) * 10));
|
116
154
|
}, [(_a = props.AdditionalProps) === null || _a === void 0 ? void 0 : _a.Data, page]);
|
117
155
|
React.useEffect(function () {
|
118
|
-
var
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
156
|
+
var callback;
|
157
|
+
function runValidation() {
|
158
|
+
return __awaiter(this, void 0, void 0, function () {
|
159
|
+
var errors, headerMap, _loop_1, _i, _a, field;
|
160
|
+
var _b, _c;
|
161
|
+
return __generator(this, function (_d) {
|
162
|
+
switch (_d.label) {
|
163
|
+
case 0:
|
164
|
+
errors = [];
|
165
|
+
if (props.AdditionalProps == null)
|
166
|
+
return [2 /*return*/];
|
167
|
+
headerMap = props.AdditionalProps.HeaderMap;
|
168
|
+
_loop_1 = function (field) {
|
169
|
+
var matchedHeader, fieldIndex, foundDuplicate, foundEmpty, foundInvalid, uniqueValues, _e, _f, row, value, result, isValid, abortCallback, allValues;
|
170
|
+
return __generator(this, function (_g) {
|
171
|
+
switch (_g.label) {
|
172
|
+
case 0:
|
173
|
+
matchedHeader = (_b = Array.from(headerMap).find(function (_a) {
|
174
|
+
var value = _a[1];
|
175
|
+
return value === field.Field;
|
176
|
+
})) === null || _b === void 0 ? void 0 : _b[0];
|
177
|
+
if (matchedHeader == null) {
|
178
|
+
if (field.Required)
|
179
|
+
errors.push("".concat(field.Label, " is required and must be mapped to a header."));
|
180
|
+
return [2 /*return*/, "continue"];
|
181
|
+
}
|
182
|
+
fieldIndex = props.AdditionalProps.Headers.indexOf(matchedHeader);
|
183
|
+
foundDuplicate = false;
|
184
|
+
foundEmpty = false;
|
185
|
+
foundInvalid = false;
|
186
|
+
uniqueValues = new Set();
|
187
|
+
_e = 0, _f = props.AdditionalProps.Data;
|
188
|
+
_g.label = 1;
|
189
|
+
case 1:
|
190
|
+
if (!(_e < _f.length)) return [3 /*break*/, 4];
|
191
|
+
row = _f[_e];
|
192
|
+
value = row[fieldIndex + 1];
|
193
|
+
// Unique check
|
194
|
+
if (field.Unique) {
|
195
|
+
if (uniqueValues.has(value))
|
196
|
+
foundDuplicate = true;
|
197
|
+
else
|
198
|
+
uniqueValues.add(value);
|
199
|
+
}
|
200
|
+
// Allowed emptiness
|
201
|
+
if (!field.AllowEmpty && (value == null || (value.trim() === '')))
|
202
|
+
foundEmpty = true;
|
203
|
+
return [4 /*yield*/, Promise.resolve(field.Validate(value))];
|
204
|
+
case 2:
|
205
|
+
result = _g.sent();
|
206
|
+
isValid = void 0;
|
207
|
+
if (Array.isArray(result)) {
|
208
|
+
//[boolean, abortCallback]
|
209
|
+
isValid = result[0];
|
210
|
+
abortCallback = result[1];
|
211
|
+
if (typeof abortCallback === 'function')
|
212
|
+
callback = abortCallback;
|
213
|
+
}
|
214
|
+
else
|
215
|
+
isValid = result;
|
216
|
+
if (!isValid) {
|
217
|
+
foundInvalid = true;
|
218
|
+
}
|
219
|
+
_g.label = 3;
|
220
|
+
case 3:
|
221
|
+
_e++;
|
222
|
+
return [3 /*break*/, 1];
|
223
|
+
case 4:
|
224
|
+
if (field.Unique && foundDuplicate)
|
225
|
+
errors.push("All ".concat(field.Label, " values must be unique."));
|
226
|
+
if (foundEmpty)
|
227
|
+
errors.push("All ".concat(field.Label, " values cannot be empty."));
|
228
|
+
if (foundInvalid)
|
229
|
+
errors.push("All ".concat(field.Label, " values must be valid."));
|
230
|
+
// Check for SameValueForAllRows
|
231
|
+
if ((_c = field.SameValueForAllRows) !== null && _c !== void 0 ? _c : false) {
|
232
|
+
allValues = props.AdditionalProps.Data.map(function (row) { var _a; return (_a = row[fieldIndex + 1]) !== null && _a !== void 0 ? _a : ''; });
|
233
|
+
if (new Set(allValues).size > 1)
|
234
|
+
errors.push("All rows must contain the same value for ".concat(field.Label, "."));
|
235
|
+
}
|
236
|
+
return [2 /*return*/];
|
237
|
+
}
|
238
|
+
});
|
239
|
+
};
|
240
|
+
_i = 0, _a = props.AdditionalProps.Fields;
|
241
|
+
_d.label = 1;
|
242
|
+
case 1:
|
243
|
+
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
244
|
+
field = _a[_i];
|
245
|
+
return [5 /*yield**/, _loop_1(field)];
|
246
|
+
case 2:
|
247
|
+
_d.sent();
|
248
|
+
_d.label = 3;
|
249
|
+
case 3:
|
250
|
+
_i++;
|
251
|
+
return [3 /*break*/, 1];
|
252
|
+
case 4:
|
253
|
+
if (!(0, lodash_1.isEqual)(props.Errors.sort(), errors.sort()))
|
254
|
+
props.SetErrors(errors);
|
255
|
+
return [2 /*return*/];
|
256
|
+
}
|
257
|
+
});
|
155
258
|
});
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
//Check for SameValueForAllRows
|
163
|
-
if ((_d = field.SameValueForAllRows) !== null && _d !== void 0 ? _d : false) {
|
164
|
-
var allValues = (_e = props.AdditionalProps) === null || _e === void 0 ? void 0 : _e.Data.map(function (row) { var _a; return (_a = row[fieldIndex + 1]) !== null && _a !== void 0 ? _a : ''; });
|
165
|
-
if (new Set(allValues).size > 1)
|
166
|
-
errors.push("All rows must contain the same value for ".concat(field.Label, "."));
|
167
|
-
}
|
168
|
-
});
|
169
|
-
if (!(0, lodash_1.isEqual)(props.Errors.sort(), errors.sort()))
|
170
|
-
props.SetErrors(errors);
|
259
|
+
}
|
260
|
+
runValidation();
|
261
|
+
return function () {
|
262
|
+
if (callback != null)
|
263
|
+
callback();
|
264
|
+
};
|
171
265
|
}, [(_b = props.AdditionalProps) === null || _b === void 0 ? void 0 : _b.Data, (_c = props.AdditionalProps) === null || _c === void 0 ? void 0 : _c.Headers, (_d = props.AdditionalProps) === null || _d === void 0 ? void 0 : _d.HeaderMap, isFileParseable, (_e = props.AdditionalProps) === null || _e === void 0 ? void 0 : _e.Fields]);
|
172
266
|
//Effect to parse rawfiledata initially
|
173
267
|
React.useEffect(function () {
|
@@ -319,57 +413,57 @@ function CsvPipelineEditStep(props) {
|
|
319
413
|
};
|
320
414
|
return (React.createElement(React.Fragment, null,
|
321
415
|
React.createElement("div", { className: "container-fluid d-flex flex-column p-0 h-100" },
|
322
|
-
React.createElement(
|
323
|
-
React.createElement("div", { className: '
|
324
|
-
React.createElement(
|
325
|
-
|
326
|
-
React.createElement("div", { className: '
|
327
|
-
React.createElement(
|
328
|
-
React.createElement(
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
React.createElement(
|
333
|
-
React.createElement(
|
334
|
-
|
335
|
-
React.createElement("div", { className: '
|
336
|
-
React.createElement(
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
416
|
+
React.createElement(ErrorBoundary_1.default, { Height: '100%', Width: '100%', BodyErrorMessage: 'Error loading page.', HeaderErrorMessage: 'Error' },
|
417
|
+
React.createElement("div", { className: 'row h-100' },
|
418
|
+
React.createElement("div", { className: 'col-12 d-flex flex-column h-100' }, pagedData.length !== 0 ?
|
419
|
+
React.createElement(React.Fragment, null,
|
420
|
+
isCSVMissingDataCellsCount > 0 && isCSVMissingHeadersCount > 0 ? (React.createElement("div", { className: 'row' },
|
421
|
+
React.createElement("div", { className: 'col-12' },
|
422
|
+
React.createElement(react_interactive_1.Alert, { Color: 'alert-info', ReTrigger: isCSVMissingDataCellsCount + isCSVMissingHeadersCount },
|
423
|
+
React.createElement("p", { style: { whiteSpace: 'nowrap' } }, "Missing data cells were added to meet the number of required fields."),
|
424
|
+
React.createElement("hr", null),
|
425
|
+
React.createElement("p", { style: { whiteSpace: 'nowrap' } }, "Missing headers were added to meet the number of required fields."))))) : isCSVMissingDataCellsCount > 0 || isCSVMissingHeadersCount > 0 ? (React.createElement("div", { className: 'row' },
|
426
|
+
React.createElement("div", { className: 'col-12' },
|
427
|
+
React.createElement(react_interactive_1.Alert, { Color: 'alert-info', ReTrigger: isCSVMissingDataCellsCount > 0 ? isCSVMissingDataCellsCount : isCSVMissingHeadersCount },
|
428
|
+
React.createElement("p", { style: { whiteSpace: 'nowrap' } }, isCSVMissingDataCellsCount > 0 ? 'Missing data cells were added to meet the number of required fields.' : 'Missing headers were added to meet the number of required fields.'))))) : null,
|
429
|
+
React.createElement("div", { className: 'row flex-grow-1', style: { overflowY: 'hidden' } },
|
430
|
+
React.createElement("div", { className: 'col-12 h-100' },
|
431
|
+
React.createElement(react_table_1.Table, { Data: pagedData, key: (_v = props.AdditionalProps) === null || _v === void 0 ? void 0 : _v.Headers.join(','), SortKey: '', Ascending: false, OnSort: function () { }, KeySelector: function (data) { return data[0]; }, TableClass: 'table', TableStyle: { height: '100%', width: ((_x = (_w = props.AdditionalProps) === null || _w === void 0 ? void 0 : _w.Headers.length) !== null && _x !== void 0 ? _x : 0) * 150 } }, (_y = props.AdditionalProps) === null || _y === void 0 ? void 0 :
|
432
|
+
_y.Headers.map(function (header, i) {
|
433
|
+
return React.createElement(react_table_1.Column, { Key: header, Field: i + 1, AllowSort: false, Content: function (_a) {
|
434
|
+
var _b, _c;
|
435
|
+
var item = _a.item, field = _a.field;
|
436
|
+
if (props.AdditionalProps == null)
|
437
|
+
return;
|
438
|
+
var mappedField = (_b = props.AdditionalProps) === null || _b === void 0 ? void 0 : _b.HeaderMap.get(header);
|
439
|
+
var matchedField = props.AdditionalProps.Fields.find(function (f) { return f.Field === mappedField; });
|
440
|
+
if (matchedField == null)
|
441
|
+
return item[field];
|
442
|
+
var value = item[field];
|
443
|
+
var feedback = matchedField.Feedback;
|
444
|
+
var selectOptions = matchedField.SelectOptions;
|
445
|
+
var allValues = {};
|
446
|
+
(_c = props.AdditionalProps) === null || _c === void 0 ? void 0 : _c.Headers.forEach(function (header, index) {
|
447
|
+
var _a;
|
448
|
+
var mappedField = (_a = props.AdditionalProps) === null || _a === void 0 ? void 0 : _a.HeaderMap.get(header);
|
449
|
+
if (mappedField != null) {
|
450
|
+
allValues[mappedField] = item[index + 1];
|
451
|
+
}
|
452
|
+
});
|
453
|
+
return (React.createElement(matchedField.EditComponent, { Value: value, SetValue: function (val) { return handleValueChange(parseInt(item[0]), field, val); }, Validate: matchedField.Validate, Feedback: feedback, AllRecordValues: allValues, SelectOptions: selectOptions }));
|
454
|
+
} },
|
455
|
+
getHeader(header),
|
456
|
+
getFieldSelect(header));
|
457
|
+
}),
|
458
|
+
React.createElement(react_table_1.Column, { Key: 'delete', Field: 0, AllowSort: false, RowStyle: { textAlign: 'right' }, Content: function (_a) {
|
459
|
+
var item = _a.item;
|
460
|
+
return (React.createElement("button", { className: 'btn', onClick: function () { return handleRowDelete(parseInt(item[0])); } },
|
461
|
+
React.createElement(gpa_symbols_1.ReactIcons.TrashCan, { Color: "red" })));
|
462
|
+
} }, '')))),
|
463
|
+
React.createElement("div", { className: 'row' },
|
464
|
+
React.createElement("div", { className: 'col-12' },
|
465
|
+
React.createElement(react_table_1.Paging, { Current: page + 1, Total: totalPages, SetPage: function (p) { return setPage(p - 1); } }))))
|
466
|
+
: null))))));
|
373
467
|
}
|
374
468
|
//Helper functions
|
375
469
|
function autoMapHeaders(headers, fields) {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@gpa-gemstone/common-pages",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.132",
|
4
4
|
"description": "Common UI pages for GPA products",
|
5
5
|
"main": "lib/index.js",
|
6
6
|
"types": "lib/index.d.ts",
|
@@ -44,12 +44,12 @@
|
|
44
44
|
"typescript": "5.5.3"
|
45
45
|
},
|
46
46
|
"dependencies": {
|
47
|
-
"@gpa-gemstone/application-typings": "0.0.
|
48
|
-
"@gpa-gemstone/gpa-symbols": "0.0.
|
47
|
+
"@gpa-gemstone/application-typings": "0.0.82",
|
48
|
+
"@gpa-gemstone/gpa-symbols": "0.0.48",
|
49
49
|
"@gpa-gemstone/helper-functions": "0.0.37",
|
50
|
-
"@gpa-gemstone/react-forms": "1.1.
|
51
|
-
"@gpa-gemstone/react-interactive": "1.0.
|
52
|
-
"@gpa-gemstone/react-table": "1.2.
|
50
|
+
"@gpa-gemstone/react-forms": "1.1.83",
|
51
|
+
"@gpa-gemstone/react-interactive": "1.0.144",
|
52
|
+
"@gpa-gemstone/react-table": "1.2.66",
|
53
53
|
"@reduxjs/toolkit": "1.8.3",
|
54
54
|
"crypto-js": "^4.2.0",
|
55
55
|
"moment": "^2.29.4",
|