@cxbox-ui/core 1.37.2-alpha.1 → 1.37.2-alpha.11

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.
@@ -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
  });
@@ -152,6 +153,8 @@ __export(actions_exports, {
152
153
  processPreInvoke: function () { return processPreInvoke; },
153
154
  refreshMeta: function () { return refreshMeta; },
154
155
  refreshMetaAndReloadPage: function () { return refreshMetaAndReloadPage; },
156
+ refreshMetaDone: function () { return refreshMetaDone; },
157
+ refreshMetaFail: function () { return refreshMetaFail; },
155
158
  removeMultivalueTag: function () { return removeMultivalueTag; },
156
159
  removeNotifications: function () { return removeNotifications; },
157
160
  removePendingRequest: function () { return removePendingRequest; },
@@ -202,7 +205,7 @@ var bcFetchRowMetaSuccess = (0, import_toolkit.createAction)("bcFetchRowMetaSucc
202
205
  var bcFetchRowMetaFail = (0, import_toolkit.createAction)("bcFetchRowMetaFail");
203
206
  var bcNewData = (0, import_toolkit.createAction)("bcNewData");
204
207
  var bcNewDataSuccess = (0, import_toolkit.createAction)("bcNewDataSuccess");
205
- var bcNewDataFail = (0, import_toolkit.createAction)("bcNewDataSuccess");
208
+ var bcNewDataFail = (0, import_toolkit.createAction)("bcNewDataFail");
206
209
  var bcDeleteDataFail = (0, import_toolkit.createAction)("bcDeleteDataFail");
207
210
  var forceActiveChangeFail = (0, import_toolkit.createAction)("forceActiveChangeFail");
208
211
  var sendOperation = (0, import_toolkit.createAction)("sendOperation");
@@ -217,7 +220,7 @@ var drillDown = (0, import_toolkit.createAction)("drillDown");
217
220
  var bcChangeCursors = (0, import_toolkit.createAction)("bcChangeCursors");
218
221
  var bcChangeDepthCursor = (0, import_toolkit.createAction)("bcChangeDepthCursor");
219
222
  var changeDataItem = (0, import_toolkit.createAction)("changeDataItem");
220
- var changeDataItems = (0, import_toolkit.createAction)("changeDataItem");
223
+ var changeDataItems = (0, import_toolkit.createAction)("changeDataItems");
221
224
  var forceActiveRmUpdate = (0, import_toolkit.createAction)("forceActiveRmUpdate");
222
225
  var showViewPopup = (0, import_toolkit.createAction)("showViewPopup");
223
226
  var showFileUploadPopup = (0, import_toolkit.createAction)("showFileUploadPopup");
@@ -271,6 +274,8 @@ var switchDebugMode = (0, import_toolkit.createAction)("switchDebugMode");
271
274
  var exportState = (0, import_toolkit.createAction)("exportState");
272
275
  var emptyAction = (0, import_toolkit.createAction)("emptyAction");
273
276
  var refreshMeta = (0, import_toolkit.createAction)("refreshMeta");
277
+ var refreshMetaDone = (0, import_toolkit.createAction)("refreshMetaDone");
278
+ var refreshMetaFail = (0, import_toolkit.createAction)("refreshMetaFail");
274
279
  var refreshMetaAndReloadPage = (0, import_toolkit.createAction)("refreshMetaAndReloadPage");
275
280
  var switchRole = (0, import_toolkit.createAction)("switchRole");
276
281
  var addPendingRequest = (0, import_toolkit.createAction)("addPendingRequest");
@@ -376,12 +381,14 @@ __export(interfaces_exports, {
376
381
  OperationPostInvokeConfirmType: function () { return OperationPostInvokeConfirmType; },
377
382
  OperationPostInvokeType: function () { return OperationPostInvokeType; },
378
383
  OperationPreInvokeType: function () { return OperationPreInvokeType; },
379
- OperationTypeCrud: function () { return import_schema4.OperationTypeCrud; },
384
+ OperationTypeCrud: function () { return import_schema5.OperationTypeCrud; },
380
385
  PaginationMode: function () { return PaginationMode; },
381
386
  PendingValidationFailsFormat: function () { return PendingValidationFailsFormat; },
382
387
  PopupWidgetTypes: function () { return PopupWidgetTypes; },
388
+ PositionTypes: function () { return import_schema4.PositionTypes; },
383
389
  RouteType: function () { return RouteType; },
384
390
  TableLikeWidgetTypes: function () { return TableLikeWidgetTypes; },
391
+ WidgetTypes: function () { return import_schema4.WidgetTypes; },
385
392
  coreOperations: function () { return coreOperations; },
386
393
  isCustomWidget: function () { return isCustomWidget; },
387
394
  isCustomWidgetConfiguration: function () { return isCustomWidgetConfiguration; },
@@ -424,6 +431,7 @@ var ApplicationErrorType = /* @__PURE__ */ (function (ApplicationErrorType2) {
424
431
  })(ApplicationErrorType || {});
425
432
  // src/interfaces/widget.ts
426
433
  var import_schema3 = require("@cxbox-ui/schema");
434
+ var import_schema4 = require("@cxbox-ui/schema");
427
435
  var TableLikeWidgetTypes = [
428
436
  import_schema3.WidgetTypes.List,
429
437
  import_schema3.WidgetTypes.DataGrid,
@@ -448,14 +456,14 @@ var PaginationMode = /* @__PURE__ */ (function (PaginationMode2) {
448
456
  return PaginationMode2;
449
457
  })(PaginationMode || {});
450
458
  // src/interfaces/operation.ts
451
- var import_schema4 = require("@cxbox-ui/schema");
459
+ var import_schema5 = require("@cxbox-ui/schema");
452
460
  var coreOperations = [
453
- import_schema4.OperationTypeCrud.create,
454
- import_schema4.OperationTypeCrud.save,
455
- import_schema4.OperationTypeCrud.delete,
456
- import_schema4.OperationTypeCrud.associate,
457
- import_schema4.OperationTypeCrud.cancelCreate,
458
- import_schema4.OperationTypeCrud.fileUpload
461
+ import_schema5.OperationTypeCrud.create,
462
+ import_schema5.OperationTypeCrud.save,
463
+ import_schema5.OperationTypeCrud.delete,
464
+ import_schema5.OperationTypeCrud.associate,
465
+ import_schema5.OperationTypeCrud.cancelCreate,
466
+ import_schema5.OperationTypeCrud.fileUpload
459
467
  ];
460
468
  function isOperationGroup(operation) {
461
469
  return Array.isArray(operation.actions);
@@ -506,6 +514,15 @@ function isViewNavigationCategory(item) {
506
514
  function isViewNavigationGroup(item) {
507
515
  return !!item && "child" in item && !("categoryName" in item);
508
516
  }
517
+ // src/reducers/router.ts
518
+ var initialRouterState = { type: "default" /* default */, path: "/", params: null, screenName: null };
519
+ var createRouterReducerBuilderManager = function (initialState) { return new ReducerBuilderManager().addCase(loginDone, function (state, action) {
520
+ state = __assign(__assign({}, state), action.payload);
521
+ }).addCase(changeLocation, function (state, action) {
522
+ state = __assign(__assign({}, state), action.payload.location);
523
+ }); };
524
+ // src/reducers/screen.ts
525
+ var import_schema6 = require("@cxbox-ui/schema");
509
526
  // src/utils/index.ts
510
527
  var utils_exports = {};
511
528
  __export(utils_exports, {
@@ -518,6 +535,8 @@ __export(utils_exports, {
518
535
  buildSearchResultTree: function () { return buildSearchResultTree; },
519
536
  buildUrl: function () { return buildUrl; },
520
537
  checkShowCondition: function () { return checkShowCondition; },
538
+ createApiError: function () { return createApiError; },
539
+ createApiErrorObservable: function () { return createApiErrorObservable; },
521
540
  defaultBuildURL: function () { return defaultBuildURL; },
522
541
  defaultParseURL: function () { return defaultParseURL; },
523
542
  deleteUndefinedFromObject: function () { return deleteUndefinedFromObject; },
@@ -526,7 +545,6 @@ __export(utils_exports, {
526
545
  getBcChildren: function () { return getBcChildren; },
527
546
  getDescendants: function () { return getDescendants; },
528
547
  getFieldTitle: function () { return getFieldTitle; },
529
- getFileUploadEndpoint: function () { return getFileUploadEndpoint; },
530
548
  getFilterType: function () { return getFilterType; },
531
549
  getFilters: function () { return getFilters; },
532
550
  getSorters: function () { return getSorters; },
@@ -566,11 +584,18 @@ function applyRawParams(url, qso) {
566
584
  var result = new URLSearchParams(qso).toString();
567
585
  return "".concat(addTailControlSequences(url)).concat(result && "".concat(result));
568
586
  }
569
- function getFileUploadEndpoint(instance) {
570
- if (!instance.defaults.baseURL) {
571
- return "/file";
572
- }
573
- return instance.defaults.baseURL.endsWith("/") ? "".concat(instance.defaults.baseURL, "file") : "".concat(instance.defaults.baseURL, "/file");
587
+ // src/utils/apiError.ts
588
+ var import_core = require("@cxbox-ui/core");
589
+ var import_rxjs = require("rxjs");
590
+ function createApiError(error, context) {
591
+ if (context === void 0) { context = { widgetName: "unknown" }; }
592
+ if (!error.isAxiosError)
593
+ return void 0;
594
+ return import_core.actions.apiError({ error: error, callContext: context });
595
+ }
596
+ function createApiErrorObservable(error, context) {
597
+ var apiError2 = createApiError(error, context);
598
+ return apiError2 ? (0, import_rxjs.of)(apiError2) : import_rxjs.EMPTY;
574
599
  }
575
600
  // src/utils/strings.ts
576
601
  function getTemplate(literals) {
@@ -586,10 +611,9 @@ function getTemplate(literals) {
586
611
  result += literals[literals.length - 1];
587
612
  return result;
588
613
  }
589
- function buildBcUrl(bcName, includeSelf, store) {
614
+ function buildBcUrl(bcName, includeSelf, state) {
590
615
  if (includeSelf === void 0) { includeSelf = false; }
591
- var storeInstance = store;
592
- var bcMap = storeInstance.screen.bo.bc;
616
+ var bcMap = state.screen.bo.bc;
593
617
  var bc = bcMap[bcName];
594
618
  if (!bc) {
595
619
  return null;
@@ -722,7 +746,7 @@ function defaultParseURL(url) {
722
746
  }
723
747
  return {
724
748
  type: type,
725
- path: path,
749
+ path: path.length !== 0 && !path.startsWith("/") ? "/".concat(path) : path,
726
750
  params: params,
727
751
  screenName: screenName,
728
752
  viewName: viewName,
@@ -770,8 +794,9 @@ function getSorters(sorters) {
770
794
  return result;
771
795
  }
772
796
  function parseFilters(defaultFilters) {
797
+ if (defaultFilters === void 0) { defaultFilters = ""; }
773
798
  var result = [];
774
- var urlParams = new URL(defaultFilters).searchParams;
799
+ var urlParams = new URL(defaultFilters, window.location.origin).searchParams;
775
800
  urlParams.forEach(function (param) {
776
801
  var _a = param.split("."), fieldName = _a[0], type = _a[1];
777
802
  if (fieldName && type && urlParams.get(param)) {
@@ -801,7 +826,7 @@ function parseSorters(sorters) {
801
826
  return null;
802
827
  }
803
828
  var result = [];
804
- var dictionary = new URL(sorters).searchParams;
829
+ var dictionary = new URL(sorters, window.location.origin).searchParams;
805
830
  Object.entries(dictionary).map(function (_a) {
806
831
  var sort = _a[0], fieldKey = _a[1];
807
832
  var _b = sort.split(".").slice(1), order = _b[0], direction = _b[1];
@@ -880,12 +905,13 @@ function getBcChildren(originBcName, widgets, bcMap) {
880
905
  return childrenBcMap;
881
906
  }
882
907
  function getHierarchyChildBc(originBcName, hierarchyWidget) {
883
- var nestedBcNames = hierarchyWidget.options.hierarchy.map(function (nestedItem) { return nestedItem.bcName; });
884
- if (originBcName !== hierarchyWidget.bcName && !nestedBcNames.includes(originBcName)) {
908
+ var _a, _b;
909
+ var nestedBcNames = (_b = (_a = hierarchyWidget === null || hierarchyWidget === void 0 ? void 0 : hierarchyWidget.options) === null || _a === void 0 ? void 0 : _a.hierarchy) === null || _b === void 0 ? void 0 : _b.map(function (nestedItem) { return nestedItem.bcName; });
910
+ if (originBcName !== hierarchyWidget.bcName && !(nestedBcNames === null || nestedBcNames === void 0 ? void 0 : nestedBcNames.includes(originBcName))) {
885
911
  return [];
886
912
  }
887
- var childHierarchyBcIndex = nestedBcNames.findIndex(function (item) { return item === originBcName; });
888
- var childHierarchyBcName = nestedBcNames[childHierarchyBcIndex + 1];
913
+ var childHierarchyBcIndex = nestedBcNames === null || nestedBcNames === void 0 ? void 0 : nestedBcNames.findIndex(function (item) { return item === originBcName; });
914
+ var childHierarchyBcName = nestedBcNames === null || nestedBcNames === void 0 ? void 0 : nestedBcNames[childHierarchyBcIndex + 1];
889
915
  return [childHierarchyBcName, hierarchyWidget.name];
890
916
  }
891
917
  function checkShowCondition(condition, cursor, data, pendingDataChanges) {
@@ -899,9 +925,9 @@ function checkShowCondition(condition, cursor, data, pendingDataChanges) {
899
925
  if (!record) {
900
926
  return false;
901
927
  }
902
- var actualValue = record === null || record === void 0 ? void 0 : record[params.fieldKey];
903
- var pendingValue = (_b = (_a = pendingDataChanges === null || pendingDataChanges === void 0 ? void 0 : pendingDataChanges[bcName]) === null || _a === void 0 ? void 0 : _a[cursor]) === null || _b === void 0 ? void 0 : _b[params.fieldKey];
904
- return pendingValue !== void 0 ? pendingValue === params.value : actualValue === params.value;
928
+ var actualValue = record === null || record === void 0 ? void 0 : record[params === null || params === void 0 ? void 0 : params.fieldKey];
929
+ var pendingValue = (_b = (_a = pendingDataChanges === null || pendingDataChanges === void 0 ? void 0 : pendingDataChanges[bcName]) === null || _a === void 0 ? void 0 : _a[cursor]) === null || _b === void 0 ? void 0 : _b[params === null || params === void 0 ? void 0 : params.fieldKey];
930
+ return pendingValue !== void 0 ? pendingValue === (params === null || params === void 0 ? void 0 : params.value) : actualValue === (params === null || params === void 0 ? void 0 : params.value);
905
931
  }
906
932
  // src/utils/tree.ts
907
933
  function assignTreeLinks(flat) {
@@ -909,6 +935,7 @@ function assignTreeLinks(flat) {
909
935
  var map12 = {};
910
936
  var orphans = [];
911
937
  result.forEach(function (item) {
938
+ var _a, _b;
912
939
  if (!item.parentId || item.parentId === "0") {
913
940
  return;
914
941
  }
@@ -927,7 +954,7 @@ function assignTreeLinks(flat) {
927
954
  result[parentIndex].children = [item];
928
955
  }
929
956
  else {
930
- result[parentIndex].children.push(item);
957
+ (_b = (_a = result[parentIndex]) === null || _a === void 0 ? void 0 : _a.children) === null || _b === void 0 ? void 0 : _b.push(item);
931
958
  }
932
959
  });
933
960
  if (orphans.length) {
@@ -1005,22 +1032,7 @@ function deleteUndefinedFromObject(obj) {
1005
1032
  }
1006
1033
  });
1007
1034
  }
1008
- // src/reducers/router.ts
1009
- var initialRouterState = { type: "default" /* default */, path: "/", params: null, screenName: null };
1010
- var createRouterReducerBuilderManager = function (initialState) { return new ReducerBuilderManager().addCase(loginDone, function (state, action) {
1011
- state = __assign(__assign({}, state), action.payload);
1012
- }).addCase(changeLocation, function (state, action) {
1013
- var _a = action.payload, url = _a.url, route = _a.route;
1014
- if (url) {
1015
- var path = new URL(url);
1016
- state = __assign(__assign({}, state), defaultParseURL(path));
1017
- }
1018
- if (route !== null) {
1019
- state = __assign(__assign({}, state), route);
1020
- }
1021
- }); };
1022
1035
  // src/reducers/screen.ts
1023
- var import_schema5 = require("@cxbox-ui/schema");
1024
1036
  var initialScreenState = {
1025
1037
  screenName: "",
1026
1038
  bo: { activeBcName: "", bc: {} },
@@ -1030,12 +1042,13 @@ var initialScreenState = {
1030
1042
  filters: {},
1031
1043
  sorters: {}
1032
1044
  };
1033
- var operationsHandledLocally = [import_schema5.OperationTypeCrud.associate, import_schema5.OperationTypeCrud.fileUpload];
1045
+ var operationsHandledLocally = [import_schema6.OperationTypeCrud.associate, import_schema6.OperationTypeCrud.fileUpload];
1034
1046
  var createScreenReducerBuilderManager = function (initialState) { return new ReducerBuilderManager().addCase(selectScreen, function (state, action) {
1047
+ var _a, _b, _c, _d, _e;
1035
1048
  var bcDictionary = {};
1036
1049
  var bcSorters = {};
1037
1050
  var bcFilters = {};
1038
- action.payload.screen.meta.bo.bc.forEach(function (item) {
1051
+ (_a = action.payload.screen.meta) === null || _a === void 0 ? void 0 : _a.bo.bc.forEach(function (item) {
1039
1052
  bcDictionary[item.name] = item;
1040
1053
  var sorter = parseSorters(item.defaultSort);
1041
1054
  var filter56 = parseFilters(item.defaultFilter);
@@ -1047,8 +1060,8 @@ var createScreenReducerBuilderManager = function (initialState) { return new Red
1047
1060
  }
1048
1061
  });
1049
1062
  state.screenName = action.payload.screen.name;
1050
- state.primaryView = action.payload.screen.meta.primary;
1051
- state.views = action.payload.screen.meta.views;
1063
+ state.primaryView = (_c = (_b = action.payload.screen.meta) === null || _b === void 0 ? void 0 : _b.primary) !== null && _c !== void 0 ? _c : state.primaryView;
1064
+ state.views = (_e = (_d = action.payload.screen.meta) === null || _d === void 0 ? void 0 : _d.views) !== null && _e !== void 0 ? _e : state.views;
1052
1065
  state.bo = { activeBcName: null, bc: bcDictionary };
1053
1066
  state.sorters = __assign(__assign({}, state.sorters), bcSorters);
1054
1067
  state.filters = __assign(__assign({}, state.filters), bcFilters);
@@ -1058,12 +1071,14 @@ var createScreenReducerBuilderManager = function (initialState) { return new Red
1058
1071
  }).addCase(bcFetchDataRequest, function (state, action) {
1059
1072
  state.bo.bc[action.payload.bcName].loading = true;
1060
1073
  }).addCase(bcLoadMore, function (state, action) {
1074
+ var _a;
1061
1075
  var currentBc = state.bo.bc[action.payload.bcName];
1062
- currentBc.page += 1;
1076
+ currentBc.page = ((_a = currentBc.page) !== null && _a !== void 0 ? _a : 1) + 1;
1063
1077
  currentBc.loading = true;
1064
1078
  }).addCase(selectView, function (state, action) {
1079
+ var _a;
1065
1080
  var newBcs = {};
1066
- Array.from(new Set(action.payload.widgets.map(function (widget) { return widget.bcName; }))
1081
+ Array.from(new Set((_a = action.payload.widgets) === null || _a === void 0 ? void 0 : _a.map(function (widget) { return widget.bcName; }))
1067
1082
  // БК которые есть на вьюхе
1068
1083
  ).filter(function (bcName) { return state.bo.bc[bcName]; }).forEach(function (bcName) {
1069
1084
  newBcs[bcName] = __assign(__assign({}, state.bo.bc[bcName]), { page: 1 });
@@ -1075,9 +1090,10 @@ var createScreenReducerBuilderManager = function (initialState) { return new Red
1075
1090
  currentBc.loading = false;
1076
1091
  state.cachedBc[action.payload.bcName] = action.payload.bcUrl;
1077
1092
  }).addCase(bcFetchDataFail, function (state, action) {
1078
- if (Object.values(state.bo.bc).some(function (bc) { return bc.name === action.payload.bcName; })) {
1079
- state.bo.bc[action.payload.bcName].loading = false;
1080
- state.cachedBc[action.payload.bcName] = action.payload.bcUrl;
1093
+ var bcName = action.payload.bcName;
1094
+ if (Object.values(state.bo.bc).some(function (bc) { return bc.name === bcName; })) {
1095
+ state.bo.bc[bcName].loading = false;
1096
+ state.cachedBc[bcName] = action.payload.bcUrl;
1081
1097
  }
1082
1098
  }).addCase(sendOperation, function (state, action) {
1083
1099
  if (!operationsHandledLocally.includes(action.payload.operationType)) {
@@ -1105,10 +1121,12 @@ var createScreenReducerBuilderManager = function (initialState) { return new Red
1105
1121
  Object.assign(state.bo.bc, newCursors);
1106
1122
  Object.assign(state.cachedBc, newCache);
1107
1123
  }).addCase(bcChangeDepthCursor, function (state, action) {
1124
+ var _a;
1108
1125
  if (action.payload.depth === 1) {
1109
1126
  state.bo.bc[action.payload.bcName].cursor = action.payload.cursor;
1110
1127
  }
1111
1128
  else {
1129
+ state.bo.bc[action.payload.bcName].depthBc = (_a = state.bo.bc[action.payload.bcName].depthBc) !== null && _a !== void 0 ? _a : {};
1112
1130
  state.bo.bc[action.payload.bcName].depthBc[action.payload.depth].cursor = action.payload.cursor;
1113
1131
  }
1114
1132
  }).addCase(bcSelectRecord, function (state, action) {
@@ -1144,7 +1162,9 @@ var createScreenReducerBuilderManager = function (initialState) { return new Red
1144
1162
  state.bo.bc[action.payload.bcName].page = action.payload.page;
1145
1163
  state.bo.bc[action.payload.bcName].loading = true;
1146
1164
  }).addCase(showViewPopup, function (state, action) {
1147
- state.bo.bc[action.payload.bcName].page = 1;
1165
+ var _a, _b;
1166
+ var currentPage = (_b = (_a = state.bo.bc[action.payload.bcName]) === null || _a === void 0 ? void 0 : _a.page) !== null && _b !== void 0 ? _b : 1;
1167
+ state.bo.bc[action.payload.bcName].page = action.payload.bcName === action.payload.calleeBCName ? currentPage : 1;
1148
1168
  state.bo.bc[action.payload.bcName].loading = action.payload.bcName !== action.payload.calleeBCName;
1149
1169
  }).addCase(sendOperationSuccess, function (state, action) {
1150
1170
  state.bo.bc[action.payload.bcName].loading = false;
@@ -1173,7 +1193,8 @@ var initialSessionState = {
1173
1193
  errorMsg: null,
1174
1194
  screens: [],
1175
1195
  pendingRequests: [],
1176
- notifications: []
1196
+ notifications: [],
1197
+ isMetaRefreshing: false
1177
1198
  };
1178
1199
  var createSessionReducerBuilderManager = function (initialState) { return new ReducerBuilderManager().addCase(login, function (state) {
1179
1200
  state.loginSpin = true;
@@ -1193,17 +1214,25 @@ var createSessionReducerBuilderManager = function (initialState) { return new Re
1193
1214
  }).addCase(switchDebugMode, function (state, action) {
1194
1215
  state.debugMode = action.payload;
1195
1216
  }).addCase(addPendingRequest, function (state, action) {
1196
- state.pendingRequests.push(action.payload.request);
1217
+ var _a;
1218
+ (_a = state.pendingRequests) === null || _a === void 0 ? void 0 : _a.push(action.payload.request);
1197
1219
  }).addCase(removePendingRequest, function (state, action) {
1198
- state.pendingRequests = state.pendingRequests.filter(function (item) { return item.requestId !== action.payload.requestId; });
1220
+ var _a;
1221
+ state.pendingRequests = (_a = state.pendingRequests) === null || _a === void 0 ? void 0 : _a.filter(function (item) { return item.requestId !== action.payload.requestId; });
1199
1222
  }).addCase(addNotification, function (state, action) {
1200
1223
  state.notifications.push(action.payload);
1201
1224
  }).addCase(removeNotifications, function (state, action) {
1202
1225
  var closingKeys = action.payload;
1203
1226
  state.notifications = state.notifications.filter(function (notification) { return !closingKeys.includes(notification.key); });
1227
+ }).addCase(refreshMeta, function (state) {
1228
+ state.isMetaRefreshing = true;
1229
+ }).addCase(refreshMetaDone, function (state) {
1230
+ state.isMetaRefreshing = false;
1231
+ }).addCase(refreshMetaFail, function (state) {
1232
+ state.isMetaRefreshing = false;
1204
1233
  }); };
1205
1234
  // src/reducers/view.ts
1206
- var import_schema6 = require("@cxbox-ui/schema");
1235
+ var import_schema7 = require("@cxbox-ui/schema");
1207
1236
  var initialViewState = {
1208
1237
  id: void 0,
1209
1238
  name: null,
@@ -1238,16 +1267,19 @@ var createViewReducerBuilderManager = function (initialState) { return new Reduc
1238
1267
  }
1239
1268
  state.infiniteWidgets = Array.from(new Set(infiniteWidgets));
1240
1269
  }).addCase(sendOperation, function (state, action) {
1241
- if (action.payload.operationType === import_schema6.OperationTypeCrud.create) {
1270
+ if (action.payload.operationType === import_schema7.OperationTypeCrud.create) {
1242
1271
  state.metaInProgress[action.payload.bcName] = true;
1243
1272
  }
1244
1273
  }).addCase(bcFetchRowMetaSuccess, function (state, action) {
1274
+ var _a;
1275
+ state.rowMeta[action.payload.bcName] = (_a = state.rowMeta[action.payload.bcName]) !== null && _a !== void 0 ? _a : {};
1245
1276
  state.rowMeta[action.payload.bcName][action.payload.bcUrl] = action.payload.rowMeta;
1246
1277
  state.metaInProgress[action.payload.bcName] = false;
1247
1278
  }).addCase(bcNewDataSuccess, function (state, action) {
1248
1279
  state.selectedCell = initialViewState.selectedCell;
1249
1280
  }).addCase(forceActiveRmUpdate, function (state, action) {
1250
- var _a = action.payload, bcName = _a.bcName, bcUrl = _a.bcUrl, currentRecordData = _a.currentRecordData, rowMeta = _a.rowMeta, cursor = _a.cursor;
1281
+ var _a, _b, _c, _d, _e;
1282
+ var _f = action.payload, bcName = _f.bcName, bcUrl = _f.bcUrl, currentRecordData = _f.currentRecordData, rowMeta = _f.rowMeta, cursor = _f.cursor;
1251
1283
  var handledForceActive = {};
1252
1284
  var rowMetaForcedValues = {};
1253
1285
  var newPendingChangesDiff = {};
@@ -1258,6 +1290,7 @@ var createViewReducerBuilderManager = function (initialState) { return new Reduc
1258
1290
  forceActiveFieldKeys.push(field.key);
1259
1291
  }
1260
1292
  });
1293
+ state.pendingDataChanges[bcName] = (_a = state.pendingDataChanges[bcName]) !== null && _a !== void 0 ? _a : {};
1261
1294
  var consolidatedFrontData = __assign(__assign({}, currentRecordData), state.pendingDataChanges[bcName][cursor]);
1262
1295
  Object.keys(consolidatedFrontData).forEach(function (key) {
1263
1296
  if (rowMetaForcedValues[key] !== void 0 && consolidatedFrontData[key] !== rowMetaForcedValues[key]) {
@@ -1270,17 +1303,21 @@ var createViewReducerBuilderManager = function (initialState) { return new Reduc
1270
1303
  handledForceActive[key] = newPendingDataChanges[key];
1271
1304
  }
1272
1305
  });
1306
+ state.handledForceActive[bcName] = (_b = state.handledForceActive[bcName]) !== null && _b !== void 0 ? _b : {};
1307
+ state.handledForceActive[bcName][cursor] = (_c = state.handledForceActive[bcName][cursor]) !== null && _c !== void 0 ? _c : {};
1273
1308
  Object.assign(state.handledForceActive[bcName][cursor], handledForceActive);
1309
+ state.pendingDataChanges[bcName] = (_d = state.pendingDataChanges[bcName]) !== null && _d !== void 0 ? _d : {};
1274
1310
  state.pendingDataChanges[bcName][cursor] = newPendingDataChanges;
1311
+ state.rowMeta[bcName] = (_e = state.rowMeta[bcName]) !== null && _e !== void 0 ? _e : {};
1275
1312
  state.rowMeta[bcName][bcUrl] = rowMeta;
1276
1313
  }).addCase(changeDataItem, function (state, action) {
1277
- var _a;
1314
+ var _a, _b, _c;
1278
1315
  var actionBcName = action.payload.bcName;
1279
1316
  var prevBc = state.pendingDataChanges[action.payload.bcName] || {};
1280
1317
  var prevCursor = prevBc[action.payload.cursor] || {};
1281
1318
  var prevPending = prevCursor || {};
1282
1319
  var nextPending = __assign(__assign({}, prevPending), action.payload.dataItem);
1283
- var bcUrl = buildBcUrl(actionBcName, true);
1320
+ var bcUrl = action.payload.bcUrl;
1284
1321
  var rowMeta = (_a = state.rowMeta[actionBcName]) === null || _a === void 0 ? void 0 : _a[bcUrl];
1285
1322
  var nextValidationFails = {};
1286
1323
  var isTargetFormatPVF = state.pendingValidationFailsFormat === "target" /* target */;
@@ -1291,10 +1328,11 @@ var createViewReducerBuilderManager = function (initialState) { return new Reduc
1291
1328
  nextValidationFails[fieldKey] = "This field is mandatory";
1292
1329
  }
1293
1330
  });
1331
+ state.pendingDataChanges[action.payload.bcName] = (_b = state.pendingDataChanges[action.payload.bcName]) !== null && _b !== void 0 ? _b : {};
1294
1332
  state.pendingDataChanges[action.payload.bcName][action.payload.cursor] = nextPending;
1295
1333
  if (isTargetFormatPVF) {
1296
1334
  ;
1297
- state.pendingValidationFails[actionBcName][action.payload.cursor] = nextValidationFails;
1335
+ ((_c = state.pendingValidationFails) === null || _c === void 0 ? void 0 : _c[actionBcName])[action.payload.cursor] = nextValidationFails;
1298
1336
  }
1299
1337
  else {
1300
1338
  state.pendingValidationFails = nextValidationFails;
@@ -1315,7 +1353,7 @@ var createViewReducerBuilderManager = function (initialState) { return new Reduc
1315
1353
  pendingDataChanges[bcName] = pendingBcChanges;
1316
1354
  });
1317
1355
  var isTargetFormatPVF = state.pendingValidationFailsFormat === "target" /* target */;
1318
- var pendingValidationFails = __assign({}, state.pendingValidationFails);
1356
+ var pendingValidationFails = state.pendingValidationFails ? __assign({}, state.pendingValidationFails) : {};
1319
1357
  if (isTargetFormatPVF) {
1320
1358
  action.payload.bcNames.forEach(function (i) {
1321
1359
  pendingValidationFails[i] = {};
@@ -1330,7 +1368,8 @@ var createViewReducerBuilderManager = function (initialState) { return new Reduc
1330
1368
  }).addCase(bcFetchRowMetaFail, function (state, action) {
1331
1369
  state.metaInProgress[action.payload.bcName] = false;
1332
1370
  }).addCase(forceActiveChangeFail, function (state, action) {
1333
- var _a = action.payload, bcName = _a.bcName, bcUrl = _a.bcUrl, entityError = _a.entityError;
1371
+ var _a;
1372
+ var _b = action.payload, bcName = _b.bcName, bcUrl = _b.bcUrl, entityError = _b.entityError;
1334
1373
  var errors = {};
1335
1374
  if (entityError) {
1336
1375
  Object.entries(entityError.fields).forEach(function (_a) {
@@ -1338,9 +1377,11 @@ var createViewReducerBuilderManager = function (initialState) { return new Reduc
1338
1377
  errors[fieldName] = violation;
1339
1378
  });
1340
1379
  }
1380
+ state.rowMeta[bcName] = (_a = state.rowMeta[bcName]) !== null && _a !== void 0 ? _a : {};
1341
1381
  state.rowMeta[bcName][bcUrl].errors = errors;
1342
1382
  }).addCase(bcSaveDataFail, function (state, action) {
1343
- var _a = action.payload, bcName = _a.bcName, bcUrl = _a.bcUrl, entityError = _a.entityError;
1383
+ var _a;
1384
+ var _b = action.payload, bcName = _b.bcName, bcUrl = _b.bcUrl, entityError = _b.entityError;
1344
1385
  var errors = {};
1345
1386
  if (entityError) {
1346
1387
  Object.entries(entityError.fields).forEach(function (_a) {
@@ -1348,9 +1389,11 @@ var createViewReducerBuilderManager = function (initialState) { return new Reduc
1348
1389
  errors[fieldName] = violation;
1349
1390
  });
1350
1391
  }
1392
+ state.rowMeta[bcName] = (_a = state.rowMeta[bcName]) !== null && _a !== void 0 ? _a : {};
1351
1393
  state.rowMeta[bcName][bcUrl].errors = errors;
1352
1394
  }).addCase(sendOperationFail, function (state, action) {
1353
- var _a = action.payload, bcName = _a.bcName, bcUrl = _a.bcUrl, entityError = _a.entityError;
1395
+ var _a;
1396
+ var _b = action.payload, bcName = _b.bcName, bcUrl = _b.bcUrl, entityError = _b.entityError;
1354
1397
  var errors = {};
1355
1398
  if (entityError) {
1356
1399
  Object.entries(entityError.fields).forEach(function (_a) {
@@ -1358,30 +1401,38 @@ var createViewReducerBuilderManager = function (initialState) { return new Reduc
1358
1401
  errors[fieldName] = violation;
1359
1402
  });
1360
1403
  }
1404
+ state.rowMeta[bcName] = (_a = state.rowMeta[bcName]) !== null && _a !== void 0 ? _a : {};
1361
1405
  state.rowMeta[bcName][bcUrl].errors = errors;
1362
1406
  }).addCase(sendOperationSuccess, function (state, action) {
1363
- var _a = action.payload, bcName = _a.bcName, cursor = _a.cursor;
1407
+ var _a, _b, _c;
1408
+ var bcName = action.payload.bcName;
1409
+ var cursor = action.payload.cursor;
1364
1410
  var isTargetFormatPVF = state.pendingValidationFailsFormat === "target" /* target */;
1411
+ state.pendingDataChanges[bcName] = (_a = state.pendingDataChanges[bcName]) !== null && _a !== void 0 ? _a : {};
1365
1412
  state.pendingDataChanges[bcName][cursor] = {};
1366
1413
  if (isTargetFormatPVF) {
1367
1414
  ;
1368
- state.pendingValidationFails[bcName][cursor] = {};
1415
+ ((_b = state.pendingValidationFails) === null || _b === void 0 ? void 0 : _b[bcName])[cursor] = {};
1369
1416
  }
1370
1417
  else {
1371
1418
  state.pendingValidationFails = initialViewState.pendingValidationFails;
1372
1419
  }
1420
+ state.handledForceActive[bcName] = (_c = state.handledForceActive[bcName]) !== null && _c !== void 0 ? _c : {};
1373
1421
  state.handledForceActive[bcName][cursor] = {};
1374
1422
  }).addCase(bcSaveDataSuccess, function (state, action) {
1375
- var _a = action.payload, bcName = _a.bcName, cursor = _a.cursor;
1423
+ var _a, _b, _c;
1424
+ var _d = action.payload, bcName = _d.bcName, cursor = _d.cursor;
1376
1425
  var isTargetFormatPVF = state.pendingValidationFailsFormat === "target" /* target */;
1426
+ state.pendingDataChanges[bcName] = (_a = state.pendingDataChanges[bcName]) !== null && _a !== void 0 ? _a : {};
1377
1427
  state.pendingDataChanges[bcName][cursor] = {};
1378
1428
  if (isTargetFormatPVF) {
1379
1429
  ;
1380
- state.pendingValidationFails[bcName][cursor] = {};
1430
+ ((_b = state.pendingValidationFails) === null || _b === void 0 ? void 0 : _b[bcName])[cursor] = {};
1381
1431
  }
1382
1432
  else {
1383
1433
  state.pendingValidationFails = initialViewState.pendingValidationFails;
1384
1434
  }
1435
+ state.handledForceActive[bcName] = (_c = state.handledForceActive[bcName]) !== null && _c !== void 0 ? _c : {};
1385
1436
  state.handledForceActive[bcName][cursor] = {};
1386
1437
  }).addCase(bcCancelPendingChanges, function (state, action) {
1387
1438
  var _a, _b;
@@ -1392,7 +1443,7 @@ var createViewReducerBuilderManager = function (initialState) { return new Reduc
1392
1443
  }
1393
1444
  }
1394
1445
  var isTargetFormatPVF = state.pendingValidationFailsFormat === "target" /* target */;
1395
- var pendingValidationFails = __assign({}, state.pendingValidationFails);
1446
+ var pendingValidationFails = state.pendingValidationFails ? __assign({}, state.pendingValidationFails) : {};
1396
1447
  if (isTargetFormatPVF) {
1397
1448
  if (((_b = (_a = action.payload) === null || _a === void 0 ? void 0 : _a.bcNames) === null || _b === void 0 ? void 0 : _b.length) > 0) {
1398
1449
  action.payload.bcNames.forEach(function (i) {
@@ -1421,8 +1472,8 @@ var createViewReducerBuilderManager = function (initialState) { return new Reduc
1421
1472
  isFilter: isFilter
1422
1473
  };
1423
1474
  }).addCase(showFileUploadPopup, function (state, action) {
1424
- var _a;
1425
- var bcName = (_a = state.widgets.find(function (item) { return item.name === action.payload.widgetName; })) === null || _a === void 0 ? void 0 : _a.bcName;
1475
+ var _a, _b;
1476
+ var bcName = (_b = (_a = state.widgets) === null || _a === void 0 ? void 0 : _a.find(function (item) { return item.name === action.payload.widgetName; })) === null || _b === void 0 ? void 0 : _b.bcName;
1426
1477
  state.popupData = {
1427
1478
  type: "file-upload",
1428
1479
  bcName: bcName,
@@ -1434,6 +1485,7 @@ var createViewReducerBuilderManager = function (initialState) { return new Reduc
1434
1485
  }).addCase(viewClearPickMap, function (state) {
1435
1486
  state.pickMap = null;
1436
1487
  }).addCase(closeViewPopup, function (state) {
1488
+ state.popupData = {};
1437
1489
  state.popupData.bcName = null;
1438
1490
  }).addCase(selectTableCell, function (state, action) {
1439
1491
  state.selectedCell = { widgetName: action.payload.widgetName, rowId: action.payload.rowId, fieldKey: action.payload.fieldKey };
@@ -1441,12 +1493,16 @@ var createViewReducerBuilderManager = function (initialState) { return new Reduc
1441
1493
  state.pendingDataChanges = initialViewState.pendingDataChanges;
1442
1494
  state.selectedCell = initialViewState.selectedCell;
1443
1495
  }).addCase(showNotification, function (state, action) {
1496
+ var _a, _b;
1497
+ state.systemNotifications = (_a = state.systemNotifications) !== null && _a !== void 0 ? _a : [];
1444
1498
  state.systemNotifications.push({
1445
1499
  type: action.payload.type,
1446
1500
  message: action.payload.message,
1447
- id: state.systemNotifications.length
1501
+ id: (_b = state.systemNotifications) === null || _b === void 0 ? void 0 : _b.length
1448
1502
  });
1449
1503
  }).addCase(closeNotification, function (state, action) {
1504
+ var _a;
1505
+ state.systemNotifications = (_a = state.systemNotifications) !== null && _a !== void 0 ? _a : [];
1450
1506
  state.systemNotifications = state.systemNotifications.filter(function (item) { return item.id !== action.payload.id; });
1451
1507
  }).addCase(showViewError, function (state, action) {
1452
1508
  state.error = action.payload.error;
@@ -1494,7 +1550,6 @@ __export(epics_exports, {
1494
1550
  httpError500Epic: function () { return httpError500Epic; },
1495
1551
  httpErrorDefaultEpic: function () { return httpErrorDefaultEpic; },
1496
1552
  inlinePickListFetchDataEpic: function () { return inlinePickListFetchDataEpic; },
1497
- knownHttpErrors: function () { return knownHttpErrors; },
1498
1553
  loginByAnotherRoleEpic: function () { return loginByAnotherRoleEpic; },
1499
1554
  loginDoneEpic: function () { return loginDoneEpic; },
1500
1555
  loginDoneSessionEpic: function () { return loginDoneSessionEpic; },
@@ -1519,9 +1574,9 @@ __export(epics_exports, {
1519
1574
  userDrillDownEpic: function () { return userDrillDownEpic; }
1520
1575
  });
1521
1576
  // src/epics/view/sendOperationEpic.ts
1522
- var import_rxjs2 = require("rxjs");
1577
+ var import_rxjs3 = require("rxjs");
1523
1578
  // src/epics/utils/postOperationRoutine.ts
1524
- var import_rxjs = require("rxjs");
1579
+ var import_rxjs2 = require("rxjs");
1525
1580
  function postOperationRoutine(widgetName, postInvoke, preInvoke, operationType, bcName) {
1526
1581
  var postInvokeConfirm = Object.values(OperationPostInvokeConfirmType).includes(postInvoke === null || postInvoke === void 0 ? void 0 : postInvoke.type);
1527
1582
  var result = [];
@@ -1544,18 +1599,18 @@ function postOperationRoutine(widgetName, postInvoke, preInvoke, operationType,
1544
1599
  preInvoke: preInvoke
1545
1600
  }));
1546
1601
  }
1547
- return result.map(function (item) { return (0, import_rxjs.of)(item); });
1602
+ return result.map(function (item) { return (0, import_rxjs2.of)(item); });
1548
1603
  }
1549
1604
  // src/epics/view/sendOperationEpic.ts
1550
1605
  var sendOperationEpic = function (action$, state$, _a) {
1551
1606
  var api = _a.api;
1552
- return action$.pipe((0, import_rxjs2.filter)(sendOperation.match), (0, import_rxjs2.filter)(function (action) { return matchOperationRole("none", action.payload, state$.value); }), (0, import_rxjs2.mergeMap)(function (action) {
1607
+ return action$.pipe((0, import_rxjs3.filter)(sendOperation.match), (0, import_rxjs3.filter)(function (action) { return matchOperationRole("none", action.payload, state$.value); }), (0, import_rxjs3.mergeMap)(function (action) {
1553
1608
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
1554
1609
  var state = state$.value;
1555
1610
  var screenName = state.screen.screenName;
1556
1611
  var _l = action.payload, bcName = _l.bcName, operationType = _l.operationType, widgetName = _l.widgetName;
1557
1612
  var confirm = ((_a = action.payload.confirmOperation) === null || _a === void 0 ? void 0 : _a.type) || action.payload.confirm;
1558
- var bcUrl = buildBcUrl(bcName, true);
1613
+ var bcUrl = buildBcUrl(bcName, true, state);
1559
1614
  var bc = state.screen.bo.bc[bcName];
1560
1615
  var rowMeta = bcUrl && ((_b = state.view.rowMeta[bcName]) === null || _b === void 0 ? void 0 : _b[bcUrl]);
1561
1616
  var fields = rowMeta === null || rowMeta === void 0 ? void 0 : rowMeta.fields;
@@ -1563,7 +1618,7 @@ var sendOperationEpic = function (action$, state$, _a) {
1563
1618
  var record = (_c = state.data[bcName]) === null || _c === void 0 ? void 0 : _c.find(function (item) { return item.id === bc.cursor; });
1564
1619
  var filters = state.screen.filters[bcName];
1565
1620
  var sorters = state.screen.sorters[bcName];
1566
- var pendingRecordChange = (_d = state.view.pendingDataChanges[bcName]) === null || _d === void 0 ? void 0 : _d[bc.cursor];
1621
+ var pendingRecordChange = __assign({}, (_d = state.view.pendingDataChanges[bcName]) === null || _d === void 0 ? void 0 : _d[bc.cursor]);
1567
1622
  var _loop_2 = function (key) {
1568
1623
  if (fields.find(function (item) { return item.key === key && item.disabled; })) {
1569
1624
  delete pendingRecordChange[key];
@@ -1579,13 +1634,13 @@ var sendOperationEpic = function (action$, state$, _a) {
1579
1634
  params._confirm = confirm;
1580
1635
  }
1581
1636
  var context = { widgetName: action.payload.widgetName };
1582
- return api.customAction(screenName, bcUrl, data, context, params).pipe((0, import_rxjs2.mergeMap)(function (response) {
1583
- var _a;
1584
- var postInvoke = response.postActions[0];
1637
+ return api.customAction(screenName, bcUrl, data, context, params).pipe((0, import_rxjs3.mergeMap)(function (response) {
1638
+ var _a, _b;
1639
+ var postInvoke = (_a = response.postActions) === null || _a === void 0 ? void 0 : _a[0];
1585
1640
  var preInvoke = response.preInvoke;
1586
- return defaultSaveOperation ? ((_a = action === null || action === void 0 ? void 0 : action.payload) === null || _a === void 0 ? void 0 : _a.onSuccessAction) ? (0, import_rxjs2.concat)((0, import_rxjs2.of)(bcCancelPendingChanges({ bcNames: [bcName] })), (0, import_rxjs2.of)(action.payload.onSuccessAction)) : import_rxjs2.EMPTY : (0, import_rxjs2.concat).apply(void 0, __spreadArray([(0, import_rxjs2.of)(sendOperationSuccess({ bcName: bcName, cursor: cursor })),
1587
- (0, import_rxjs2.of)(bcForceUpdate({ bcName: bcName }))], postOperationRoutine(widgetName, postInvoke, preInvoke, operationType, bcName), false));
1588
- }), (0, import_rxjs2.catchError)(function (e) {
1641
+ return defaultSaveOperation ? ((_b = action === null || action === void 0 ? void 0 : action.payload) === null || _b === void 0 ? void 0 : _b.onSuccessAction) ? (0, import_rxjs3.concat)((0, import_rxjs3.of)(bcCancelPendingChanges({ bcNames: [bcName] })), (0, import_rxjs3.of)(action.payload.onSuccessAction)) : import_rxjs3.EMPTY : (0, import_rxjs3.concat).apply(void 0, __spreadArray([(0, import_rxjs3.of)(sendOperationSuccess({ bcName: bcName, cursor: cursor })),
1642
+ (0, import_rxjs3.of)(bcForceUpdate({ bcName: bcName }))], postOperationRoutine(widgetName, postInvoke, preInvoke, operationType, bcName), false));
1643
+ }), (0, import_rxjs3.catchError)(function (e) {
1589
1644
  var _a, _b, _c, _d, _e, _f;
1590
1645
  console.error(e);
1591
1646
  var viewError = null;
@@ -1595,25 +1650,25 @@ var sendOperationEpic = function (action$, state$, _a) {
1595
1650
  entityError = (_d = operationError === null || operationError === void 0 ? void 0 : operationError.error) === null || _d === void 0 ? void 0 : _d.entity;
1596
1651
  viewError = (_f = (_e = operationError === null || operationError === void 0 ? void 0 : operationError.error) === null || _e === void 0 ? void 0 : _e.popup) === null || _f === void 0 ? void 0 : _f[0];
1597
1652
  }
1598
- return (0, import_rxjs2.of)(sendOperationFail({ bcName: bcName, bcUrl: bcUrl, viewError: viewError, entityError: entityError }));
1653
+ return (0, import_rxjs3.concat)((0, import_rxjs3.of)(sendOperationFail({ bcName: bcName, bcUrl: bcUrl, viewError: viewError, entityError: entityError })), createApiErrorObservable(e, context));
1599
1654
  }));
1600
1655
  }));
1601
1656
  };
1602
1657
  // src/epics/view/showAssocPopupEpic.ts
1603
- var import_rxjs3 = require("rxjs");
1604
- var import_schema7 = require("@cxbox-ui/schema");
1605
- var showAssocPopupEpic = function (action$, state$) { return action$.pipe((0, import_rxjs3.filter)(showViewPopup.match), (0, import_rxjs3.filter)(function (action) { return !!(action.payload.calleeBCName && action.payload.associateFieldKey); }), (0, import_rxjs3.mergeMap)(function (action) {
1658
+ var import_rxjs4 = require("rxjs");
1659
+ var import_schema8 = require("@cxbox-ui/schema");
1660
+ var showAssocPopupEpic = function (action$, state$) { return action$.pipe((0, import_rxjs4.filter)(showViewPopup.match), (0, import_rxjs4.filter)(function (action) { return !!(action.payload.calleeBCName && action.payload.associateFieldKey); }), (0, import_rxjs4.mergeMap)(function (action) {
1606
1661
  var _a, _b, _c, _d;
1607
1662
  var _e = action.payload, bcName = _e.bcName, calleeBCName = _e.calleeBCName;
1608
1663
  var state = state$.value;
1609
- var assocWidget = state.view.widgets.find(function (widget) { return widget.bcName === bcName && widget.type === import_schema7.WidgetTypes.AssocListPopup; });
1664
+ var assocWidget = state.view.widgets.find(function (widget) { return widget.bcName === bcName && widget.type === import_schema8.WidgetTypes.AssocListPopup; });
1610
1665
  var calleeCursor = (_a = state.screen.bo.bc[calleeBCName]) === null || _a === void 0 ? void 0 : _a.cursor;
1611
1666
  var calleePendingChanges = (_b = state.view.pendingDataChanges[calleeBCName]) === null || _b === void 0 ? void 0 : _b[calleeCursor];
1612
1667
  var assocFieldKey = action.payload.associateFieldKey;
1613
1668
  var assocFieldChanges = calleePendingChanges === null || calleePendingChanges === void 0 ? void 0 : calleePendingChanges[assocFieldKey];
1614
1669
  var somethingMissing = !assocWidget || !calleePendingChanges || !assocFieldChanges || !assocFieldChanges;
1615
1670
  if (somethingMissing || assocWidget.options && !assocWidget.options.hierarchyFull) {
1616
- return import_rxjs3.EMPTY;
1671
+ return import_rxjs4.EMPTY;
1617
1672
  }
1618
1673
  var popupInitPendingChanges = {};
1619
1674
  assocFieldChanges.forEach(function (record) {
@@ -1636,65 +1691,69 @@ var showAssocPopupEpic = function (action$, state$) { return action$.pipe((0, im
1636
1691
  }
1637
1692
  });
1638
1693
  }
1639
- return (0, import_rxjs3.of)(changeDataItems({
1694
+ return (0, import_rxjs4.of)(changeDataItems({
1640
1695
  bcName: bcName,
1641
1696
  cursors: Object.keys(popupInitPendingChanges),
1642
1697
  dataItems: Object.values(popupInitPendingChanges)
1643
1698
  }));
1644
1699
  })); };
1645
1700
  // src/epics/view/fileUploadConfirmEpic.ts
1646
- var import_rxjs4 = require("rxjs");
1647
- var import_schema8 = require("@cxbox-ui/schema");
1701
+ var import_rxjs5 = require("rxjs");
1702
+ var import_schema9 = require("@cxbox-ui/schema");
1648
1703
  var fileUploadConfirmEpic = function (action$, state$, _a) {
1649
1704
  var api = _a.api;
1650
- return action$.pipe((0, import_rxjs4.filter)(bulkUploadFiles.match), (0, import_rxjs4.mergeMap)(function (action) {
1651
- var _a;
1705
+ return action$.pipe((0, import_rxjs5.filter)(bulkUploadFiles.match), (0, import_rxjs5.mergeMap)(function (action) {
1706
+ var _a, _b;
1652
1707
  var state = state$.value;
1653
- var bcName = state.view.popupData.bcName;
1654
- var bcUrl = buildBcUrl(bcName, true);
1655
- var widgetName = (_a = state.view.widgets.find(function (item) { return item.bcName === bcName; })) === null || _a === void 0 ? void 0 : _a.name;
1708
+ var bcName = (_a = state.view.popupData) === null || _a === void 0 ? void 0 : _a.bcName;
1709
+ var bcUrl = buildBcUrl(bcName, true, state);
1710
+ var widgetName = (_b = state.view.widgets.find(function (item) { return item.bcName === bcName; })) === null || _b === void 0 ? void 0 : _b.name;
1656
1711
  var data = {
1657
1712
  bulkIds: action.payload.fileIds
1658
1713
  };
1659
- return api.customAction(state.screen.screenName, bcUrl, data, null, { _action: "file-upload-save" }).pipe((0, import_rxjs4.mergeMap)(function (response) {
1660
- var postInvoke = response.postActions[0];
1714
+ return api.customAction(state.screen.screenName, bcUrl, data, null, { _action: "file-upload-save" }).pipe((0, import_rxjs5.mergeMap)(function (response) {
1715
+ var _a;
1716
+ var postInvoke = (_a = response.postActions) === null || _a === void 0 ? void 0 : _a[0];
1661
1717
  var preInvoke = response.preInvoke;
1662
- return (0, import_rxjs4.concat).apply(void 0, __spreadArray([(0, import_rxjs4.of)(sendOperationSuccess({ bcName: bcName, cursor: null })),
1663
- (0, import_rxjs4.of)(bcForceUpdate({ bcName: bcName })),
1664
- (0, import_rxjs4.of)(closeViewPopup(null))], postOperationRoutine(widgetName, postInvoke, preInvoke, import_schema8.OperationTypeCrud.save, bcName), false));
1718
+ return (0, import_rxjs5.concat).apply(void 0, __spreadArray([(0, import_rxjs5.of)(sendOperationSuccess({ bcName: bcName, cursor: null })),
1719
+ (0, import_rxjs5.of)(bcForceUpdate({ bcName: bcName })),
1720
+ (0, import_rxjs5.of)(closeViewPopup(null))], postOperationRoutine(widgetName, postInvoke, preInvoke, import_schema9.OperationTypeCrud.save, bcName), false));
1721
+ }), (0, import_rxjs5.catchError)(function (error) {
1722
+ console.error(error);
1723
+ return createApiErrorObservable(error);
1665
1724
  }));
1666
1725
  }));
1667
1726
  };
1668
1727
  // src/epics/view/selectTableCellInitEpic.ts
1669
- var import_rxjs5 = require("rxjs");
1670
- var selectTableCellInitEpic = function (action$, state$) { return action$.pipe((0, import_rxjs5.filter)(selectTableCellInit.match), (0, import_rxjs5.mergeMap)(function (action) {
1728
+ var import_rxjs6 = require("rxjs");
1729
+ var selectTableCellInitEpic = function (action$, state$) { return action$.pipe((0, import_rxjs6.filter)(selectTableCellInit.match), (0, import_rxjs6.mergeMap)(function (action) {
1671
1730
  var _a;
1672
1731
  var resultObservables = [];
1673
1732
  var state = state$.value;
1674
1733
  var _b = action.payload, nextRowId = _b.rowId, fieldKey = _b.fieldKey;
1675
1734
  var nextWidget = state.view.widgets.find(function (widget) { return widget.name === action.payload.widgetName; });
1676
- var nextBcName = nextWidget.bcName;
1735
+ var nextBcName = nextWidget === null || nextWidget === void 0 ? void 0 : nextWidget.bcName;
1677
1736
  var nextBcCursor = (_a = state.screen.bo.bc[nextBcName]) === null || _a === void 0 ? void 0 : _a.cursor;
1678
1737
  var selectedCell = state.view.selectedCell;
1679
1738
  if (nextRowId !== nextBcCursor) {
1680
- resultObservables.push((0, import_rxjs5.of)(bcSelectRecord({ bcName: nextBcName, cursor: nextRowId })));
1739
+ resultObservables.push((0, import_rxjs6.of)(bcSelectRecord({ bcName: nextBcName, cursor: nextRowId })));
1681
1740
  }
1682
- if (!selectedCell || fieldKey !== selectedCell.fieldKey || nextRowId !== selectedCell.rowId || nextWidget.name !== selectedCell.widgetName) {
1683
- resultObservables.push((0, import_rxjs5.of)(selectTableCell({ widgetName: nextWidget.name, rowId: nextRowId, fieldKey: fieldKey })));
1741
+ if (!selectedCell || fieldKey !== selectedCell.fieldKey || nextRowId !== selectedCell.rowId || (nextWidget === null || nextWidget === void 0 ? void 0 : nextWidget.name) !== selectedCell.widgetName) {
1742
+ resultObservables.push((0, import_rxjs6.of)(selectTableCell({ widgetName: nextWidget === null || nextWidget === void 0 ? void 0 : nextWidget.name, rowId: nextRowId, fieldKey: fieldKey })));
1684
1743
  }
1685
- return (0, import_rxjs5.concat).apply(void 0, resultObservables);
1744
+ return (0, import_rxjs6.concat).apply(void 0, resultObservables);
1686
1745
  })); };
1687
1746
  // src/epics/view/showFileUploadPopupEpic.ts
1688
- var import_rxjs6 = require("rxjs");
1689
- var import_schema9 = require("@cxbox-ui/schema");
1690
- var showFileUploadPopupEpic = function (action$, state$) { return action$.pipe((0, import_rxjs6.filter)(sendOperation.match), (0, import_rxjs6.filter)(function (action) { return matchOperationRole(import_schema9.OperationTypeCrud.fileUpload, action.payload, state$.value); }), (0, import_rxjs6.mergeMap)(function (action) {
1747
+ var import_rxjs7 = require("rxjs");
1748
+ var import_schema10 = require("@cxbox-ui/schema");
1749
+ var showFileUploadPopupEpic = function (action$, state$) { return action$.pipe((0, import_rxjs7.filter)(sendOperation.match), (0, import_rxjs7.filter)(function (action) { return matchOperationRole(import_schema10.OperationTypeCrud.fileUpload, action.payload, state$.value); }), (0, import_rxjs7.mergeMap)(function (action) {
1691
1750
  var _a;
1692
- return (0, import_rxjs6.concat)((0, import_rxjs6.of)(bcChangeCursors({ cursorsMap: (_a = {}, _a[action.payload.bcName] = null, _a) })), (0, import_rxjs6.of)(showFileUploadPopup({ widgetName: action.payload.widgetName })));
1751
+ return (0, import_rxjs7.concat)((0, import_rxjs7.of)(bcChangeCursors({ cursorsMap: (_a = {}, _a[action.payload.bcName] = null, _a) })), (0, import_rxjs7.of)(showFileUploadPopup({ widgetName: action.payload.widgetName })));
1693
1752
  })); };
1694
1753
  // src/epics/view/sendOperationAssociateEpic.ts
1695
- var import_rxjs7 = require("rxjs");
1696
- var import_schema10 = require("@cxbox-ui/schema");
1697
- var sendOperationAssociateEpic = function (action$, state$) { return action$.pipe((0, import_rxjs7.filter)(sendOperation.match), (0, import_rxjs7.filter)(function (action) { return matchOperationRole(import_schema10.OperationTypeCrud.associate, action.payload, state$.value); }), (0, import_rxjs7.map)(function (action) {
1754
+ var import_rxjs8 = require("rxjs");
1755
+ var import_schema11 = require("@cxbox-ui/schema");
1756
+ var sendOperationAssociateEpic = function (action$, state$) { return action$.pipe((0, import_rxjs8.filter)(sendOperation.match), (0, import_rxjs8.filter)(function (action) { return matchOperationRole(import_schema11.OperationTypeCrud.associate, action.payload, state$.value); }), (0, import_rxjs8.map)(function (action) {
1698
1757
  return showViewPopup({
1699
1758
  // TODO: 2.0.0 bcKey and bcName will be removed in favor `widgetName`
1700
1759
  bcName: action.payload.bcKey ? "".concat(action.payload.bcKey) : "".concat(action.payload.bcName, "Assoc"),
@@ -1704,31 +1763,31 @@ var sendOperationAssociateEpic = function (action$, state$) { return action$.pip
1704
1763
  });
1705
1764
  })); };
1706
1765
  // src/epics/view/getRowMetaByForceActiveEpic.ts
1707
- var import_rxjs8 = require("rxjs");
1708
- var import_schema11 = require("@cxbox-ui/schema");
1766
+ var import_rxjs9 = require("rxjs");
1767
+ var import_schema12 = require("@cxbox-ui/schema");
1709
1768
  var import_toolkit2 = require("@reduxjs/toolkit");
1710
1769
  var getRowMetaByForceActiveEpic = function (action$, state$, _a) {
1711
1770
  var api = _a.api;
1712
- return action$.pipe((0, import_rxjs8.filter)(changeDataItem.match), (0, import_rxjs8.mergeMap)(function (action) {
1713
- var _a, _b, _c, _d;
1771
+ return action$.pipe((0, import_rxjs9.filter)(changeDataItem.match), (0, import_rxjs9.mergeMap)(function (action) {
1772
+ var _a, _b, _c, _d, _e;
1714
1773
  var state = state$.value;
1715
1774
  var initUrl = state.view.url;
1716
- var _e = action.payload, bcName = _e.bcName, cursor = _e.cursor, disableRetry = _e.disableRetry;
1775
+ var _f = action.payload, bcName = _f.bcName, cursor = _f.cursor, disableRetry = _f.disableRetry;
1717
1776
  var isBcHierarchy = state.view.widgets.some(function (widget) {
1718
1777
  var _a, _b;
1719
- return widget.bcName === bcName && widget.type === import_schema11.WidgetTypes.AssocListPopup && (((_a = widget.options) === null || _a === void 0 ? void 0 : _a.hierarchySameBc) || ((_b = widget.options) === null || _b === void 0 ? void 0 : _b.hierarchyFull));
1778
+ return widget.bcName === bcName && widget.type === import_schema12.WidgetTypes.AssocListPopup && (((_a = widget.options) === null || _a === void 0 ? void 0 : _a.hierarchySameBc) || ((_b = widget.options) === null || _b === void 0 ? void 0 : _b.hierarchyFull));
1720
1779
  });
1721
1780
  if (isBcHierarchy) {
1722
- return import_rxjs8.EMPTY;
1723
- }
1724
- var isPickListPopup = state.view.widgets.find(function (item) { var _a; return item.name === ((_a = state.view.popupData) === null || _a === void 0 ? void 0 : _a.widgetName) && [import_schema11.WidgetTypes.PickListPopup, import_schema11.WidgetTypes.FlatTreePopup].includes(item.type); });
1725
- var bcUrl = buildBcUrl(bcName, true);
1726
- var pendingChanges = state.view.pendingDataChanges[bcName][cursor];
1727
- var handledForceActive = ((_a = state.view.handledForceActive[bcName]) === null || _a === void 0 ? void 0 : _a[cursor]) || {};
1728
- var currentRecordData = (_b = state.data[bcName]) === null || _b === void 0 ? void 0 : _b.find(function (record) { return record.id === cursor; });
1729
- var fieldsRowMeta = (_d = (_c = state.view.rowMeta[bcName]) === null || _c === void 0 ? void 0 : _c[bcUrl]) === null || _d === void 0 ? void 0 : _d.fields;
1781
+ return import_rxjs9.EMPTY;
1782
+ }
1783
+ var isPickListPopup = state.view.widgets.find(function (item) { var _a; return item.name === ((_a = state.view.popupData) === null || _a === void 0 ? void 0 : _a.widgetName) && [import_schema12.WidgetTypes.PickListPopup, import_schema12.WidgetTypes.FlatTreePopup].includes(item.type); });
1784
+ var bcUrl = buildBcUrl(bcName, true, state);
1785
+ var pendingChanges = (_a = state.view.pendingDataChanges[bcName]) === null || _a === void 0 ? void 0 : _a[cursor];
1786
+ var handledForceActive = ((_b = state.view.handledForceActive[bcName]) === null || _b === void 0 ? void 0 : _b[cursor]) || {};
1787
+ var currentRecordData = (_c = state.data[bcName]) === null || _c === void 0 ? void 0 : _c.find(function (record) { return record.id === cursor; });
1788
+ var fieldsRowMeta = (_e = (_d = state.view.rowMeta[bcName]) === null || _d === void 0 ? void 0 : _d[bcUrl]) === null || _e === void 0 ? void 0 : _e.fields;
1730
1789
  var changedFiledKey = null;
1731
- var closePopup = (0, import_rxjs8.concat)((0, import_rxjs8.of)(viewClearPickMap(null)), (0, import_rxjs8.of)(closeViewPopup(null)), (0, import_rxjs8.of)(bcRemoveAllFilters({ bcName: bcName })));
1790
+ var closePopup = (0, import_rxjs9.concat)((0, import_rxjs9.of)(closeViewPopup(null)), (0, import_rxjs9.of)(viewClearPickMap(null)), (0, import_rxjs9.of)(bcRemoveAllFilters({ bcName: bcName })));
1732
1791
  var someForceActiveChanged = fieldsRowMeta === null || fieldsRowMeta === void 0 ? void 0 : fieldsRowMeta.filter(function (field) { return field.forceActive && pendingChanges[field.key] !== void 0; }).some(function (field) {
1733
1792
  var result = pendingChanges[field.key] !== handledForceActive[field.key];
1734
1793
  if (result) {
@@ -1738,10 +1797,10 @@ var getRowMetaByForceActiveEpic = function (action$, state$, _a) {
1738
1797
  });
1739
1798
  var requestId = (0, import_toolkit2.nanoid)();
1740
1799
  if (someForceActiveChanged && !disableRetry) {
1741
- return (0, import_rxjs8.concat)((0, import_rxjs8.of)(addPendingRequest({ request: { requestId: requestId, type: "force-active" } })), api.getRmByForceActive(state.screen.screenName, bcUrl, __assign(__assign({}, pendingChanges), { vstamp: currentRecordData.vstamp })).pipe((0, import_rxjs8.mergeMap)(function (data) {
1742
- var result = [(0, import_rxjs8.of)(removePendingRequest({ requestId: requestId }))];
1800
+ return (0, import_rxjs9.concat)((0, import_rxjs9.of)(addPendingRequest({ request: { requestId: requestId, type: "force-active" } })), api.getRmByForceActive(state.screen.screenName, bcUrl, __assign(__assign({}, pendingChanges), { vstamp: currentRecordData === null || currentRecordData === void 0 ? void 0 : currentRecordData.vstamp })).pipe((0, import_rxjs9.mergeMap)(function (data) {
1801
+ var result = [(0, import_rxjs9.of)(removePendingRequest({ requestId: requestId }))];
1743
1802
  if (state.view.url === initUrl) {
1744
- result.push((0, import_rxjs8.of)(forceActiveRmUpdate({
1803
+ result.push((0, import_rxjs9.of)(forceActiveRmUpdate({
1745
1804
  rowMeta: data,
1746
1805
  currentRecordData: currentRecordData,
1747
1806
  bcName: bcName,
@@ -1752,8 +1811,8 @@ var getRowMetaByForceActiveEpic = function (action$, state$, _a) {
1752
1811
  if (isPickListPopup) {
1753
1812
  result.push(closePopup);
1754
1813
  }
1755
- return (0, import_rxjs8.concat).apply(void 0, result);
1756
- }), (0, import_rxjs8.catchError)(function (e) {
1814
+ return (0, import_rxjs9.concat).apply(void 0, result);
1815
+ }), (0, import_rxjs9.catchError)(function (e) {
1757
1816
  var _a;
1758
1817
  var _b, _c, _d, _e, _f, _g;
1759
1818
  console.error(e);
@@ -1764,30 +1823,36 @@ var getRowMetaByForceActiveEpic = function (action$, state$, _a) {
1764
1823
  entityError = (_e = operationError === null || operationError === void 0 ? void 0 : operationError.error) === null || _e === void 0 ? void 0 : _e.entity;
1765
1824
  viewError = (_g = (_f = operationError === null || operationError === void 0 ? void 0 : operationError.error) === null || _f === void 0 ? void 0 : _f.popup) === null || _g === void 0 ? void 0 : _g[0];
1766
1825
  }
1767
- return (0, import_rxjs8.concat)((0, import_rxjs8.of)(removePendingRequest({ requestId: requestId })), state.view.url === initUrl ? (0, import_rxjs8.concat)((0, import_rxjs8.of)(changeDataItem({
1826
+ return (0, import_rxjs9.concat)((0, import_rxjs9.of)(removePendingRequest({ requestId: requestId })), state.view.url === initUrl ? (0, import_rxjs9.concat)((0, import_rxjs9.of)(changeDataItem({
1768
1827
  bcName: bcName,
1828
+ bcUrl: buildBcUrl(bcName, true, state),
1769
1829
  cursor: cursor,
1770
- dataItem: (_a = {}, _a[changedFiledKey] = currentRecordData[changedFiledKey], _a),
1830
+ dataItem: (_a = {}, _a[changedFiledKey] = currentRecordData === null || currentRecordData === void 0 ? void 0 : currentRecordData[changedFiledKey], _a),
1771
1831
  disableRetry: true
1772
- })), (0, import_rxjs8.of)(forceActiveChangeFail({ bcName: bcName, bcUrl: bcUrl, viewError: viewError, entityError: entityError }))) : import_rxjs8.EMPTY);
1832
+ })), (0, import_rxjs9.of)(forceActiveChangeFail({ bcName: bcName, bcUrl: bcUrl, viewError: viewError, entityError: entityError }))) : import_rxjs9.EMPTY, createApiErrorObservable(e));
1773
1833
  })));
1774
1834
  }
1775
- return isPickListPopup ? closePopup : import_rxjs8.EMPTY;
1835
+ return isPickListPopup ? closePopup : import_rxjs9.EMPTY;
1776
1836
  }));
1777
1837
  };
1778
1838
  // src/epics/view/showAllTableRecordsInitEpic.ts
1779
- var import_rxjs9 = require("rxjs");
1780
- var showAllTableRecordsInitEpic = function (action$, state$) { return action$.pipe((0, import_rxjs9.filter)(showAllTableRecordsInit.match), (0, import_rxjs9.mergeMap)(function (action) {
1839
+ var import_rxjs10 = require("rxjs");
1840
+ var showAllTableRecordsInitEpic = function (action$, state$) { return action$.pipe((0, import_rxjs10.filter)(showAllTableRecordsInit.match), (0, import_rxjs10.mergeMap)(function (action) {
1781
1841
  var _a;
1782
1842
  var resultObservables = [];
1783
- var bcName = action.payload.bcName;
1784
- resultObservables.push((0, import_rxjs9.of)(bcChangeCursors({ cursorsMap: (_a = {}, _a[bcName] = null, _a) })));
1785
- resultObservables.push((0, import_rxjs9.of)(bcForceUpdate({ bcName: bcName })));
1786
- return (0, import_rxjs9.concat).apply(void 0, resultObservables);
1843
+ var _b = action.payload, bcName = _b.bcName, cursor = _b.cursor;
1844
+ var state = state$.value;
1845
+ var route = state.router;
1846
+ resultObservables.push((0, import_rxjs10.of)(bcChangeCursors({ cursorsMap: (_a = {}, _a[bcName] = null, _a) })));
1847
+ var bcPath = route.bcPath.slice(0, route.bcPath.indexOf("".concat(bcName, "/").concat(cursor)));
1848
+ var url = defaultBuildURL(__assign(__assign({}, route), { bcPath: bcPath }));
1849
+ resultObservables.push((0, import_rxjs10.of)(bcForceUpdate({ bcName: bcName })));
1850
+ resultObservables.push((0, import_rxjs10.of)(changeLocation({ location: defaultParseURL(new URL(url, window.location.origin)) })));
1851
+ return (0, import_rxjs10.concat).apply(void 0, resultObservables);
1787
1852
  })); };
1788
1853
  // src/epics/view/clearPendingDataChangesAfterCursorChangeEpic.ts
1789
- var import_rxjs10 = require("rxjs");
1790
- var clearPendingDataChangesAfterCursorChangeEpic = function (action$, state$) { return action$.pipe((0, import_rxjs10.filter)(bcChangeCursors.match), (0, import_rxjs10.mergeMap)(function (action) {
1854
+ var import_rxjs11 = require("rxjs");
1855
+ var clearPendingDataChangesAfterCursorChangeEpic = function (action$, state$) { return action$.pipe((0, import_rxjs11.filter)(bcChangeCursors.match), (0, import_rxjs11.mergeMap)(function (action) {
1791
1856
  var state = state$.value;
1792
1857
  var nextCursors = parseBcCursors(state.router.bcPath) || {};
1793
1858
  var cursorsDiffMap = {};
@@ -1799,29 +1864,129 @@ var clearPendingDataChangesAfterCursorChangeEpic = function (action$, state$) {
1799
1864
  }
1800
1865
  });
1801
1866
  if (Object.keys(cursorsDiffMap).length) {
1802
- return (0, import_rxjs10.of)(bcChangeCursors({ cursorsMap: cursorsDiffMap }));
1867
+ return (0, import_rxjs11.of)(bcChangeCursors({ cursorsMap: cursorsDiffMap }));
1803
1868
  }
1804
- return import_rxjs10.EMPTY;
1869
+ return import_rxjs11.EMPTY;
1805
1870
  })); };
1806
1871
  // src/epics/router/drilldownEpic.ts
1807
- var import_rxjs11 = require("rxjs");
1808
- var drillDownEpic = function (action$, state$) { return action$.pipe((0, import_rxjs11.filter)(drillDown.match), (0, import_rxjs11.switchMap)(function (action) {
1809
- return import_rxjs11.EMPTY;
1872
+ var import_rxjs12 = require("rxjs");
1873
+ var drillDownEpic = function (action$, state$) { return action$.pipe((0, import_rxjs12.filter)(drillDown.match), (0, import_rxjs12.switchMap)(function (action) {
1874
+ var _a, _b;
1875
+ var state = state$.value;
1876
+ var url = action.payload.url;
1877
+ var result = [];
1878
+ switch (action.payload.drillDownType) {
1879
+ case import_schema.DrillDownType.external:
1880
+ window.location.href = url;
1881
+ break;
1882
+ case import_schema.DrillDownType.externalNew:
1883
+ if (/^[a-z0-9]+:\/\//i.test(url)) {
1884
+ window.open(url);
1885
+ }
1886
+ break;
1887
+ case import_schema.DrillDownType.relative:
1888
+ window.location.href = "".concat(window.location.origin, "/").concat(url);
1889
+ break;
1890
+ case import_schema.DrillDownType.relativeNew:
1891
+ window.open("".concat(window.location.origin, "/").concat(url), "_blank");
1892
+ break;
1893
+ case import_schema.DrillDownType.inner:
1894
+ default:
1895
+ var urlBase = url.split("?")[0];
1896
+ var urlObject = new URL(url, window.location.origin);
1897
+ var urlFilters = urlObject.searchParams.get("filters");
1898
+ var urlSorters = urlObject.searchParams.get("sorters");
1899
+ var newFilters_1 = {};
1900
+ var newSorters = {};
1901
+ try {
1902
+ newFilters_1 = (_a = JSON.parse(urlFilters)) !== null && _a !== void 0 ? _a : newFilters_1;
1903
+ }
1904
+ catch (_c) {
1905
+ urlFilters && console.warn("Failed to parse filters on drilldown");
1906
+ newFilters_1 = {};
1907
+ }
1908
+ try {
1909
+ newSorters = (_b = JSON.parse(urlSorters)) !== null && _b !== void 0 ? _b : newSorters;
1910
+ }
1911
+ catch (_d) {
1912
+ urlSorters && console.warn("Failed to parse sorters on drilldown");
1913
+ newSorters = {};
1914
+ }
1915
+ var bcToUpdate_1 = {};
1916
+ Object.keys(state.screen.filters).forEach(function (bcName) {
1917
+ if (newFilters_1[bcName] === "" || newFilters_1[bcName]) {
1918
+ bcToUpdate_1[bcName] = true;
1919
+ result.push(bcRemoveAllFilters({ bcName: bcName }));
1920
+ }
1921
+ });
1922
+ var nextState = defaultParseURL(urlObject);
1923
+ var viewName_1 = nextState.viewName;
1924
+ Object.entries(newFilters_1).forEach(function (_a) {
1925
+ var _b;
1926
+ var bcName = _a[0], filterExpression = _a[1];
1927
+ var parsedFilters = (_b = parseFilters(filterExpression)) === null || _b === void 0 ? void 0 : _b.map(function (item) { return (__assign(__assign({}, item), { viewName: viewName_1 })); });
1928
+ parsedFilters === null || parsedFilters === void 0 ? void 0 : parsedFilters.forEach(function (parsedFilter) {
1929
+ bcToUpdate_1[bcName] = true;
1930
+ result.push(bcAddFilter({ bcName: bcName, filter: parsedFilter }));
1931
+ });
1932
+ });
1933
+ Object.entries(newSorters).forEach(function (_a) {
1934
+ var bcName = _a[0], sortExpression = _a[1];
1935
+ var sorter = parseSorters(sortExpression);
1936
+ result.push(bcAddSorter({ bcName: bcName, sorter: sorter }));
1937
+ bcToUpdate_1[bcName] = true;
1938
+ });
1939
+ var prevState = state.router;
1940
+ var willUpdateAnyway = shallowCompare(prevState, nextState, ["params"]).length > 0;
1941
+ if (!willUpdateAnyway) {
1942
+ Object.keys(bcToUpdate_1).forEach(function (bcName) {
1943
+ result.push(bcForceUpdate({ bcName: bcName }));
1944
+ });
1945
+ }
1946
+ result.push(changeLocation({ location: defaultParseURL(new URL(makeRelativeUrl(urlBase), window.location.origin)) }));
1947
+ break;
1948
+ }
1949
+ return result.length ? (0, import_rxjs12.concat)(result) : import_rxjs12.EMPTY;
1810
1950
  })); };
1951
+ function shallowCompare(prevProps, nextProps, ignore) {
1952
+ if (ignore === void 0) { ignore = []; }
1953
+ var diffProps = [];
1954
+ if (!prevProps && !nextProps) {
1955
+ return null;
1956
+ }
1957
+ if (!prevProps) {
1958
+ return Object.keys(nextProps);
1959
+ }
1960
+ if (!nextProps) {
1961
+ return Object.keys(prevProps);
1962
+ }
1963
+ var newKeys = Object.keys(nextProps);
1964
+ newKeys.forEach(function (key) {
1965
+ if (prevProps[key] !== nextProps[key] && !ignore.includes(key)) {
1966
+ diffProps.push(key);
1967
+ }
1968
+ });
1969
+ Object.keys(prevProps).forEach(function (key) {
1970
+ if (!newKeys.includes(key)) {
1971
+ diffProps.push(key);
1972
+ }
1973
+ });
1974
+ return diffProps;
1975
+ }
1811
1976
  // src/epics/router/loginDoneEpic.ts
1812
- var import_rxjs12 = require("rxjs");
1813
- var loginDoneEpic = function (action$, state$) { return action$.pipe((0, import_rxjs12.filter)(loginDone.match), (0, import_rxjs12.switchMap)(function (action) {
1977
+ var import_rxjs13 = require("rxjs");
1978
+ var loginDoneEpic = function (action$, state$) { return action$.pipe((0, import_rxjs13.filter)(loginDone.match), (0, import_rxjs13.switchMap)(function (action) {
1814
1979
  var state = state$.value;
1815
1980
  if (state.router.type === "router" /* router */) {
1816
- return (0, import_rxjs12.of)(handleRouter(state.router));
1981
+ return (0, import_rxjs13.of)(handleRouter(state.router));
1817
1982
  }
1818
1983
  var nextScreenName = state.router.screenName;
1819
1984
  var nextScreen = state.session.screens.find(function (item) { return nextScreenName ? item.name === nextScreenName : item.defaultScreen; }) || state.session.screens[0];
1820
- return nextScreen ? (0, import_rxjs12.of)(selectScreen({ screen: nextScreen })) : (0, import_rxjs12.of)(selectScreenFail({ screenName: nextScreenName }));
1985
+ return nextScreen ? (0, import_rxjs13.of)(selectScreen({ screen: nextScreen })) : (0, import_rxjs13.of)(selectScreenFail({ screenName: nextScreenName }));
1821
1986
  })); };
1822
1987
  // src/epics/router/selectViewEpic.ts
1823
- var import_rxjs13 = require("rxjs");
1824
- var changeViewEpic = function (action$, state$) { return action$.pipe((0, import_rxjs13.filter)(selectView.match), (0, import_rxjs13.switchMap)(function (action) {
1988
+ var import_rxjs14 = require("rxjs");
1989
+ var changeViewEpic = function (action$, state$) { return action$.pipe((0, import_rxjs14.filter)(selectView.match), (0, import_rxjs14.switchMap)(function (action) {
1825
1990
  var state = state$.value;
1826
1991
  var nextCursors = parseBcCursors(state.router.bcPath) || {};
1827
1992
  var cursorsDiffMap = {};
@@ -1833,77 +1998,77 @@ var changeViewEpic = function (action$, state$) { return action$.pipe((0, import
1833
1998
  }
1834
1999
  });
1835
2000
  if (Object.keys(cursorsDiffMap).length) {
1836
- return (0, import_rxjs13.of)(bcChangeCursors({ cursorsMap: cursorsDiffMap }));
2001
+ return (0, import_rxjs14.of)(bcChangeCursors({ cursorsMap: cursorsDiffMap }));
1837
2002
  }
1838
- return import_rxjs13.EMPTY;
2003
+ return import_rxjs14.EMPTY;
1839
2004
  })); };
1840
2005
  // src/epics/router/handleRouterEpic.ts
1841
- var import_rxjs14 = require("rxjs");
2006
+ var import_rxjs15 = require("rxjs");
1842
2007
  var handleRouterEpic = function (action$, state$, _a) {
1843
2008
  var api = _a.api;
1844
- return action$.pipe((0, import_rxjs14.filter)(handleRouter.match), (0, import_rxjs14.switchMap)(function (action) {
2009
+ return action$.pipe((0, import_rxjs15.filter)(handleRouter.match), (0, import_rxjs15.switchMap)(function (action) {
1845
2010
  var path = action.payload.path;
1846
2011
  var params = action.payload.params;
1847
- return api.routerRequest(path, params).pipe((0, import_rxjs14.mergeMap)(function () {
1848
- return import_rxjs14.EMPTY;
1849
- }), (0, import_rxjs14.catchError)(function (error) {
2012
+ return api.routerRequest(path, params).pipe((0, import_rxjs15.mergeMap)(function () {
2013
+ return import_rxjs15.EMPTY;
2014
+ }), (0, import_rxjs15.catchError)(function (error) {
1850
2015
  console.error(error);
1851
- return import_rxjs14.EMPTY;
2016
+ return createApiErrorObservable(error);
1852
2017
  }));
1853
2018
  }));
1854
2019
  };
1855
2020
  // src/epics/router/selectScreenEpic.ts
1856
- var import_rxjs15 = require("rxjs");
1857
- var changeScreen = function (action$, state$) { return action$.pipe((0, import_rxjs15.filter)(selectScreen.match), (0, import_rxjs15.switchMap)(function (action) {
2021
+ var import_rxjs16 = require("rxjs");
2022
+ var changeScreen = function (action$, state$) { return action$.pipe((0, import_rxjs16.filter)(selectScreen.match), (0, import_rxjs16.switchMap)(function (action) {
1858
2023
  var state = state$.value;
1859
2024
  var nextViewName = state.router.viewName;
1860
2025
  var requestedView = state.screen.views.find(function (item) { return item.name === nextViewName; });
1861
2026
  var defaultView = !nextViewName && state.screen.primaryView && state.screen.views.find(function (item) { return item.name === state.screen.primaryView; });
1862
2027
  var nextView = requestedView || defaultView || state.screen.views[0];
1863
- return nextView ? (0, import_rxjs15.of)(selectView(nextView)) : (0, import_rxjs15.of)(selectViewFail({ viewName: nextViewName }));
2028
+ return nextView ? (0, import_rxjs16.of)(selectView(nextView)) : (0, import_rxjs16.of)(selectViewFail({ viewName: nextViewName }));
1864
2029
  })); };
1865
2030
  // src/epics/router/userDrillDownEpic.ts
1866
- var import_rxjs16 = require("rxjs");
2031
+ var import_rxjs17 = require("rxjs");
1867
2032
  var userDrillDownEpic = function (action$, state$, _a) {
1868
2033
  var api = _a.api;
1869
- return action$.pipe((0, import_rxjs16.filter)(userDrillDown.match), (0, import_rxjs16.switchMap)(function (action) {
2034
+ return action$.pipe((0, import_rxjs17.filter)(userDrillDown.match), (0, import_rxjs17.switchMap)(function (action) {
1870
2035
  var state = state$.value;
1871
2036
  var _a = action.payload, bcName = _a.bcName, fieldKey = _a.fieldKey, cursor = _a.cursor;
1872
- var bcUrl = buildBcUrl(bcName, true);
1873
- return api.fetchRowMeta(state.screen.screenName, bcUrl).pipe((0, import_rxjs16.mergeMap)(function (rowMeta) {
2037
+ var bcUrl = buildBcUrl(bcName, true, state);
2038
+ return api.fetchRowMeta(state.screen.screenName, bcUrl).pipe((0, import_rxjs17.mergeMap)(function (rowMeta) {
1874
2039
  var _a, _b, _c, _d;
1875
2040
  var drillDownField = rowMeta.fields.find(function (field) { return field.key === fieldKey; });
1876
2041
  var route = state.router;
1877
2042
  var drillDownKey = (_b = (_a = state.view.widgets.find(function (widget) { return widget.bcName === bcName; })) === null || _a === void 0 ? void 0 : _a.fields.find(function (field) { return field.key === fieldKey; })) === null || _b === void 0 ? void 0 : _b.drillDownKey;
1878
2043
  var customDrillDownUrl = (_d = (_c = state.data[bcName]) === null || _c === void 0 ? void 0 : _c.find(function (record) { return record.id === cursor; })) === null || _d === void 0 ? void 0 : _d[drillDownKey];
1879
- return customDrillDownUrl || (drillDownField === null || drillDownField === void 0 ? void 0 : drillDownField.drillDown) || (drillDownField === null || drillDownField === void 0 ? void 0 : drillDownField.drillDown) !== route.path ? (0, import_rxjs16.concat)(drillDownField.drillDownType !== import_schema.DrillDownType.inner ? (0, import_rxjs16.of)(bcFetchRowMetaSuccess({ bcName: bcName, rowMeta: rowMeta, bcUrl: bcUrl, cursor: cursor })) : import_rxjs16.EMPTY, (0, import_rxjs16.of)(userDrillDownSuccess({ bcName: bcName, bcUrl: bcUrl, cursor: cursor })), (0, import_rxjs16.of)(drillDown({
2044
+ return customDrillDownUrl || (drillDownField === null || drillDownField === void 0 ? void 0 : drillDownField.drillDown) || (drillDownField === null || drillDownField === void 0 ? void 0 : drillDownField.drillDown) !== route.path ? (0, import_rxjs17.concat)((drillDownField === null || drillDownField === void 0 ? void 0 : drillDownField.drillDownType) !== import_schema.DrillDownType.inner ? (0, import_rxjs17.of)(bcFetchRowMetaSuccess({ bcName: bcName, rowMeta: rowMeta, bcUrl: bcUrl, cursor: cursor })) : import_rxjs17.EMPTY, (0, import_rxjs17.of)(userDrillDownSuccess({ bcName: bcName, bcUrl: bcUrl, cursor: cursor })), (0, import_rxjs17.of)(drillDown({
1880
2045
  url: customDrillDownUrl || drillDownField.drillDown,
1881
2046
  drillDownType: drillDownField.drillDownType,
1882
2047
  route: route
1883
- }))) : import_rxjs16.EMPTY;
1884
- }), (0, import_rxjs16.catchError)(function (error) {
2048
+ }))) : import_rxjs17.EMPTY;
2049
+ }), (0, import_rxjs17.catchError)(function (error) {
1885
2050
  console.error(error);
1886
- return import_rxjs16.EMPTY;
2051
+ return createApiErrorObservable(error);
1887
2052
  }));
1888
2053
  }));
1889
2054
  };
1890
2055
  // src/epics/router/changeLocationEpic.ts
1891
- var import_rxjs17 = require("rxjs");
1892
- var changeLocationEpic = function (action$, state$) { return action$.pipe((0, import_rxjs17.filter)(changeLocation.match), (0, import_rxjs17.mergeMap)(function (action) {
2056
+ var import_rxjs18 = require("rxjs");
2057
+ var changeLocationEpic = function (action$, state$) { return action$.pipe((0, import_rxjs18.filter)(changeLocation.match), (0, import_rxjs18.mergeMap)(function (action) {
1893
2058
  var _a, _b;
1894
2059
  var state = state$.value;
1895
2060
  if (!state.session.active) {
1896
- return import_rxjs17.EMPTY;
2061
+ return import_rxjs18.EMPTY;
1897
2062
  }
1898
2063
  if (state.router.type === "router" /* router */) {
1899
- return (0, import_rxjs17.of)(handleRouter(state.router));
2064
+ return (0, import_rxjs18.of)(handleRouter(state.router));
1900
2065
  }
1901
2066
  var currentScreenName = state.screen.screenName;
1902
2067
  var defaultScreenName = ((_a = state.session.screens.find(function (screen) { return screen.defaultScreen; })) === null || _a === void 0 ? void 0 : _a.name) || ((_b = state.session.screens[0]) === null || _b === void 0 ? void 0 : _b.name);
1903
2068
  var nextScreenName = state.router.type === "default" /* default */ ? defaultScreenName : state.router.screenName;
1904
2069
  if (nextScreenName !== currentScreenName) {
1905
2070
  var nextScreen = state.session.screens.find(function (item) { return item.name === nextScreenName; });
1906
- return nextScreen ? (0, import_rxjs17.of)(selectScreen({ screen: nextScreen })) : (0, import_rxjs17.of)(selectScreenFail({ screenName: nextScreenName }));
2071
+ return nextScreen ? (0, import_rxjs18.of)(selectScreen({ screen: nextScreen })) : (0, import_rxjs18.of)(selectScreenFail({ screenName: nextScreenName }));
1907
2072
  }
1908
2073
  var currentViewName = state.view.name;
1909
2074
  var nextViewName = state.router.viewName;
@@ -1920,25 +2085,25 @@ var changeLocationEpic = function (action$, state$) { return action$.pipe((0, im
1920
2085
  var needUpdateViews = nextViewName !== currentViewName;
1921
2086
  var resultObservables = [];
1922
2087
  if (needUpdateCursors) {
1923
- resultObservables.push((0, import_rxjs17.of)(bcChangeCursors({ cursorsMap: cursorsDiffMap })));
2088
+ resultObservables.push((0, import_rxjs18.of)(bcChangeCursors({ cursorsMap: cursorsDiffMap })));
1924
2089
  }
1925
2090
  if (needUpdateViews) {
1926
2091
  var nextView = nextViewName ? state.screen.views.find(function (item) { return item.name === nextViewName; }) : state.screen.primaryView ? state.screen.views.find(function (item) { return item.name === state.screen.primaryView; }) : state.screen.views[0];
1927
- resultObservables.push(nextView ? (0, import_rxjs17.of)(selectView(nextView)) : (0, import_rxjs17.of)(selectViewFail({ viewName: nextViewName })));
2092
+ resultObservables.push(nextView ? (0, import_rxjs18.of)(selectView(nextView)) : (0, import_rxjs18.of)(selectViewFail({ viewName: nextViewName })));
1928
2093
  }
1929
2094
  if (needUpdateCursors && !needUpdateViews) {
1930
2095
  Object.entries(nextCursors).forEach(function (entry) {
1931
2096
  var bcName = entry[0], cursor = entry[1];
1932
2097
  if (!state.data[bcName].find(function (item) { return item.id === cursor; })) {
1933
- resultObservables.push((0, import_rxjs17.of)(bcForceUpdate({ bcName: bcName })));
2098
+ resultObservables.push((0, import_rxjs18.of)(bcForceUpdate({ bcName: bcName })));
1934
2099
  }
1935
2100
  });
1936
2101
  }
1937
- return (0, import_rxjs17.concat).apply(void 0, resultObservables);
2102
+ return (0, import_rxjs18.concat).apply(void 0, resultObservables);
1938
2103
  })); };
1939
2104
  // src/epics/router/selectViewFailEpic.ts
1940
- var import_rxjs18 = require("rxjs");
1941
- var selectViewFailEpic = function (action$, state$) { return action$.pipe((0, import_rxjs18.filter)(selectViewFail.match), (0, import_rxjs18.map)(function (action) {
2105
+ var import_rxjs19 = require("rxjs");
2106
+ var selectViewFailEpic = function (action$, state$) { return action$.pipe((0, import_rxjs19.filter)(selectViewFail.match), (0, import_rxjs19.map)(function (action) {
1942
2107
  return addNotification({
1943
2108
  type: "error",
1944
2109
  key: "selectViewFail",
@@ -1947,8 +2112,8 @@ var selectViewFailEpic = function (action$, state$) { return action$.pipe((0, im
1947
2112
  });
1948
2113
  })); };
1949
2114
  // src/epics/router/selectScreenFailEpic.ts
1950
- var import_rxjs19 = require("rxjs");
1951
- var selectScreenFailEpic = function (action$) { return action$.pipe((0, import_rxjs19.filter)(selectScreenFail.match), (0, import_rxjs19.map)(function (action) {
2115
+ var import_rxjs20 = require("rxjs");
2116
+ var selectScreenFailEpic = function (action$) { return action$.pipe((0, import_rxjs20.filter)(selectScreenFail.match), (0, import_rxjs20.map)(function (action) {
1952
2117
  return addNotification({
1953
2118
  type: "error",
1954
2119
  key: "selectScreenFail",
@@ -1957,8 +2122,8 @@ var selectScreenFailEpic = function (action$) { return action$.pipe((0, import_r
1957
2122
  });
1958
2123
  })); };
1959
2124
  // src/epics/router/userDrilldownChangeCursorsEpic.ts
1960
- var import_rxjs20 = require("rxjs");
1961
- var userDrillDownChangeCursorsEpic = function (action$, state$) { return action$.pipe((0, import_rxjs20.filter)(userDrillDown.match), (0, import_rxjs20.map)(function (action) {
2125
+ var import_rxjs21 = require("rxjs");
2126
+ var userDrillDownChangeCursorsEpic = function (action$, state$) { return action$.pipe((0, import_rxjs21.filter)(userDrillDown.match), (0, import_rxjs21.map)(function (action) {
1962
2127
  var _a;
1963
2128
  var _b;
1964
2129
  var state = state$.value;
@@ -1967,54 +2132,55 @@ var userDrillDownChangeCursorsEpic = function (action$, state$) { return action$
1967
2132
  if (cursor !== action.payload.cursor) {
1968
2133
  return bcChangeCursors({ cursorsMap: (_a = {}, _a[action.payload.bcName] = action.payload.cursor, _a) });
1969
2134
  }
1970
- return void 0;
2135
+ return emptyAction;
1971
2136
  })); };
1972
2137
  // src/epics/screen/apiErrorEpic.ts
1973
2138
  var import_axios = __toESM(require("axios"));
1974
- var import_rxjs21 = require("rxjs");
1975
- var knownHttpErrors = [401, 409, 418, 500];
1976
- var apiErrorEpic = function (action$) { return action$.pipe((0, import_rxjs21.filter)(apiError.match), (0, import_rxjs21.mergeMap)(function (action) {
2139
+ var import_rxjs22 = require("rxjs");
2140
+ var apiErrorEpic = function (action$) { return action$.pipe((0, import_rxjs22.filter)(apiError.match), (0, import_rxjs22.mergeMap)(function (action) {
1977
2141
  var _a = action.payload, error = _a.error, callContext = _a.callContext;
1978
2142
  if (error.response) {
1979
- return (0, import_rxjs21.of)(httpError({
2143
+ return (0, import_rxjs22.of)(httpError({
1980
2144
  statusCode: error.response.status,
1981
2145
  error: error,
1982
2146
  callContext: callContext
1983
2147
  }));
1984
2148
  }
1985
2149
  else if (!import_axios.default.isCancel(error)) {
1986
- return (0, import_rxjs21.of)(showViewError({
2150
+ return (0, import_rxjs22.of)(showViewError({
1987
2151
  error: {
1988
2152
  type: 2 /* NetworkError */
1989
2153
  }
1990
2154
  }));
1991
2155
  }
1992
- return import_rxjs21.EMPTY;
2156
+ return import_rxjs22.EMPTY;
1993
2157
  })); };
1994
2158
  // src/epics/screen/downloadFileEpic.ts
1995
- var import_rxjs22 = require("rxjs");
2159
+ var import_rxjs23 = require("rxjs");
1996
2160
  var downloadFileEpic = function (action$, state$, _a) {
1997
2161
  var api = _a.api;
1998
- return action$.pipe((0, import_rxjs22.filter)(downloadFile.match), (0, import_rxjs22.tap)(function (action) {
2162
+ return action$.pipe((0, import_rxjs23.filter)(downloadFile.match), (0, import_rxjs23.tap)(function (action) {
2163
+ var fileId = action.payload.fileId;
1999
2164
  var anchor = document.createElement("a");
2165
+ anchor.href = "".concat(api.fileUploadEndpoint, "?id=").concat(encodeURIComponent(fileId));
2000
2166
  anchor.style.display = "none";
2001
2167
  document.body.appendChild(anchor);
2002
2168
  setTimeout(function () {
2003
2169
  anchor.click();
2004
2170
  document.body.removeChild(anchor);
2005
2171
  }, 100);
2006
- }), (0, import_rxjs22.mergeMap)(function () { return import_rxjs22.EMPTY; }));
2172
+ }), (0, import_rxjs23.mergeMap)(function () { return import_rxjs23.EMPTY; }));
2007
2173
  };
2008
2174
  // src/epics/screen/httpError401Epic.ts
2009
- var import_rxjs23 = require("rxjs");
2010
- var httpError401Epic = function (action$) { return action$.pipe((0, import_rxjs23.filter)(httpError.match), (0, import_rxjs23.filter)(function (action) { return action.payload.statusCode === 401; }), (0, import_rxjs23.map)(function (action) {
2175
+ var import_rxjs24 = require("rxjs");
2176
+ var httpError401Epic = function (action$) { return action$.pipe((0, import_rxjs24.filter)(httpError.match), (0, import_rxjs24.filter)(function (action) { return action.payload.statusCode === 401; }), (0, import_rxjs24.map)(function (action) {
2011
2177
  return logoutDone(null);
2012
2178
  })); };
2013
2179
  // src/epics/screen/httpError409Epic.ts
2014
- var import_rxjs24 = require("rxjs");
2015
- var httpError409Epic = function (action$, state$) { return action$.pipe((0, import_rxjs24.filter)(httpError.match), (0, import_rxjs24.filter)(function (action) { return action.payload.statusCode === 409; }), (0, import_rxjs24.map)(function (action) {
2016
- var _a, _b;
2017
- var notificationMessage = ((_b = (_a = action.payload.error.response.data.error) === null || _a === void 0 ? void 0 : _a.popup) === null || _b === void 0 ? void 0 : _b[0]) || "";
2180
+ var import_rxjs25 = require("rxjs");
2181
+ var httpError409Epic = function (action$, state$) { return action$.pipe((0, import_rxjs25.filter)(httpError.match), (0, import_rxjs25.filter)(function (action) { return action.payload.statusCode === 409; }), (0, import_rxjs25.map)(function (action) {
2182
+ var _a, _b, _c;
2183
+ var notificationMessage = ((_c = (_b = ((_a = action.payload.error.response) === null || _a === void 0 ? void 0 : _a.data).error) === null || _b === void 0 ? void 0 : _b.popup) === null || _c === void 0 ? void 0 : _c[0]) || "";
2018
2184
  return addNotification({
2019
2185
  key: "action_edit_error",
2020
2186
  message: notificationMessage,
@@ -2028,34 +2194,34 @@ var httpError409Epic = function (action$, state$) { return action$.pipe((0, impo
2028
2194
  });
2029
2195
  })); };
2030
2196
  // src/epics/screen/httpError418Epic.ts
2031
- var import_rxjs25 = require("rxjs");
2032
- var httpError418Epic = function (action$, state$) { return action$.pipe((0, import_rxjs25.filter)(httpError.match), (0, import_rxjs25.filter)(function (action) { return action.payload.statusCode === 418; }), (0, import_rxjs25.mergeMap)(function (action) {
2033
- var _a;
2034
- var _b = action.payload, error = _b.error, callContext = _b.callContext;
2197
+ var import_rxjs26 = require("rxjs");
2198
+ var httpError418Epic = function (action$, state$) { return action$.pipe((0, import_rxjs26.filter)(httpError.match), (0, import_rxjs26.filter)(function (action) { return action.payload.statusCode === 418; }), (0, import_rxjs26.mergeMap)(function (action) {
2199
+ var _a, _b;
2200
+ var _c = action.payload, error = _c.error, callContext = _c.callContext;
2035
2201
  var result = [];
2036
- var typedError = error.response.data;
2202
+ var typedError = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data;
2037
2203
  if (!typedError.error.popup) {
2038
- return import_rxjs25.EMPTY;
2204
+ return import_rxjs26.EMPTY;
2039
2205
  }
2040
2206
  var businessError = {
2041
2207
  type: 0 /* BusinessError */,
2042
2208
  message: typedError.error.popup[0]
2043
2209
  };
2044
- result.push((0, import_rxjs25.of)(showViewError({ error: businessError })));
2045
- if ((_a = typedError.error.postActions) === null || _a === void 0 ? void 0 : _a[0]) {
2210
+ result.push((0, import_rxjs26.of)(showViewError({ error: businessError })));
2211
+ if ((_b = typedError.error.postActions) === null || _b === void 0 ? void 0 : _b[0]) {
2046
2212
  var widget = state$.value.view.widgets.find(function (item) { return item.name === callContext.widgetName; });
2047
- var bcName = widget.bcName;
2048
- result.push((0, import_rxjs25.of)(processPostInvoke({
2213
+ var bcName = widget === null || widget === void 0 ? void 0 : widget.bcName;
2214
+ result.push((0, import_rxjs26.of)(processPostInvoke({
2049
2215
  bcName: bcName,
2050
2216
  postInvoke: typedError.error.postActions[0],
2051
- widgetName: widget.name
2217
+ widgetName: widget === null || widget === void 0 ? void 0 : widget.name
2052
2218
  })));
2053
2219
  }
2054
- return (0, import_rxjs25.concat).apply(void 0, result);
2220
+ return (0, import_rxjs26.concat).apply(void 0, result);
2055
2221
  })); };
2056
2222
  // src/epics/screen/httpError500Epic.ts
2057
- var import_rxjs26 = require("rxjs");
2058
- var httpError500Epic = function (action$, state$) { return action$.pipe((0, import_rxjs26.filter)(httpError.match), (0, import_rxjs26.filter)(function (action) { return action.payload.statusCode === 500; }), (0, import_rxjs26.map)(function (action) {
2223
+ var import_rxjs27 = require("rxjs");
2224
+ var httpError500Epic = function (action$, state$) { return action$.pipe((0, import_rxjs27.filter)(httpError.match), (0, import_rxjs27.filter)(function (action) { return action.payload.statusCode === 500; }), (0, import_rxjs27.map)(function (action) {
2059
2225
  var _a;
2060
2226
  var systemError = {
2061
2227
  type: 1 /* SystemError */,
@@ -2065,18 +2231,20 @@ var httpError500Epic = function (action$, state$) { return action$.pipe((0, impo
2065
2231
  return showViewError({ error: systemError });
2066
2232
  })); };
2067
2233
  // src/epics/screen/httpErrorDefaultEpic.ts
2068
- var import_rxjs27 = require("rxjs");
2069
- var httpErrorDefaultEpic = function (action$, store) { return action$.pipe((0, import_rxjs27.filter)(httpError.match), (0, import_rxjs27.filter)(function (action) { return !knownHttpErrors.includes(action.payload.statusCode); }), (0, import_rxjs27.map)(function (action) {
2234
+ var import_rxjs28 = require("rxjs");
2235
+ var knownHttpErrors = [401, 409, 418, 500];
2236
+ var httpErrorDefaultEpic = function (action$, state$) { return action$.pipe((0, import_rxjs28.filter)(httpError.match), (0, import_rxjs28.filter)(function (action) { return !knownHttpErrors.includes(action.payload.statusCode); }), (0, import_rxjs28.map)(function (action) {
2237
+ var _a, _b;
2070
2238
  var businessError = {
2071
2239
  type: 0 /* BusinessError */,
2072
- code: action.payload.error.response.status,
2073
- details: action.payload.error.response.data
2240
+ code: (_a = action.payload.error.response) === null || _a === void 0 ? void 0 : _a.status,
2241
+ details: (_b = action.payload.error.response) === null || _b === void 0 ? void 0 : _b.data
2074
2242
  };
2075
2243
  return showViewError({ error: businessError });
2076
2244
  })); };
2077
2245
  // src/epics/screen/downloadFileByUrlEpic.ts
2078
- var import_rxjs28 = require("rxjs");
2079
- var downloadFileByUrlEpic = function (action$, state$) { return action$.pipe((0, import_rxjs28.filter)(downloadFileByUrl.match), (0, import_rxjs28.tap)(function (action) {
2246
+ var import_rxjs29 = require("rxjs");
2247
+ var downloadFileByUrlEpic = function (action$, state$) { return action$.pipe((0, import_rxjs29.filter)(downloadFileByUrl.match), (0, import_rxjs29.tap)(function (action) {
2080
2248
  var url = action.payload.url;
2081
2249
  var anchor = document.createElement("a");
2082
2250
  anchor.href = url;
@@ -2086,19 +2254,23 @@ var downloadFileByUrlEpic = function (action$, state$) { return action$.pipe((0,
2086
2254
  anchor.click();
2087
2255
  document.body.removeChild(anchor);
2088
2256
  }, 100);
2089
- }), (0, import_rxjs28.mergeMap)(function () { return import_rxjs28.EMPTY; })); };
2257
+ }), (0, import_rxjs29.mergeMap)(function () { return import_rxjs29.EMPTY; })); };
2090
2258
  // src/epics/screen/processPostInvokeEpic.ts
2091
- var import_rxjs29 = require("rxjs");
2092
- var processPostInvokeEpic = function (action$, state$) { return action$.pipe((0, import_rxjs29.filter)(processPostInvoke.match), (0, import_rxjs29.mergeMap)(function (action) {
2259
+ var import_rxjs30 = require("rxjs");
2260
+ var processPostInvokeEpic = function (action$, state$) { return action$.pipe((0, import_rxjs30.filter)(processPostInvoke.match), (0, import_rxjs30.mergeMap)(function (action) {
2093
2261
  var _a;
2262
+ var _b;
2094
2263
  var state = state$.value;
2095
2264
  switch (action.payload.postInvoke.type) {
2096
2265
  case "drillDown" /* drillDown */:
2097
- return (0, import_rxjs29.of)(drillDown(__assign(__assign({}, action.payload.postInvoke), { route: state.router, widgetName: action.payload.widgetName })));
2266
+ return (0, import_rxjs30.of)(drillDown(__assign(__assign({}, action.payload.postInvoke), { route: state.router, widgetName: action.payload.widgetName })));
2098
2267
  case "postDelete" /* postDelete */: {
2099
2268
  var cursorsMap = (_a = {}, _a[action.payload.bcName] = null, _a);
2100
2269
  var result = [bcChangeCursors({ cursorsMap: cursorsMap })];
2101
- if (state.router.bcPath.includes("".concat(action.payload.bcName, "/"))) {
2270
+ if ((_b = state.router.bcPath) === null || _b === void 0 ? void 0 : _b.includes("".concat(action.payload.bcName, "/"))) {
2271
+ var newBcUrl = state.router.bcPath.split(action.payload.bcName)[0] || "";
2272
+ var newUrl = "/screen/".concat(state.router.screenName, "/view/").concat(state.router.viewName, "/").concat(newBcUrl);
2273
+ result.push(changeLocation({ location: defaultParseURL(new URL(newUrl, window.location.origin)) }));
2102
2274
  }
2103
2275
  else {
2104
2276
  result.push(bcFetchDataRequest({
@@ -2106,7 +2278,7 @@ var processPostInvokeEpic = function (action$, state$) { return action$.pipe((0,
2106
2278
  widgetName: action.payload.widgetName
2107
2279
  }));
2108
2280
  }
2109
- return (0, import_rxjs29.of).apply(void 0, result);
2281
+ return (0, import_rxjs30.of).apply(void 0, result);
2110
2282
  }
2111
2283
  case "refreshBC" /* refreshBC */: {
2112
2284
  var bo = state.screen.bo;
@@ -2116,36 +2288,36 @@ var processPostInvokeEpic = function (action$, state$) { return action$.pipe((0,
2116
2288
  var widgetName = action.payload.widgetName || "";
2117
2289
  var infiniteWidgets_1 = state.view.infiniteWidgets || [];
2118
2290
  var infinitePagination = state.view.widgets.some(function (item) { return item.bcName === postInvokeBC_1 && infiniteWidgets_1.includes(item.name); });
2119
- return infinitePagination ? (0, import_rxjs29.of)(bcFetchDataPages({
2291
+ return infinitePagination ? (0, import_rxjs30.of)(bcFetchDataPages({
2120
2292
  bcName: postInvokeBCItem.name,
2121
2293
  widgetName: widgetName,
2122
2294
  from: 1,
2123
2295
  to: postInvokeBCItem.page
2124
- })) : (0, import_rxjs29.of)(bcFetchDataRequest({
2296
+ })) : (0, import_rxjs30.of)(bcFetchDataRequest({
2125
2297
  bcName: postInvokeBCItem.name,
2126
2298
  widgetName: widgetName
2127
2299
  }));
2128
2300
  }
2129
2301
  case "showMessage" /* showMessage */: {
2130
2302
  var postInvoke = action.payload.postInvoke;
2131
- return (0, import_rxjs29.of)(showNotification({ type: postInvoke.messageType, message: postInvoke.messageText }));
2303
+ return (0, import_rxjs30.of)(showNotification({ type: postInvoke.messageType, message: postInvoke.messageText }));
2132
2304
  }
2133
2305
  case "downloadFile" /* downloadFile */: {
2134
2306
  var postInvoke = action.payload.postInvoke;
2135
- return (0, import_rxjs29.of)(downloadFile({ fileId: postInvoke.fileId }));
2307
+ return (0, import_rxjs30.of)(downloadFile({ fileId: postInvoke.fileId }));
2136
2308
  }
2137
2309
  case "downloadFileByUrl" /* downloadFileByUrl */: {
2138
2310
  var postInvoke = action.payload.postInvoke;
2139
- return (0, import_rxjs29.of)(downloadFileByUrl({ url: postInvoke.url }));
2311
+ return (0, import_rxjs30.of)(downloadFileByUrl({ url: postInvoke.url }));
2140
2312
  }
2141
2313
  default:
2142
- return import_rxjs29.EMPTY;
2314
+ return import_rxjs30.EMPTY;
2143
2315
  }
2144
2316
  })); };
2145
2317
  // src/epics/screen/processPostInvokeConfirmEpic.ts
2146
- var import_rxjs30 = require("rxjs");
2318
+ var import_rxjs31 = require("rxjs");
2147
2319
  var import_toolkit3 = require("@reduxjs/toolkit");
2148
- var processPostInvokeConfirmEpic = function (action$, state$) { return action$.pipe((0, import_rxjs30.filter)((0, import_toolkit3.isAnyOf)(processPostInvokeConfirm, processPreInvoke)), (0, import_rxjs30.mergeMap)(function (action) {
2320
+ var processPostInvokeConfirmEpic = function (action$, state$) { return action$.pipe((0, import_rxjs31.filter)((0, import_toolkit3.isAnyOf)(processPostInvokeConfirm, processPreInvoke)), (0, import_rxjs31.mergeMap)(function (action) {
2149
2321
  var _a = action.payload, bcName = _a.bcName, operationType = _a.operationType, widgetName = _a.widgetName;
2150
2322
  var confirm = processPostInvokeConfirm.match(action) ? action.payload.postInvokeConfirm : action.payload.preInvoke;
2151
2323
  switch (confirm.type) {
@@ -2153,7 +2325,7 @@ var processPostInvokeConfirmEpic = function (action$, state$) { return action$.p
2153
2325
  case "info" /* info */:
2154
2326
  case "error" /* error */:
2155
2327
  case "confirmText" /* confirmText */: {
2156
- return (0, import_rxjs30.of)(operationConfirmation({
2328
+ return (0, import_rxjs31.of)(operationConfirmation({
2157
2329
  operation: {
2158
2330
  bcName: bcName,
2159
2331
  operationType: operationType,
@@ -2163,112 +2335,132 @@ var processPostInvokeConfirmEpic = function (action$, state$) { return action$.p
2163
2335
  }));
2164
2336
  }
2165
2337
  default:
2166
- return import_rxjs30.EMPTY;
2338
+ return import_rxjs31.EMPTY;
2167
2339
  }
2168
2340
  })); };
2169
2341
  // src/epics/session/switchRoleEpic.ts
2170
- var import_rxjs31 = require("rxjs");
2171
- var switchRoleEpic = function (action$, state$) { return action$.pipe((0, import_rxjs31.filter)(switchRole.match), (0, import_rxjs31.switchMap)(function (action) {
2172
- return (0, import_rxjs31.concat)([logoutDone(null), login({ login: "", password: "", role: action.payload.role })]);
2342
+ var import_rxjs32 = require("rxjs");
2343
+ var switchRoleEpic = function (action$, state$) { return action$.pipe((0, import_rxjs32.filter)(switchRole.match), (0, import_rxjs32.switchMap)(function (action) {
2344
+ return (0, import_rxjs32.concat)([logoutDone(null), login({ login: "", password: "", role: action.payload.role })]);
2173
2345
  })); };
2174
2346
  // src/epics/session/refreshMetaEpic.ts
2175
- var import_rxjs32 = require("rxjs");
2347
+ var import_rxjs33 = require("rxjs");
2176
2348
  var refreshMetaEpic = function (action$, state$, _a) {
2177
2349
  var api = _a.api;
2178
- return action$.pipe((0, import_rxjs32.filter)(refreshMeta.match), (0, import_rxjs32.mergeMap)(function () {
2350
+ return action$.pipe((0, import_rxjs33.filter)(refreshMeta.match), (0, import_rxjs33.mergeMap)(function () {
2179
2351
  var state = state$.value;
2180
2352
  var router = state.router;
2181
2353
  var activeRole = state.session.activeRole;
2182
- return api.refreshMeta().pipe((0, import_rxjs32.switchMap)(function () { return (0, import_rxjs32.concat)([
2354
+ return api.refreshMeta().pipe((0, import_rxjs33.switchMap)(function () { return (0, import_rxjs33.concat)([
2355
+ refreshMetaDone(),
2183
2356
  logoutDone(null),
2184
2357
  login({ login: "", password: "", role: activeRole }),
2185
2358
  changeLocation({
2186
- route: router,
2187
- action: "PUSH"
2359
+ location: router
2188
2360
  })
2189
- ]); }), (0, import_rxjs32.catchError)(function (error) { return (0, import_rxjs32.of)(loginFail(error)); }));
2361
+ ]); }), (0, import_rxjs33.catchError)(function (error) { return (0, import_rxjs33.concat)([loginFail(error), refreshMetaFail(), createApiError(error)]); }));
2190
2362
  }));
2191
2363
  };
2192
2364
  // src/epics/session/loginDoneEpic.ts
2193
- var import_rxjs33 = require("rxjs");
2194
- var loginDoneSessionEpic = function (action$, store) { return action$.pipe((0, import_rxjs33.filter)(login.match), (0, import_rxjs33.switchMap)(function (action) { return import_rxjs33.EMPTY; })); };
2195
- // src/epics/session/loginByAnotherRoleEpic.ts
2196
2365
  var import_rxjs34 = require("rxjs");
2366
+ var loginDoneSessionEpic = function (action$, store) { return action$.pipe((0, import_rxjs34.filter)(login.match), (0, import_rxjs34.switchMap)(function (action) { return import_rxjs34.EMPTY; })); };
2367
+ // src/epics/session/loginByAnotherRoleEpic.ts
2368
+ var import_rxjs35 = require("rxjs");
2197
2369
  var responseStatusMessages = {
2198
2370
  401: "Invalid credentials",
2199
2371
  403: "Access denied"
2200
2372
  };
2201
2373
  var loginByAnotherRoleEpic = function (action$, state$, _a) {
2202
2374
  var api = _a.api;
2203
- return action$.pipe((0, import_rxjs34.filter)(login.match), (0, import_rxjs34.filter)(function (action) { var _a; return !!((_a = action.payload) === null || _a === void 0 ? void 0 : _a.role); }), (0, import_rxjs34.switchMap)(function (action) {
2375
+ return action$.pipe((0, import_rxjs35.filter)(login.match), (0, import_rxjs35.filter)(function (action) { var _a; return !!((_a = action.payload) === null || _a === void 0 ? void 0 : _a.role); }), (0, import_rxjs35.switchMap)(function (action) {
2204
2376
  var _a;
2205
2377
  var role = (_a = action.payload.role) !== null && _a !== void 0 ? _a : "";
2206
2378
  var isSwitchRole = role && role !== state$.value.session.activeRole;
2207
- return api.loginByRoleRequest(role).pipe((0, import_rxjs34.mergeMap)(function (data) {
2379
+ return api.loginByRoleRequest(role).pipe((0, import_rxjs35.mergeMap)(function (data) {
2380
+ var _a;
2381
+ var result = [];
2208
2382
  if (isSwitchRole) {
2383
+ var defaultScreen = data.screens.find(function (screen) { return screen.defaultScreen; }) || data.screens[0];
2384
+ var defaultViewName_1 = (_a = defaultScreen === null || defaultScreen === void 0 ? void 0 : defaultScreen.primary) !== null && _a !== void 0 ? _a : defaultScreen.meta.views[0].name;
2385
+ var defaultView = defaultScreen === null || defaultScreen === void 0 ? void 0 : defaultScreen.meta.views.find(function (view) { return defaultViewName_1 === view.name; });
2386
+ if (defaultView)
2387
+ result.push(changeLocation({ location: defaultParseURL(new URL(defaultView.url, window.location.origin)) }));
2209
2388
  }
2210
- return import_rxjs34.EMPTY;
2211
- }), (0, import_rxjs34.catchError)(function (error) {
2389
+ return (0, import_rxjs35.concat)(__spreadArray(__spreadArray([], result, true), [
2390
+ loginDone({
2391
+ devPanelEnabled: data.devPanelEnabled,
2392
+ activeRole: data.activeRole,
2393
+ roles: data.roles,
2394
+ screens: data.screens,
2395
+ firstName: data.firstName,
2396
+ lastName: data.lastName,
2397
+ login: data.login
2398
+ })
2399
+ ], false));
2400
+ }), (0, import_rxjs35.catchError)(function (error) {
2212
2401
  console.error(error);
2213
2402
  var errorMsg = error.response ? responseStatusMessages[error.response.status] || "Server application unavailable" : "Empty server response";
2214
- return (0, import_rxjs34.of)(loginFail({ errorMsg: errorMsg }));
2403
+ return (0, import_rxjs35.concat)((0, import_rxjs35.of)(loginFail({ errorMsg: errorMsg })), createApiErrorObservable(error));
2215
2404
  }));
2216
2405
  }));
2217
2406
  };
2218
2407
  // src/epics/session/refreshMetaAndReloadPageEpic.ts
2219
- var import_rxjs35 = require("rxjs");
2220
- var refreshMetaAndReloadPageEpic = function (action$, state$) { return action$.pipe((0, import_rxjs35.filter)(refreshMetaAndReloadPage.match), (0, import_rxjs35.switchMap)(function () { return (0, import_rxjs35.concat)((0, import_rxjs35.of)(refreshMeta(null)), action$.pipe((0, import_rxjs35.filter)(loginDone.match), (0, import_rxjs35.take)(1), (0, import_rxjs35.tap)(function () { return location.reload(); }), (0, import_rxjs35.switchMap)(function () { return import_rxjs35.EMPTY; }))); })); };
2221
- // src/epics/data/bcNewDataEpic.ts
2222
2408
  var import_rxjs36 = require("rxjs");
2223
- var import_schema12 = require("@cxbox-ui/schema");
2409
+ var refreshMetaAndReloadPageEpic = function (action$, state$) { return action$.pipe((0, import_rxjs36.filter)(refreshMetaAndReloadPage.match), (0, import_rxjs36.switchMap)(function () { return (0, import_rxjs36.concat)((0, import_rxjs36.of)(refreshMeta()), action$.pipe((0, import_rxjs36.filter)(loginDone.match), (0, import_rxjs36.take)(1), (0, import_rxjs36.tap)(function () { return location.reload(); }), (0, import_rxjs36.switchMap)(function () { return import_rxjs36.EMPTY; }))); })); };
2410
+ // src/epics/data/bcNewDataEpic.ts
2411
+ var import_rxjs37 = require("rxjs");
2412
+ var import_schema13 = require("@cxbox-ui/schema");
2224
2413
  var bcNewDataEpic = function (action$, state$, _a) {
2225
2414
  var api = _a.api;
2226
- return action$.pipe((0, import_rxjs36.filter)(sendOperation.match), (0, import_rxjs36.filter)(function (action) { return matchOperationRole(import_schema12.OperationTypeCrud.create, action.payload, state$.value); }), (0, import_rxjs36.mergeMap)(function (action) {
2415
+ return action$.pipe((0, import_rxjs37.filter)(sendOperation.match), (0, import_rxjs37.filter)(function (action) { return matchOperationRole(import_schema13.OperationTypeCrud.create, action.payload, state$.value); }), (0, import_rxjs37.mergeMap)(function (action) {
2416
+ var _a;
2227
2417
  var state = state$.value;
2228
2418
  var bcName = action.payload.bcName;
2229
- var bcUrl = buildBcUrl(bcName);
2419
+ var bcUrl = (_a = buildBcUrl(bcName, false, state)) !== null && _a !== void 0 ? _a : "";
2230
2420
  var context = { widgetName: action.payload.widgetName };
2231
2421
  var params = { _action: action.payload.operationType };
2232
- return api.newBcData(state.screen.screenName, bcUrl, context, params).pipe((0, import_rxjs36.mergeMap)(function (data) {
2422
+ return api.newBcData(state.screen.screenName, bcUrl, context, params).pipe((0, import_rxjs37.mergeMap)(function (data) {
2423
+ var _a, _b;
2233
2424
  var rowMeta = data.row;
2234
2425
  var dataItem = { id: null, vstamp: -1 };
2235
2426
  data.row.fields.forEach(function (field) {
2236
2427
  dataItem[field.key] = field.currentValue;
2237
2428
  });
2238
- var postInvoke = data.postActions[0];
2429
+ var postInvoke = (_a = data.postActions) === null || _a === void 0 ? void 0 : _a[0];
2239
2430
  var cursor = dataItem.id;
2240
- return (0, import_rxjs36.concat)((0, import_rxjs36.of)(bcNewDataSuccess({ bcName: bcName, dataItem: dataItem, bcUrl: bcUrl })), (0, import_rxjs36.of)(bcFetchRowMetaSuccess({ bcName: bcName, bcUrl: "".concat(bcUrl, "/").concat(cursor), rowMeta: rowMeta, cursor: cursor })), (0, import_rxjs36.of)(changeDataItem({
2241
- bcName: action.payload.bcName,
2431
+ return (0, import_rxjs37.concat)((0, import_rxjs37.of)(bcNewDataSuccess({ bcName: bcName, dataItem: dataItem, bcUrl: bcUrl })), (0, import_rxjs37.of)(bcFetchRowMetaSuccess({ bcName: bcName, bcUrl: "".concat(bcUrl, "/").concat(cursor), rowMeta: rowMeta, cursor: cursor })), (0, import_rxjs37.of)(changeDataItem({
2432
+ bcName: bcName,
2433
+ bcUrl: (_b = buildBcUrl(bcName, true, state)) !== null && _b !== void 0 ? _b : "",
2242
2434
  cursor: cursor,
2243
2435
  dataItem: {
2244
2436
  id: cursor
2245
2437
  }
2246
- })), postInvoke ? (0, import_rxjs36.of)(processPostInvoke({ bcName: bcName, postInvoke: postInvoke, cursor: cursor, widgetName: action.payload.widgetName })) : import_rxjs36.EMPTY);
2247
- }), (0, import_rxjs36.catchError)(function (error) {
2438
+ })), postInvoke ? (0, import_rxjs37.of)(processPostInvoke({ bcName: bcName, postInvoke: postInvoke, cursor: cursor, widgetName: action.payload.widgetName })) : import_rxjs37.EMPTY);
2439
+ }), (0, import_rxjs37.catchError)(function (error) {
2248
2440
  console.error(error);
2249
- return (0, import_rxjs36.of)(bcNewDataFail({ bcName: bcName }));
2441
+ return (0, import_rxjs37.concat)((0, import_rxjs37.of)(bcNewDataFail({ bcName: bcName })), createApiErrorObservable(error, context));
2250
2442
  }));
2251
2443
  }));
2252
2444
  };
2253
2445
  // src/epics/data/bcLoadMoreEpic.ts
2254
- var import_rxjs38 = require("rxjs");
2446
+ var import_rxjs39 = require("rxjs");
2255
2447
  // src/utils/cancelRequestEpic.ts
2256
- var import_rxjs37 = require("rxjs");
2448
+ var import_rxjs38 = require("rxjs");
2257
2449
  var import_toolkit4 = require("@reduxjs/toolkit");
2258
2450
  var cancelRequestActionTypes = [selectView, logout];
2259
2451
  function cancelRequestEpic(action$, actionTypes, cancelFn, cancelActionCreator, filterFn) {
2260
2452
  if (filterFn === void 0) { filterFn = function (item) {
2261
2453
  return true;
2262
2454
  }; }
2263
- return action$.pipe((0, import_rxjs37.filter)((0, import_toolkit4.isAnyOf).apply(void 0, actionTypes)), (0, import_rxjs37.filter)(filterFn), (0, import_rxjs37.mergeMap)(function () {
2264
- cancelFn();
2265
- return (0, import_rxjs37.of)(cancelActionCreator);
2266
- }), (0, import_rxjs37.take)(1));
2455
+ return action$.pipe((0, import_rxjs38.filter)((0, import_toolkit4.isAnyOf).apply(void 0, actionTypes)), (0, import_rxjs38.filter)(filterFn), (0, import_rxjs38.mergeMap)(function () {
2456
+ cancelFn === null || cancelFn === void 0 ? void 0 : cancelFn();
2457
+ return (0, import_rxjs38.of)(cancelActionCreator);
2458
+ }), (0, import_rxjs38.take)(1));
2267
2459
  }
2268
2460
  // src/epics/data/bcLoadMoreEpic.ts
2269
2461
  var bcLoadMoreEpic = function (action$, state$, _a) {
2270
2462
  var api = _a.api;
2271
- return action$.pipe((0, import_rxjs38.filter)(bcLoadMore.match), (0, import_rxjs38.mergeMap)(function (action) {
2463
+ return action$.pipe((0, import_rxjs39.filter)(bcLoadMore.match), (0, import_rxjs39.mergeMap)(function (action) {
2272
2464
  var _a, _b;
2273
2465
  var state = state$.value;
2274
2466
  var bcName = action.payload.bcName;
@@ -2276,44 +2468,44 @@ var bcLoadMoreEpic = function (action$, state$, _a) {
2276
2468
  var cursor = bc.cursor, page = bc.page;
2277
2469
  var limit = ((_a = state.view.widgets.find(function (i) { return i.bcName === bcName; })) === null || _a === void 0 ? void 0 : _a.limit) || bc.limit;
2278
2470
  var limitBySelfCursor = (_b = state.router.bcPath) === null || _b === void 0 ? void 0 : _b.includes("".concat(bcName, "/").concat(cursor));
2279
- var bcUrl = buildBcUrl(bcName, limitBySelfCursor);
2471
+ var bcUrl = buildBcUrl(bcName, limitBySelfCursor, state);
2280
2472
  var filters = state.screen.filters[bcName] || [];
2281
2473
  var sorters = state.screen.sorters[bcName];
2282
2474
  var fetchParams = __assign(__assign({ _page: page, _limit: limit }, getFilters(filters)), getSorters(sorters));
2283
2475
  var canceler = api.createCanceler();
2284
2476
  var cancelFlow = cancelRequestEpic(action$, cancelRequestActionTypes, canceler.cancel, bcFetchDataFail({ bcName: bcName, bcUrl: bcUrl }));
2285
- var normalFlow = api.fetchBcData(state.screen.screenName, bcUrl, fetchParams, canceler.cancelToken).pipe((0, import_rxjs38.mergeMap)(function (data) {
2477
+ var normalFlow = api.fetchBcData(state.screen.screenName, bcUrl, fetchParams, canceler.cancelToken).pipe((0, import_rxjs39.mergeMap)(function (data) {
2286
2478
  var _a;
2287
2479
  var oldBcDataIds = (_a = state.data[bcName]) === null || _a === void 0 ? void 0 : _a.map(function (i) { return i.id; });
2288
2480
  var newData = __spreadArray(__spreadArray([], state.data[bcName], true), data.data.filter(function (i) { return !oldBcDataIds.includes(i.id); }), true);
2289
- return (0, import_rxjs38.of)(bcFetchDataSuccess({
2481
+ return (0, import_rxjs39.of)(bcFetchDataSuccess({
2290
2482
  bcName: bcName,
2291
2483
  data: newData,
2292
2484
  bcUrl: bcUrl,
2293
2485
  hasNext: data.hasNext
2294
2486
  }));
2295
- }), (0, import_rxjs38.catchError)(function (error) {
2487
+ }), (0, import_rxjs39.catchError)(function (error) {
2296
2488
  console.error(error);
2297
- return (0, import_rxjs38.of)(bcFetchDataFail({ bcName: bcName, bcUrl: bcUrl }));
2489
+ return (0, import_rxjs39.concat)((0, import_rxjs39.of)(bcFetchDataFail({ bcName: bcName, bcUrl: bcUrl })), createApiErrorObservable(error));
2298
2490
  }));
2299
- return (0, import_rxjs38.race)(cancelFlow, normalFlow);
2491
+ return (0, import_rxjs39.race)(cancelFlow, normalFlow);
2300
2492
  }));
2301
2493
  };
2302
2494
  // src/epics/data/bcSaveDataEpic.ts
2303
- var import_rxjs39 = require("rxjs");
2495
+ var import_rxjs40 = require("rxjs");
2304
2496
  var bcSaveDataEpic = function (action$, state$, _a) {
2305
2497
  var api = _a.api;
2306
- return action$.pipe((0, import_rxjs39.filter)(sendOperation.match), (0, import_rxjs39.filter)(function (action) { return matchOperationRole(import_schema4.OperationTypeCrud.save, action.payload, state$.value); }), (0, import_rxjs39.mergeMap)(function (action) {
2307
- var _a, _b, _c;
2498
+ return action$.pipe((0, import_rxjs40.filter)(sendOperation.match), (0, import_rxjs40.filter)(function (action) { return matchOperationRole(import_schema5.OperationTypeCrud.save, action.payload, state$.value); }), (0, import_rxjs40.mergeMap)(function (action) {
2499
+ var _a, _b, _c, _d;
2308
2500
  var state = state$.value;
2309
2501
  var bcName = action.payload.bcName;
2310
- var bcUrl = buildBcUrl(bcName, true);
2502
+ var bcUrl = (_a = buildBcUrl(bcName, true, state)) !== null && _a !== void 0 ? _a : "";
2311
2503
  var widgetName = action.payload.widgetName;
2312
2504
  var cursor = state.screen.bo.bc[bcName].cursor;
2313
2505
  var dataItem = state.data[bcName].find(function (item) { return item.id === cursor; });
2314
- var pendingChanges = (_a = state.view.pendingDataChanges[bcName]) === null || _a === void 0 ? void 0 : _a[cursor];
2315
- var rowMeta = bcUrl && ((_b = state.view.rowMeta[bcName]) === null || _b === void 0 ? void 0 : _b[bcUrl]);
2316
- var options = (_c = state.view.widgets.find(function (widget) { return widget.name === widgetName; })) === null || _c === void 0 ? void 0 : _c.options;
2506
+ var pendingChanges = __assign({}, (_b = state.view.pendingDataChanges[bcName]) === null || _b === void 0 ? void 0 : _b[cursor]);
2507
+ var rowMeta = bcUrl && ((_c = state.view.rowMeta[bcName]) === null || _c === void 0 ? void 0 : _c[bcUrl]);
2508
+ var options = (_d = state.view.widgets.find(function (widget) { return widget.name === widgetName; })) === null || _d === void 0 ? void 0 : _d.options;
2317
2509
  if (rowMeta) {
2318
2510
  var fields = rowMeta.fields;
2319
2511
  var _loop_3 = function (key) {
@@ -2330,21 +2522,22 @@ var bcSaveDataEpic = function (action$, state$, _a) {
2330
2522
  return bcFetchDataRequest({ bcName: childBcName, widgetName: widgetNames[0] });
2331
2523
  });
2332
2524
  var context = { widgetName: action.payload.widgetName };
2333
- return api.saveBcData(state.screen.screenName, bcUrl, __assign(__assign({}, pendingChanges), { vstamp: dataItem.vstamp }), context).pipe((0, import_rxjs39.mergeMap)(function (data) {
2334
- var postInvoke = data.postActions[0];
2525
+ return api.saveBcData(state.screen.screenName, bcUrl, __assign(__assign({}, pendingChanges), { vstamp: dataItem === null || dataItem === void 0 ? void 0 : dataItem.vstamp }), context).pipe((0, import_rxjs40.mergeMap)(function (data) {
2526
+ var _a;
2527
+ var postInvoke = (_a = data.postActions) === null || _a === void 0 ? void 0 : _a[0];
2335
2528
  var responseDataItem = data.record;
2336
- return (0, import_rxjs39.concat)((0, import_rxjs39.of)(bcSaveDataSuccess({ bcName: bcName, cursor: cursor, dataItem: responseDataItem })), (0, import_rxjs39.of)(bcFetchRowMeta({ widgetName: widgetName, bcName: bcName })), (0, import_rxjs39.of).apply(void 0, fetchChildrenBcData), postInvoke ? (0, import_rxjs39.of)(processPostInvoke({
2529
+ return (0, import_rxjs40.concat)((0, import_rxjs40.of)(bcSaveDataSuccess({ bcName: bcName, cursor: cursor, dataItem: responseDataItem })), (0, import_rxjs40.of)(bcFetchRowMeta({ widgetName: widgetName, bcName: bcName })), (0, import_rxjs40.of).apply(void 0, fetchChildrenBcData), postInvoke ? (0, import_rxjs40.of)(processPostInvoke({
2337
2530
  bcName: bcName,
2338
2531
  widgetName: widgetName,
2339
2532
  postInvoke: postInvoke,
2340
2533
  cursor: responseDataItem.id
2341
- })) : import_rxjs39.EMPTY, action.payload.onSuccessAction ? (0, import_rxjs39.of)(action.payload.onSuccessAction) : import_rxjs39.EMPTY);
2342
- }), (0, import_rxjs39.catchError)(function (e) {
2343
- var _a, _b, _c, _d, _e, _f;
2534
+ })) : import_rxjs40.EMPTY, action.payload.onSuccessAction ? (0, import_rxjs40.of)(action.payload.onSuccessAction) : import_rxjs40.EMPTY);
2535
+ }), (0, import_rxjs40.catchError)(function (e) {
2536
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2344
2537
  console.error(e);
2345
- var notification$ = import_rxjs39.EMPTY;
2538
+ var notification$ = import_rxjs40.EMPTY;
2346
2539
  if (action.payload.onSuccessAction && !(options === null || options === void 0 ? void 0 : options.disableNotification)) {
2347
- notification$ = (0, import_rxjs39.of)(addNotification({
2540
+ notification$ = (0, import_rxjs40.of)(addNotification({
2348
2541
  key: "data_autosave_undo",
2349
2542
  type: "buttonWarningNotification",
2350
2543
  message: "There are pending changes. Please save them or cancel.",
@@ -2361,16 +2554,16 @@ var bcSaveDataEpic = function (action$, state$, _a) {
2361
2554
  var entityError = null;
2362
2555
  var operationError = (_a = e.response) === null || _a === void 0 ? void 0 : _a.data;
2363
2556
  if (((_b = e.response) === null || _b === void 0 ? void 0 : _b.data) === Object((_c = e.response) === null || _c === void 0 ? void 0 : _c.data)) {
2364
- entityError = (_d = operationError === null || operationError === void 0 ? void 0 : operationError.error) === null || _d === void 0 ? void 0 : _d.entity;
2365
- viewError = (_f = (_e = operationError === null || operationError === void 0 ? void 0 : operationError.error) === null || _e === void 0 ? void 0 : _e.popup) === null || _f === void 0 ? void 0 : _f[0];
2557
+ entityError = (_e = (_d = operationError === null || operationError === void 0 ? void 0 : operationError.error) === null || _d === void 0 ? void 0 : _d.entity) !== null && _e !== void 0 ? _e : entityError;
2558
+ viewError = (_h = (_g = (_f = operationError === null || operationError === void 0 ? void 0 : operationError.error) === null || _f === void 0 ? void 0 : _f.popup) === null || _g === void 0 ? void 0 : _g[0]) !== null && _h !== void 0 ? _h : viewError;
2366
2559
  }
2367
- return (0, import_rxjs39.concat)((0, import_rxjs39.of)(bcSaveDataFail({ bcName: bcName, bcUrl: bcUrl, viewError: viewError, entityError: entityError })), notification$);
2560
+ return (0, import_rxjs40.concat)((0, import_rxjs40.of)(bcSaveDataFail({ bcName: bcName, bcUrl: bcUrl, viewError: viewError, entityError: entityError })), notification$, createApiErrorObservable(e, context));
2368
2561
  }));
2369
2562
  }));
2370
2563
  };
2371
2564
  // src/epics/data/selectViewEpic.ts
2372
- var import_rxjs40 = require("rxjs");
2373
- var selectViewEpic = function (action$, state$) { return action$.pipe((0, import_rxjs40.filter)(selectView.match), (0, import_rxjs40.mergeMap)(function (action) {
2565
+ var import_rxjs41 = require("rxjs");
2566
+ var selectViewEpic = function (action$, state$) { return action$.pipe((0, import_rxjs41.filter)(selectView.match), (0, import_rxjs41.mergeMap)(function (action) {
2374
2567
  try {
2375
2568
  var state_1 = state$.value;
2376
2569
  var bcToLoad_1 = {};
@@ -2395,23 +2588,23 @@ var selectViewEpic = function (action$, state$) { return action$.pipe((0, import
2395
2588
  }
2396
2589
  catch (e) {
2397
2590
  console.error("selectView Epic:: ".concat(e));
2398
- return import_rxjs40.EMPTY;
2591
+ return import_rxjs41.EMPTY;
2399
2592
  }
2400
2593
  })); };
2401
2594
  // src/epics/data/bcFetchDataEpic.ts
2402
- var import_rxjs41 = require("rxjs");
2403
- var import_schema13 = require("@cxbox-ui/schema");
2595
+ var import_rxjs42 = require("rxjs");
2596
+ var import_schema14 = require("@cxbox-ui/schema");
2404
2597
  var import_toolkit5 = require("@reduxjs/toolkit");
2405
2598
  var bcFetchDataEpic = function (action$, state$, _a) {
2406
2599
  var api = _a.api;
2407
- return action$.pipe((0, import_rxjs41.filter)((0, import_toolkit5.isAnyOf)(bcFetchDataRequest, bcFetchDataPages, showViewPopup, bcForceUpdate, bcChangePage)), (0, import_rxjs41.mergeMap)(function (action) {
2600
+ return action$.pipe((0, import_rxjs42.filter)((0, import_toolkit5.isAnyOf)(bcFetchDataRequest, bcFetchDataPages, showViewPopup, bcForceUpdate, bcChangePage)), (0, import_rxjs42.mergeMap)(function (action) {
2408
2601
  var getCursorChange = function (data, prevCursor, isHierarchy) {
2409
2602
  var _a;
2410
2603
  var _b;
2411
2604
  var bcName = action.payload.bcName;
2412
2605
  var keepDelta = bcFetchDataRequest.match(action) ? action.payload.keepDelta : void 0;
2413
2606
  var newCursor = (_b = data[0]) === null || _b === void 0 ? void 0 : _b.id;
2414
- return (0, import_rxjs41.of)(bcChangeCursors({
2607
+ return (0, import_rxjs42.of)(bcChangeCursors({
2415
2608
  cursorsMap: (_a = {},
2416
2609
  _a[bcName] = data.some(function (i) { return i.id === prevCursor; }) ? prevCursor : newCursor,
2417
2610
  _a),
@@ -2421,7 +2614,7 @@ var bcFetchDataEpic = function (action$, state$, _a) {
2421
2614
  var getChildrenData = function (widgets, bcDictionary, isHierarchy, showConditionCheck) {
2422
2615
  var bcName = action.payload.bcName;
2423
2616
  var _a = bcFetchDataRequest.match(action) ? action.payload : { ignorePageLimit: void 0, keepDelta: void 0 }, ignorePageLimit = _a.ignorePageLimit, keepDelta = _a.keepDelta;
2424
- return (0, import_rxjs41.concat).apply(void 0, Object.entries(getBcChildren(bcName, widgets, bcDictionary)).filter(function (_a) {
2617
+ return (0, import_rxjs42.concat).apply(void 0, Object.entries(getBcChildren(bcName, widgets, bcDictionary)).filter(function (_a) {
2425
2618
  var childBcName = _a[0], widgetNames = _a[1];
2426
2619
  var nonLazyWidget = widgets.find(function (item) {
2427
2620
  return widgetNames.includes(item.name) && !PopupWidgetTypes.includes(item.type) && showConditionCheck(item);
@@ -2436,43 +2629,43 @@ var bcFetchDataEpic = function (action$, state$, _a) {
2436
2629
  var nonLazyWidget = widgets.find(function (item) {
2437
2630
  return widgetNames.includes(item.name) && !PopupWidgetTypes.includes(item.type) && showConditionCheck(item);
2438
2631
  });
2439
- return (0, import_rxjs41.of)(bcFetchDataRequest({
2632
+ return (0, import_rxjs42.of)(bcFetchDataRequest({
2440
2633
  bcName: childBcName,
2441
- widgetName: nonLazyWidget.name,
2634
+ widgetName: nonLazyWidget === null || nonLazyWidget === void 0 ? void 0 : nonLazyWidget.name,
2442
2635
  ignorePageLimit: ignorePageLimit || showViewPopup.match(action),
2443
2636
  keepDelta: isHierarchy || keepDelta
2444
2637
  }));
2445
2638
  }));
2446
2639
  };
2447
2640
  var bcFetchDataImpl = function () {
2448
- var _a, _b, _c, _d, _e, _f;
2641
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2449
2642
  var state = state$.value;
2450
- var widgetName = action.payload.widgetName;
2451
- var _g = state.view, widgets = _g.widgets, infiniteWidgets = _g.infiniteWidgets;
2452
- var widget = (_a = widgets.find(function (item) { return item.name === widgetName; })) !== null && _a !== void 0 ? _a : widgets.find(function (item) { return item.bcName === action.payload.bcName; });
2643
+ var _j = action.payload.widgetName, widgetName = _j === void 0 ? "" : _j;
2644
+ var _k = state.view, widgets = _k.widgets, infiniteWidgets = _k.infiniteWidgets;
2645
+ var widget = (_a = widgets === null || widgets === void 0 ? void 0 : widgets.find(function (item) { return item.name === widgetName; })) !== null && _a !== void 0 ? _a : widgets === null || widgets === void 0 ? void 0 : widgets.find(function (item) { return item.bcName === action.payload.bcName; });
2453
2646
  if (!widget) {
2454
- return [import_rxjs41.EMPTY];
2647
+ return [import_rxjs42.EMPTY];
2455
2648
  }
2456
2649
  var bcName = action.payload.bcName;
2457
2650
  var bc = state.screen.bo.bc[bcName];
2458
- var cursor = bc.cursor, page = bc.page;
2459
- var limit = ((_b = widgets.find(function (i) { return i.bcName === bcName; })) === null || _b === void 0 ? void 0 : _b.limit) || bc.limit;
2651
+ var cursor = bc.cursor, _l = bc.page, page = _l === void 0 ? 1 : _l;
2652
+ var limit = (_c = (((_b = widgets === null || widgets === void 0 ? void 0 : widgets.find(function (i) { return i.bcName === bcName; })) === null || _b === void 0 ? void 0 : _b.limit) || bc.limit)) !== null && _c !== void 0 ? _c : 5;
2460
2653
  var sorters = state.screen.sorters[bcName];
2461
2654
  if (showViewPopup.match(action) && bcName === action.payload.calleeBCName) {
2462
- return [import_rxjs41.EMPTY];
2655
+ return [import_rxjs42.EMPTY];
2463
2656
  }
2464
- var anyHierarchyWidget = widgets.find(function (item) {
2465
- return item.bcName === widget.bcName && item.type === import_schema13.WidgetTypes.AssocListPopup && isHierarchyWidget(item);
2657
+ var anyHierarchyWidget = widgets === null || widgets === void 0 ? void 0 : widgets.find(function (item) {
2658
+ return item.bcName === widget.bcName && item.type === import_schema14.WidgetTypes.AssocListPopup && isHierarchyWidget(item);
2466
2659
  });
2467
- var fullHierarchyWidget = state.view.widgets.find(function (item) {
2660
+ var fullHierarchyWidget = (_d = state.view.widgets) === null || _d === void 0 ? void 0 : _d.find(function (item) {
2468
2661
  var _a;
2469
- return item.bcName === widget.bcName && item.type === import_schema13.WidgetTypes.AssocListPopup && ((_a = item.options) === null || _a === void 0 ? void 0 : _a.hierarchyFull);
2662
+ return item.bcName === widget.bcName && item.type === import_schema14.WidgetTypes.AssocListPopup && ((_a = item.options) === null || _a === void 0 ? void 0 : _a.hierarchyFull);
2470
2663
  });
2471
- var limitBySelfCursor = (_c = state.router.bcPath) === null || _c === void 0 ? void 0 : _c.includes("".concat(bcName, "/").concat(cursor));
2472
- var bcUrl = buildBcUrl(bcName, limitBySelfCursor);
2664
+ var limitBySelfCursor = (_e = state.router.bcPath) === null || _e === void 0 ? void 0 : _e.includes("".concat(bcName, "/").concat(cursor));
2665
+ var bcUrl = buildBcUrl(bcName, limitBySelfCursor, state);
2473
2666
  var fetchParams = __assign(__assign({ _page: page, _limit: limit }, getFilters(fullHierarchyWidget ? [] : state.screen.filters[bcName] || [])), getSorters(sorters));
2474
2667
  if (bcForceUpdate.match(action)) {
2475
- var infinityPaginationWidget = widgetName && infiniteWidgets.includes(widgetName) || ((_e = (_d = widgets === null || widgets === void 0 ? void 0 : widgets.filter(function (item) { return item.bcName === bcName; })) === null || _d === void 0 ? void 0 : _d.find(function (item) { return infiniteWidgets.includes(item.name); })) === null || _e === void 0 ? void 0 : _e.name);
2668
+ var infinityPaginationWidget = widgetName && (infiniteWidgets === null || infiniteWidgets === void 0 ? void 0 : infiniteWidgets.includes(widgetName)) || ((_g = (_f = widgets === null || widgets === void 0 ? void 0 : widgets.filter(function (item) { return item.bcName === bcName; })) === null || _f === void 0 ? void 0 : _f.find(function (item) { return infiniteWidgets === null || infiniteWidgets === void 0 ? void 0 : infiniteWidgets.includes(item.name); })) === null || _g === void 0 ? void 0 : _g.name);
2476
2669
  if (infinityPaginationWidget) {
2477
2670
  fetchParams._page = 1;
2478
2671
  fetchParams._limit = limit * page;
@@ -2482,7 +2675,7 @@ var bcFetchDataEpic = function (action$, state$, _a) {
2482
2675
  fetchParams._page = action.payload.from || 1;
2483
2676
  fetchParams._limit = (action.payload.to || page - fetchParams._page) * limit;
2484
2677
  }
2485
- if (bcFetchDataRequest.match(action) && action.payload.ignorePageLimit || ((_f = anyHierarchyWidget === null || anyHierarchyWidget === void 0 ? void 0 : anyHierarchyWidget.options) === null || _f === void 0 ? void 0 : _f.hierarchyFull)) {
2678
+ if (bcFetchDataRequest.match(action) && action.payload.ignorePageLimit || ((_h = anyHierarchyWidget === null || anyHierarchyWidget === void 0 ? void 0 : anyHierarchyWidget.options) === null || _h === void 0 ? void 0 : _h.hierarchyFull)) {
2486
2679
  fetchParams._limit = 0;
2487
2680
  }
2488
2681
  var canceler = api.createCanceler();
@@ -2491,10 +2684,10 @@ var bcFetchDataEpic = function (action$, state$, _a) {
2491
2684
  var actionBc = filteredAction.payload.bcName;
2492
2685
  return bc.parentName === actionBc;
2493
2686
  });
2494
- var normalFlow = api.fetchBcData(state.screen.screenName, bcUrl, fetchParams, canceler.cancelToken).pipe((0, import_rxjs41.mergeMap)(function (response) {
2687
+ var normalFlow = api.fetchBcData(state.screen.screenName, bcUrl, fetchParams, canceler.cancelToken).pipe((0, import_rxjs42.mergeMap)(function (response) {
2495
2688
  var _a, _b;
2496
2689
  var cursorChange = getCursorChange(response.data, cursor, !!anyHierarchyWidget);
2497
- var parentOfNotLazyWidget = widgets.some(function (item) {
2690
+ var parentOfNotLazyWidget = widgets === null || widgets === void 0 ? void 0 : widgets.some(function (item) {
2498
2691
  var _a;
2499
2692
  return ((_a = state.screen.bo.bc[item.bcName]) === null || _a === void 0 ? void 0 : _a.parentName) === bcName && !PopupWidgetTypes.includes(item.type);
2500
2693
  });
@@ -2517,23 +2710,23 @@ var bcFetchDataEpic = function (action$, state$, _a) {
2517
2710
  var lazyWidget = (!isWidgetVisible(widget) || PopupWidgetTypes.includes(widget.type)) && !parentOfNotLazyWidget;
2518
2711
  var skipLazy = ((_a = state.view.popupData) === null || _a === void 0 ? void 0 : _a.bcName) !== widget.bcName;
2519
2712
  if (lazyWidget && skipLazy) {
2520
- return import_rxjs41.EMPTY;
2713
+ return import_rxjs42.EMPTY;
2521
2714
  }
2522
- var fetchChildren = ((_b = response.data) === null || _b === void 0 ? void 0 : _b.length) ? getChildrenData(widgets, state.screen.bo.bc, !!anyHierarchyWidget, isWidgetVisible) : import_rxjs41.EMPTY;
2523
- var fetchRowMeta = (0, import_rxjs41.of)(bcFetchRowMeta({ widgetName: widgetName, bcName: bcName }));
2524
- return (0, import_rxjs41.concat)(cursorChange, (0, import_rxjs41.of)(bcFetchDataSuccess({
2715
+ var fetchChildren = ((_b = response.data) === null || _b === void 0 ? void 0 : _b.length) ? getChildrenData(widgets, state.screen.bo.bc, !!anyHierarchyWidget, isWidgetVisible) : import_rxjs42.EMPTY;
2716
+ var fetchRowMeta = (0, import_rxjs42.of)(bcFetchRowMeta({ widgetName: widgetName, bcName: bcName }));
2717
+ return (0, import_rxjs42.concat)(cursorChange, (0, import_rxjs42.of)(bcFetchDataSuccess({
2525
2718
  bcName: bcName,
2526
2719
  data: response.data,
2527
2720
  bcUrl: bcUrl,
2528
2721
  hasNext: response.hasNext
2529
2722
  })), fetchRowMeta, fetchChildren);
2530
- }), (0, import_rxjs41.catchError)(function (error) {
2723
+ }), (0, import_rxjs42.catchError)(function (error) {
2531
2724
  console.error(error);
2532
- return (0, import_rxjs41.of)(bcFetchDataFail({ bcName: action.payload.bcName, bcUrl: bcUrl }));
2725
+ return (0, import_rxjs42.concat)((0, import_rxjs42.of)(bcFetchDataFail({ bcName: action.payload.bcName, bcUrl: bcUrl })), createApiErrorObservable(error));
2533
2726
  }));
2534
2727
  return [cancelFlow, cancelByParentBc, normalFlow];
2535
2728
  };
2536
- return (0, import_rxjs41.race).apply(void 0, bcFetchDataImpl());
2729
+ return (0, import_rxjs42.race).apply(void 0, bcFetchDataImpl());
2537
2730
  }));
2538
2731
  };
2539
2732
  function isHierarchyWidget(widget) {
@@ -2541,30 +2734,31 @@ function isHierarchyWidget(widget) {
2541
2734
  return ((_a = widget.options) === null || _a === void 0 ? void 0 : _a.hierarchy) || ((_b = widget.options) === null || _b === void 0 ? void 0 : _b.hierarchyFull);
2542
2735
  }
2543
2736
  // src/epics/data/bcDeleteDataEpic.ts
2544
- var import_rxjs42 = require("rxjs");
2545
- var import_schema14 = require("@cxbox-ui/schema");
2737
+ var import_rxjs43 = require("rxjs");
2738
+ var import_schema15 = require("@cxbox-ui/schema");
2546
2739
  var bcDeleteDataEpic = function (action$, store$, _a) {
2547
2740
  var api = _a.api;
2548
- return action$.pipe((0, import_rxjs42.filter)(sendOperation.match), (0, import_rxjs42.filter)(function (action) { return matchOperationRole(import_schema14.OperationTypeCrud.delete, action.payload, store$.value); }), (0, import_rxjs42.mergeMap)(function (action) {
2741
+ return action$.pipe((0, import_rxjs43.filter)(sendOperation.match), (0, import_rxjs43.filter)(function (action) { return matchOperationRole(import_schema15.OperationTypeCrud.delete, action.payload, store$.value); }), (0, import_rxjs43.mergeMap)(function (action) {
2549
2742
  var widgetName = action.payload.widgetName;
2550
2743
  var state = store$.value;
2551
2744
  var bcName = action.payload.bcName;
2552
2745
  var cursor = state.screen.bo.bc[bcName].cursor;
2553
- var bcUrl = buildBcUrl(bcName, true);
2746
+ var bcUrl = buildBcUrl(bcName, true, state);
2554
2747
  var context = { widgetName: action.payload.widgetName };
2555
2748
  var isTargetFormatPVF = state.view.pendingValidationFailsFormat === "target" /* target */;
2556
- return api.deleteBcData(state.screen.screenName, bcUrl, context).pipe((0, import_rxjs42.mergeMap)(function (data) {
2557
- var postInvoke = data.postActions[0];
2558
- return (0, import_rxjs42.concat)(isTargetFormatPVF ? (0, import_rxjs42.of)(bcCancelPendingChanges({ bcNames: [bcName] })) : import_rxjs42.EMPTY, (0, import_rxjs42.of)(bcFetchDataRequest({ bcName: bcName, widgetName: widgetName })), postInvoke ? (0, import_rxjs42.of)(processPostInvoke({ bcName: bcName, postInvoke: postInvoke, cursor: cursor, widgetName: widgetName })) : import_rxjs42.EMPTY);
2559
- }), (0, import_rxjs42.catchError)(function (error) {
2749
+ return api.deleteBcData(state.screen.screenName, bcUrl, context).pipe((0, import_rxjs43.mergeMap)(function (data) {
2750
+ var _a;
2751
+ var postInvoke = (_a = data.postActions) === null || _a === void 0 ? void 0 : _a[0];
2752
+ return (0, import_rxjs43.concat)(isTargetFormatPVF ? (0, import_rxjs43.of)(bcCancelPendingChanges({ bcNames: [bcName] })) : import_rxjs43.EMPTY, (0, import_rxjs43.of)(bcFetchDataRequest({ bcName: bcName, widgetName: widgetName })), postInvoke ? (0, import_rxjs43.of)(processPostInvoke({ bcName: bcName, postInvoke: postInvoke, cursor: cursor, widgetName: widgetName })) : import_rxjs43.EMPTY);
2753
+ }), (0, import_rxjs43.catchError)(function (error) {
2560
2754
  console.error(error);
2561
- return (0, import_rxjs42.of)(bcDeleteDataFail({ bcName: bcName }));
2755
+ return (0, import_rxjs43.concat)((0, import_rxjs43.of)(bcDeleteDataFail({ bcName: bcName })), createApiErrorObservable(error, context));
2562
2756
  }));
2563
2757
  }));
2564
2758
  };
2565
2759
  // src/epics/data/bcSelectRecordEpic.ts
2566
- var import_rxjs43 = require("rxjs");
2567
- var bcSelectRecordEpic = function (action$, store$) { return action$.pipe((0, import_rxjs43.filter)(bcSelectRecord.match), (0, import_rxjs43.mergeMap)(function (action) {
2760
+ var import_rxjs44 = require("rxjs");
2761
+ var bcSelectRecordEpic = function (action$, store$) { return action$.pipe((0, import_rxjs44.filter)(bcSelectRecord.match), (0, import_rxjs44.mergeMap)(function (action) {
2568
2762
  var _a;
2569
2763
  var _b = action.payload, bcName = _b.bcName, cursor = _b.cursor;
2570
2764
  var widgets = store$.value.view.widgets;
@@ -2578,17 +2772,19 @@ var bcSelectRecordEpic = function (action$, store$) { return action$.pipe((0, im
2578
2772
  keepDelta: action.payload.keepDelta
2579
2773
  });
2580
2774
  });
2581
- return (0, import_rxjs43.concat)((0, import_rxjs43.of)(bcChangeCursors({ cursorsMap: (_a = {}, _a[bcName] = cursor, _a), keepDelta: action.payload.keepDelta })), (0, import_rxjs43.of)(bcFetchRowMeta({ widgetName: "", bcName: bcName })), fetchChildrenBcData);
2775
+ return (0, import_rxjs44.concat)((0, import_rxjs44.of)(bcChangeCursors({ cursorsMap: (_a = {}, _a[bcName] = cursor, _a), keepDelta: action.payload.keepDelta })), (0, import_rxjs44.of)(bcFetchRowMeta({ widgetName: "", bcName: bcName })), fetchChildrenBcData);
2582
2776
  })); };
2583
2777
  // src/epics/data/changeAssociationEpic.ts
2584
- var import_rxjs44 = require("rxjs");
2585
- var changeAssociationEpic = function (action$, state$) { return action$.pipe((0, import_rxjs44.filter)(changeAssociation.match), (0, import_rxjs44.mergeMap)(function (action) {
2778
+ var import_rxjs45 = require("rxjs");
2779
+ var changeAssociationEpic = function (action$, state$) { return action$.pipe((0, import_rxjs45.filter)(changeAssociation.match), (0, import_rxjs45.mergeMap)(function (action) {
2586
2780
  var _a, _b, _c, _d, _e;
2587
2781
  var state = state$.value;
2588
2782
  var selected = action.payload.dataItem._associate;
2783
+ var bcName = action.payload.bcName;
2589
2784
  var result = [
2590
- (0, import_rxjs44.of)(changeDataItem({
2591
- bcName: action.payload.bcName,
2785
+ (0, import_rxjs45.of)(changeDataItem({
2786
+ bcName: bcName,
2787
+ bcUrl: buildBcUrl(bcName, true, state),
2592
2788
  cursor: action.payload.dataItem.id,
2593
2789
  dataItem: action.payload.dataItem
2594
2790
  }))
@@ -2601,30 +2797,30 @@ var changeAssociationEpic = function (action$, state$) { return action$.pipe((0,
2601
2797
  fields: widget.fields
2602
2798
  };
2603
2799
  var hierarchy = (_b = widget.options) === null || _b === void 0 ? void 0 : _b.hierarchy;
2604
- var hierarchyDescriptor = isRoot ? rootHierarchyDescriptor : hierarchy.find(function (item) { return item.bcName === action.payload.bcName; });
2800
+ var hierarchyDescriptor = isRoot ? rootHierarchyDescriptor : hierarchy === null || hierarchy === void 0 ? void 0 : hierarchy.find(function (item) { return item.bcName === action.payload.bcName; });
2605
2801
  var hierarchyGroupSelection = (_c = widget.options) === null || _c === void 0 ? void 0 : _c.hierarchyGroupSelection;
2606
2802
  var hierarchyTraverse = (_d = widget.options) === null || _d === void 0 ? void 0 : _d.hierarchyTraverse;
2607
- var childrenBc = hierarchy.slice(hierarchy.findIndex(function (item) { return item.bcName === action.payload.bcName; }) + 1).map(function (item) { return item.bcName; });
2803
+ var childrenBc = hierarchy === null || hierarchy === void 0 ? void 0 : hierarchy.slice(hierarchy.findIndex(function (item) { return item.bcName === action.payload.bcName; }) + 1).map(function (item) { return item.bcName; });
2608
2804
  if (hierarchyGroupSelection && hierarchyDescriptor.radio && !selected) {
2609
- result.push((0, import_rxjs44.of)(dropAllAssociations({
2805
+ result.push((0, import_rxjs45.of)(dropAllAssociations({
2610
2806
  bcNames: childrenBc
2611
2807
  })));
2612
2808
  }
2613
- var parent = isRoot ? null : hierarchy.find(function (item, index) {
2809
+ var parent = isRoot ? null : (hierarchy === null || hierarchy === void 0 ? void 0 : hierarchy.find(function (item, index) {
2614
2810
  var _a;
2615
2811
  return ((_a = hierarchy[index + 1]) === null || _a === void 0 ? void 0 : _a.bcName) === action.payload.bcName;
2616
- }) || rootHierarchyDescriptor;
2812
+ })) || rootHierarchyDescriptor;
2617
2813
  var parentItem = (_e = state.data[parent === null || parent === void 0 ? void 0 : parent.bcName]) === null || _e === void 0 ? void 0 : _e.find(function (item) { return item.id === state.screen.bo.bc[parent === null || parent === void 0 ? void 0 : parent.bcName].cursor; });
2618
2814
  if (parent && hierarchyTraverse && selected) {
2619
2815
  if (hierarchyDescriptor.radio) {
2620
- result.push((0, import_rxjs44.of)(dropAllAssociations({
2816
+ result.push((0, import_rxjs45.of)(dropAllAssociations({
2621
2817
  bcNames: [parent.bcName]
2622
2818
  })));
2623
2819
  }
2624
- result.push((0, import_rxjs44.of)(changeAssociation({
2820
+ result.push((0, import_rxjs45.of)(changeAssociation({
2625
2821
  bcName: parent.bcName,
2626
2822
  widgetName: action.payload.widgetName,
2627
- dataItem: __assign(__assign({}, parentItem), { _associate: true, _value: parentItem[parent.assocValueKey || action.payload.assocValueKey] }),
2823
+ dataItem: __assign(__assign({}, parentItem), { _associate: true, _value: parentItem === null || parentItem === void 0 ? void 0 : parentItem[parent.assocValueKey || action.payload.assocValueKey] }),
2628
2824
  assocValueKey: action.payload.assocValueKey
2629
2825
  })));
2630
2826
  }
@@ -2638,7 +2834,7 @@ var changeAssociationEpic = function (action$, state$) { return action$.pipe((0,
2638
2834
  data_1.find(function (dataValue) { return dataValue.id === deltaValue.id; });
2639
2835
  });
2640
2836
  if (wasLastInData && wasLastInDelta) {
2641
- result.push((0, import_rxjs44.of)(changeAssociation({
2837
+ result.push((0, import_rxjs45.of)(changeAssociation({
2642
2838
  bcName: parent.bcName,
2643
2839
  widgetName: action.payload.widgetName,
2644
2840
  dataItem: __assign(__assign({}, parentItem), { _associate: false }),
@@ -2646,22 +2842,22 @@ var changeAssociationEpic = function (action$, state$) { return action$.pipe((0,
2646
2842
  })));
2647
2843
  }
2648
2844
  }
2649
- return (0, import_rxjs44.concat).apply(void 0, result);
2845
+ return (0, import_rxjs45.concat).apply(void 0, result);
2650
2846
  })); };
2651
2847
  // src/epics/data/bcCancelCreateDataEpic.ts
2652
- var import_rxjs45 = require("rxjs");
2653
- var import_schema15 = require("@cxbox-ui/schema");
2848
+ var import_rxjs46 = require("rxjs");
2849
+ var import_schema16 = require("@cxbox-ui/schema");
2654
2850
  var import_toolkit6 = require("@reduxjs/toolkit");
2655
2851
  var actionTypesMatcher = (0, import_toolkit6.isAnyOf)(sendOperation);
2656
2852
  var bcCancelCreateDataEpic = function (action$, state$, _a) {
2657
2853
  var api = _a.api;
2658
- return action$.pipe((0, import_rxjs45.filter)(actionTypesMatcher), (0, import_rxjs45.filter)(function (action) { return matchOperationRole(import_schema15.OperationTypeCrud.cancelCreate, action.payload, state$.value); }), (0, import_rxjs45.mergeMap)(function (action) {
2854
+ return action$.pipe((0, import_rxjs46.filter)(actionTypesMatcher), (0, import_rxjs46.filter)(function (action) { return matchOperationRole(import_schema16.OperationTypeCrud.cancelCreate, action.payload, state$.value); }), (0, import_rxjs46.mergeMap)(function (action) {
2659
2855
  var _a;
2660
2856
  var _b, _c;
2661
2857
  var state = state$.value;
2662
2858
  var screenName = state.screen.screenName;
2663
2859
  var bcName = action.payload.bcName;
2664
- var bcUrl = buildBcUrl(bcName, true);
2860
+ var bcUrl = buildBcUrl(bcName, true, state);
2665
2861
  var bc = state.screen.bo.bc[bcName];
2666
2862
  var cursor = bc === null || bc === void 0 ? void 0 : bc.cursor;
2667
2863
  var context = { widgetName: action.payload.widgetName };
@@ -2670,20 +2866,21 @@ var bcCancelCreateDataEpic = function (action$, state$, _a) {
2670
2866
  var data = record && __assign(__assign({}, pendingRecordChange), { vstamp: record.vstamp });
2671
2867
  var params = { _action: action.payload.operationType };
2672
2868
  var cursorsMap = (_a = {}, _a[action.payload.bcName] = null, _a);
2673
- return api.customAction(screenName, bcUrl, data, context, params).pipe((0, import_rxjs45.mergeMap)(function (response) {
2674
- var postInvoke = response.postActions[0];
2675
- return (0, import_rxjs45.concat)((0, import_rxjs45.of)(sendOperationSuccess({ bcName: bcName, cursor: cursor })), (0, import_rxjs45.of)(bcChangeCursors({ cursorsMap: cursorsMap })), postInvoke ? (0, import_rxjs45.of)(processPostInvoke({ bcName: bcName, postInvoke: postInvoke, cursor: cursor, widgetName: context.widgetName })) : import_rxjs45.EMPTY);
2676
- }), (0, import_rxjs45.catchError)(function (error) {
2869
+ return api.customAction(screenName, bcUrl, data, context, params).pipe((0, import_rxjs46.mergeMap)(function (response) {
2870
+ var _a;
2871
+ var postInvoke = (_a = response.postActions) === null || _a === void 0 ? void 0 : _a[0];
2872
+ return (0, import_rxjs46.concat)((0, import_rxjs46.of)(sendOperationSuccess({ bcName: bcName, cursor: cursor })), (0, import_rxjs46.of)(bcChangeCursors({ cursorsMap: cursorsMap })), postInvoke ? (0, import_rxjs46.of)(processPostInvoke({ bcName: bcName, postInvoke: postInvoke, cursor: cursor, widgetName: context.widgetName })) : import_rxjs46.EMPTY);
2873
+ }), (0, import_rxjs46.catchError)(function (error) {
2677
2874
  console.error(error);
2678
- return (0, import_rxjs45.of)(bcDeleteDataFail({ bcName: bcName }));
2875
+ return (0, import_rxjs46.concat)((0, import_rxjs46.of)(bcDeleteDataFail({ bcName: bcName })), createApiErrorObservable(error, context));
2679
2876
  }));
2680
2877
  }));
2681
2878
  };
2682
2879
  // src/epics/data/bcSelectDepthRecordEpic.ts
2683
- var import_rxjs46 = require("rxjs");
2684
- var bcSelectDepthRecordEpic = function (action$) { return action$.pipe((0, import_rxjs46.filter)(bcSelectDepthRecord.match), (0, import_rxjs46.mergeMap)(function (action) {
2880
+ var import_rxjs47 = require("rxjs");
2881
+ var bcSelectDepthRecordEpic = function (action$) { return action$.pipe((0, import_rxjs47.filter)(bcSelectDepthRecord.match), (0, import_rxjs47.mergeMap)(function (action) {
2685
2882
  var _a = action.payload, bcName = _a.bcName, cursor = _a.cursor, depth = _a.depth;
2686
- return (0, import_rxjs46.concat)((0, import_rxjs46.of)(bcChangeDepthCursor({ bcName: bcName, depth: depth, cursor: cursor })), (0, import_rxjs46.of)(bcFetchDataRequest({
2883
+ return (0, import_rxjs47.concat)((0, import_rxjs47.of)(bcChangeDepthCursor({ bcName: bcName, depth: depth, cursor: cursor })), (0, import_rxjs47.of)(bcFetchDataRequest({
2687
2884
  bcName: bcName,
2688
2885
  depth: depth + 1,
2689
2886
  widgetName: "",
@@ -2691,8 +2888,8 @@ var bcSelectDepthRecordEpic = function (action$) { return action$.pipe((0, impor
2691
2888
  })));
2692
2889
  })); };
2693
2890
  // src/epics/data/removeMultivalueTagEpic.ts
2694
- var import_rxjs47 = require("rxjs");
2695
- var removeMultivalueTagEpic = function (action$, state$) { return action$.pipe((0, import_rxjs47.filter)(removeMultivalueTag.match), (0, import_rxjs47.mergeMap)(function (action) {
2891
+ var import_rxjs48 = require("rxjs");
2892
+ var removeMultivalueTagEpic = function (action$, state$) { return action$.pipe((0, import_rxjs48.filter)(removeMultivalueTag.match), (0, import_rxjs48.mergeMap)(function (action) {
2696
2893
  var _a, _b, _c;
2697
2894
  var _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
2698
2895
  var state = state$.value;
@@ -2707,28 +2904,28 @@ var removeMultivalueTagEpic = function (action$, state$) { return action$.pipe((
2707
2904
  var removedItem = data.find(function (item) { return item.id === action.payload.removedItem.id; });
2708
2905
  var associated = action.payload.dataItem.map(function (item) { return item.id; });
2709
2906
  var removedNodes = [];
2710
- if ((_d = widget.options) === null || _d === void 0 ? void 0 : _d.hierarchyGroupDeselection) {
2711
- if ((_e = widget.options) === null || _e === void 0 ? void 0 : _e.hierarchyTraverse) {
2907
+ if ((_d = widget === null || widget === void 0 ? void 0 : widget.options) === null || _d === void 0 ? void 0 : _d.hierarchyGroupDeselection) {
2908
+ if ((_e = widget === null || widget === void 0 ? void 0 : widget.options) === null || _e === void 0 ? void 0 : _e.hierarchyTraverse) {
2712
2909
  data = assignTreeLinks(data);
2713
2910
  }
2714
- var removedItemChildren = data.filter(function (item) { return item.parentId === removedItem.id; });
2715
- removedNodes = __spreadArray([removedItem.id], removedItemChildren.filter(function (item) { return associated.includes(item.id); }).map(function (item) { return item.id; }), true);
2716
- if ((_f = widget.options) === null || _f === void 0 ? void 0 : _f.hierarchyTraverse) {
2911
+ var removedItemChildren = data.filter(function (item) { return item.parentId === (removedItem === null || removedItem === void 0 ? void 0 : removedItem.id); });
2912
+ removedNodes = __spreadArray([removedItem === null || removedItem === void 0 ? void 0 : removedItem.id], removedItemChildren.filter(function (item) { return associated.includes(item.id); }).map(function (item) { return item.id; }), true);
2913
+ if ((_f = widget === null || widget === void 0 ? void 0 : widget.options) === null || _f === void 0 ? void 0 : _f.hierarchyTraverse) {
2717
2914
  getDescendants(removedItemChildren, removedNodes);
2718
2915
  removedNodes = data.filter(function (item) { return removedNodes.includes(item.id) && associated.includes(item.id); }).map(function (item) { return item.id; });
2719
2916
  }
2720
- var parent_1 = data.find(function (item) { return item.id === removedItem.parentId; });
2917
+ var parent_1 = data.find(function (item) { return item.id === (removedItem === null || removedItem === void 0 ? void 0 : removedItem.parentId); });
2721
2918
  var siblings = data.filter(function (item) { return item.parentId === (parent_1 === null || parent_1 === void 0 ? void 0 : parent_1.id); });
2722
2919
  var parentEmpty = siblings.every(function (child) { return removedNodes.includes(child.id) || !associated.includes(child.id); });
2723
2920
  if (parent_1 && parentEmpty) {
2724
- if ((_g = widget.options) === null || _g === void 0 ? void 0 : _g.hierarchyTraverse) {
2921
+ if ((_g = widget === null || widget === void 0 ? void 0 : widget.options) === null || _g === void 0 ? void 0 : _g.hierarchyTraverse) {
2725
2922
  var parentDescendants = [];
2726
2923
  getDescendants(siblings, parentDescendants);
2727
2924
  var parentDeepEmpty = parentDescendants.every(function (descendant) {
2728
2925
  return removedNodes.includes(descendant) || !associated.includes(descendant);
2729
2926
  });
2730
2927
  if (parentDeepEmpty) {
2731
- return (0, import_rxjs47.concat)((0, import_rxjs47.of)(removeMultivalueTag(__assign(__assign({}, action.payload), { removedItem: { id: parent_1.id, value: null } }))));
2928
+ return (0, import_rxjs48.concat)((0, import_rxjs48.of)(removeMultivalueTag(__assign(__assign({}, action.payload), { removedItem: { id: parent_1.id, value: null } }))));
2732
2929
  }
2733
2930
  }
2734
2931
  else {
@@ -2736,71 +2933,78 @@ var removeMultivalueTagEpic = function (action$, state$) { return action$.pipe((
2736
2933
  }
2737
2934
  }
2738
2935
  }
2739
- if ((_h = widget.options) === null || _h === void 0 ? void 0 : _h.hierarchyFull) {
2740
- return (0, import_rxjs47.of)(changeDataItem({
2936
+ if ((_h = widget === null || widget === void 0 ? void 0 : widget.options) === null || _h === void 0 ? void 0 : _h.hierarchyFull) {
2937
+ return (0, import_rxjs48.of)(changeDataItem({
2741
2938
  bcName: bcName,
2939
+ bcUrl: buildBcUrl(bcName, true, state),
2742
2940
  cursor: cursor,
2743
2941
  dataItem: (_a = {}, _a[associateFieldKey] = action.payload.dataItem.filter(function (item) { return !removedNodes.includes(item.id); }), _a)
2744
2942
  }));
2745
2943
  }
2746
- if ((_j = widget.options) === null || _j === void 0 ? void 0 : _j.hierarchy) {
2747
- return (0, import_rxjs47.concat)((0, import_rxjs47.of)(changeDataItem({
2944
+ if ((_j = widget === null || widget === void 0 ? void 0 : widget.options) === null || _j === void 0 ? void 0 : _j.hierarchy) {
2945
+ var hierarchyBcName = (_o = (_m = (_l = (_k = widget === null || widget === void 0 ? void 0 : widget.options) === null || _k === void 0 ? void 0 : _k.hierarchy) === null || _l === void 0 ? void 0 : _l.find(function (hierarchyData) {
2946
+ var _a;
2947
+ return (_a = state.view.pendingDataChanges[hierarchyData.bcName]) === null || _a === void 0 ? void 0 : _a[action.payload.removedItem.id];
2948
+ })) === null || _m === void 0 ? void 0 : _m.bcName) !== null && _o !== void 0 ? _o : bcName;
2949
+ return (0, import_rxjs48.concat)((0, import_rxjs48.of)(changeDataItem({
2748
2950
  /**
2749
2951
  * This is incorrect and will break if different BC has records with
2750
2952
  * identical ids.
2751
2953
  *
2752
2954
  * TODO: Record `level` should be mapped to hierarchyData index instead
2753
2955
  */
2754
- bcName: (_o = (_m = (_l = (_k = widget.options) === null || _k === void 0 ? void 0 : _k.hierarchy) === null || _l === void 0 ? void 0 : _l.find(function (hierarchyData) {
2755
- var _a;
2756
- return (_a = state.view.pendingDataChanges[hierarchyData.bcName]) === null || _a === void 0 ? void 0 : _a[action.payload.removedItem.id];
2757
- })) === null || _m === void 0 ? void 0 : _m.bcName) !== null && _o !== void 0 ? _o : bcName,
2956
+ bcName: hierarchyBcName,
2957
+ bcUrl: buildBcUrl(hierarchyBcName, true, state),
2758
2958
  cursor: action.payload.removedItem.id,
2759
2959
  dataItem: __assign(__assign({}, action.payload.removedItem), { _associate: false })
2760
- })), (0, import_rxjs47.of)(changeDataItem({
2960
+ })), (0, import_rxjs48.of)(changeDataItem({
2761
2961
  bcName: bcName,
2962
+ bcUrl: buildBcUrl(bcName, true, state),
2762
2963
  cursor: cursor,
2763
2964
  dataItem: (_b = {}, _b[associateFieldKey] = action.payload.dataItem, _b)
2764
2965
  })));
2765
2966
  }
2766
- return (0, import_rxjs47.concat)((0, import_rxjs47.of)(changeDataItem({
2967
+ return (0, import_rxjs48.concat)((0, import_rxjs48.of)(changeDataItem({
2767
2968
  bcName: popupBcName,
2969
+ bcUrl: buildBcUrl(popupBcName, true, state),
2768
2970
  cursor: action.payload.removedItem.id,
2769
2971
  dataItem: __assign(__assign({}, action.payload.removedItem), { _associate: false })
2770
- })), (0, import_rxjs47.of)(changeDataItem({
2972
+ })), (0, import_rxjs48.of)(changeDataItem({
2771
2973
  bcName: bcName,
2974
+ bcUrl: buildBcUrl(bcName, true, state),
2772
2975
  cursor: cursor,
2773
2976
  dataItem: (_c = {}, _c[associateFieldKey] = action.payload.dataItem, _c)
2774
2977
  })));
2775
2978
  })); };
2776
2979
  // src/epics/data/bcFetchRowMetaRequestEpic.ts
2777
- var import_rxjs48 = require("rxjs");
2980
+ var import_rxjs49 = require("rxjs");
2778
2981
  var bcFetchRowMetaRequestEpic = function (action$, state$, _a) {
2779
2982
  var api = _a.api;
2780
- return action$.pipe((0, import_rxjs48.filter)(bcFetchRowMeta.match), (0, import_rxjs48.mergeMap)(function (action) {
2983
+ return action$.pipe((0, import_rxjs49.filter)(bcFetchRowMeta.match), (0, import_rxjs49.mergeMap)(function (action) {
2984
+ var _a, _b;
2781
2985
  var state = state$.value;
2782
2986
  var screenName = state.screen.screenName;
2783
2987
  var bcName = action.payload.bcName;
2784
- var cursor = state.screen.bo.bc[bcName].cursor;
2785
- var bcUrl = buildBcUrl(bcName, true);
2988
+ var cursor = (_a = state.screen.bo.bc[bcName].cursor) !== null && _a !== void 0 ? _a : "";
2989
+ var bcUrl = (_b = buildBcUrl(bcName, true, state)) !== null && _b !== void 0 ? _b : "";
2786
2990
  var canceler = api.createCanceler();
2787
2991
  var cancelFlow = cancelRequestEpic(action$, cancelRequestActionTypes, canceler.cancel, bcFetchRowMetaFail({ bcName: bcName }));
2788
2992
  var cancelByParentBc = cancelRequestEpic(action$, [bcSelectRecord], canceler.cancel, bcFetchRowMetaFail({ bcName: bcName }), function (filteredAction) {
2789
2993
  var actionBc = filteredAction.payload.bcName;
2790
2994
  return state.screen.bo.bc[bcName].parentName === actionBc;
2791
2995
  });
2792
- var normalFlow = api.fetchRowMeta(screenName, bcUrl, void 0, canceler.cancelToken).pipe((0, import_rxjs48.map)(function (rowMeta) {
2996
+ var normalFlow = api.fetchRowMeta(screenName, bcUrl, void 0, canceler.cancelToken).pipe((0, import_rxjs49.map)(function (rowMeta) {
2793
2997
  return bcFetchRowMetaSuccess({ bcName: bcName, rowMeta: rowMeta, bcUrl: bcUrl, cursor: cursor });
2794
- }), (0, import_rxjs48.catchError)(function (error) {
2998
+ }), (0, import_rxjs49.catchError)(function (error) {
2795
2999
  console.error(error);
2796
- return (0, import_rxjs48.of)(bcFetchRowMetaFail({ bcName: bcName }));
3000
+ return (0, import_rxjs49.concat)((0, import_rxjs49.of)(bcFetchRowMetaFail({ bcName: bcName })), createApiErrorObservable(error));
2797
3001
  }));
2798
- return (0, import_rxjs48.race)(cancelFlow, cancelByParentBc, normalFlow);
3002
+ return (0, import_rxjs49.race)(cancelFlow, cancelByParentBc, normalFlow);
2799
3003
  }));
2800
3004
  };
2801
3005
  // src/epics/data/changeAssociationFullEpic.ts
2802
- var import_rxjs49 = require("rxjs");
2803
- var changeAssociationFullEpic = function (action$, state$) { return action$.pipe((0, import_rxjs49.filter)(changeAssociationFull.match), (0, import_rxjs49.mergeMap)(function (action) {
3006
+ var import_rxjs50 = require("rxjs");
3007
+ var changeAssociationFullEpic = function (action$, state$) { return action$.pipe((0, import_rxjs50.filter)(changeAssociationFull.match), (0, import_rxjs50.mergeMap)(function (action) {
2804
3008
  var _a, _b, _c, _d, _e;
2805
3009
  var state = state$.value;
2806
3010
  var result = [];
@@ -2829,7 +3033,7 @@ var changeAssociationFullEpic = function (action$, state$) { return action$.pipe
2829
3033
  return false;
2830
3034
  });
2831
3035
  if (prevSelected) {
2832
- result.push((0, import_rxjs49.of)(changeAssociationFull({
3036
+ result.push((0, import_rxjs50.of)(changeAssociationFull({
2833
3037
  bcName: bcName,
2834
3038
  depth: depth,
2835
3039
  widgetName: action.payload.widgetName,
@@ -2839,7 +3043,7 @@ var changeAssociationFullEpic = function (action$, state$) { return action$.pipe
2839
3043
  }
2840
3044
  }
2841
3045
  else {
2842
- result.push((0, import_rxjs49.of)(changeDescendantsAssociationsFull({
3046
+ result.push((0, import_rxjs50.of)(changeDescendantsAssociationsFull({
2843
3047
  bcName: bcName,
2844
3048
  parentId: action.payload.dataItem.id,
2845
3049
  depth: depth + 1,
@@ -2848,17 +3052,18 @@ var changeAssociationFullEpic = function (action$, state$) { return action$.pipe
2848
3052
  })));
2849
3053
  }
2850
3054
  }
2851
- result.push((0, import_rxjs49.of)(changeDataItem({
3055
+ result.push((0, import_rxjs50.of)(changeDataItem({
2852
3056
  bcName: action.payload.bcName,
3057
+ bcUrl: buildBcUrl(action.payload.bcName, true, state),
2853
3058
  cursor: action.payload.dataItem.id,
2854
3059
  dataItem: action.payload.dataItem
2855
3060
  })));
2856
3061
  if (parentDepth && hierarchyTraverse && selected) {
2857
- result.push((0, import_rxjs49.of)(changeAssociationFull({
3062
+ result.push((0, import_rxjs50.of)(changeAssociationFull({
2858
3063
  bcName: bcName,
2859
3064
  depth: parentDepth,
2860
3065
  widgetName: action.payload.widgetName,
2861
- dataItem: __assign(__assign({}, parentItem), { _associate: true, _value: parentItem[assocValueKey] }),
3066
+ dataItem: __assign(__assign({}, parentItem), { _associate: true, _value: parentItem === null || parentItem === void 0 ? void 0 : parentItem[assocValueKey] }),
2862
3067
  assocValueKey: assocValueKey
2863
3068
  })));
2864
3069
  }
@@ -2870,7 +3075,7 @@ var changeAssociationFullEpic = function (action$, state$) { return action$.pipe
2870
3075
  var deltaFalseId_1 = delta && ((_e = Object.values(delta)) === null || _e === void 0 ? void 0 : _e.filter(function (item) { return item._associate === false; }).map(function (item) { return item.id; }));
2871
3076
  var wasLastInData = currentLevelData.filter(function (item) { return item.id !== action.payload.dataItem.id && !(deltaFalseId_1 === null || deltaFalseId_1 === void 0 ? void 0 : deltaFalseId_1.includes(item.id)); }).every(function (item) { return !item._associate; });
2872
3077
  if (wasLastInData && wasLastInDelta) {
2873
- result.push((0, import_rxjs49.of)(changeAssociationFull({
3078
+ result.push((0, import_rxjs50.of)(changeAssociationFull({
2874
3079
  bcName: bcName,
2875
3080
  depth: parentDepth,
2876
3081
  widgetName: action.payload.widgetName,
@@ -2879,66 +3084,69 @@ var changeAssociationFullEpic = function (action$, state$) { return action$.pipe
2879
3084
  })));
2880
3085
  }
2881
3086
  }
2882
- return (0, import_rxjs49.concat).apply(void 0, result);
3087
+ return (0, import_rxjs50.concat).apply(void 0, result);
2883
3088
  })); };
2884
3089
  // src/epics/data/saveAssociationsActiveEpic.ts
2885
- var import_rxjs50 = require("rxjs");
3090
+ var import_rxjs51 = require("rxjs");
2886
3091
  var saveAssociationsActiveEpic = function (action$, state$, _a) {
2887
3092
  var api = _a.api;
2888
- return action$.pipe((0, import_rxjs50.filter)(saveAssociations.match), (0, import_rxjs50.filter)(function (action) {
2889
- return state$.value.view.popupData.active;
2890
- }), (0, import_rxjs50.switchMap)(function (action) {
3093
+ return action$.pipe((0, import_rxjs51.filter)(saveAssociations.match), (0, import_rxjs51.filter)(function (action) {
3094
+ var _a;
3095
+ return (_a = state$.value.view.popupData) === null || _a === void 0 ? void 0 : _a.active;
3096
+ }), (0, import_rxjs51.switchMap)(function (action) {
3097
+ var _a, _b;
2891
3098
  var state = state$.value;
2892
- var calleeBCName = state.view.popupData.calleeBCName;
2893
- var calleeWidgetName = state.view.popupData.calleeWidgetName;
3099
+ var calleeBCName = (_a = state.view.popupData) === null || _a === void 0 ? void 0 : _a.calleeBCName;
3100
+ var calleeWidgetName = (_b = state.view.popupData) === null || _b === void 0 ? void 0 : _b.calleeWidgetName;
2894
3101
  var bcNames = action.payload.bcNames;
2895
- var bcUrl = buildBcUrl(calleeBCName, true);
3102
+ var bcUrl = buildBcUrl(calleeBCName, true, state);
2896
3103
  var pendingChanges = state.view.pendingDataChanges[bcNames[0]] || {};
2897
3104
  var params = bcNames.length ? { _bcName: bcNames[bcNames.length - 1] } : {};
2898
- return api.associate(state.screen.screenName, bcUrl, Object.values(pendingChanges).filter(function (i) { return i._associate; }), params).pipe((0, import_rxjs50.mergeMap)(function (response) {
3105
+ return api.associate(state.screen.screenName, bcUrl, Object.values(pendingChanges).filter(function (i) { return i._associate; }), params).pipe((0, import_rxjs51.mergeMap)(function (response) {
2899
3106
  var postInvoke = response.postActions[0];
2900
3107
  var calleeWidget = state.view.widgets.find(function (widgetItem) { return widgetItem.bcName === calleeBCName; });
2901
- return (0, import_rxjs50.concat)(postInvoke ? (0, import_rxjs50.of)(processPostInvoke({ bcName: calleeBCName, postInvoke: postInvoke, widgetName: calleeWidget.name })) : import_rxjs50.EMPTY, (0, import_rxjs50.of)(bcCancelPendingChanges({ bcNames: bcNames })), (0, import_rxjs50.of)(bcForceUpdate({ bcName: calleeBCName, widgetName: calleeWidgetName })));
2902
- }), (0, import_rxjs50.catchError)(function (err) {
3108
+ return (0, import_rxjs51.concat)(postInvoke ? (0, import_rxjs51.of)(processPostInvoke({ bcName: calleeBCName, postInvoke: postInvoke, widgetName: calleeWidget === null || calleeWidget === void 0 ? void 0 : calleeWidget.name })) : import_rxjs51.EMPTY, (0, import_rxjs51.of)(bcCancelPendingChanges({ bcNames: bcNames })), (0, import_rxjs51.of)(bcForceUpdate({ bcName: calleeBCName, widgetName: calleeWidgetName })));
3109
+ }), (0, import_rxjs51.catchError)(function (err) {
2903
3110
  console.error(err);
2904
- return import_rxjs50.EMPTY;
3111
+ return import_rxjs51.EMPTY;
2905
3112
  }));
2906
3113
  }));
2907
3114
  };
2908
3115
  // src/epics/data/changeAssociationSameBcEpic.ts
2909
- var import_rxjs51 = require("rxjs");
2910
- var changeAssociationSameBcEpic = function (action$, state$) { return action$.pipe((0, import_rxjs51.filter)(changeAssociationSameBc.match), (0, import_rxjs51.mergeMap)(function (action) {
2911
- var _a, _b, _c, _d, _e;
3116
+ var import_rxjs52 = require("rxjs");
3117
+ var changeAssociationSameBcEpic = function (action$, state$) { return action$.pipe((0, import_rxjs52.filter)(changeAssociationSameBc.match), (0, import_rxjs52.mergeMap)(function (action) {
3118
+ var _a, _b, _c, _d, _e, _f;
3119
+ var state = state$.value;
2912
3120
  var bcName = action.payload.bcName;
2913
3121
  var result = [
2914
- (0, import_rxjs51.of)(changeDataItem({
3122
+ (0, import_rxjs52.of)(changeDataItem({
2915
3123
  bcName: bcName,
3124
+ bcUrl: buildBcUrl(bcName, true, state),
2916
3125
  cursor: action.payload.dataItem.id,
2917
3126
  dataItem: action.payload.dataItem
2918
3127
  }))
2919
3128
  ];
2920
- var state = state$.value;
2921
3129
  var selected = action.payload.dataItem._associate;
2922
3130
  var depth = action.payload.depth || 1;
2923
3131
  var parentDepth = depth - 1;
2924
3132
  var widget = state.view.widgets.find(function (item) { return item.name === action.payload.widgetName; });
2925
3133
  var hierarchyTraverse = (_a = widget.options) === null || _a === void 0 ? void 0 : _a.hierarchyTraverse;
2926
3134
  var currentData = depth > 1 ? (_b = state.depthData[depth]) === null || _b === void 0 ? void 0 : _b[bcName] : state.data[bcName];
2927
- var parentCursor = parentDepth ? parentDepth > 1 ? (_c = state.screen.bo.bc[bcName].depthBc[parentDepth]) === null || _c === void 0 ? void 0 : _c.cursor : state.screen.bo.bc[bcName].cursor : null;
2928
- var parentItem = parentCursor ? parentDepth > 1 ? (_e = (_d = state.depthData[parentDepth]) === null || _d === void 0 ? void 0 : _d[bcName]) === null || _e === void 0 ? void 0 : _e.find(function (item) { return item.id === parentCursor; }) : state.data[bcName].find(function (item) { return item.id === parentCursor; }) : null;
3135
+ var parentCursor = parentDepth ? parentDepth > 1 ? (_d = (_c = state.screen.bo.bc[bcName].depthBc) === null || _c === void 0 ? void 0 : _c[parentDepth]) === null || _d === void 0 ? void 0 : _d.cursor : state.screen.bo.bc[bcName].cursor : null;
3136
+ var parentItem = parentCursor ? parentDepth > 1 ? (_f = (_e = state.depthData[parentDepth]) === null || _e === void 0 ? void 0 : _e[bcName]) === null || _f === void 0 ? void 0 : _f.find(function (item) { return item.id === parentCursor; }) : state.data[bcName].find(function (item) { return item.id === parentCursor; }) : null;
2929
3137
  if (parentDepth && hierarchyTraverse && selected) {
2930
- result.push((0, import_rxjs51.of)(changeAssociationSameBc({
3138
+ result.push((0, import_rxjs52.of)(changeAssociationSameBc({
2931
3139
  bcName: bcName,
2932
3140
  depth: parentDepth,
2933
3141
  widgetName: action.payload.widgetName,
2934
- dataItem: __assign(__assign({}, parentItem), { _associate: true, _value: parentItem[action.payload.assocValueKey] }),
3142
+ dataItem: __assign(__assign({}, parentItem), { _associate: true, _value: parentItem === null || parentItem === void 0 ? void 0 : parentItem[action.payload.assocValueKey] }),
2935
3143
  assocValueKey: action.payload.assocValueKey
2936
3144
  })));
2937
3145
  }
2938
3146
  if (parentDepth && hierarchyTraverse && !selected) {
2939
3147
  var wasLastInData = currentData.filter(function (item) { return item.id !== action.payload.dataItem.id; }).every(function (item) { return !item._associate; });
2940
3148
  if (wasLastInData) {
2941
- result.push((0, import_rxjs51.of)(changeAssociationSameBc({
3149
+ result.push((0, import_rxjs52.of)(changeAssociationSameBc({
2942
3150
  bcName: bcName,
2943
3151
  depth: parentDepth,
2944
3152
  widgetName: action.payload.widgetName,
@@ -2947,38 +3155,40 @@ var changeAssociationSameBcEpic = function (action$, state$) { return action$.pi
2947
3155
  })));
2948
3156
  }
2949
3157
  }
2950
- return (0, import_rxjs51.concat).apply(void 0, result);
3158
+ return (0, import_rxjs52.concat).apply(void 0, result);
2951
3159
  })); };
2952
3160
  // src/epics/data/inlinePickListFetchDataEpic.ts
2953
- var import_rxjs52 = require("rxjs");
3161
+ var import_rxjs53 = require("rxjs");
2954
3162
  var inlinePickListFetchDataEpic = function (action$, state$, _a) {
2955
3163
  var api = _a.api;
2956
- return action$.pipe((0, import_rxjs52.filter)(inlinePickListFetchDataRequest.match), (0, import_rxjs52.mergeMap)(function (action) {
3164
+ return action$.pipe((0, import_rxjs53.filter)(inlinePickListFetchDataRequest.match), (0, import_rxjs53.mergeMap)(function (action) {
2957
3165
  var _a;
2958
3166
  var _b = action.payload, bcName = _b.bcName, searchSpec = _b.searchSpec, searchString = _b.searchString;
2959
- var bcUrl = buildBcUrl(bcName, false);
3167
+ var state = state$.value;
3168
+ var bcUrl = buildBcUrl(bcName, false, state);
2960
3169
  var canceler = api.createCanceler();
2961
3170
  var cancelFlow = cancelRequestEpic(action$, cancelRequestActionTypes, canceler.cancel, bcFetchDataFail({ bcName: bcName, bcUrl: bcUrl }));
2962
- var normalFlow = api.fetchBcData(state$.value.screen.screenName, bcUrl, (_a = {}, _a[searchSpec + ".contains"] = searchString, _a), canceler.cancelToken).pipe((0, import_rxjs52.mergeMap)(function (data) {
2963
- return (0, import_rxjs52.of)(bcFetchDataSuccess({ bcName: bcName, data: data.data, bcUrl: bcUrl }));
2964
- }), (0, import_rxjs52.catchError)(function (error) {
3171
+ var normalFlow = api.fetchBcData(state$.value.screen.screenName, bcUrl, (_a = {}, _a[searchSpec + ".contains"] = searchString, _a), canceler.cancelToken).pipe((0, import_rxjs53.mergeMap)(function (data) {
3172
+ return (0, import_rxjs53.of)(bcFetchDataSuccess({ bcName: bcName, data: data.data, bcUrl: bcUrl }));
3173
+ }), (0, import_rxjs53.catchError)(function (error) {
2965
3174
  console.error(error);
2966
- return (0, import_rxjs52.of)(bcFetchDataFail({ bcName: action.payload.bcName, bcUrl: bcUrl }));
3175
+ return (0, import_rxjs53.of)(bcFetchDataFail({ bcName: action.payload.bcName, bcUrl: bcUrl }));
2967
3176
  }));
2968
- return (0, import_rxjs52.race)(cancelFlow, normalFlow);
3177
+ return (0, import_rxjs53.race)(cancelFlow, normalFlow);
2969
3178
  }));
2970
3179
  };
2971
3180
  // src/epics/data/saveAssociationsPassiveEpic.ts
2972
- var import_rxjs53 = require("rxjs");
2973
- var saveAssociationsPassiveEpic = function (action$, state$) { return action$.pipe((0, import_rxjs53.filter)(saveAssociations.match), (0, import_rxjs53.filter)(function () {
2974
- return !state$.value.view.popupData.active;
2975
- }), (0, import_rxjs53.switchMap)(function (action) {
3181
+ var import_rxjs54 = require("rxjs");
3182
+ var saveAssociationsPassiveEpic = function (action$, state$) { return action$.pipe((0, import_rxjs54.filter)(saveAssociations.match), (0, import_rxjs54.filter)(function () {
3183
+ var _a;
3184
+ return !((_a = state$.value.view.popupData) === null || _a === void 0 ? void 0 : _a.active);
3185
+ }), (0, import_rxjs54.switchMap)(function (action) {
2976
3186
  var _a, _b;
2977
- var _c;
3187
+ var _c, _d;
2978
3188
  var state = state$.value;
2979
- var _d = state.view.popupData, _e = _d.calleeBCName, calleeBCName = _e === void 0 ? action.payload.calleeBcName : _e, _f = _d.associateFieldKey, associateFieldKey = _f === void 0 ? action.payload.associateFieldKey : _f;
3189
+ var _e = (_c = state.view.popupData) !== null && _c !== void 0 ? _c : {}, _f = _e.calleeBCName, calleeBCName = _f === void 0 ? action.payload.calleeBcName : _f, _g = _e.associateFieldKey, associateFieldKey = _g === void 0 ? action.payload.associateFieldKey : _g;
2980
3190
  var cursor = state.screen.bo.bc[calleeBCName].cursor;
2981
- var recordPrevData = (_c = state.data[calleeBCName].find(function (dataStateRecord) { return dataStateRecord.id === cursor; })[associateFieldKey]) !== null && _c !== void 0 ? _c : [];
3191
+ var recordPrevData = (_d = state.data[calleeBCName].find(function (dataStateRecord) { return dataStateRecord.id === cursor; })[associateFieldKey]) !== null && _d !== void 0 ? _d : [];
2982
3192
  var newValues = [];
2983
3193
  action.payload.bcNames.forEach(function (pendingBc) {
2984
3194
  var pendingChanges = state.view.pendingDataChanges[pendingBc] || {};
@@ -3002,8 +3212,9 @@ var saveAssociationsPassiveEpic = function (action$, state$) { return action$.pi
3002
3212
  }
3003
3213
  return true;
3004
3214
  })).concat.apply(_a, addedItems);
3005
- return (0, import_rxjs53.of)(changeDataItem({
3215
+ return (0, import_rxjs54.of)(changeDataItem({
3006
3216
  bcName: calleeBCName,
3217
+ bcUrl: buildBcUrl(calleeBCName, true, state),
3007
3218
  cursor: cursor,
3008
3219
  dataItem: (_b = {},
3009
3220
  _b[associateFieldKey] = result,
@@ -3011,13 +3222,13 @@ var saveAssociationsPassiveEpic = function (action$, state$) { return action$.pi
3011
3222
  }));
3012
3223
  })); };
3013
3224
  // src/epics/data/changeChildrenAssociationsEpic.ts
3014
- var import_rxjs54 = require("rxjs");
3225
+ var import_rxjs55 = require("rxjs");
3015
3226
  var changeChildrenAssociationsEpic = function (action$, state$, _a) {
3016
3227
  var api = _a.api;
3017
- return action$.pipe((0, import_rxjs54.filter)(changeChildrenAssociations.match), (0, import_rxjs54.mergeMap)(function (action) {
3228
+ return action$.pipe((0, import_rxjs55.filter)(changeChildrenAssociations.match), (0, import_rxjs55.mergeMap)(function (action) {
3018
3229
  var state = state$.value;
3019
3230
  var data = state.data[action.payload.bcName];
3020
- return (0, import_rxjs54.of)(changeDataItems({
3231
+ return (0, import_rxjs55.of)(changeDataItems({
3021
3232
  bcName: action.payload.bcName,
3022
3233
  cursors: data.map(function (item) { return item.id; }),
3023
3234
  dataItems: data.map(function (item) { return (__assign(__assign({}, item), { _value: item[action.payload.assocValueKey], _associate: action.payload.selected })); })
@@ -3025,26 +3236,26 @@ var changeChildrenAssociationsEpic = function (action$, state$, _a) {
3025
3236
  }));
3026
3237
  };
3027
3238
  // src/epics/data/changeChildrenAssociationsSameBcEpic.ts
3028
- var import_rxjs55 = require("rxjs");
3029
- var changeChildrenAssociationsSameBcEpic = function (action$, state$) { return action$.pipe((0, import_rxjs55.filter)(changeChildrenAssociationsSameBc.match), (0, import_rxjs55.mergeMap)(function (action) {
3239
+ var import_rxjs56 = require("rxjs");
3240
+ var changeChildrenAssociationsSameBcEpic = function (action$, state$) { return action$.pipe((0, import_rxjs56.filter)(changeChildrenAssociationsSameBc.match), (0, import_rxjs56.mergeMap)(function (action) {
3030
3241
  var _a;
3031
3242
  var state = state$.value;
3032
3243
  var data = ((_a = state.depthData[action.payload.depth]) === null || _a === void 0 ? void 0 : _a[action.payload.bcName]) || [];
3033
- return (0, import_rxjs55.of)(changeDataItems({
3244
+ return (0, import_rxjs56.of)(changeDataItems({
3034
3245
  bcName: action.payload.bcName,
3035
3246
  cursors: data.map(function (item) { return item.id; }),
3036
3247
  dataItems: data.map(function (item) { return (__assign(__assign({}, item), { _value: item[action.payload.assocValueKey], _associate: action.payload.selected })); })
3037
3248
  }));
3038
3249
  })); };
3039
3250
  // src/epics/data/changeDescendantsAssociationsFullEpic.ts
3040
- var import_rxjs56 = require("rxjs");
3041
- var changeDescendantsAssociationsFullEpic = function (action$, state$) { return action$.pipe((0, import_rxjs56.filter)(changeDescendantsAssociationsFull.match), (0, import_rxjs56.mergeMap)(function (action) {
3251
+ var import_rxjs57 = require("rxjs");
3252
+ var changeDescendantsAssociationsFullEpic = function (action$, state$) { return action$.pipe((0, import_rxjs57.filter)(changeDescendantsAssociationsFull.match), (0, import_rxjs57.mergeMap)(function (action) {
3042
3253
  var state = state$.value;
3043
3254
  var depth = action.payload.depth;
3044
3255
  var data = state.data[action.payload.bcName];
3045
3256
  var targetData = (data || []).filter(function (item) { return item.level === depth && item.parentId === action.payload.parentId; });
3046
3257
  var result = [
3047
- (0, import_rxjs56.of)(changeDataItems({
3258
+ (0, import_rxjs57.of)(changeDataItems({
3048
3259
  bcName: action.payload.bcName,
3049
3260
  cursors: targetData.map(function (item) { return item.id; }),
3050
3261
  dataItems: targetData.map(function (item) { return (__assign(__assign({}, item), { _value: item[action.payload.assocValueKey], _associate: action.payload.selected })); })
@@ -3052,14 +3263,14 @@ var changeDescendantsAssociationsFullEpic = function (action$, state$) { return
3052
3263
  ];
3053
3264
  targetData.forEach(function (targetDataItem) {
3054
3265
  if (data.find(function (dataItem) { return dataItem.parentId === targetDataItem.id; })) {
3055
- result.push((0, import_rxjs56.of)(changeDescendantsAssociationsFull(__assign(__assign({}, action.payload), { parentId: targetDataItem.id, depth: depth + 1 }))));
3266
+ result.push((0, import_rxjs57.of)(changeDescendantsAssociationsFull(__assign(__assign({}, action.payload), { parentId: targetDataItem.id, depth: depth + 1 }))));
3056
3267
  }
3057
3268
  });
3058
- return (0, import_rxjs56.concat).apply(void 0, result);
3269
+ return (0, import_rxjs57.concat).apply(void 0, result);
3059
3270
  })); };
3060
3271
  // src/api/ObservableApiWrapper.ts
3061
3272
  var import_axios2 = __toESM(require("axios"));
3062
- var import_rxjs57 = require("rxjs");
3273
+ var import_rxjs58 = require("rxjs");
3063
3274
  function redirectOccurred(value) {
3064
3275
  var _a;
3065
3276
  if ((_a = value.data) === null || _a === void 0 ? void 0 : _a.redirectUrl) {
@@ -3084,26 +3295,24 @@ var ObservableApiWrapper = /** @class */ (function () {
3084
3295
  this.instance = instance;
3085
3296
  }
3086
3297
  class_2.prototype.get = function (path, config, callContext) {
3087
- if (config === void 0) { config = {}; }
3088
- return (0, import_rxjs57.from)(this.instance.get(path, config)).pipe((0, import_rxjs57.takeWhile)(redirectOccurred), (0, import_rxjs57.map)(function (response) { return response.data; }));
3298
+ return (0, import_rxjs58.from)(this.instance.get(path, config)).pipe((0, import_rxjs58.takeWhile)(redirectOccurred), (0, import_rxjs58.map)(function (response) { return response.data; }));
3089
3299
  };
3090
3300
  class_2.prototype.put = function (path, data, callContext) {
3091
- return (0, import_rxjs57.from)(this.instance.put(path, data)).pipe((0, import_rxjs57.takeWhile)(redirectOccurred), (0, import_rxjs57.map)(function (response) { return response.data; }));
3301
+ return (0, import_rxjs58.from)(this.instance.put(path, data)).pipe((0, import_rxjs58.takeWhile)(redirectOccurred), (0, import_rxjs58.map)(function (response) { return response.data; }));
3092
3302
  };
3093
3303
  class_2.prototype.post = function (path, data, config, callContext) {
3094
- return (0, import_rxjs57.from)(this.instance.post(path, data)).pipe((0, import_rxjs57.takeWhile)(redirectOccurred), (0, import_rxjs57.map)(function (response) { return response.data; }));
3304
+ return (0, import_rxjs58.from)(this.instance.post(path, data)).pipe((0, import_rxjs58.takeWhile)(redirectOccurred), (0, import_rxjs58.map)(function (response) { return response.data; }));
3095
3305
  };
3096
3306
  class_2.prototype.delete = function (path, data, config, callContext) {
3097
- return (0, import_rxjs57.from)(this.instance.delete(path, data)).pipe((0, import_rxjs57.takeWhile)(redirectOccurred), (0, import_rxjs57.map)(function (response) { return response.data; }));
3307
+ return (0, import_rxjs58.from)(this.instance.delete(path, data)).pipe((0, import_rxjs58.takeWhile)(redirectOccurred), (0, import_rxjs58.map)(function (response) { return response.data; }));
3098
3308
  };
3099
3309
  return class_2;
3100
3310
  }());
3101
3311
  // src/api/ObservableApi.ts
3102
3312
  var import_axios3 = __toESM(require("axios"));
3103
- var import_rxjs58 = require("rxjs");
3313
+ var import_rxjs59 = require("rxjs");
3104
3314
  var Api = /** @class */ (function () {
3105
3315
  function class_3(instance) {
3106
- this.api$ = new ObservableApiWrapper();
3107
3316
  this.api$ = new ObservableApiWrapper(instance);
3108
3317
  }
3109
3318
  class_3.prototype.routerRequest = function (path, params) {
@@ -3120,31 +3329,32 @@ var Api = /** @class */ (function () {
3120
3329
  var _this = this;
3121
3330
  if (params === void 0) { params = {}; }
3122
3331
  var currentPage = 1;
3123
- return this.fetchBcData(screenName, bcUrl, __assign(__assign({}, params), { _page: currentPage })).pipe((0, import_rxjs58.expand)(function (response) {
3124
- return response.hasNext ? _this.fetchBcData(screenName, bcUrl, __assign(__assign({}, params), { _page: ++currentPage })) : import_rxjs58.EMPTY;
3125
- }), (0, import_rxjs58.reduce)(function (items, nextResponse) {
3332
+ return this.fetchBcData(screenName, bcUrl, __assign(__assign({}, params), { _page: currentPage })).pipe((0, import_rxjs59.expand)(function (response) {
3333
+ return response.hasNext ? _this.fetchBcData(screenName, bcUrl, __assign(__assign({}, params), { _page: ++currentPage })) : import_rxjs59.EMPTY;
3334
+ }), (0, import_rxjs59.reduce)(function (items, nextResponse) {
3126
3335
  return __spreadArray(__spreadArray([], items, true), nextResponse.data, true);
3127
3336
  }, []));
3128
3337
  };
3129
3338
  class_3.prototype.fetchRowMeta = function (screenName, bcUrl, params, cancelToken) {
3130
3339
  var url = applyParams(buildUrl(__makeTemplateObject(["row-meta/", "/"], ["row-meta/", "/"]), screenName) + bcUrl, params);
3131
- return this.api$.get(url, { cancelToken: cancelToken }).pipe((0, import_rxjs58.map)(function (response) { return response.data.row; }));
3340
+ return this.api$.get(url, { cancelToken: cancelToken }).pipe((0, import_rxjs59.map)(function (response) { var _a; return (_a = response.data) === null || _a === void 0 ? void 0 : _a.row; }));
3132
3341
  };
3133
3342
  class_3.prototype.newBcData = function (screenName, bcUrl, context, params) {
3134
3343
  var url = applyParams(buildUrl(__makeTemplateObject(["row-meta-new/", "/"], ["row-meta-new/", "/"]), screenName) + bcUrl, params);
3135
- return this.api$.get(url, null, context).pipe((0, import_rxjs58.map)(function (response) { return response.data; }));
3344
+ return this.api$.get(url, void 0, context).pipe((0, import_rxjs59.map)(function (response) { return response.data; }));
3136
3345
  };
3137
3346
  class_3.prototype.saveBcData = function (screenName, bcUrl, data, context, params) {
3138
3347
  var url = applyParams(buildUrl(__makeTemplateObject(["data/", "/"], ["data/", "/"]), screenName) + bcUrl, params);
3139
- return this.api$.put(url, { data: data }, context).pipe((0, import_rxjs58.map)(function (response) { return response.data; }));
3348
+ return this.api$.put(url, { data: data }, context).pipe((0, import_rxjs59.map)(function (response) { return response.data; }));
3140
3349
  };
3141
3350
  class_3.prototype.deleteBcData = function (screenName, bcUrl, context, params) {
3351
+ if (bcUrl === void 0) { bcUrl = ""; }
3142
3352
  var url = applyParams(buildUrl(__makeTemplateObject(["data/", "/"], ["data/", "/"]), screenName) + bcUrl, params);
3143
- return this.api$.delete(url, context).pipe((0, import_rxjs58.map)(function (response) { return response.data; }));
3353
+ return this.api$.delete(url, context).pipe((0, import_rxjs59.map)(function (response) { return response.data; }));
3144
3354
  };
3145
3355
  class_3.prototype.customAction = function (screenName, bcUrl, data, context, params) {
3146
3356
  var url = applyParams(buildUrl(__makeTemplateObject(["custom-action/", "/"], ["custom-action/", "/"]), screenName) + bcUrl, params);
3147
- return this.api$.post(url, { data: data || {} }, null, context).pipe((0, import_rxjs58.map)(function (response) { return response.data; }));
3357
+ return this.api$.post(url, { data: data || {} }, void 0, context).pipe((0, import_rxjs59.map)(function (response) { return response.data; }));
3148
3358
  };
3149
3359
  class_3.prototype.associate = function (screenName, bcUrl, data, params) {
3150
3360
  var processedData = Array.isArray(data) ? data.map(function (item) { return ({
@@ -3153,12 +3363,30 @@ var Api = /** @class */ (function () {
3153
3363
  associated: item._associate
3154
3364
  }); }) : data;
3155
3365
  var url = applyParams(buildUrl(__makeTemplateObject(["associate/", "/"], ["associate/", "/"]), screenName) + bcUrl, params);
3156
- return this.api$.post(url, processedData).pipe((0, import_rxjs58.map)(function (response) { return response.data; }));
3366
+ return this.api$.post(url, processedData).pipe((0, import_rxjs59.map)(function (response) { return response.data; }));
3157
3367
  };
3158
3368
  class_3.prototype.getRmByForceActive = function (screenName, bcUrl, data, params) {
3159
- var url = applyParams(buildUrl(__makeTemplateObject(["row-meta/", "/"], ["row-meta/", "/"]), screenName) + bcUrl, params);
3160
- return this.api$.post(url, { data: data }).pipe((0, import_rxjs58.map)(function (response) { return response.data.row; }));
3369
+ var url = applyParams(buildUrl(__makeTemplateObject(["row-meta/", "/"], ["row-meta/", "/"]), screenName) + (bcUrl !== null && bcUrl !== void 0 ? bcUrl : ""), params);
3370
+ return this.api$.post(url, { data: data }).pipe((0, import_rxjs59.map)(function (response) { return response.data.row; }));
3161
3371
  };
3372
+ Object.defineProperty(class_3.prototype, "fileUploadEndpoint", {
3373
+ /**
3374
+ * Get Cxbox API file upload endpoint based on baseURL of axios instance
3375
+ *
3376
+ * Handles empty baseURL and trailing slash
3377
+ *
3378
+ * @returns File upload endpoint
3379
+ */
3380
+ get: function () {
3381
+ var instance = this.api$.instance;
3382
+ if (!instance.defaults.baseURL) {
3383
+ return "/file";
3384
+ }
3385
+ return instance.defaults.baseURL.endsWith("/") ? "".concat(instance.defaults.baseURL, "file") : "".concat(instance.defaults.baseURL, "/file");
3386
+ },
3387
+ enumerable: false,
3388
+ configurable: true
3389
+ });
3162
3390
  class_3.prototype.refreshMeta = function () {
3163
3391
  return this.api$.get(buildUrl(__makeTemplateObject(["bc-registry/refresh-meta"], ["bc-registry/refresh-meta"])));
3164
3392
  };
@@ -3177,13 +3405,241 @@ var Api = /** @class */ (function () {
3177
3405
  };
3178
3406
  return class_3;
3179
3407
  }());
3180
- // Annotate the CommonJS export names for ESM import in node:
3181
- 0 && (module.exports = {
3182
- Api: Api,
3183
- actions: actions,
3184
- epics: epics,
3185
- interfaces: interfaces,
3186
- reducers: reducers,
3187
- utils: utils
3188
- });
3408
+ // src/utils/autosave.ts
3409
+ function autosaveRoutine(action, store, next) {
3410
+ var _a, _b, _c;
3411
+ var state = store.getState();
3412
+ var dispatch = store.dispatch;
3413
+ var pendingDataChanges = state.view.pendingDataChanges;
3414
+ var bcList = Object.keys(pendingDataChanges);
3415
+ 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); });
3416
+ var baseBcName = bcList[baseBcNameIndex];
3417
+ if (baseBcNameIndex > -1) {
3418
+ bcList.splice(baseBcNameIndex, 1);
3419
+ }
3420
+ if (baseBcName) {
3421
+ bcList.forEach(function (bcName) {
3422
+ var _a, _b;
3423
+ var widget = (_a = state.view.widgets) === null || _a === void 0 ? void 0 : _a.find(function (v) { return v.bcName === bcName; });
3424
+ var cursor = (_b = state.screen.bo.bc[bcName]) === null || _b === void 0 ? void 0 : _b.cursor;
3425
+ if (bcHasPendingAutosaveChanges(state, bcName, cursor)) {
3426
+ dispatch(sendOperation({
3427
+ bcName: bcName,
3428
+ operationType: import_schema5.OperationTypeCrud.save,
3429
+ widgetName: widget === null || widget === void 0 ? void 0 : widget.name
3430
+ }));
3431
+ }
3432
+ });
3433
+ var baseWidget = (_c = state.view.widgets) === null || _c === void 0 ? void 0 : _c.find(function (v) { return v.bcName === baseBcName; });
3434
+ return next(sendOperation({
3435
+ bcName: baseBcName,
3436
+ operationType: import_schema5.OperationTypeCrud.save,
3437
+ widgetName: baseWidget === null || baseWidget === void 0 ? void 0 : baseWidget.name,
3438
+ onSuccessAction: action
3439
+ }));
3440
+ }
3441
+ return next(action);
3442
+ }
3443
+ function bcHasPendingAutosaveChanges(store, bcName, cursor) {
3444
+ var _a;
3445
+ var pendingChanges = store.view.pendingDataChanges;
3446
+ var cursorChanges = (_a = pendingChanges[bcName]) === null || _a === void 0 ? void 0 : _a[cursor];
3447
+ var result = cursorChanges && !Object.keys(cursorChanges).includes("_associate") && Object.values(cursorChanges).length > 0;
3448
+ return result;
3449
+ }
3450
+ function checkUnsavedChangesOfBc(store, bcName) {
3451
+ var _a, _b;
3452
+ var pendingCursors = Object.keys((_b = (_a = store.view.pendingDataChanges) === null || _a === void 0 ? void 0 : _a[bcName]) !== null && _b !== void 0 ? _b : {});
3453
+ return pendingCursors.some(function (cursor) { return bcHasPendingAutosaveChanges(store, bcName, cursor); });
3454
+ }
3455
+ // src/middlewares/autosaveMiddleware.ts
3456
+ var saveFormMiddleware = function (_a) {
3457
+ var getState = _a.getState, dispatch = _a.dispatch;
3458
+ return function (next) { return function (action) {
3459
+ var _a, _b, _c, _d, _e, _f, _g;
3460
+ var state = getState();
3461
+ var isSendOperation = sendOperation.match(action);
3462
+ var isCoreSendOperation = isSendOperation && coreOperations.includes(action.payload.operationType);
3463
+ var isSelectTableCellInit = selectTableCellInit.match(action);
3464
+ var isSaveAction = isSendOperation && action.payload.operationType === import_schema5.OperationTypeCrud.save;
3465
+ var isNotSaveAction = !isSaveAction;
3466
+ var actionBcName = isSendOperation && action.payload.bcName;
3467
+ var hasAnotherUnsavedBc = Object.keys(state.view.pendingDataChanges).filter(function (key) { return key !== actionBcName; }).filter(function (key) { return checkUnsavedChangesOfBc(state, key); }).length > 0;
3468
+ var isSendOperationForAnotherBc = isCoreSendOperation && hasAnotherUnsavedBc;
3469
+ var selectedCell = state.view.selectedCell;
3470
+ var isSelectTableCellInitOnAnotherRowOrWidget = selectedCell && isSelectTableCellInit && (selectedCell.widgetName !== action.payload.widgetName || selectedCell.rowId !== action.payload.rowId);
3471
+ 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; });
3472
+ 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;
3473
+ 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];
3474
+ var isChangeLocation = defaultSaveWidget && changeLocation.match(action) && Object.keys(pendingData || {}).length > 0;
3475
+ if (isChangeLocation) {
3476
+ return next(sendOperation({
3477
+ bcName: defaultSaveWidget.bcName,
3478
+ operationType: ((_g = defaultSaveWidget.options) === null || _g === void 0 ? void 0 : _g.actionGroups).defaultSave,
3479
+ widgetName: defaultSaveWidget.name,
3480
+ onSuccessAction: action
3481
+ }));
3482
+ }
3483
+ var isNeedSaveCondition = isNotSaveAction && (isSendOperationForAnotherBc || isSelectTableCellInitOnAnotherRowOrWidget);
3484
+ if (isNeedSaveCondition) {
3485
+ return autosaveRoutine(action, { getState: getState, dispatch: dispatch }, next);
3486
+ }
3487
+ return next(action);
3488
+ }; };
3489
+ };
3490
+ // src/middlewares/requiredFieldsMiddleware.ts
3491
+ var requiredFields = function (_a) {
3492
+ var getState = _a.getState, dispatch = _a.dispatch;
3493
+ return function (next) { return function (action) {
3494
+ var _a, _b, _c, _d;
3495
+ var state = getState();
3496
+ if (sendOperation.match(action)) {
3497
+ var _e = action.payload, bcName = _e.bcName, operationType = _e.operationType, widgetName_1 = _e.widgetName;
3498
+ var cursor_1 = (_a = state.screen.bo.bc[bcName]) === null || _a === void 0 ? void 0 : _a.cursor;
3499
+ if (cursor_1) {
3500
+ var bcUrl = buildBcUrl(bcName, true, state);
3501
+ var record = (_b = state.data[bcName]) === null || _b === void 0 ? void 0 : _b.find(function (item) { return item.id === cursor_1; });
3502
+ var rowMeta_1 = bcUrl && ((_c = state.view.rowMeta[bcName]) === null || _c === void 0 ? void 0 : _c[bcUrl]);
3503
+ var pendingValues = (_d = state.view.pendingDataChanges[bcName]) === null || _d === void 0 ? void 0 : _d[cursor_1];
3504
+ var widget_1 = state.view.widgets.find(function (item) { return item.name === widgetName_1; });
3505
+ if (operationRequiresAutosave(operationType, rowMeta_1 === null || rowMeta_1 === void 0 ? void 0 : rowMeta_1.actions)) {
3506
+ var fieldsToCheck_1 = {};
3507
+ state.view.widgets.filter(function (item) { return item.bcName === (widget_1 === null || widget_1 === void 0 ? void 0 : widget_1.bcName); }).forEach(function (item) {
3508
+ var itemFieldsCalc = item.fields;
3509
+ if (item.fields) {
3510
+ item.fields.forEach(function (block) {
3511
+ if (isWidgetFieldBlock(block)) {
3512
+ block.fields.forEach(function (field) { return itemFieldsCalc.push(field); });
3513
+ }
3514
+ });
3515
+ }
3516
+ itemFieldsCalc.forEach(function (widgetField) {
3517
+ var _a;
3518
+ 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; });
3519
+ if (!fieldsToCheck_1[widgetField.key] && matchingRowMeta && !matchingRowMeta.hidden) {
3520
+ fieldsToCheck_1[widgetField.key] = matchingRowMeta;
3521
+ }
3522
+ });
3523
+ });
3524
+ var dataItem = getRequiredFieldsMissing(record, pendingValues, Object.values(fieldsToCheck_1));
3525
+ if (dataItem && TableLikeWidgetTypes.includes(widget_1 === null || widget_1 === void 0 ? void 0 : widget_1.type)) {
3526
+ dispatch(selectTableCellInit({ widgetName: widgetName_1, rowId: cursor_1, fieldKey: Object.keys(dataItem)[0] }));
3527
+ }
3528
+ return dataItem ? next(changeDataItem({ bcName: bcName, bcUrl: buildBcUrl(bcName, true, state), cursor: cursor_1, dataItem: dataItem })) : next(action);
3529
+ }
3530
+ if (hasPendingValidationFails(state, bcName)) {
3531
+ return addNotification({
3532
+ key: "requiredFieldsMissing",
3533
+ type: "buttonWarningNotification",
3534
+ message: "Required fields are missing",
3535
+ duration: 0,
3536
+ options: {
3537
+ buttonWarningNotificationOptions: {
3538
+ buttonText: "Cancel changes",
3539
+ actionsForClick: [bcCancelPendingChanges(null), clearValidationFails(null)]
3540
+ }
3541
+ }
3542
+ });
3543
+ }
3544
+ }
3545
+ }
3546
+ return next(action);
3547
+ }; };
3548
+ };
3549
+ function operationRequiresAutosave(operationType, actions2) {
3550
+ var result = false;
3551
+ if (!actions2) {
3552
+ console.error('rowMeta is missing in the middle of "sendOperation" action');
3553
+ return result;
3554
+ }
3555
+ result = flattenOperations(actions2).some(function (action) { return action.type === operationType && action.autoSaveBefore; });
3556
+ return result;
3557
+ }
3558
+ function getRequiredFieldsMissing(record, pendingChanges, fieldsMeta) {
3559
+ var result = {};
3560
+ fieldsMeta.forEach(function (field) {
3561
+ var value = record === null || record === void 0 ? void 0 : record[field.key];
3562
+ var pendingValue = pendingChanges === null || pendingChanges === void 0 ? void 0 : pendingChanges[field.key];
3563
+ var effectiveValue = pendingValue !== void 0 ? pendingValue : value;
3564
+ var falsyValue = false;
3565
+ if (effectiveValue === null || effectiveValue === void 0 || effectiveValue === "") {
3566
+ falsyValue = true;
3567
+ }
3568
+ else if (Array.isArray(effectiveValue) && !effectiveValue.length) {
3569
+ falsyValue = true;
3570
+ }
3571
+ else if (effectiveValue && typeof effectiveValue === "object" && !Object.keys(effectiveValue).length) {
3572
+ falsyValue = true;
3573
+ }
3574
+ if (field.required && falsyValue) {
3575
+ result[field.key] = Array.isArray(effectiveValue) ? [] : null;
3576
+ }
3577
+ });
3578
+ return Object.keys(result).length > 0 ? result : null;
3579
+ }
3580
+ function hasPendingValidationFails(store, bcName) {
3581
+ var _a;
3582
+ if (store.view.pendingValidationFailsFormat !== "target" /* target */ && store.view.pendingValidationFails && Object.keys(store.view.pendingValidationFails).length) {
3583
+ return true;
3584
+ }
3585
+ var checkResult = false;
3586
+ var bcPendingValidations = (_a = store.view.pendingValidationFails) === null || _a === void 0 ? void 0 : _a[bcName];
3587
+ var cursorsList = bcPendingValidations && Object.keys(bcPendingValidations);
3588
+ if (!cursorsList) {
3589
+ return false;
3590
+ }
3591
+ var i = 0;
3592
+ for (; i < cursorsList.length; i++) {
3593
+ if (Object.keys(bcPendingValidations[cursorsList[i]]).length) {
3594
+ checkResult = true;
3595
+ break;
3596
+ }
3597
+ }
3598
+ return checkResult;
3599
+ }
3600
+ // src/middlewares/preInvokeMiddleware.ts
3601
+ var preInvokeAction = function (_a) {
3602
+ var getState = _a.getState;
3603
+ return function (next) { return function (action) {
3604
+ var _a, _b, _c;
3605
+ if (sendOperation.match(action)) {
3606
+ var state = getState();
3607
+ var _d = action.payload, operationType_1 = _d.operationType, widgetName_2 = _d.widgetName, confirm = _d.confirm;
3608
+ var bcName = (_a = state.view.widgets.find(function (widgetItem) { return widgetItem.name === widgetName_2; })) === null || _a === void 0 ? void 0 : _a.bcName;
3609
+ var bcUrl = buildBcUrl(bcName, true, state);
3610
+ var rowMeta = bcUrl && ((_b = state.view.rowMeta[bcName]) === null || _b === void 0 ? void 0 : _b[bcUrl]);
3611
+ var actions2 = rowMeta && flattenOperations(rowMeta.actions);
3612
+ var preInvoke = (_c = actions2 === null || actions2 === void 0 ? void 0 : actions2.find(function (item) { return item.type === operationType_1; })) === null || _c === void 0 ? void 0 : _c.preInvoke;
3613
+ return preInvoke && !confirm ? next(processPreInvoke({
3614
+ bcName: bcName,
3615
+ operationType: operationType_1,
3616
+ widgetName: widgetName_2,
3617
+ preInvoke: preInvoke
3618
+ })) : next(action);
3619
+ }
3620
+ return next(action);
3621
+ }; };
3622
+ };
3623
+ // src/middlewares/popupMiddleware.ts
3624
+ var popupMiddleware = function (_a) {
3625
+ var getState = _a.getState;
3626
+ return function (next) { return function (action) {
3627
+ var _a, _b, _c;
3628
+ if (showViewPopup.match(action)) {
3629
+ var state = getState();
3630
+ var bcName_1 = action.payload.bcName;
3631
+ 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;
3632
+ var assocValueKey = (_c = action.payload.assocValueKey) !== null && _c !== void 0 ? _c : widgetValueKey;
3633
+ return widgetValueKey ? next(showViewPopup(__assign(__assign({}, action.payload), { assocValueKey: assocValueKey }))) : next(action);
3634
+ }
3635
+ return next(action);
3636
+ }; };
3637
+ };
3638
+ // src/middlewares/index.ts
3639
+ var middlewares = {
3640
+ autosave: saveFormMiddleware,
3641
+ requiredFields: requiredFields,
3642
+ preInvoke: preInvokeAction,
3643
+ popup: popupMiddleware
3644
+ };
3189
3645
  //# sourceMappingURL=cxbox-ui-core.cjs.development.js.map