@cxbox-ui/core 1.37.2-alpha.8 → 1.37.2-alpha.9
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/dist/cxbox-ui-core.cjs.development.js +241 -3
- package/dist/cxbox-ui-core.cjs.production.min.js +1 -1
- package/dist/cxbox-ui-core.esm.js +241 -4
- package/dist/cxbox-ui-core.modern.development.js +241 -4
- package/dist/cxbox-ui-core.modern.js +241 -4
- package/dist/cxbox-ui-core.modern.production.min.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/middlewares/autosaveMiddleware.d.ts +2 -17
- package/dist/middlewares/index.d.ts +1 -12
- package/dist/middlewares/popupMiddleware.d.ts +2 -5
- package/dist/middlewares/preInvokeMiddleware.d.ts +2 -5
- package/dist/middlewares/requiredFieldsMiddleware.d.ts +2 -5
- package/dist/utils/combineMiddlewares.d.ts +1 -12
- package/package.json +1 -1
|
@@ -60,6 +60,7 @@ __export(src_exports, {
|
|
|
60
60
|
actions: function () { return actions_exports; },
|
|
61
61
|
epics: function () { return epics_exports; },
|
|
62
62
|
interfaces: function () { return interfaces_exports; },
|
|
63
|
+
middlewares: function () { return middlewares; },
|
|
63
64
|
reducers: function () { return reducers_exports; },
|
|
64
65
|
utils: function () { return utils_exports; }
|
|
65
66
|
});
|
|
@@ -1588,7 +1589,7 @@ var sendOperationEpic = function (action$, state$, _a) {
|
|
|
1588
1589
|
var record = (_c = state.data[bcName]) === null || _c === void 0 ? void 0 : _c.find(function (item) { return item.id === bc.cursor; });
|
|
1589
1590
|
var filters = state.screen.filters[bcName];
|
|
1590
1591
|
var sorters = state.screen.sorters[bcName];
|
|
1591
|
-
var pendingRecordChange = (_d = state.view.pendingDataChanges[bcName]) === null || _d === void 0 ? void 0 : _d[bc.cursor];
|
|
1592
|
+
var pendingRecordChange = __assign({}, (_d = state.view.pendingDataChanges[bcName]) === null || _d === void 0 ? void 0 : _d[bc.cursor]);
|
|
1592
1593
|
var _loop_2 = function (key) {
|
|
1593
1594
|
if (fields.find(function (item) { return item.key === key && item.disabled; })) {
|
|
1594
1595
|
delete pendingRecordChange[key];
|
|
@@ -2469,7 +2470,7 @@ var bcSaveDataEpic = function (action$, state$, _a) {
|
|
|
2469
2470
|
var widgetName = action.payload.widgetName;
|
|
2470
2471
|
var cursor = state.screen.bo.bc[bcName].cursor;
|
|
2471
2472
|
var dataItem = state.data[bcName].find(function (item) { return item.id === cursor; });
|
|
2472
|
-
var pendingChanges = (_b = state.view.pendingDataChanges[bcName]) === null || _b === void 0 ? void 0 : _b[cursor];
|
|
2473
|
+
var pendingChanges = __assign({}, (_b = state.view.pendingDataChanges[bcName]) === null || _b === void 0 ? void 0 : _b[cursor]);
|
|
2473
2474
|
var rowMeta = bcUrl && ((_c = state.view.rowMeta[bcName]) === null || _c === void 0 ? void 0 : _c[bcUrl]);
|
|
2474
2475
|
var options = (_d = state.view.widgets.find(function (widget) { return widget.name === widgetName; })) === null || _d === void 0 ? void 0 : _d.options;
|
|
2475
2476
|
if (rowMeta) {
|
|
@@ -3303,7 +3304,7 @@ var Api = /** @class */ (function () {
|
|
|
3303
3304
|
};
|
|
3304
3305
|
class_3.prototype.fetchRowMeta = function (screenName, bcUrl, params, cancelToken) {
|
|
3305
3306
|
var url = applyParams(buildUrl(__makeTemplateObject(["row-meta/", "/"], ["row-meta/", "/"]), screenName) + bcUrl, params);
|
|
3306
|
-
return this.api$.get(url, { cancelToken: cancelToken }).pipe((0, import_rxjs58.map)(function (response) { return response.data.row; }));
|
|
3307
|
+
return this.api$.get(url, { cancelToken: cancelToken }).pipe((0, import_rxjs58.map)(function (response) { var _a; return (_a = response.data) === null || _a === void 0 ? void 0 : _a.row; }));
|
|
3307
3308
|
};
|
|
3308
3309
|
class_3.prototype.newBcData = function (screenName, bcUrl, context, params) {
|
|
3309
3310
|
var url = applyParams(buildUrl(__makeTemplateObject(["row-meta-new/", "/"], ["row-meta-new/", "/"]), screenName) + bcUrl, params);
|
|
@@ -3371,4 +3372,241 @@ var Api = /** @class */ (function () {
|
|
|
3371
3372
|
};
|
|
3372
3373
|
return class_3;
|
|
3373
3374
|
}());
|
|
3375
|
+
// src/utils/autosave.ts
|
|
3376
|
+
function autosaveRoutine(action, store, next) {
|
|
3377
|
+
var _a, _b, _c;
|
|
3378
|
+
var state = store.getState();
|
|
3379
|
+
var dispatch = store.dispatch;
|
|
3380
|
+
var pendingDataChanges = state.view.pendingDataChanges;
|
|
3381
|
+
var bcList = Object.keys(pendingDataChanges);
|
|
3382
|
+
var baseBcNameIndex = ((_a = action.payload) === null || _a === void 0 ? void 0 : _a.bcName) && bcHasPendingAutosaveChanges(state, action.payload.bcName, (_b = state.screen.bo.bc[action.payload.bcName]) === null || _b === void 0 ? void 0 : _b.cursor) ? bcList.findIndex(function (bcName) { var _a; return bcName === ((_a = action.payload) === null || _a === void 0 ? void 0 : _a.bcName); }) : bcList.findIndex(function (bcName) { var _a; return bcHasPendingAutosaveChanges(state, bcName, (_a = state.screen.bo.bc[bcName]) === null || _a === void 0 ? void 0 : _a.cursor); });
|
|
3383
|
+
var baseBcName = bcList[baseBcNameIndex];
|
|
3384
|
+
if (baseBcNameIndex > -1) {
|
|
3385
|
+
bcList.splice(baseBcNameIndex, 1);
|
|
3386
|
+
}
|
|
3387
|
+
if (baseBcName) {
|
|
3388
|
+
bcList.forEach(function (bcName) {
|
|
3389
|
+
var _a, _b;
|
|
3390
|
+
var widget = (_a = state.view.widgets) === null || _a === void 0 ? void 0 : _a.find(function (v) { return v.bcName === bcName; });
|
|
3391
|
+
var cursor = (_b = state.screen.bo.bc[bcName]) === null || _b === void 0 ? void 0 : _b.cursor;
|
|
3392
|
+
if (bcHasPendingAutosaveChanges(state, bcName, cursor)) {
|
|
3393
|
+
dispatch(sendOperation({
|
|
3394
|
+
bcName: bcName,
|
|
3395
|
+
operationType: import_schema5.OperationTypeCrud.save,
|
|
3396
|
+
widgetName: widget === null || widget === void 0 ? void 0 : widget.name
|
|
3397
|
+
}));
|
|
3398
|
+
}
|
|
3399
|
+
});
|
|
3400
|
+
var baseWidget = (_c = state.view.widgets) === null || _c === void 0 ? void 0 : _c.find(function (v) { return v.bcName === baseBcName; });
|
|
3401
|
+
return next(sendOperation({
|
|
3402
|
+
bcName: baseBcName,
|
|
3403
|
+
operationType: import_schema5.OperationTypeCrud.save,
|
|
3404
|
+
widgetName: baseWidget === null || baseWidget === void 0 ? void 0 : baseWidget.name,
|
|
3405
|
+
onSuccessAction: action
|
|
3406
|
+
}));
|
|
3407
|
+
}
|
|
3408
|
+
return next(action);
|
|
3409
|
+
}
|
|
3410
|
+
function bcHasPendingAutosaveChanges(store, bcName, cursor) {
|
|
3411
|
+
var _a;
|
|
3412
|
+
var pendingChanges = store.view.pendingDataChanges;
|
|
3413
|
+
var cursorChanges = (_a = pendingChanges[bcName]) === null || _a === void 0 ? void 0 : _a[cursor];
|
|
3414
|
+
var result = cursorChanges && !Object.keys(cursorChanges).includes("_associate") && Object.values(cursorChanges).length > 0;
|
|
3415
|
+
return result;
|
|
3416
|
+
}
|
|
3417
|
+
function checkUnsavedChangesOfBc(store, bcName) {
|
|
3418
|
+
var _a, _b;
|
|
3419
|
+
var pendingCursors = Object.keys((_b = (_a = store.view.pendingDataChanges) === null || _a === void 0 ? void 0 : _a[bcName]) !== null && _b !== void 0 ? _b : {});
|
|
3420
|
+
return pendingCursors.some(function (cursor) { return bcHasPendingAutosaveChanges(store, bcName, cursor); });
|
|
3421
|
+
}
|
|
3422
|
+
// src/middlewares/autosaveMiddleware.ts
|
|
3423
|
+
var saveFormMiddleware = function (_a) {
|
|
3424
|
+
var getState = _a.getState, dispatch = _a.dispatch;
|
|
3425
|
+
return function (next) { return function (action) {
|
|
3426
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
3427
|
+
var state = getState();
|
|
3428
|
+
var isSendOperation = sendOperation.match(action);
|
|
3429
|
+
var isCoreSendOperation = isSendOperation && coreOperations.includes(action.payload.operationType);
|
|
3430
|
+
var isSelectTableCellInit = selectTableCellInit.match(action);
|
|
3431
|
+
var isSaveAction = isSendOperation && action.payload.operationType === import_schema5.OperationTypeCrud.save;
|
|
3432
|
+
var isNotSaveAction = !isSaveAction;
|
|
3433
|
+
var actionBcName = isSendOperation && action.payload.bcName;
|
|
3434
|
+
var hasAnotherUnsavedBc = Object.keys(state.view.pendingDataChanges).filter(function (key) { return key !== actionBcName; }).filter(function (key) { return checkUnsavedChangesOfBc(state, key); }).length > 0;
|
|
3435
|
+
var isSendOperationForAnotherBc = isCoreSendOperation && hasAnotherUnsavedBc;
|
|
3436
|
+
var selectedCell = state.view.selectedCell;
|
|
3437
|
+
var isSelectTableCellInitOnAnotherRowOrWidget = selectedCell && isSelectTableCellInit && (selectedCell.widgetName !== action.payload.widgetName || selectedCell.rowId !== action.payload.rowId);
|
|
3438
|
+
var defaultSaveWidget = (_a = state.view.widgets) === null || _a === void 0 ? void 0 : _a.find(function (item) { var _a, _b; return (_b = (_a = item === null || item === void 0 ? void 0 : item.options) === null || _a === void 0 ? void 0 : _a.actionGroups) === null || _b === void 0 ? void 0 : _b.defaultSave; });
|
|
3439
|
+
var defaultCursor = (_c = (_b = state.screen.bo.bc) === null || _b === void 0 ? void 0 : _b[defaultSaveWidget === null || defaultSaveWidget === void 0 ? void 0 : defaultSaveWidget.bcName]) === null || _c === void 0 ? void 0 : _c.cursor;
|
|
3440
|
+
var pendingData = (_f = (_e = (_d = state.view) === null || _d === void 0 ? void 0 : _d.pendingDataChanges) === null || _e === void 0 ? void 0 : _e[defaultSaveWidget === null || defaultSaveWidget === void 0 ? void 0 : defaultSaveWidget.bcName]) === null || _f === void 0 ? void 0 : _f[defaultCursor];
|
|
3441
|
+
var isChangeLocation = defaultSaveWidget && changeLocation.match(action) && Object.keys(pendingData || {}).length > 0;
|
|
3442
|
+
if (isChangeLocation) {
|
|
3443
|
+
return next(sendOperation({
|
|
3444
|
+
bcName: defaultSaveWidget.bcName,
|
|
3445
|
+
operationType: ((_g = defaultSaveWidget.options) === null || _g === void 0 ? void 0 : _g.actionGroups).defaultSave,
|
|
3446
|
+
widgetName: defaultSaveWidget.name,
|
|
3447
|
+
onSuccessAction: action
|
|
3448
|
+
}));
|
|
3449
|
+
}
|
|
3450
|
+
var isNeedSaveCondition = isNotSaveAction && (isSendOperationForAnotherBc || isSelectTableCellInitOnAnotherRowOrWidget);
|
|
3451
|
+
if (isNeedSaveCondition) {
|
|
3452
|
+
return autosaveRoutine(action, { getState: getState, dispatch: dispatch }, next);
|
|
3453
|
+
}
|
|
3454
|
+
return next(action);
|
|
3455
|
+
}; };
|
|
3456
|
+
};
|
|
3457
|
+
// src/middlewares/requiredFieldsMiddleware.ts
|
|
3458
|
+
var requiredFields = function (_a) {
|
|
3459
|
+
var getState = _a.getState, dispatch = _a.dispatch;
|
|
3460
|
+
return function (next) { return function (action) {
|
|
3461
|
+
var _a, _b, _c, _d;
|
|
3462
|
+
var state = getState();
|
|
3463
|
+
if (sendOperation.match(action)) {
|
|
3464
|
+
var _e = action.payload, bcName = _e.bcName, operationType = _e.operationType, widgetName_1 = _e.widgetName;
|
|
3465
|
+
var cursor_1 = (_a = state.screen.bo.bc[bcName]) === null || _a === void 0 ? void 0 : _a.cursor;
|
|
3466
|
+
if (cursor_1) {
|
|
3467
|
+
var bcUrl = buildBcUrl(bcName, true, state);
|
|
3468
|
+
var record = (_b = state.data[bcName]) === null || _b === void 0 ? void 0 : _b.find(function (item) { return item.id === cursor_1; });
|
|
3469
|
+
var rowMeta_1 = bcUrl && ((_c = state.view.rowMeta[bcName]) === null || _c === void 0 ? void 0 : _c[bcUrl]);
|
|
3470
|
+
var pendingValues = (_d = state.view.pendingDataChanges[bcName]) === null || _d === void 0 ? void 0 : _d[cursor_1];
|
|
3471
|
+
var widget_1 = state.view.widgets.find(function (item) { return item.name === widgetName_1; });
|
|
3472
|
+
if (operationRequiresAutosave(operationType, rowMeta_1 === null || rowMeta_1 === void 0 ? void 0 : rowMeta_1.actions)) {
|
|
3473
|
+
var fieldsToCheck_1 = {};
|
|
3474
|
+
state.view.widgets.filter(function (item) { return item.bcName === (widget_1 === null || widget_1 === void 0 ? void 0 : widget_1.bcName); }).forEach(function (item) {
|
|
3475
|
+
var itemFieldsCalc = item.fields;
|
|
3476
|
+
if (item.fields) {
|
|
3477
|
+
item.fields.forEach(function (block) {
|
|
3478
|
+
if (isWidgetFieldBlock(block)) {
|
|
3479
|
+
block.fields.forEach(function (field) { return itemFieldsCalc.push(field); });
|
|
3480
|
+
}
|
|
3481
|
+
});
|
|
3482
|
+
}
|
|
3483
|
+
itemFieldsCalc.forEach(function (widgetField) {
|
|
3484
|
+
var _a;
|
|
3485
|
+
var matchingRowMeta = (_a = rowMeta_1 === null || rowMeta_1 === void 0 ? void 0 : rowMeta_1.fields) === null || _a === void 0 ? void 0 : _a.find(function (rowMetaField) { return rowMetaField.key === widgetField.key; });
|
|
3486
|
+
if (!fieldsToCheck_1[widgetField.key] && matchingRowMeta && !matchingRowMeta.hidden) {
|
|
3487
|
+
fieldsToCheck_1[widgetField.key] = matchingRowMeta;
|
|
3488
|
+
}
|
|
3489
|
+
});
|
|
3490
|
+
});
|
|
3491
|
+
var dataItem = getRequiredFieldsMissing(record, pendingValues, Object.values(fieldsToCheck_1));
|
|
3492
|
+
if (dataItem && TableLikeWidgetTypes.includes(widget_1 === null || widget_1 === void 0 ? void 0 : widget_1.type)) {
|
|
3493
|
+
dispatch(selectTableCellInit({ widgetName: widgetName_1, rowId: cursor_1, fieldKey: Object.keys(dataItem)[0] }));
|
|
3494
|
+
}
|
|
3495
|
+
return dataItem ? next(changeDataItem({ bcName: bcName, bcUrl: buildBcUrl(bcName, true, state), cursor: cursor_1, dataItem: dataItem })) : next(action);
|
|
3496
|
+
}
|
|
3497
|
+
if (hasPendingValidationFails(state, bcName)) {
|
|
3498
|
+
return addNotification({
|
|
3499
|
+
key: "requiredFieldsMissing",
|
|
3500
|
+
type: "buttonWarningNotification",
|
|
3501
|
+
message: "Required fields are missing",
|
|
3502
|
+
duration: 0,
|
|
3503
|
+
options: {
|
|
3504
|
+
buttonWarningNotificationOptions: {
|
|
3505
|
+
buttonText: "Cancel changes",
|
|
3506
|
+
actionsForClick: [bcCancelPendingChanges(null), clearValidationFails(null)]
|
|
3507
|
+
}
|
|
3508
|
+
}
|
|
3509
|
+
});
|
|
3510
|
+
}
|
|
3511
|
+
}
|
|
3512
|
+
}
|
|
3513
|
+
return next(action);
|
|
3514
|
+
}; };
|
|
3515
|
+
};
|
|
3516
|
+
function operationRequiresAutosave(operationType, actions) {
|
|
3517
|
+
var result = false;
|
|
3518
|
+
if (!actions) {
|
|
3519
|
+
console.error('rowMeta is missing in the middle of "sendOperation" action');
|
|
3520
|
+
return result;
|
|
3521
|
+
}
|
|
3522
|
+
result = flattenOperations(actions).some(function (action) { return action.type === operationType && action.autoSaveBefore; });
|
|
3523
|
+
return result;
|
|
3524
|
+
}
|
|
3525
|
+
function getRequiredFieldsMissing(record, pendingChanges, fieldsMeta) {
|
|
3526
|
+
var result = {};
|
|
3527
|
+
fieldsMeta.forEach(function (field) {
|
|
3528
|
+
var value = record === null || record === void 0 ? void 0 : record[field.key];
|
|
3529
|
+
var pendingValue = pendingChanges === null || pendingChanges === void 0 ? void 0 : pendingChanges[field.key];
|
|
3530
|
+
var effectiveValue = pendingValue !== void 0 ? pendingValue : value;
|
|
3531
|
+
var falsyValue = false;
|
|
3532
|
+
if (effectiveValue === null || effectiveValue === void 0 || effectiveValue === "") {
|
|
3533
|
+
falsyValue = true;
|
|
3534
|
+
}
|
|
3535
|
+
else if (Array.isArray(effectiveValue) && !effectiveValue.length) {
|
|
3536
|
+
falsyValue = true;
|
|
3537
|
+
}
|
|
3538
|
+
else if (effectiveValue && typeof effectiveValue === "object" && !Object.keys(effectiveValue).length) {
|
|
3539
|
+
falsyValue = true;
|
|
3540
|
+
}
|
|
3541
|
+
if (field.required && falsyValue) {
|
|
3542
|
+
result[field.key] = Array.isArray(effectiveValue) ? [] : null;
|
|
3543
|
+
}
|
|
3544
|
+
});
|
|
3545
|
+
return Object.keys(result).length > 0 ? result : null;
|
|
3546
|
+
}
|
|
3547
|
+
function hasPendingValidationFails(store, bcName) {
|
|
3548
|
+
var _a;
|
|
3549
|
+
if (store.view.pendingValidationFailsFormat !== "target" /* target */ && store.view.pendingValidationFails && Object.keys(store.view.pendingValidationFails).length) {
|
|
3550
|
+
return true;
|
|
3551
|
+
}
|
|
3552
|
+
var checkResult = false;
|
|
3553
|
+
var bcPendingValidations = (_a = store.view.pendingValidationFails) === null || _a === void 0 ? void 0 : _a[bcName];
|
|
3554
|
+
var cursorsList = bcPendingValidations && Object.keys(bcPendingValidations);
|
|
3555
|
+
if (!cursorsList) {
|
|
3556
|
+
return false;
|
|
3557
|
+
}
|
|
3558
|
+
var i = 0;
|
|
3559
|
+
for (; i < cursorsList.length; i++) {
|
|
3560
|
+
if (Object.keys(bcPendingValidations[cursorsList[i]]).length) {
|
|
3561
|
+
checkResult = true;
|
|
3562
|
+
break;
|
|
3563
|
+
}
|
|
3564
|
+
}
|
|
3565
|
+
return checkResult;
|
|
3566
|
+
}
|
|
3567
|
+
// src/middlewares/preInvokeMiddleware.ts
|
|
3568
|
+
var preInvokeAction = function (_a) {
|
|
3569
|
+
var getState = _a.getState;
|
|
3570
|
+
return function (next) { return function (action) {
|
|
3571
|
+
var _a, _b, _c;
|
|
3572
|
+
if (sendOperation.match(action)) {
|
|
3573
|
+
var state = getState();
|
|
3574
|
+
var _d = action.payload, operationType_1 = _d.operationType, widgetName_2 = _d.widgetName, confirm = _d.confirm;
|
|
3575
|
+
var bcName = (_a = state.view.widgets.find(function (widgetItem) { return widgetItem.name === widgetName_2; })) === null || _a === void 0 ? void 0 : _a.bcName;
|
|
3576
|
+
var bcUrl = buildBcUrl(bcName, true, state);
|
|
3577
|
+
var rowMeta = bcUrl && ((_b = state.view.rowMeta[bcName]) === null || _b === void 0 ? void 0 : _b[bcUrl]);
|
|
3578
|
+
var actions = rowMeta && flattenOperations(rowMeta.actions);
|
|
3579
|
+
var preInvoke = (_c = actions === null || actions === void 0 ? void 0 : actions.find(function (item) { return item.type === operationType_1; })) === null || _c === void 0 ? void 0 : _c.preInvoke;
|
|
3580
|
+
return preInvoke && !confirm ? next(processPreInvoke({
|
|
3581
|
+
bcName: bcName,
|
|
3582
|
+
operationType: operationType_1,
|
|
3583
|
+
widgetName: widgetName_2,
|
|
3584
|
+
preInvoke: preInvoke
|
|
3585
|
+
})) : next(action);
|
|
3586
|
+
}
|
|
3587
|
+
return next(action);
|
|
3588
|
+
}; };
|
|
3589
|
+
};
|
|
3590
|
+
// src/middlewares/popupMiddleware.ts
|
|
3591
|
+
var popupMiddleware = function (_a) {
|
|
3592
|
+
var getState = _a.getState;
|
|
3593
|
+
return function (next) { return function (action) {
|
|
3594
|
+
var _a, _b, _c;
|
|
3595
|
+
if (showViewPopup.match(action)) {
|
|
3596
|
+
var state = getState();
|
|
3597
|
+
var bcName_1 = action.payload.bcName;
|
|
3598
|
+
var widgetValueKey = (_b = (_a = state.view.widgets.find(function (item) { return item.bcName === bcName_1; })) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.displayedValueKey;
|
|
3599
|
+
var assocValueKey = (_c = action.payload.assocValueKey) !== null && _c !== void 0 ? _c : widgetValueKey;
|
|
3600
|
+
return widgetValueKey ? next(showViewPopup(__assign(__assign({}, action.payload), { assocValueKey: assocValueKey }))) : next(action);
|
|
3601
|
+
}
|
|
3602
|
+
return next(action);
|
|
3603
|
+
}; };
|
|
3604
|
+
};
|
|
3605
|
+
// src/middlewares/index.ts
|
|
3606
|
+
var middlewares = {
|
|
3607
|
+
autosave: saveFormMiddleware,
|
|
3608
|
+
requiredFields: requiredFields,
|
|
3609
|
+
preInvoke: preInvokeAction,
|
|
3610
|
+
popup: popupMiddleware
|
|
3611
|
+
};
|
|
3374
3612
|
//# sourceMappingURL=cxbox-ui-core.cjs.development.js.map
|