@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
|
@@ -1551,7 +1551,7 @@ var sendOperationEpic = function (action$, state$, _a) {
|
|
|
1551
1551
|
var record = (_c = state.data[bcName]) === null || _c === void 0 ? void 0 : _c.find(function (item) { return item.id === bc.cursor; });
|
|
1552
1552
|
var filters = state.screen.filters[bcName];
|
|
1553
1553
|
var sorters = state.screen.sorters[bcName];
|
|
1554
|
-
var pendingRecordChange = (_d = state.view.pendingDataChanges[bcName]) === null || _d === void 0 ? void 0 : _d[bc.cursor];
|
|
1554
|
+
var pendingRecordChange = __assign({}, (_d = state.view.pendingDataChanges[bcName]) === null || _d === void 0 ? void 0 : _d[bc.cursor]);
|
|
1555
1555
|
var _loop_1 = function (key) {
|
|
1556
1556
|
if (fields.find(function (item) { return item.key === key && item.disabled; })) {
|
|
1557
1557
|
delete pendingRecordChange[key];
|
|
@@ -2432,7 +2432,7 @@ var bcSaveDataEpic = function (action$, state$, _a) {
|
|
|
2432
2432
|
var widgetName = action.payload.widgetName;
|
|
2433
2433
|
var cursor = state.screen.bo.bc[bcName].cursor;
|
|
2434
2434
|
var dataItem = state.data[bcName].find(function (item) { return item.id === cursor; });
|
|
2435
|
-
var pendingChanges = (_b = state.view.pendingDataChanges[bcName]) === null || _b === void 0 ? void 0 : _b[cursor];
|
|
2435
|
+
var pendingChanges = __assign({}, (_b = state.view.pendingDataChanges[bcName]) === null || _b === void 0 ? void 0 : _b[cursor]);
|
|
2436
2436
|
var rowMeta = bcUrl && ((_c = state.view.rowMeta[bcName]) === null || _c === void 0 ? void 0 : _c[bcUrl]);
|
|
2437
2437
|
var options = (_d = state.view.widgets.find(function (widget) { return widget.name === widgetName; })) === null || _d === void 0 ? void 0 : _d.options;
|
|
2438
2438
|
if (rowMeta) {
|
|
@@ -3266,7 +3266,7 @@ var Api = /** @class */ (function () {
|
|
|
3266
3266
|
};
|
|
3267
3267
|
class_3.prototype.fetchRowMeta = function (screenName, bcUrl, params, cancelToken) {
|
|
3268
3268
|
var url = applyParams(buildUrl(templateObject_2 || (templateObject_2 = __makeTemplateObject(["row-meta/", "/"], ["row-meta/", "/"])), screenName) + bcUrl, params);
|
|
3269
|
-
return this.api$.get(url, { cancelToken: cancelToken }).pipe(map11(function (response) { return response.data.row; }));
|
|
3269
|
+
return this.api$.get(url, { cancelToken: cancelToken }).pipe(map11(function (response) { var _a; return (_a = response.data) === null || _a === void 0 ? void 0 : _a.row; }));
|
|
3270
3270
|
};
|
|
3271
3271
|
class_3.prototype.newBcData = function (screenName, bcUrl, context, params) {
|
|
3272
3272
|
var url = applyParams(buildUrl(templateObject_3 || (templateObject_3 = __makeTemplateObject(["row-meta-new/", "/"], ["row-meta-new/", "/"])), screenName) + bcUrl, params);
|
|
@@ -3334,6 +3334,243 @@ var Api = /** @class */ (function () {
|
|
|
3334
3334
|
};
|
|
3335
3335
|
return class_3;
|
|
3336
3336
|
}());
|
|
3337
|
-
|
|
3337
|
+
// src/utils/autosave.ts
|
|
3338
|
+
function autosaveRoutine(action, store, next) {
|
|
3339
|
+
var _a, _b, _c;
|
|
3340
|
+
var state = store.getState();
|
|
3341
|
+
var dispatch = store.dispatch;
|
|
3342
|
+
var pendingDataChanges = state.view.pendingDataChanges;
|
|
3343
|
+
var bcList = Object.keys(pendingDataChanges);
|
|
3344
|
+
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); });
|
|
3345
|
+
var baseBcName = bcList[baseBcNameIndex];
|
|
3346
|
+
if (baseBcNameIndex > -1) {
|
|
3347
|
+
bcList.splice(baseBcNameIndex, 1);
|
|
3348
|
+
}
|
|
3349
|
+
if (baseBcName) {
|
|
3350
|
+
bcList.forEach(function (bcName) {
|
|
3351
|
+
var _a, _b;
|
|
3352
|
+
var widget = (_a = state.view.widgets) === null || _a === void 0 ? void 0 : _a.find(function (v) { return v.bcName === bcName; });
|
|
3353
|
+
var cursor = (_b = state.screen.bo.bc[bcName]) === null || _b === void 0 ? void 0 : _b.cursor;
|
|
3354
|
+
if (bcHasPendingAutosaveChanges(state, bcName, cursor)) {
|
|
3355
|
+
dispatch(sendOperation({
|
|
3356
|
+
bcName: bcName,
|
|
3357
|
+
operationType: OperationTypeCrud.save,
|
|
3358
|
+
widgetName: widget === null || widget === void 0 ? void 0 : widget.name
|
|
3359
|
+
}));
|
|
3360
|
+
}
|
|
3361
|
+
});
|
|
3362
|
+
var baseWidget = (_c = state.view.widgets) === null || _c === void 0 ? void 0 : _c.find(function (v) { return v.bcName === baseBcName; });
|
|
3363
|
+
return next(sendOperation({
|
|
3364
|
+
bcName: baseBcName,
|
|
3365
|
+
operationType: OperationTypeCrud.save,
|
|
3366
|
+
widgetName: baseWidget === null || baseWidget === void 0 ? void 0 : baseWidget.name,
|
|
3367
|
+
onSuccessAction: action
|
|
3368
|
+
}));
|
|
3369
|
+
}
|
|
3370
|
+
return next(action);
|
|
3371
|
+
}
|
|
3372
|
+
function bcHasPendingAutosaveChanges(store, bcName, cursor) {
|
|
3373
|
+
var _a;
|
|
3374
|
+
var pendingChanges = store.view.pendingDataChanges;
|
|
3375
|
+
var cursorChanges = (_a = pendingChanges[bcName]) === null || _a === void 0 ? void 0 : _a[cursor];
|
|
3376
|
+
var result = cursorChanges && !Object.keys(cursorChanges).includes("_associate") && Object.values(cursorChanges).length > 0;
|
|
3377
|
+
return result;
|
|
3378
|
+
}
|
|
3379
|
+
function checkUnsavedChangesOfBc(store, bcName) {
|
|
3380
|
+
var _a, _b;
|
|
3381
|
+
var pendingCursors = Object.keys((_b = (_a = store.view.pendingDataChanges) === null || _a === void 0 ? void 0 : _a[bcName]) !== null && _b !== void 0 ? _b : {});
|
|
3382
|
+
return pendingCursors.some(function (cursor) { return bcHasPendingAutosaveChanges(store, bcName, cursor); });
|
|
3383
|
+
}
|
|
3384
|
+
// src/middlewares/autosaveMiddleware.ts
|
|
3385
|
+
var saveFormMiddleware = function (_a) {
|
|
3386
|
+
var getState = _a.getState, dispatch = _a.dispatch;
|
|
3387
|
+
return function (next) { return function (action) {
|
|
3388
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
3389
|
+
var state = getState();
|
|
3390
|
+
var isSendOperation = sendOperation.match(action);
|
|
3391
|
+
var isCoreSendOperation = isSendOperation && coreOperations.includes(action.payload.operationType);
|
|
3392
|
+
var isSelectTableCellInit = selectTableCellInit.match(action);
|
|
3393
|
+
var isSaveAction = isSendOperation && action.payload.operationType === OperationTypeCrud.save;
|
|
3394
|
+
var isNotSaveAction = !isSaveAction;
|
|
3395
|
+
var actionBcName = isSendOperation && action.payload.bcName;
|
|
3396
|
+
var hasAnotherUnsavedBc = Object.keys(state.view.pendingDataChanges).filter(function (key) { return key !== actionBcName; }).filter(function (key) { return checkUnsavedChangesOfBc(state, key); }).length > 0;
|
|
3397
|
+
var isSendOperationForAnotherBc = isCoreSendOperation && hasAnotherUnsavedBc;
|
|
3398
|
+
var selectedCell = state.view.selectedCell;
|
|
3399
|
+
var isSelectTableCellInitOnAnotherRowOrWidget = selectedCell && isSelectTableCellInit && (selectedCell.widgetName !== action.payload.widgetName || selectedCell.rowId !== action.payload.rowId);
|
|
3400
|
+
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; });
|
|
3401
|
+
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;
|
|
3402
|
+
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];
|
|
3403
|
+
var isChangeLocation = defaultSaveWidget && changeLocation.match(action) && Object.keys(pendingData || {}).length > 0;
|
|
3404
|
+
if (isChangeLocation) {
|
|
3405
|
+
return next(sendOperation({
|
|
3406
|
+
bcName: defaultSaveWidget.bcName,
|
|
3407
|
+
operationType: ((_g = defaultSaveWidget.options) === null || _g === void 0 ? void 0 : _g.actionGroups).defaultSave,
|
|
3408
|
+
widgetName: defaultSaveWidget.name,
|
|
3409
|
+
onSuccessAction: action
|
|
3410
|
+
}));
|
|
3411
|
+
}
|
|
3412
|
+
var isNeedSaveCondition = isNotSaveAction && (isSendOperationForAnotherBc || isSelectTableCellInitOnAnotherRowOrWidget);
|
|
3413
|
+
if (isNeedSaveCondition) {
|
|
3414
|
+
return autosaveRoutine(action, { getState: getState, dispatch: dispatch }, next);
|
|
3415
|
+
}
|
|
3416
|
+
return next(action);
|
|
3417
|
+
}; };
|
|
3418
|
+
};
|
|
3419
|
+
// src/middlewares/requiredFieldsMiddleware.ts
|
|
3420
|
+
var requiredFields = function (_a) {
|
|
3421
|
+
var getState = _a.getState, dispatch = _a.dispatch;
|
|
3422
|
+
return function (next) { return function (action) {
|
|
3423
|
+
var _a, _b, _c, _d;
|
|
3424
|
+
var state = getState();
|
|
3425
|
+
if (sendOperation.match(action)) {
|
|
3426
|
+
var _e = action.payload, bcName = _e.bcName, operationType = _e.operationType, widgetName_1 = _e.widgetName;
|
|
3427
|
+
var cursor_1 = (_a = state.screen.bo.bc[bcName]) === null || _a === void 0 ? void 0 : _a.cursor;
|
|
3428
|
+
if (cursor_1) {
|
|
3429
|
+
var bcUrl = buildBcUrl(bcName, true, state);
|
|
3430
|
+
var record = (_b = state.data[bcName]) === null || _b === void 0 ? void 0 : _b.find(function (item) { return item.id === cursor_1; });
|
|
3431
|
+
var rowMeta_1 = bcUrl && ((_c = state.view.rowMeta[bcName]) === null || _c === void 0 ? void 0 : _c[bcUrl]);
|
|
3432
|
+
var pendingValues = (_d = state.view.pendingDataChanges[bcName]) === null || _d === void 0 ? void 0 : _d[cursor_1];
|
|
3433
|
+
var widget_1 = state.view.widgets.find(function (item) { return item.name === widgetName_1; });
|
|
3434
|
+
if (operationRequiresAutosave(operationType, rowMeta_1 === null || rowMeta_1 === void 0 ? void 0 : rowMeta_1.actions)) {
|
|
3435
|
+
var fieldsToCheck_1 = {};
|
|
3436
|
+
state.view.widgets.filter(function (item) { return item.bcName === (widget_1 === null || widget_1 === void 0 ? void 0 : widget_1.bcName); }).forEach(function (item) {
|
|
3437
|
+
var itemFieldsCalc = item.fields;
|
|
3438
|
+
if (item.fields) {
|
|
3439
|
+
item.fields.forEach(function (block) {
|
|
3440
|
+
if (isWidgetFieldBlock(block)) {
|
|
3441
|
+
block.fields.forEach(function (field) { return itemFieldsCalc.push(field); });
|
|
3442
|
+
}
|
|
3443
|
+
});
|
|
3444
|
+
}
|
|
3445
|
+
itemFieldsCalc.forEach(function (widgetField) {
|
|
3446
|
+
var _a;
|
|
3447
|
+
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; });
|
|
3448
|
+
if (!fieldsToCheck_1[widgetField.key] && matchingRowMeta && !matchingRowMeta.hidden) {
|
|
3449
|
+
fieldsToCheck_1[widgetField.key] = matchingRowMeta;
|
|
3450
|
+
}
|
|
3451
|
+
});
|
|
3452
|
+
});
|
|
3453
|
+
var dataItem = getRequiredFieldsMissing(record, pendingValues, Object.values(fieldsToCheck_1));
|
|
3454
|
+
if (dataItem && TableLikeWidgetTypes.includes(widget_1 === null || widget_1 === void 0 ? void 0 : widget_1.type)) {
|
|
3455
|
+
dispatch(selectTableCellInit({ widgetName: widgetName_1, rowId: cursor_1, fieldKey: Object.keys(dataItem)[0] }));
|
|
3456
|
+
}
|
|
3457
|
+
return dataItem ? next(changeDataItem({ bcName: bcName, bcUrl: buildBcUrl(bcName, true, state), cursor: cursor_1, dataItem: dataItem })) : next(action);
|
|
3458
|
+
}
|
|
3459
|
+
if (hasPendingValidationFails(state, bcName)) {
|
|
3460
|
+
return addNotification({
|
|
3461
|
+
key: "requiredFieldsMissing",
|
|
3462
|
+
type: "buttonWarningNotification",
|
|
3463
|
+
message: "Required fields are missing",
|
|
3464
|
+
duration: 0,
|
|
3465
|
+
options: {
|
|
3466
|
+
buttonWarningNotificationOptions: {
|
|
3467
|
+
buttonText: "Cancel changes",
|
|
3468
|
+
actionsForClick: [bcCancelPendingChanges(null), clearValidationFails(null)]
|
|
3469
|
+
}
|
|
3470
|
+
}
|
|
3471
|
+
});
|
|
3472
|
+
}
|
|
3473
|
+
}
|
|
3474
|
+
}
|
|
3475
|
+
return next(action);
|
|
3476
|
+
}; };
|
|
3477
|
+
};
|
|
3478
|
+
function operationRequiresAutosave(operationType, actions) {
|
|
3479
|
+
var result = false;
|
|
3480
|
+
if (!actions) {
|
|
3481
|
+
console.error('rowMeta is missing in the middle of "sendOperation" action');
|
|
3482
|
+
return result;
|
|
3483
|
+
}
|
|
3484
|
+
result = flattenOperations(actions).some(function (action) { return action.type === operationType && action.autoSaveBefore; });
|
|
3485
|
+
return result;
|
|
3486
|
+
}
|
|
3487
|
+
function getRequiredFieldsMissing(record, pendingChanges, fieldsMeta) {
|
|
3488
|
+
var result = {};
|
|
3489
|
+
fieldsMeta.forEach(function (field) {
|
|
3490
|
+
var value = record === null || record === void 0 ? void 0 : record[field.key];
|
|
3491
|
+
var pendingValue = pendingChanges === null || pendingChanges === void 0 ? void 0 : pendingChanges[field.key];
|
|
3492
|
+
var effectiveValue = pendingValue !== void 0 ? pendingValue : value;
|
|
3493
|
+
var falsyValue = false;
|
|
3494
|
+
if (effectiveValue === null || effectiveValue === void 0 || effectiveValue === "") {
|
|
3495
|
+
falsyValue = true;
|
|
3496
|
+
}
|
|
3497
|
+
else if (Array.isArray(effectiveValue) && !effectiveValue.length) {
|
|
3498
|
+
falsyValue = true;
|
|
3499
|
+
}
|
|
3500
|
+
else if (effectiveValue && typeof effectiveValue === "object" && !Object.keys(effectiveValue).length) {
|
|
3501
|
+
falsyValue = true;
|
|
3502
|
+
}
|
|
3503
|
+
if (field.required && falsyValue) {
|
|
3504
|
+
result[field.key] = Array.isArray(effectiveValue) ? [] : null;
|
|
3505
|
+
}
|
|
3506
|
+
});
|
|
3507
|
+
return Object.keys(result).length > 0 ? result : null;
|
|
3508
|
+
}
|
|
3509
|
+
function hasPendingValidationFails(store, bcName) {
|
|
3510
|
+
var _a;
|
|
3511
|
+
if (store.view.pendingValidationFailsFormat !== "target" /* target */ && store.view.pendingValidationFails && Object.keys(store.view.pendingValidationFails).length) {
|
|
3512
|
+
return true;
|
|
3513
|
+
}
|
|
3514
|
+
var checkResult = false;
|
|
3515
|
+
var bcPendingValidations = (_a = store.view.pendingValidationFails) === null || _a === void 0 ? void 0 : _a[bcName];
|
|
3516
|
+
var cursorsList = bcPendingValidations && Object.keys(bcPendingValidations);
|
|
3517
|
+
if (!cursorsList) {
|
|
3518
|
+
return false;
|
|
3519
|
+
}
|
|
3520
|
+
var i = 0;
|
|
3521
|
+
for (; i < cursorsList.length; i++) {
|
|
3522
|
+
if (Object.keys(bcPendingValidations[cursorsList[i]]).length) {
|
|
3523
|
+
checkResult = true;
|
|
3524
|
+
break;
|
|
3525
|
+
}
|
|
3526
|
+
}
|
|
3527
|
+
return checkResult;
|
|
3528
|
+
}
|
|
3529
|
+
// src/middlewares/preInvokeMiddleware.ts
|
|
3530
|
+
var preInvokeAction = function (_a) {
|
|
3531
|
+
var getState = _a.getState;
|
|
3532
|
+
return function (next) { return function (action) {
|
|
3533
|
+
var _a, _b, _c;
|
|
3534
|
+
if (sendOperation.match(action)) {
|
|
3535
|
+
var state = getState();
|
|
3536
|
+
var _d = action.payload, operationType_1 = _d.operationType, widgetName_2 = _d.widgetName, confirm = _d.confirm;
|
|
3537
|
+
var bcName = (_a = state.view.widgets.find(function (widgetItem) { return widgetItem.name === widgetName_2; })) === null || _a === void 0 ? void 0 : _a.bcName;
|
|
3538
|
+
var bcUrl = buildBcUrl(bcName, true, state);
|
|
3539
|
+
var rowMeta = bcUrl && ((_b = state.view.rowMeta[bcName]) === null || _b === void 0 ? void 0 : _b[bcUrl]);
|
|
3540
|
+
var actions = rowMeta && flattenOperations(rowMeta.actions);
|
|
3541
|
+
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;
|
|
3542
|
+
return preInvoke && !confirm ? next(processPreInvoke({
|
|
3543
|
+
bcName: bcName,
|
|
3544
|
+
operationType: operationType_1,
|
|
3545
|
+
widgetName: widgetName_2,
|
|
3546
|
+
preInvoke: preInvoke
|
|
3547
|
+
})) : next(action);
|
|
3548
|
+
}
|
|
3549
|
+
return next(action);
|
|
3550
|
+
}; };
|
|
3551
|
+
};
|
|
3552
|
+
// src/middlewares/popupMiddleware.ts
|
|
3553
|
+
var popupMiddleware = function (_a) {
|
|
3554
|
+
var getState = _a.getState;
|
|
3555
|
+
return function (next) { return function (action) {
|
|
3556
|
+
var _a, _b, _c;
|
|
3557
|
+
if (showViewPopup.match(action)) {
|
|
3558
|
+
var state = getState();
|
|
3559
|
+
var bcName_1 = action.payload.bcName;
|
|
3560
|
+
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;
|
|
3561
|
+
var assocValueKey = (_c = action.payload.assocValueKey) !== null && _c !== void 0 ? _c : widgetValueKey;
|
|
3562
|
+
return widgetValueKey ? next(showViewPopup(__assign(__assign({}, action.payload), { assocValueKey: assocValueKey }))) : next(action);
|
|
3563
|
+
}
|
|
3564
|
+
return next(action);
|
|
3565
|
+
}; };
|
|
3566
|
+
};
|
|
3567
|
+
// src/middlewares/index.ts
|
|
3568
|
+
var middlewares = {
|
|
3569
|
+
autosave: saveFormMiddleware,
|
|
3570
|
+
requiredFields: requiredFields,
|
|
3571
|
+
preInvoke: preInvokeAction,
|
|
3572
|
+
popup: popupMiddleware
|
|
3573
|
+
};
|
|
3574
|
+
export { Api, actions_exports as actions, epics_exports as epics, interfaces_exports as interfaces, middlewares, reducers_exports as reducers, utils_exports as utils };
|
|
3338
3575
|
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10;
|
|
3339
3576
|
//# sourceMappingURL=cxbox-ui-core.esm.js.map
|
|
@@ -1531,7 +1531,7 @@ var sendOperationEpic = (action$, state$, { api }) => action$.pipe(filter(sendOp
|
|
|
1531
1531
|
const record = (_c = state.data[bcName]) == null ? void 0 : _c.find((item) => item.id === bc.cursor);
|
|
1532
1532
|
const filters = state.screen.filters[bcName];
|
|
1533
1533
|
const sorters = state.screen.sorters[bcName];
|
|
1534
|
-
const pendingRecordChange = (_d = state.view.pendingDataChanges[bcName]) == null ? void 0 : _d[bc.cursor];
|
|
1534
|
+
const pendingRecordChange = __spreadValues({}, (_d = state.view.pendingDataChanges[bcName]) == null ? void 0 : _d[bc.cursor]);
|
|
1535
1535
|
for (const key in pendingRecordChange) {
|
|
1536
1536
|
if (fields.find((item) => item.key === key && item.disabled)) {
|
|
1537
1537
|
delete pendingRecordChange[key];
|
|
@@ -2382,7 +2382,7 @@ var bcSaveDataEpic = (action$, state$, { api }) => action$.pipe(filter38(sendOpe
|
|
|
2382
2382
|
const widgetName = action.payload.widgetName;
|
|
2383
2383
|
const cursor = state.screen.bo.bc[bcName].cursor;
|
|
2384
2384
|
const dataItem = state.data[bcName].find((item) => item.id === cursor);
|
|
2385
|
-
const pendingChanges = (_b = state.view.pendingDataChanges[bcName]) == null ? void 0 : _b[cursor];
|
|
2385
|
+
const pendingChanges = __spreadValues({}, (_b = state.view.pendingDataChanges[bcName]) == null ? void 0 : _b[cursor]);
|
|
2386
2386
|
const rowMeta = bcUrl && ((_c = state.view.rowMeta[bcName]) == null ? void 0 : _c[bcUrl]);
|
|
2387
2387
|
const options = (_d = state.view.widgets.find((widget) => widget.name === widgetName)) == null ? void 0 : _d.options;
|
|
2388
2388
|
if (rowMeta) {
|
|
@@ -3207,7 +3207,10 @@ var Api = class {
|
|
|
3207
3207
|
}
|
|
3208
3208
|
fetchRowMeta(screenName, bcUrl, params, cancelToken) {
|
|
3209
3209
|
const url = applyParams(buildUrl `row-meta/${screenName}/` + bcUrl, params);
|
|
3210
|
-
return this.api$.get(url, { cancelToken }).pipe(map11((response) =>
|
|
3210
|
+
return this.api$.get(url, { cancelToken }).pipe(map11((response) => {
|
|
3211
|
+
var _a;
|
|
3212
|
+
return (_a = response.data) == null ? void 0 : _a.row;
|
|
3213
|
+
}));
|
|
3211
3214
|
}
|
|
3212
3215
|
newBcData(screenName, bcUrl, context, params) {
|
|
3213
3216
|
const url = applyParams(buildUrl `row-meta-new/${screenName}/` + bcUrl, params);
|
|
@@ -3269,5 +3272,239 @@ var Api = class {
|
|
|
3269
3272
|
};
|
|
3270
3273
|
}
|
|
3271
3274
|
};
|
|
3272
|
-
|
|
3275
|
+
// src/utils/autosave.ts
|
|
3276
|
+
function autosaveRoutine(action, store, next) {
|
|
3277
|
+
var _a, _b, _c;
|
|
3278
|
+
const state = store.getState();
|
|
3279
|
+
const dispatch = store.dispatch;
|
|
3280
|
+
const pendingDataChanges = state.view.pendingDataChanges;
|
|
3281
|
+
const bcList = Object.keys(pendingDataChanges);
|
|
3282
|
+
const baseBcNameIndex = ((_a = action.payload) == null ? void 0 : _a.bcName) && bcHasPendingAutosaveChanges(state, action.payload.bcName, (_b = state.screen.bo.bc[action.payload.bcName]) == null ? void 0 : _b.cursor) ? bcList.findIndex((bcName) => {
|
|
3283
|
+
var _a2;
|
|
3284
|
+
return bcName === ((_a2 = action.payload) == null ? void 0 : _a2.bcName);
|
|
3285
|
+
}) : bcList.findIndex((bcName) => {
|
|
3286
|
+
var _a2;
|
|
3287
|
+
return bcHasPendingAutosaveChanges(state, bcName, (_a2 = state.screen.bo.bc[bcName]) == null ? void 0 : _a2.cursor);
|
|
3288
|
+
});
|
|
3289
|
+
const baseBcName = bcList[baseBcNameIndex];
|
|
3290
|
+
if (baseBcNameIndex > -1) {
|
|
3291
|
+
bcList.splice(baseBcNameIndex, 1);
|
|
3292
|
+
}
|
|
3293
|
+
if (baseBcName) {
|
|
3294
|
+
bcList.forEach((bcName) => {
|
|
3295
|
+
var _a2, _b2;
|
|
3296
|
+
const widget = (_a2 = state.view.widgets) == null ? void 0 : _a2.find((v) => v.bcName === bcName);
|
|
3297
|
+
const cursor = (_b2 = state.screen.bo.bc[bcName]) == null ? void 0 : _b2.cursor;
|
|
3298
|
+
if (bcHasPendingAutosaveChanges(state, bcName, cursor)) {
|
|
3299
|
+
dispatch(sendOperation({
|
|
3300
|
+
bcName,
|
|
3301
|
+
operationType: OperationTypeCrud.save,
|
|
3302
|
+
widgetName: widget == null ? void 0 : widget.name
|
|
3303
|
+
}));
|
|
3304
|
+
}
|
|
3305
|
+
});
|
|
3306
|
+
const baseWidget = (_c = state.view.widgets) == null ? void 0 : _c.find((v) => v.bcName === baseBcName);
|
|
3307
|
+
return next(sendOperation({
|
|
3308
|
+
bcName: baseBcName,
|
|
3309
|
+
operationType: OperationTypeCrud.save,
|
|
3310
|
+
widgetName: baseWidget == null ? void 0 : baseWidget.name,
|
|
3311
|
+
onSuccessAction: action
|
|
3312
|
+
}));
|
|
3313
|
+
}
|
|
3314
|
+
return next(action);
|
|
3315
|
+
}
|
|
3316
|
+
function bcHasPendingAutosaveChanges(store, bcName, cursor) {
|
|
3317
|
+
var _a;
|
|
3318
|
+
const pendingChanges = store.view.pendingDataChanges;
|
|
3319
|
+
const cursorChanges = (_a = pendingChanges[bcName]) == null ? void 0 : _a[cursor];
|
|
3320
|
+
const result = cursorChanges && !Object.keys(cursorChanges).includes("_associate") && Object.values(cursorChanges).length > 0;
|
|
3321
|
+
return result;
|
|
3322
|
+
}
|
|
3323
|
+
function checkUnsavedChangesOfBc(store, bcName) {
|
|
3324
|
+
var _a, _b;
|
|
3325
|
+
const pendingCursors = Object.keys((_b = (_a = store.view.pendingDataChanges) == null ? void 0 : _a[bcName]) != null ? _b : {});
|
|
3326
|
+
return pendingCursors.some((cursor) => bcHasPendingAutosaveChanges(store, bcName, cursor));
|
|
3327
|
+
}
|
|
3328
|
+
// src/middlewares/autosaveMiddleware.ts
|
|
3329
|
+
var saveFormMiddleware = ({ getState, dispatch }) => (next) => (action) => {
|
|
3330
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
3331
|
+
const state = getState();
|
|
3332
|
+
const isSendOperation = sendOperation.match(action);
|
|
3333
|
+
const isCoreSendOperation = isSendOperation && coreOperations.includes(action.payload.operationType);
|
|
3334
|
+
const isSelectTableCellInit = selectTableCellInit.match(action);
|
|
3335
|
+
const isSaveAction = isSendOperation && action.payload.operationType === OperationTypeCrud.save;
|
|
3336
|
+
const isNotSaveAction = !isSaveAction;
|
|
3337
|
+
const actionBcName = isSendOperation && action.payload.bcName;
|
|
3338
|
+
const hasAnotherUnsavedBc = Object.keys(state.view.pendingDataChanges).filter((key) => key !== actionBcName).filter((key) => checkUnsavedChangesOfBc(state, key)).length > 0;
|
|
3339
|
+
const isSendOperationForAnotherBc = isCoreSendOperation && hasAnotherUnsavedBc;
|
|
3340
|
+
const selectedCell = state.view.selectedCell;
|
|
3341
|
+
const isSelectTableCellInitOnAnotherRowOrWidget = selectedCell && isSelectTableCellInit && (selectedCell.widgetName !== action.payload.widgetName || selectedCell.rowId !== action.payload.rowId);
|
|
3342
|
+
const defaultSaveWidget = (_a = state.view.widgets) == null ? void 0 : _a.find((item) => {
|
|
3343
|
+
var _a2, _b2;
|
|
3344
|
+
return (_b2 = (_a2 = item == null ? void 0 : item.options) == null ? void 0 : _a2.actionGroups) == null ? void 0 : _b2.defaultSave;
|
|
3345
|
+
});
|
|
3346
|
+
const defaultCursor = (_c = (_b = state.screen.bo.bc) == null ? void 0 : _b[defaultSaveWidget == null ? void 0 : defaultSaveWidget.bcName]) == null ? void 0 : _c.cursor;
|
|
3347
|
+
const pendingData = (_f = (_e = (_d = state.view) == null ? void 0 : _d.pendingDataChanges) == null ? void 0 : _e[defaultSaveWidget == null ? void 0 : defaultSaveWidget.bcName]) == null ? void 0 : _f[defaultCursor];
|
|
3348
|
+
const isChangeLocation = defaultSaveWidget && changeLocation.match(action) && Object.keys(pendingData || {}).length > 0;
|
|
3349
|
+
if (isChangeLocation) {
|
|
3350
|
+
return next(sendOperation({
|
|
3351
|
+
bcName: defaultSaveWidget.bcName,
|
|
3352
|
+
operationType: ((_g = defaultSaveWidget.options) == null ? void 0 : _g.actionGroups).defaultSave,
|
|
3353
|
+
widgetName: defaultSaveWidget.name,
|
|
3354
|
+
onSuccessAction: action
|
|
3355
|
+
}));
|
|
3356
|
+
}
|
|
3357
|
+
const isNeedSaveCondition = isNotSaveAction && (isSendOperationForAnotherBc || isSelectTableCellInitOnAnotherRowOrWidget);
|
|
3358
|
+
if (isNeedSaveCondition) {
|
|
3359
|
+
return autosaveRoutine(action, { getState, dispatch }, next);
|
|
3360
|
+
}
|
|
3361
|
+
return next(action);
|
|
3362
|
+
};
|
|
3363
|
+
// src/middlewares/requiredFieldsMiddleware.ts
|
|
3364
|
+
var requiredFields = ({ getState, dispatch }) => (next) => (action) => {
|
|
3365
|
+
var _a, _b, _c, _d;
|
|
3366
|
+
const state = getState();
|
|
3367
|
+
if (sendOperation.match(action)) {
|
|
3368
|
+
const { bcName, operationType, widgetName } = action.payload;
|
|
3369
|
+
const cursor = (_a = state.screen.bo.bc[bcName]) == null ? void 0 : _a.cursor;
|
|
3370
|
+
if (cursor) {
|
|
3371
|
+
const bcUrl = buildBcUrl(bcName, true, state);
|
|
3372
|
+
const record = (_b = state.data[bcName]) == null ? void 0 : _b.find((item) => item.id === cursor);
|
|
3373
|
+
const rowMeta = bcUrl && ((_c = state.view.rowMeta[bcName]) == null ? void 0 : _c[bcUrl]);
|
|
3374
|
+
const pendingValues = (_d = state.view.pendingDataChanges[bcName]) == null ? void 0 : _d[cursor];
|
|
3375
|
+
const widget = state.view.widgets.find((item) => item.name === widgetName);
|
|
3376
|
+
if (operationRequiresAutosave(operationType, rowMeta == null ? void 0 : rowMeta.actions)) {
|
|
3377
|
+
const fieldsToCheck = {};
|
|
3378
|
+
state.view.widgets.filter((item) => item.bcName === (widget == null ? void 0 : widget.bcName)).forEach((item) => {
|
|
3379
|
+
const itemFieldsCalc = item.fields;
|
|
3380
|
+
if (item.fields) {
|
|
3381
|
+
item.fields.forEach((block) => {
|
|
3382
|
+
if (isWidgetFieldBlock(block)) {
|
|
3383
|
+
block.fields.forEach((field) => itemFieldsCalc.push(field));
|
|
3384
|
+
}
|
|
3385
|
+
});
|
|
3386
|
+
}
|
|
3387
|
+
itemFieldsCalc.forEach((widgetField) => {
|
|
3388
|
+
var _a2;
|
|
3389
|
+
const matchingRowMeta = (_a2 = rowMeta == null ? void 0 : rowMeta.fields) == null ? void 0 : _a2.find((rowMetaField) => rowMetaField.key === widgetField.key);
|
|
3390
|
+
if (!fieldsToCheck[widgetField.key] && matchingRowMeta && !matchingRowMeta.hidden) {
|
|
3391
|
+
fieldsToCheck[widgetField.key] = matchingRowMeta;
|
|
3392
|
+
}
|
|
3393
|
+
});
|
|
3394
|
+
});
|
|
3395
|
+
const dataItem = getRequiredFieldsMissing(record, pendingValues, Object.values(fieldsToCheck));
|
|
3396
|
+
if (dataItem && TableLikeWidgetTypes.includes(widget == null ? void 0 : widget.type)) {
|
|
3397
|
+
dispatch(selectTableCellInit({ widgetName, rowId: cursor, fieldKey: Object.keys(dataItem)[0] }));
|
|
3398
|
+
}
|
|
3399
|
+
return dataItem ? next(changeDataItem({ bcName, bcUrl: buildBcUrl(bcName, true, state), cursor, dataItem })) : next(action);
|
|
3400
|
+
}
|
|
3401
|
+
if (hasPendingValidationFails(state, bcName)) {
|
|
3402
|
+
return addNotification({
|
|
3403
|
+
key: "requiredFieldsMissing",
|
|
3404
|
+
type: "buttonWarningNotification",
|
|
3405
|
+
message: "Required fields are missing",
|
|
3406
|
+
duration: 0,
|
|
3407
|
+
options: {
|
|
3408
|
+
buttonWarningNotificationOptions: {
|
|
3409
|
+
buttonText: "Cancel changes",
|
|
3410
|
+
actionsForClick: [bcCancelPendingChanges(null), clearValidationFails(null)]
|
|
3411
|
+
}
|
|
3412
|
+
}
|
|
3413
|
+
});
|
|
3414
|
+
}
|
|
3415
|
+
}
|
|
3416
|
+
}
|
|
3417
|
+
return next(action);
|
|
3418
|
+
};
|
|
3419
|
+
function operationRequiresAutosave(operationType, actions) {
|
|
3420
|
+
let result = false;
|
|
3421
|
+
if (!actions) {
|
|
3422
|
+
console.error('rowMeta is missing in the middle of "sendOperation" action');
|
|
3423
|
+
return result;
|
|
3424
|
+
}
|
|
3425
|
+
result = flattenOperations(actions).some((action) => action.type === operationType && action.autoSaveBefore);
|
|
3426
|
+
return result;
|
|
3427
|
+
}
|
|
3428
|
+
function getRequiredFieldsMissing(record, pendingChanges, fieldsMeta) {
|
|
3429
|
+
const result = {};
|
|
3430
|
+
fieldsMeta.forEach((field) => {
|
|
3431
|
+
const value = record == null ? void 0 : record[field.key];
|
|
3432
|
+
const pendingValue = pendingChanges == null ? void 0 : pendingChanges[field.key];
|
|
3433
|
+
const effectiveValue = pendingValue !== void 0 ? pendingValue : value;
|
|
3434
|
+
let falsyValue = false;
|
|
3435
|
+
if (effectiveValue === null || effectiveValue === void 0 || effectiveValue === "") {
|
|
3436
|
+
falsyValue = true;
|
|
3437
|
+
}
|
|
3438
|
+
else if (Array.isArray(effectiveValue) && !effectiveValue.length) {
|
|
3439
|
+
falsyValue = true;
|
|
3440
|
+
}
|
|
3441
|
+
else if (effectiveValue && typeof effectiveValue === "object" && !Object.keys(effectiveValue).length) {
|
|
3442
|
+
falsyValue = true;
|
|
3443
|
+
}
|
|
3444
|
+
if (field.required && falsyValue) {
|
|
3445
|
+
result[field.key] = Array.isArray(effectiveValue) ? [] : null;
|
|
3446
|
+
}
|
|
3447
|
+
});
|
|
3448
|
+
return Object.keys(result).length > 0 ? result : null;
|
|
3449
|
+
}
|
|
3450
|
+
function hasPendingValidationFails(store, bcName) {
|
|
3451
|
+
var _a;
|
|
3452
|
+
if (store.view.pendingValidationFailsFormat !== "target" /* target */ && store.view.pendingValidationFails && Object.keys(store.view.pendingValidationFails).length) {
|
|
3453
|
+
return true;
|
|
3454
|
+
}
|
|
3455
|
+
let checkResult = false;
|
|
3456
|
+
const bcPendingValidations = (_a = store.view.pendingValidationFails) == null ? void 0 : _a[bcName];
|
|
3457
|
+
const cursorsList = bcPendingValidations && Object.keys(bcPendingValidations);
|
|
3458
|
+
if (!cursorsList) {
|
|
3459
|
+
return false;
|
|
3460
|
+
}
|
|
3461
|
+
let i = 0;
|
|
3462
|
+
for (; i < cursorsList.length; i++) {
|
|
3463
|
+
if (Object.keys(bcPendingValidations[cursorsList[i]]).length) {
|
|
3464
|
+
checkResult = true;
|
|
3465
|
+
break;
|
|
3466
|
+
}
|
|
3467
|
+
}
|
|
3468
|
+
return checkResult;
|
|
3469
|
+
}
|
|
3470
|
+
// src/middlewares/preInvokeMiddleware.ts
|
|
3471
|
+
var preInvokeAction = ({ getState }) => (next) => (action) => {
|
|
3472
|
+
var _a, _b, _c;
|
|
3473
|
+
if (sendOperation.match(action)) {
|
|
3474
|
+
const state = getState();
|
|
3475
|
+
const { operationType, widgetName, confirm } = action.payload;
|
|
3476
|
+
const bcName = (_a = state.view.widgets.find((widgetItem) => widgetItem.name === widgetName)) == null ? void 0 : _a.bcName;
|
|
3477
|
+
const bcUrl = buildBcUrl(bcName, true, state);
|
|
3478
|
+
const rowMeta = bcUrl && ((_b = state.view.rowMeta[bcName]) == null ? void 0 : _b[bcUrl]);
|
|
3479
|
+
const actions = rowMeta && flattenOperations(rowMeta.actions);
|
|
3480
|
+
const preInvoke = (_c = actions == null ? void 0 : actions.find((item) => item.type === operationType)) == null ? void 0 : _c.preInvoke;
|
|
3481
|
+
return preInvoke && !confirm ? next(processPreInvoke({
|
|
3482
|
+
bcName,
|
|
3483
|
+
operationType,
|
|
3484
|
+
widgetName,
|
|
3485
|
+
preInvoke
|
|
3486
|
+
})) : next(action);
|
|
3487
|
+
}
|
|
3488
|
+
return next(action);
|
|
3489
|
+
};
|
|
3490
|
+
// src/middlewares/popupMiddleware.ts
|
|
3491
|
+
var popupMiddleware = ({ getState }) => (next) => (action) => {
|
|
3492
|
+
var _a, _b, _c;
|
|
3493
|
+
if (showViewPopup.match(action)) {
|
|
3494
|
+
const state = getState();
|
|
3495
|
+
const bcName = action.payload.bcName;
|
|
3496
|
+
const widgetValueKey = (_b = (_a = state.view.widgets.find((item) => item.bcName === bcName)) == null ? void 0 : _a.options) == null ? void 0 : _b.displayedValueKey;
|
|
3497
|
+
const assocValueKey = (_c = action.payload.assocValueKey) != null ? _c : widgetValueKey;
|
|
3498
|
+
return widgetValueKey ? next(showViewPopup(__spreadProps(__spreadValues({}, action.payload), { assocValueKey }))) : next(action);
|
|
3499
|
+
}
|
|
3500
|
+
return next(action);
|
|
3501
|
+
};
|
|
3502
|
+
// src/middlewares/index.ts
|
|
3503
|
+
var middlewares = {
|
|
3504
|
+
autosave: saveFormMiddleware,
|
|
3505
|
+
requiredFields,
|
|
3506
|
+
preInvoke: preInvokeAction,
|
|
3507
|
+
popup: popupMiddleware
|
|
3508
|
+
};
|
|
3509
|
+
export { Api, actions_exports as actions, epics_exports as epics, interfaces_exports as interfaces, middlewares, reducers_exports as reducers, utils_exports as utils };
|
|
3273
3510
|
//# sourceMappingURL=cxbox-ui-core.modern.development.js.map
|