@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
|
@@ -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.js.map
|