@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.
@@ -115,6 +115,8 @@ __export(actions_exports, {
115
115
  processPreInvoke: function () { return processPreInvoke; },
116
116
  refreshMeta: function () { return refreshMeta; },
117
117
  refreshMetaAndReloadPage: function () { return refreshMetaAndReloadPage; },
118
+ refreshMetaDone: function () { return refreshMetaDone; },
119
+ refreshMetaFail: function () { return refreshMetaFail; },
118
120
  removeMultivalueTag: function () { return removeMultivalueTag; },
119
121
  removeNotifications: function () { return removeNotifications; },
120
122
  removePendingRequest: function () { return removePendingRequest; },
@@ -165,7 +167,7 @@ var bcFetchRowMetaSuccess = createAction("bcFetchRowMetaSuccess");
165
167
  var bcFetchRowMetaFail = createAction("bcFetchRowMetaFail");
166
168
  var bcNewData = createAction("bcNewData");
167
169
  var bcNewDataSuccess = createAction("bcNewDataSuccess");
168
- var bcNewDataFail = createAction("bcNewDataSuccess");
170
+ var bcNewDataFail = createAction("bcNewDataFail");
169
171
  var bcDeleteDataFail = createAction("bcDeleteDataFail");
170
172
  var forceActiveChangeFail = createAction("forceActiveChangeFail");
171
173
  var sendOperation = createAction("sendOperation");
@@ -180,7 +182,7 @@ var drillDown = createAction("drillDown");
180
182
  var bcChangeCursors = createAction("bcChangeCursors");
181
183
  var bcChangeDepthCursor = createAction("bcChangeDepthCursor");
182
184
  var changeDataItem = createAction("changeDataItem");
183
- var changeDataItems = createAction("changeDataItem");
185
+ var changeDataItems = createAction("changeDataItems");
184
186
  var forceActiveRmUpdate = createAction("forceActiveRmUpdate");
185
187
  var showViewPopup = createAction("showViewPopup");
186
188
  var showFileUploadPopup = createAction("showFileUploadPopup");
@@ -234,6 +236,8 @@ var switchDebugMode = createAction("switchDebugMode");
234
236
  var exportState = createAction("exportState");
235
237
  var emptyAction = createAction("emptyAction");
236
238
  var refreshMeta = createAction("refreshMeta");
239
+ var refreshMetaDone = createAction("refreshMetaDone");
240
+ var refreshMetaFail = createAction("refreshMetaFail");
237
241
  var refreshMetaAndReloadPage = createAction("refreshMetaAndReloadPage");
238
242
  var switchRole = createAction("switchRole");
239
243
  var addPendingRequest = createAction("addPendingRequest");
@@ -343,8 +347,10 @@ __export(interfaces_exports, {
343
347
  PaginationMode: function () { return PaginationMode; },
344
348
  PendingValidationFailsFormat: function () { return PendingValidationFailsFormat; },
345
349
  PopupWidgetTypes: function () { return PopupWidgetTypes; },
350
+ PositionTypes: function () { return PositionTypes; },
346
351
  RouteType: function () { return RouteType; },
347
352
  TableLikeWidgetTypes: function () { return TableLikeWidgetTypes; },
353
+ WidgetTypes: function () { return WidgetTypes2; },
348
354
  coreOperations: function () { return coreOperations; },
349
355
  isCustomWidget: function () { return isCustomWidget; },
350
356
  isCustomWidgetConfiguration: function () { return isCustomWidgetConfiguration; },
@@ -387,6 +393,7 @@ var ApplicationErrorType = /* @__PURE__ */ (function (ApplicationErrorType2) {
387
393
  })(ApplicationErrorType || {});
388
394
  // src/interfaces/widget.ts
389
395
  import { WidgetTypes } from "@cxbox-ui/schema";
396
+ import { WidgetTypes as WidgetTypes2, PositionTypes } from "@cxbox-ui/schema";
390
397
  var TableLikeWidgetTypes = [
391
398
  WidgetTypes.List,
392
399
  WidgetTypes.DataGrid,
@@ -469,6 +476,15 @@ function isViewNavigationCategory(item) {
469
476
  function isViewNavigationGroup(item) {
470
477
  return !!item && "child" in item && !("categoryName" in item);
471
478
  }
479
+ // src/reducers/router.ts
480
+ var initialRouterState = { type: "default" /* default */, path: "/", params: null, screenName: null };
481
+ var createRouterReducerBuilderManager = function (initialState) { return new ReducerBuilderManager().addCase(loginDone, function (state, action) {
482
+ state = __assign(__assign({}, state), action.payload);
483
+ }).addCase(changeLocation, function (state, action) {
484
+ state = __assign(__assign({}, state), action.payload.location);
485
+ }); };
486
+ // src/reducers/screen.ts
487
+ import { OperationTypeCrud as OperationTypeCrud3 } from "@cxbox-ui/schema";
472
488
  // src/utils/index.ts
473
489
  var utils_exports = {};
474
490
  __export(utils_exports, {
@@ -481,6 +497,8 @@ __export(utils_exports, {
481
497
  buildSearchResultTree: function () { return buildSearchResultTree; },
482
498
  buildUrl: function () { return buildUrl; },
483
499
  checkShowCondition: function () { return checkShowCondition; },
500
+ createApiError: function () { return createApiError; },
501
+ createApiErrorObservable: function () { return createApiErrorObservable; },
484
502
  defaultBuildURL: function () { return defaultBuildURL; },
485
503
  defaultParseURL: function () { return defaultParseURL; },
486
504
  deleteUndefinedFromObject: function () { return deleteUndefinedFromObject; },
@@ -489,7 +507,6 @@ __export(utils_exports, {
489
507
  getBcChildren: function () { return getBcChildren; },
490
508
  getDescendants: function () { return getDescendants; },
491
509
  getFieldTitle: function () { return getFieldTitle; },
492
- getFileUploadEndpoint: function () { return getFileUploadEndpoint; },
493
510
  getFilterType: function () { return getFilterType; },
494
511
  getFilters: function () { return getFilters; },
495
512
  getSorters: function () { return getSorters; },
@@ -529,11 +546,18 @@ function applyRawParams(url, qso) {
529
546
  var result = new URLSearchParams(qso).toString();
530
547
  return "".concat(addTailControlSequences(url)).concat(result && "".concat(result));
531
548
  }
532
- function getFileUploadEndpoint(instance) {
533
- if (!instance.defaults.baseURL) {
534
- return "/file";
535
- }
536
- return instance.defaults.baseURL.endsWith("/") ? "".concat(instance.defaults.baseURL, "file") : "".concat(instance.defaults.baseURL, "/file");
549
+ // src/utils/apiError.ts
550
+ import { actions } from "@cxbox-ui/core";
551
+ import { EMPTY, of } from "rxjs";
552
+ function createApiError(error, context) {
553
+ if (context === void 0) { context = { widgetName: "unknown" }; }
554
+ if (!error.isAxiosError)
555
+ return void 0;
556
+ return actions.apiError({ error: error, callContext: context });
557
+ }
558
+ function createApiErrorObservable(error, context) {
559
+ var apiError2 = createApiError(error, context);
560
+ return apiError2 ? of(apiError2) : EMPTY;
537
561
  }
538
562
  // src/utils/strings.ts
539
563
  function getTemplate(literals) {
@@ -549,10 +573,9 @@ function getTemplate(literals) {
549
573
  result += literals[literals.length - 1];
550
574
  return result;
551
575
  }
552
- function buildBcUrl(bcName, includeSelf, store) {
576
+ function buildBcUrl(bcName, includeSelf, state) {
553
577
  if (includeSelf === void 0) { includeSelf = false; }
554
- var storeInstance = store;
555
- var bcMap = storeInstance.screen.bo.bc;
578
+ var bcMap = state.screen.bo.bc;
556
579
  var bc = bcMap[bcName];
557
580
  if (!bc) {
558
581
  return null;
@@ -685,7 +708,7 @@ function defaultParseURL(url) {
685
708
  }
686
709
  return {
687
710
  type: type,
688
- path: path,
711
+ path: path.length !== 0 && !path.startsWith("/") ? "/".concat(path) : path,
689
712
  params: params,
690
713
  screenName: screenName,
691
714
  viewName: viewName,
@@ -733,8 +756,9 @@ function getSorters(sorters) {
733
756
  return result;
734
757
  }
735
758
  function parseFilters(defaultFilters) {
759
+ if (defaultFilters === void 0) { defaultFilters = ""; }
736
760
  var result = [];
737
- var urlParams = new URL(defaultFilters).searchParams;
761
+ var urlParams = new URL(defaultFilters, window.location.origin).searchParams;
738
762
  urlParams.forEach(function (param) {
739
763
  var _a = param.split("."), fieldName = _a[0], type = _a[1];
740
764
  if (fieldName && type && urlParams.get(param)) {
@@ -764,7 +788,7 @@ function parseSorters(sorters) {
764
788
  return null;
765
789
  }
766
790
  var result = [];
767
- var dictionary = new URL(sorters).searchParams;
791
+ var dictionary = new URL(sorters, window.location.origin).searchParams;
768
792
  Object.entries(dictionary).map(function (_a) {
769
793
  var sort = _a[0], fieldKey = _a[1];
770
794
  var _b = sort.split(".").slice(1), order = _b[0], direction = _b[1];
@@ -843,12 +867,13 @@ function getBcChildren(originBcName, widgets, bcMap) {
843
867
  return childrenBcMap;
844
868
  }
845
869
  function getHierarchyChildBc(originBcName, hierarchyWidget) {
846
- var nestedBcNames = hierarchyWidget.options.hierarchy.map(function (nestedItem) { return nestedItem.bcName; });
847
- if (originBcName !== hierarchyWidget.bcName && !nestedBcNames.includes(originBcName)) {
870
+ var _a, _b;
871
+ 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; });
872
+ if (originBcName !== hierarchyWidget.bcName && !(nestedBcNames === null || nestedBcNames === void 0 ? void 0 : nestedBcNames.includes(originBcName))) {
848
873
  return [];
849
874
  }
850
- var childHierarchyBcIndex = nestedBcNames.findIndex(function (item) { return item === originBcName; });
851
- var childHierarchyBcName = nestedBcNames[childHierarchyBcIndex + 1];
875
+ var childHierarchyBcIndex = nestedBcNames === null || nestedBcNames === void 0 ? void 0 : nestedBcNames.findIndex(function (item) { return item === originBcName; });
876
+ var childHierarchyBcName = nestedBcNames === null || nestedBcNames === void 0 ? void 0 : nestedBcNames[childHierarchyBcIndex + 1];
852
877
  return [childHierarchyBcName, hierarchyWidget.name];
853
878
  }
854
879
  function checkShowCondition(condition, cursor, data, pendingDataChanges) {
@@ -862,9 +887,9 @@ function checkShowCondition(condition, cursor, data, pendingDataChanges) {
862
887
  if (!record) {
863
888
  return false;
864
889
  }
865
- var actualValue = record === null || record === void 0 ? void 0 : record[params.fieldKey];
866
- 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];
867
- return pendingValue !== void 0 ? pendingValue === params.value : actualValue === params.value;
890
+ var actualValue = record === null || record === void 0 ? void 0 : record[params === null || params === void 0 ? void 0 : params.fieldKey];
891
+ 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];
892
+ return pendingValue !== void 0 ? pendingValue === (params === null || params === void 0 ? void 0 : params.value) : actualValue === (params === null || params === void 0 ? void 0 : params.value);
868
893
  }
869
894
  // src/utils/tree.ts
870
895
  function assignTreeLinks(flat) {
@@ -872,6 +897,7 @@ function assignTreeLinks(flat) {
872
897
  var map12 = {};
873
898
  var orphans = [];
874
899
  result.forEach(function (item) {
900
+ var _a, _b;
875
901
  if (!item.parentId || item.parentId === "0") {
876
902
  return;
877
903
  }
@@ -890,7 +916,7 @@ function assignTreeLinks(flat) {
890
916
  result[parentIndex].children = [item];
891
917
  }
892
918
  else {
893
- result[parentIndex].children.push(item);
919
+ (_b = (_a = result[parentIndex]) === null || _a === void 0 ? void 0 : _a.children) === null || _b === void 0 ? void 0 : _b.push(item);
894
920
  }
895
921
  });
896
922
  if (orphans.length) {
@@ -968,22 +994,7 @@ function deleteUndefinedFromObject(obj) {
968
994
  }
969
995
  });
970
996
  }
971
- // src/reducers/router.ts
972
- var initialRouterState = { type: "default" /* default */, path: "/", params: null, screenName: null };
973
- var createRouterReducerBuilderManager = function (initialState) { return new ReducerBuilderManager().addCase(loginDone, function (state, action) {
974
- state = __assign(__assign({}, state), action.payload);
975
- }).addCase(changeLocation, function (state, action) {
976
- var _a = action.payload, url = _a.url, route = _a.route;
977
- if (url) {
978
- var path = new URL(url);
979
- state = __assign(__assign({}, state), defaultParseURL(path));
980
- }
981
- if (route !== null) {
982
- state = __assign(__assign({}, state), route);
983
- }
984
- }); };
985
997
  // src/reducers/screen.ts
986
- import { OperationTypeCrud as OperationTypeCrud3 } from "@cxbox-ui/schema";
987
998
  var initialScreenState = {
988
999
  screenName: "",
989
1000
  bo: { activeBcName: "", bc: {} },
@@ -995,10 +1006,11 @@ var initialScreenState = {
995
1006
  };
996
1007
  var operationsHandledLocally = [OperationTypeCrud3.associate, OperationTypeCrud3.fileUpload];
997
1008
  var createScreenReducerBuilderManager = function (initialState) { return new ReducerBuilderManager().addCase(selectScreen, function (state, action) {
1009
+ var _a, _b, _c, _d, _e;
998
1010
  var bcDictionary = {};
999
1011
  var bcSorters = {};
1000
1012
  var bcFilters = {};
1001
- action.payload.screen.meta.bo.bc.forEach(function (item) {
1013
+ (_a = action.payload.screen.meta) === null || _a === void 0 ? void 0 : _a.bo.bc.forEach(function (item) {
1002
1014
  bcDictionary[item.name] = item;
1003
1015
  var sorter = parseSorters(item.defaultSort);
1004
1016
  var filter56 = parseFilters(item.defaultFilter);
@@ -1010,8 +1022,8 @@ var createScreenReducerBuilderManager = function (initialState) { return new Red
1010
1022
  }
1011
1023
  });
1012
1024
  state.screenName = action.payload.screen.name;
1013
- state.primaryView = action.payload.screen.meta.primary;
1014
- state.views = action.payload.screen.meta.views;
1025
+ state.primaryView = (_c = (_b = action.payload.screen.meta) === null || _b === void 0 ? void 0 : _b.primary) !== null && _c !== void 0 ? _c : state.primaryView;
1026
+ state.views = (_e = (_d = action.payload.screen.meta) === null || _d === void 0 ? void 0 : _d.views) !== null && _e !== void 0 ? _e : state.views;
1015
1027
  state.bo = { activeBcName: null, bc: bcDictionary };
1016
1028
  state.sorters = __assign(__assign({}, state.sorters), bcSorters);
1017
1029
  state.filters = __assign(__assign({}, state.filters), bcFilters);
@@ -1021,12 +1033,14 @@ var createScreenReducerBuilderManager = function (initialState) { return new Red
1021
1033
  }).addCase(bcFetchDataRequest, function (state, action) {
1022
1034
  state.bo.bc[action.payload.bcName].loading = true;
1023
1035
  }).addCase(bcLoadMore, function (state, action) {
1036
+ var _a;
1024
1037
  var currentBc = state.bo.bc[action.payload.bcName];
1025
- currentBc.page += 1;
1038
+ currentBc.page = ((_a = currentBc.page) !== null && _a !== void 0 ? _a : 1) + 1;
1026
1039
  currentBc.loading = true;
1027
1040
  }).addCase(selectView, function (state, action) {
1041
+ var _a;
1028
1042
  var newBcs = {};
1029
- Array.from(new Set(action.payload.widgets.map(function (widget) { return widget.bcName; }))
1043
+ Array.from(new Set((_a = action.payload.widgets) === null || _a === void 0 ? void 0 : _a.map(function (widget) { return widget.bcName; }))
1030
1044
  // БК которые есть на вьюхе
1031
1045
  ).filter(function (bcName) { return state.bo.bc[bcName]; }).forEach(function (bcName) {
1032
1046
  newBcs[bcName] = __assign(__assign({}, state.bo.bc[bcName]), { page: 1 });
@@ -1038,9 +1052,10 @@ var createScreenReducerBuilderManager = function (initialState) { return new Red
1038
1052
  currentBc.loading = false;
1039
1053
  state.cachedBc[action.payload.bcName] = action.payload.bcUrl;
1040
1054
  }).addCase(bcFetchDataFail, function (state, action) {
1041
- if (Object.values(state.bo.bc).some(function (bc) { return bc.name === action.payload.bcName; })) {
1042
- state.bo.bc[action.payload.bcName].loading = false;
1043
- state.cachedBc[action.payload.bcName] = action.payload.bcUrl;
1055
+ var bcName = action.payload.bcName;
1056
+ if (Object.values(state.bo.bc).some(function (bc) { return bc.name === bcName; })) {
1057
+ state.bo.bc[bcName].loading = false;
1058
+ state.cachedBc[bcName] = action.payload.bcUrl;
1044
1059
  }
1045
1060
  }).addCase(sendOperation, function (state, action) {
1046
1061
  if (!operationsHandledLocally.includes(action.payload.operationType)) {
@@ -1068,10 +1083,12 @@ var createScreenReducerBuilderManager = function (initialState) { return new Red
1068
1083
  Object.assign(state.bo.bc, newCursors);
1069
1084
  Object.assign(state.cachedBc, newCache);
1070
1085
  }).addCase(bcChangeDepthCursor, function (state, action) {
1086
+ var _a;
1071
1087
  if (action.payload.depth === 1) {
1072
1088
  state.bo.bc[action.payload.bcName].cursor = action.payload.cursor;
1073
1089
  }
1074
1090
  else {
1091
+ state.bo.bc[action.payload.bcName].depthBc = (_a = state.bo.bc[action.payload.bcName].depthBc) !== null && _a !== void 0 ? _a : {};
1075
1092
  state.bo.bc[action.payload.bcName].depthBc[action.payload.depth].cursor = action.payload.cursor;
1076
1093
  }
1077
1094
  }).addCase(bcSelectRecord, function (state, action) {
@@ -1107,7 +1124,9 @@ var createScreenReducerBuilderManager = function (initialState) { return new Red
1107
1124
  state.bo.bc[action.payload.bcName].page = action.payload.page;
1108
1125
  state.bo.bc[action.payload.bcName].loading = true;
1109
1126
  }).addCase(showViewPopup, function (state, action) {
1110
- state.bo.bc[action.payload.bcName].page = 1;
1127
+ var _a, _b;
1128
+ var currentPage = (_b = (_a = state.bo.bc[action.payload.bcName]) === null || _a === void 0 ? void 0 : _a.page) !== null && _b !== void 0 ? _b : 1;
1129
+ state.bo.bc[action.payload.bcName].page = action.payload.bcName === action.payload.calleeBCName ? currentPage : 1;
1111
1130
  state.bo.bc[action.payload.bcName].loading = action.payload.bcName !== action.payload.calleeBCName;
1112
1131
  }).addCase(sendOperationSuccess, function (state, action) {
1113
1132
  state.bo.bc[action.payload.bcName].loading = false;
@@ -1136,7 +1155,8 @@ var initialSessionState = {
1136
1155
  errorMsg: null,
1137
1156
  screens: [],
1138
1157
  pendingRequests: [],
1139
- notifications: []
1158
+ notifications: [],
1159
+ isMetaRefreshing: false
1140
1160
  };
1141
1161
  var createSessionReducerBuilderManager = function (initialState) { return new ReducerBuilderManager().addCase(login, function (state) {
1142
1162
  state.loginSpin = true;
@@ -1156,14 +1176,22 @@ var createSessionReducerBuilderManager = function (initialState) { return new Re
1156
1176
  }).addCase(switchDebugMode, function (state, action) {
1157
1177
  state.debugMode = action.payload;
1158
1178
  }).addCase(addPendingRequest, function (state, action) {
1159
- state.pendingRequests.push(action.payload.request);
1179
+ var _a;
1180
+ (_a = state.pendingRequests) === null || _a === void 0 ? void 0 : _a.push(action.payload.request);
1160
1181
  }).addCase(removePendingRequest, function (state, action) {
1161
- state.pendingRequests = state.pendingRequests.filter(function (item) { return item.requestId !== action.payload.requestId; });
1182
+ var _a;
1183
+ state.pendingRequests = (_a = state.pendingRequests) === null || _a === void 0 ? void 0 : _a.filter(function (item) { return item.requestId !== action.payload.requestId; });
1162
1184
  }).addCase(addNotification, function (state, action) {
1163
1185
  state.notifications.push(action.payload);
1164
1186
  }).addCase(removeNotifications, function (state, action) {
1165
1187
  var closingKeys = action.payload;
1166
1188
  state.notifications = state.notifications.filter(function (notification) { return !closingKeys.includes(notification.key); });
1189
+ }).addCase(refreshMeta, function (state) {
1190
+ state.isMetaRefreshing = true;
1191
+ }).addCase(refreshMetaDone, function (state) {
1192
+ state.isMetaRefreshing = false;
1193
+ }).addCase(refreshMetaFail, function (state) {
1194
+ state.isMetaRefreshing = false;
1167
1195
  }); };
1168
1196
  // src/reducers/view.ts
1169
1197
  import { OperationTypeCrud as OperationTypeCrud4 } from "@cxbox-ui/schema";
@@ -1205,12 +1233,15 @@ var createViewReducerBuilderManager = function (initialState) { return new Reduc
1205
1233
  state.metaInProgress[action.payload.bcName] = true;
1206
1234
  }
1207
1235
  }).addCase(bcFetchRowMetaSuccess, function (state, action) {
1236
+ var _a;
1237
+ state.rowMeta[action.payload.bcName] = (_a = state.rowMeta[action.payload.bcName]) !== null && _a !== void 0 ? _a : {};
1208
1238
  state.rowMeta[action.payload.bcName][action.payload.bcUrl] = action.payload.rowMeta;
1209
1239
  state.metaInProgress[action.payload.bcName] = false;
1210
1240
  }).addCase(bcNewDataSuccess, function (state, action) {
1211
1241
  state.selectedCell = initialViewState.selectedCell;
1212
1242
  }).addCase(forceActiveRmUpdate, function (state, action) {
1213
- var _a = action.payload, bcName = _a.bcName, bcUrl = _a.bcUrl, currentRecordData = _a.currentRecordData, rowMeta = _a.rowMeta, cursor = _a.cursor;
1243
+ var _a, _b, _c, _d, _e;
1244
+ var _f = action.payload, bcName = _f.bcName, bcUrl = _f.bcUrl, currentRecordData = _f.currentRecordData, rowMeta = _f.rowMeta, cursor = _f.cursor;
1214
1245
  var handledForceActive = {};
1215
1246
  var rowMetaForcedValues = {};
1216
1247
  var newPendingChangesDiff = {};
@@ -1221,6 +1252,7 @@ var createViewReducerBuilderManager = function (initialState) { return new Reduc
1221
1252
  forceActiveFieldKeys.push(field.key);
1222
1253
  }
1223
1254
  });
1255
+ state.pendingDataChanges[bcName] = (_a = state.pendingDataChanges[bcName]) !== null && _a !== void 0 ? _a : {};
1224
1256
  var consolidatedFrontData = __assign(__assign({}, currentRecordData), state.pendingDataChanges[bcName][cursor]);
1225
1257
  Object.keys(consolidatedFrontData).forEach(function (key) {
1226
1258
  if (rowMetaForcedValues[key] !== void 0 && consolidatedFrontData[key] !== rowMetaForcedValues[key]) {
@@ -1233,17 +1265,21 @@ var createViewReducerBuilderManager = function (initialState) { return new Reduc
1233
1265
  handledForceActive[key] = newPendingDataChanges[key];
1234
1266
  }
1235
1267
  });
1268
+ state.handledForceActive[bcName] = (_b = state.handledForceActive[bcName]) !== null && _b !== void 0 ? _b : {};
1269
+ state.handledForceActive[bcName][cursor] = (_c = state.handledForceActive[bcName][cursor]) !== null && _c !== void 0 ? _c : {};
1236
1270
  Object.assign(state.handledForceActive[bcName][cursor], handledForceActive);
1271
+ state.pendingDataChanges[bcName] = (_d = state.pendingDataChanges[bcName]) !== null && _d !== void 0 ? _d : {};
1237
1272
  state.pendingDataChanges[bcName][cursor] = newPendingDataChanges;
1273
+ state.rowMeta[bcName] = (_e = state.rowMeta[bcName]) !== null && _e !== void 0 ? _e : {};
1238
1274
  state.rowMeta[bcName][bcUrl] = rowMeta;
1239
1275
  }).addCase(changeDataItem, function (state, action) {
1240
- var _a;
1276
+ var _a, _b, _c;
1241
1277
  var actionBcName = action.payload.bcName;
1242
1278
  var prevBc = state.pendingDataChanges[action.payload.bcName] || {};
1243
1279
  var prevCursor = prevBc[action.payload.cursor] || {};
1244
1280
  var prevPending = prevCursor || {};
1245
1281
  var nextPending = __assign(__assign({}, prevPending), action.payload.dataItem);
1246
- var bcUrl = buildBcUrl(actionBcName, true);
1282
+ var bcUrl = action.payload.bcUrl;
1247
1283
  var rowMeta = (_a = state.rowMeta[actionBcName]) === null || _a === void 0 ? void 0 : _a[bcUrl];
1248
1284
  var nextValidationFails = {};
1249
1285
  var isTargetFormatPVF = state.pendingValidationFailsFormat === "target" /* target */;
@@ -1254,10 +1290,11 @@ var createViewReducerBuilderManager = function (initialState) { return new Reduc
1254
1290
  nextValidationFails[fieldKey] = "This field is mandatory";
1255
1291
  }
1256
1292
  });
1293
+ state.pendingDataChanges[action.payload.bcName] = (_b = state.pendingDataChanges[action.payload.bcName]) !== null && _b !== void 0 ? _b : {};
1257
1294
  state.pendingDataChanges[action.payload.bcName][action.payload.cursor] = nextPending;
1258
1295
  if (isTargetFormatPVF) {
1259
1296
  ;
1260
- state.pendingValidationFails[actionBcName][action.payload.cursor] = nextValidationFails;
1297
+ ((_c = state.pendingValidationFails) === null || _c === void 0 ? void 0 : _c[actionBcName])[action.payload.cursor] = nextValidationFails;
1261
1298
  }
1262
1299
  else {
1263
1300
  state.pendingValidationFails = nextValidationFails;
@@ -1278,7 +1315,7 @@ var createViewReducerBuilderManager = function (initialState) { return new Reduc
1278
1315
  pendingDataChanges[bcName] = pendingBcChanges;
1279
1316
  });
1280
1317
  var isTargetFormatPVF = state.pendingValidationFailsFormat === "target" /* target */;
1281
- var pendingValidationFails = __assign({}, state.pendingValidationFails);
1318
+ var pendingValidationFails = state.pendingValidationFails ? __assign({}, state.pendingValidationFails) : {};
1282
1319
  if (isTargetFormatPVF) {
1283
1320
  action.payload.bcNames.forEach(function (i) {
1284
1321
  pendingValidationFails[i] = {};
@@ -1293,7 +1330,8 @@ var createViewReducerBuilderManager = function (initialState) { return new Reduc
1293
1330
  }).addCase(bcFetchRowMetaFail, function (state, action) {
1294
1331
  state.metaInProgress[action.payload.bcName] = false;
1295
1332
  }).addCase(forceActiveChangeFail, function (state, action) {
1296
- var _a = action.payload, bcName = _a.bcName, bcUrl = _a.bcUrl, entityError = _a.entityError;
1333
+ var _a;
1334
+ var _b = action.payload, bcName = _b.bcName, bcUrl = _b.bcUrl, entityError = _b.entityError;
1297
1335
  var errors = {};
1298
1336
  if (entityError) {
1299
1337
  Object.entries(entityError.fields).forEach(function (_a) {
@@ -1301,9 +1339,11 @@ var createViewReducerBuilderManager = function (initialState) { return new Reduc
1301
1339
  errors[fieldName] = violation;
1302
1340
  });
1303
1341
  }
1342
+ state.rowMeta[bcName] = (_a = state.rowMeta[bcName]) !== null && _a !== void 0 ? _a : {};
1304
1343
  state.rowMeta[bcName][bcUrl].errors = errors;
1305
1344
  }).addCase(bcSaveDataFail, function (state, action) {
1306
- var _a = action.payload, bcName = _a.bcName, bcUrl = _a.bcUrl, entityError = _a.entityError;
1345
+ var _a;
1346
+ var _b = action.payload, bcName = _b.bcName, bcUrl = _b.bcUrl, entityError = _b.entityError;
1307
1347
  var errors = {};
1308
1348
  if (entityError) {
1309
1349
  Object.entries(entityError.fields).forEach(function (_a) {
@@ -1311,9 +1351,11 @@ var createViewReducerBuilderManager = function (initialState) { return new Reduc
1311
1351
  errors[fieldName] = violation;
1312
1352
  });
1313
1353
  }
1354
+ state.rowMeta[bcName] = (_a = state.rowMeta[bcName]) !== null && _a !== void 0 ? _a : {};
1314
1355
  state.rowMeta[bcName][bcUrl].errors = errors;
1315
1356
  }).addCase(sendOperationFail, function (state, action) {
1316
- var _a = action.payload, bcName = _a.bcName, bcUrl = _a.bcUrl, entityError = _a.entityError;
1357
+ var _a;
1358
+ var _b = action.payload, bcName = _b.bcName, bcUrl = _b.bcUrl, entityError = _b.entityError;
1317
1359
  var errors = {};
1318
1360
  if (entityError) {
1319
1361
  Object.entries(entityError.fields).forEach(function (_a) {
@@ -1321,30 +1363,38 @@ var createViewReducerBuilderManager = function (initialState) { return new Reduc
1321
1363
  errors[fieldName] = violation;
1322
1364
  });
1323
1365
  }
1366
+ state.rowMeta[bcName] = (_a = state.rowMeta[bcName]) !== null && _a !== void 0 ? _a : {};
1324
1367
  state.rowMeta[bcName][bcUrl].errors = errors;
1325
1368
  }).addCase(sendOperationSuccess, function (state, action) {
1326
- var _a = action.payload, bcName = _a.bcName, cursor = _a.cursor;
1369
+ var _a, _b, _c;
1370
+ var bcName = action.payload.bcName;
1371
+ var cursor = action.payload.cursor;
1327
1372
  var isTargetFormatPVF = state.pendingValidationFailsFormat === "target" /* target */;
1373
+ state.pendingDataChanges[bcName] = (_a = state.pendingDataChanges[bcName]) !== null && _a !== void 0 ? _a : {};
1328
1374
  state.pendingDataChanges[bcName][cursor] = {};
1329
1375
  if (isTargetFormatPVF) {
1330
1376
  ;
1331
- state.pendingValidationFails[bcName][cursor] = {};
1377
+ ((_b = state.pendingValidationFails) === null || _b === void 0 ? void 0 : _b[bcName])[cursor] = {};
1332
1378
  }
1333
1379
  else {
1334
1380
  state.pendingValidationFails = initialViewState.pendingValidationFails;
1335
1381
  }
1382
+ state.handledForceActive[bcName] = (_c = state.handledForceActive[bcName]) !== null && _c !== void 0 ? _c : {};
1336
1383
  state.handledForceActive[bcName][cursor] = {};
1337
1384
  }).addCase(bcSaveDataSuccess, function (state, action) {
1338
- var _a = action.payload, bcName = _a.bcName, cursor = _a.cursor;
1385
+ var _a, _b, _c;
1386
+ var _d = action.payload, bcName = _d.bcName, cursor = _d.cursor;
1339
1387
  var isTargetFormatPVF = state.pendingValidationFailsFormat === "target" /* target */;
1388
+ state.pendingDataChanges[bcName] = (_a = state.pendingDataChanges[bcName]) !== null && _a !== void 0 ? _a : {};
1340
1389
  state.pendingDataChanges[bcName][cursor] = {};
1341
1390
  if (isTargetFormatPVF) {
1342
1391
  ;
1343
- state.pendingValidationFails[bcName][cursor] = {};
1392
+ ((_b = state.pendingValidationFails) === null || _b === void 0 ? void 0 : _b[bcName])[cursor] = {};
1344
1393
  }
1345
1394
  else {
1346
1395
  state.pendingValidationFails = initialViewState.pendingValidationFails;
1347
1396
  }
1397
+ state.handledForceActive[bcName] = (_c = state.handledForceActive[bcName]) !== null && _c !== void 0 ? _c : {};
1348
1398
  state.handledForceActive[bcName][cursor] = {};
1349
1399
  }).addCase(bcCancelPendingChanges, function (state, action) {
1350
1400
  var _a, _b;
@@ -1355,7 +1405,7 @@ var createViewReducerBuilderManager = function (initialState) { return new Reduc
1355
1405
  }
1356
1406
  }
1357
1407
  var isTargetFormatPVF = state.pendingValidationFailsFormat === "target" /* target */;
1358
- var pendingValidationFails = __assign({}, state.pendingValidationFails);
1408
+ var pendingValidationFails = state.pendingValidationFails ? __assign({}, state.pendingValidationFails) : {};
1359
1409
  if (isTargetFormatPVF) {
1360
1410
  if (((_b = (_a = action.payload) === null || _a === void 0 ? void 0 : _a.bcNames) === null || _b === void 0 ? void 0 : _b.length) > 0) {
1361
1411
  action.payload.bcNames.forEach(function (i) {
@@ -1384,8 +1434,8 @@ var createViewReducerBuilderManager = function (initialState) { return new Reduc
1384
1434
  isFilter: isFilter
1385
1435
  };
1386
1436
  }).addCase(showFileUploadPopup, function (state, action) {
1387
- var _a;
1388
- var bcName = (_a = state.widgets.find(function (item) { return item.name === action.payload.widgetName; })) === null || _a === void 0 ? void 0 : _a.bcName;
1437
+ var _a, _b;
1438
+ 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;
1389
1439
  state.popupData = {
1390
1440
  type: "file-upload",
1391
1441
  bcName: bcName,
@@ -1397,6 +1447,7 @@ var createViewReducerBuilderManager = function (initialState) { return new Reduc
1397
1447
  }).addCase(viewClearPickMap, function (state) {
1398
1448
  state.pickMap = null;
1399
1449
  }).addCase(closeViewPopup, function (state) {
1450
+ state.popupData = {};
1400
1451
  state.popupData.bcName = null;
1401
1452
  }).addCase(selectTableCell, function (state, action) {
1402
1453
  state.selectedCell = { widgetName: action.payload.widgetName, rowId: action.payload.rowId, fieldKey: action.payload.fieldKey };
@@ -1404,12 +1455,16 @@ var createViewReducerBuilderManager = function (initialState) { return new Reduc
1404
1455
  state.pendingDataChanges = initialViewState.pendingDataChanges;
1405
1456
  state.selectedCell = initialViewState.selectedCell;
1406
1457
  }).addCase(showNotification, function (state, action) {
1458
+ var _a, _b;
1459
+ state.systemNotifications = (_a = state.systemNotifications) !== null && _a !== void 0 ? _a : [];
1407
1460
  state.systemNotifications.push({
1408
1461
  type: action.payload.type,
1409
1462
  message: action.payload.message,
1410
- id: state.systemNotifications.length
1463
+ id: (_b = state.systemNotifications) === null || _b === void 0 ? void 0 : _b.length
1411
1464
  });
1412
1465
  }).addCase(closeNotification, function (state, action) {
1466
+ var _a;
1467
+ state.systemNotifications = (_a = state.systemNotifications) !== null && _a !== void 0 ? _a : [];
1413
1468
  state.systemNotifications = state.systemNotifications.filter(function (item) { return item.id !== action.payload.id; });
1414
1469
  }).addCase(showViewError, function (state, action) {
1415
1470
  state.error = action.payload.error;
@@ -1457,7 +1512,6 @@ __export(epics_exports, {
1457
1512
  httpError500Epic: function () { return httpError500Epic; },
1458
1513
  httpErrorDefaultEpic: function () { return httpErrorDefaultEpic; },
1459
1514
  inlinePickListFetchDataEpic: function () { return inlinePickListFetchDataEpic; },
1460
- knownHttpErrors: function () { return knownHttpErrors; },
1461
1515
  loginByAnotherRoleEpic: function () { return loginByAnotherRoleEpic; },
1462
1516
  loginDoneEpic: function () { return loginDoneEpic; },
1463
1517
  loginDoneSessionEpic: function () { return loginDoneSessionEpic; },
@@ -1482,9 +1536,9 @@ __export(epics_exports, {
1482
1536
  userDrillDownEpic: function () { return userDrillDownEpic; }
1483
1537
  });
1484
1538
  // src/epics/view/sendOperationEpic.ts
1485
- import { catchError, concat, EMPTY, filter, mergeMap, of as of2 } from "rxjs";
1539
+ import { catchError, concat, EMPTY as EMPTY2, filter, mergeMap, of as of3 } from "rxjs";
1486
1540
  // src/epics/utils/postOperationRoutine.ts
1487
- import { of } from "rxjs";
1541
+ import { of as of2 } from "rxjs";
1488
1542
  function postOperationRoutine(widgetName, postInvoke, preInvoke, operationType, bcName) {
1489
1543
  var postInvokeConfirm = Object.values(OperationPostInvokeConfirmType).includes(postInvoke === null || postInvoke === void 0 ? void 0 : postInvoke.type);
1490
1544
  var result = [];
@@ -1507,7 +1561,7 @@ function postOperationRoutine(widgetName, postInvoke, preInvoke, operationType,
1507
1561
  preInvoke: preInvoke
1508
1562
  }));
1509
1563
  }
1510
- return result.map(function (item) { return of(item); });
1564
+ return result.map(function (item) { return of2(item); });
1511
1565
  }
1512
1566
  // src/epics/view/sendOperationEpic.ts
1513
1567
  var sendOperationEpic = function (action$, state$, _a) {
@@ -1518,7 +1572,7 @@ var sendOperationEpic = function (action$, state$, _a) {
1518
1572
  var screenName = state.screen.screenName;
1519
1573
  var _l = action.payload, bcName = _l.bcName, operationType = _l.operationType, widgetName = _l.widgetName;
1520
1574
  var confirm = ((_a = action.payload.confirmOperation) === null || _a === void 0 ? void 0 : _a.type) || action.payload.confirm;
1521
- var bcUrl = buildBcUrl(bcName, true);
1575
+ var bcUrl = buildBcUrl(bcName, true, state);
1522
1576
  var bc = state.screen.bo.bc[bcName];
1523
1577
  var rowMeta = bcUrl && ((_b = state.view.rowMeta[bcName]) === null || _b === void 0 ? void 0 : _b[bcUrl]);
1524
1578
  var fields = rowMeta === null || rowMeta === void 0 ? void 0 : rowMeta.fields;
@@ -1526,7 +1580,7 @@ var sendOperationEpic = function (action$, state$, _a) {
1526
1580
  var record = (_c = state.data[bcName]) === null || _c === void 0 ? void 0 : _c.find(function (item) { return item.id === bc.cursor; });
1527
1581
  var filters = state.screen.filters[bcName];
1528
1582
  var sorters = state.screen.sorters[bcName];
1529
- var pendingRecordChange = (_d = state.view.pendingDataChanges[bcName]) === null || _d === void 0 ? void 0 : _d[bc.cursor];
1583
+ var pendingRecordChange = __assign({}, (_d = state.view.pendingDataChanges[bcName]) === null || _d === void 0 ? void 0 : _d[bc.cursor]);
1530
1584
  var _loop_1 = function (key) {
1531
1585
  if (fields.find(function (item) { return item.key === key && item.disabled; })) {
1532
1586
  delete pendingRecordChange[key];
@@ -1543,11 +1597,11 @@ var sendOperationEpic = function (action$, state$, _a) {
1543
1597
  }
1544
1598
  var context = { widgetName: action.payload.widgetName };
1545
1599
  return api.customAction(screenName, bcUrl, data, context, params).pipe(mergeMap(function (response) {
1546
- var _a;
1547
- var postInvoke = response.postActions[0];
1600
+ var _a, _b;
1601
+ var postInvoke = (_a = response.postActions) === null || _a === void 0 ? void 0 : _a[0];
1548
1602
  var preInvoke = response.preInvoke;
1549
- return defaultSaveOperation ? ((_a = action === null || action === void 0 ? void 0 : action.payload) === null || _a === void 0 ? void 0 : _a.onSuccessAction) ? concat(of2(bcCancelPendingChanges({ bcNames: [bcName] })), of2(action.payload.onSuccessAction)) : EMPTY : concat.apply(void 0, __spreadArray([of2(sendOperationSuccess({ bcName: bcName, cursor: cursor })),
1550
- of2(bcForceUpdate({ bcName: bcName }))], postOperationRoutine(widgetName, postInvoke, preInvoke, operationType, bcName), false));
1603
+ return defaultSaveOperation ? ((_b = action === null || action === void 0 ? void 0 : action.payload) === null || _b === void 0 ? void 0 : _b.onSuccessAction) ? concat(of3(bcCancelPendingChanges({ bcNames: [bcName] })), of3(action.payload.onSuccessAction)) : EMPTY2 : concat.apply(void 0, __spreadArray([of3(sendOperationSuccess({ bcName: bcName, cursor: cursor })),
1604
+ of3(bcForceUpdate({ bcName: bcName }))], postOperationRoutine(widgetName, postInvoke, preInvoke, operationType, bcName), false));
1551
1605
  }), catchError(function (e) {
1552
1606
  var _a, _b, _c, _d, _e, _f;
1553
1607
  console.error(e);
@@ -1558,25 +1612,25 @@ var sendOperationEpic = function (action$, state$, _a) {
1558
1612
  entityError = (_d = operationError === null || operationError === void 0 ? void 0 : operationError.error) === null || _d === void 0 ? void 0 : _d.entity;
1559
1613
  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];
1560
1614
  }
1561
- return of2(sendOperationFail({ bcName: bcName, bcUrl: bcUrl, viewError: viewError, entityError: entityError }));
1615
+ return concat(of3(sendOperationFail({ bcName: bcName, bcUrl: bcUrl, viewError: viewError, entityError: entityError })), createApiErrorObservable(e, context));
1562
1616
  }));
1563
1617
  }));
1564
1618
  };
1565
1619
  // src/epics/view/showAssocPopupEpic.ts
1566
- import { EMPTY as EMPTY2, filter as filter2, mergeMap as mergeMap2, of as of3 } from "rxjs";
1567
- import { WidgetTypes as WidgetTypes2 } from "@cxbox-ui/schema";
1620
+ import { EMPTY as EMPTY3, filter as filter2, mergeMap as mergeMap2, of as of4 } from "rxjs";
1621
+ import { WidgetTypes as WidgetTypes3 } from "@cxbox-ui/schema";
1568
1622
  var showAssocPopupEpic = function (action$, state$) { return action$.pipe(filter2(showViewPopup.match), filter2(function (action) { return !!(action.payload.calleeBCName && action.payload.associateFieldKey); }), mergeMap2(function (action) {
1569
1623
  var _a, _b, _c, _d;
1570
1624
  var _e = action.payload, bcName = _e.bcName, calleeBCName = _e.calleeBCName;
1571
1625
  var state = state$.value;
1572
- var assocWidget = state.view.widgets.find(function (widget) { return widget.bcName === bcName && widget.type === WidgetTypes2.AssocListPopup; });
1626
+ var assocWidget = state.view.widgets.find(function (widget) { return widget.bcName === bcName && widget.type === WidgetTypes3.AssocListPopup; });
1573
1627
  var calleeCursor = (_a = state.screen.bo.bc[calleeBCName]) === null || _a === void 0 ? void 0 : _a.cursor;
1574
1628
  var calleePendingChanges = (_b = state.view.pendingDataChanges[calleeBCName]) === null || _b === void 0 ? void 0 : _b[calleeCursor];
1575
1629
  var assocFieldKey = action.payload.associateFieldKey;
1576
1630
  var assocFieldChanges = calleePendingChanges === null || calleePendingChanges === void 0 ? void 0 : calleePendingChanges[assocFieldKey];
1577
1631
  var somethingMissing = !assocWidget || !calleePendingChanges || !assocFieldChanges || !assocFieldChanges;
1578
1632
  if (somethingMissing || assocWidget.options && !assocWidget.options.hierarchyFull) {
1579
- return EMPTY2;
1633
+ return EMPTY3;
1580
1634
  }
1581
1635
  var popupInitPendingChanges = {};
1582
1636
  assocFieldChanges.forEach(function (record) {
@@ -1599,60 +1653,64 @@ var showAssocPopupEpic = function (action$, state$) { return action$.pipe(filter
1599
1653
  }
1600
1654
  });
1601
1655
  }
1602
- return of3(changeDataItems({
1656
+ return of4(changeDataItems({
1603
1657
  bcName: bcName,
1604
1658
  cursors: Object.keys(popupInitPendingChanges),
1605
1659
  dataItems: Object.values(popupInitPendingChanges)
1606
1660
  }));
1607
1661
  })); };
1608
1662
  // src/epics/view/fileUploadConfirmEpic.ts
1609
- import { concat as concat2, filter as filter3, mergeMap as mergeMap3, of as of4 } from "rxjs";
1663
+ import { catchError as catchError2, concat as concat2, filter as filter3, mergeMap as mergeMap3, of as of5 } from "rxjs";
1610
1664
  import { OperationTypeCrud as OperationTypeCrud5 } from "@cxbox-ui/schema";
1611
1665
  var fileUploadConfirmEpic = function (action$, state$, _a) {
1612
1666
  var api = _a.api;
1613
1667
  return action$.pipe(filter3(bulkUploadFiles.match), mergeMap3(function (action) {
1614
- var _a;
1668
+ var _a, _b;
1615
1669
  var state = state$.value;
1616
- var bcName = state.view.popupData.bcName;
1617
- var bcUrl = buildBcUrl(bcName, true);
1618
- var widgetName = (_a = state.view.widgets.find(function (item) { return item.bcName === bcName; })) === null || _a === void 0 ? void 0 : _a.name;
1670
+ var bcName = (_a = state.view.popupData) === null || _a === void 0 ? void 0 : _a.bcName;
1671
+ var bcUrl = buildBcUrl(bcName, true, state);
1672
+ var widgetName = (_b = state.view.widgets.find(function (item) { return item.bcName === bcName; })) === null || _b === void 0 ? void 0 : _b.name;
1619
1673
  var data = {
1620
1674
  bulkIds: action.payload.fileIds
1621
1675
  };
1622
1676
  return api.customAction(state.screen.screenName, bcUrl, data, null, { _action: "file-upload-save" }).pipe(mergeMap3(function (response) {
1623
- var postInvoke = response.postActions[0];
1677
+ var _a;
1678
+ var postInvoke = (_a = response.postActions) === null || _a === void 0 ? void 0 : _a[0];
1624
1679
  var preInvoke = response.preInvoke;
1625
- return concat2.apply(void 0, __spreadArray([of4(sendOperationSuccess({ bcName: bcName, cursor: null })),
1626
- of4(bcForceUpdate({ bcName: bcName })),
1627
- of4(closeViewPopup(null))], postOperationRoutine(widgetName, postInvoke, preInvoke, OperationTypeCrud5.save, bcName), false));
1680
+ return concat2.apply(void 0, __spreadArray([of5(sendOperationSuccess({ bcName: bcName, cursor: null })),
1681
+ of5(bcForceUpdate({ bcName: bcName })),
1682
+ of5(closeViewPopup(null))], postOperationRoutine(widgetName, postInvoke, preInvoke, OperationTypeCrud5.save, bcName), false));
1683
+ }), catchError2(function (error) {
1684
+ console.error(error);
1685
+ return createApiErrorObservable(error);
1628
1686
  }));
1629
1687
  }));
1630
1688
  };
1631
1689
  // src/epics/view/selectTableCellInitEpic.ts
1632
- import { concat as concat3, filter as filter4, mergeMap as mergeMap4, of as of5 } from "rxjs";
1690
+ import { concat as concat3, filter as filter4, mergeMap as mergeMap4, of as of6 } from "rxjs";
1633
1691
  var selectTableCellInitEpic = function (action$, state$) { return action$.pipe(filter4(selectTableCellInit.match), mergeMap4(function (action) {
1634
1692
  var _a;
1635
1693
  var resultObservables = [];
1636
1694
  var state = state$.value;
1637
1695
  var _b = action.payload, nextRowId = _b.rowId, fieldKey = _b.fieldKey;
1638
1696
  var nextWidget = state.view.widgets.find(function (widget) { return widget.name === action.payload.widgetName; });
1639
- var nextBcName = nextWidget.bcName;
1697
+ var nextBcName = nextWidget === null || nextWidget === void 0 ? void 0 : nextWidget.bcName;
1640
1698
  var nextBcCursor = (_a = state.screen.bo.bc[nextBcName]) === null || _a === void 0 ? void 0 : _a.cursor;
1641
1699
  var selectedCell = state.view.selectedCell;
1642
1700
  if (nextRowId !== nextBcCursor) {
1643
- resultObservables.push(of5(bcSelectRecord({ bcName: nextBcName, cursor: nextRowId })));
1701
+ resultObservables.push(of6(bcSelectRecord({ bcName: nextBcName, cursor: nextRowId })));
1644
1702
  }
1645
- if (!selectedCell || fieldKey !== selectedCell.fieldKey || nextRowId !== selectedCell.rowId || nextWidget.name !== selectedCell.widgetName) {
1646
- resultObservables.push(of5(selectTableCell({ widgetName: nextWidget.name, rowId: nextRowId, fieldKey: fieldKey })));
1703
+ if (!selectedCell || fieldKey !== selectedCell.fieldKey || nextRowId !== selectedCell.rowId || (nextWidget === null || nextWidget === void 0 ? void 0 : nextWidget.name) !== selectedCell.widgetName) {
1704
+ resultObservables.push(of6(selectTableCell({ widgetName: nextWidget === null || nextWidget === void 0 ? void 0 : nextWidget.name, rowId: nextRowId, fieldKey: fieldKey })));
1647
1705
  }
1648
1706
  return concat3.apply(void 0, resultObservables);
1649
1707
  })); };
1650
1708
  // src/epics/view/showFileUploadPopupEpic.ts
1651
- import { concat as concat4, filter as filter5, mergeMap as mergeMap5, of as of6 } from "rxjs";
1709
+ import { concat as concat4, filter as filter5, mergeMap as mergeMap5, of as of7 } from "rxjs";
1652
1710
  import { OperationTypeCrud as OperationTypeCrud6 } from "@cxbox-ui/schema";
1653
1711
  var showFileUploadPopupEpic = function (action$, state$) { return action$.pipe(filter5(sendOperation.match), filter5(function (action) { return matchOperationRole(OperationTypeCrud6.fileUpload, action.payload, state$.value); }), mergeMap5(function (action) {
1654
1712
  var _a;
1655
- return concat4(of6(bcChangeCursors({ cursorsMap: (_a = {}, _a[action.payload.bcName] = null, _a) })), of6(showFileUploadPopup({ widgetName: action.payload.widgetName })));
1713
+ return concat4(of7(bcChangeCursors({ cursorsMap: (_a = {}, _a[action.payload.bcName] = null, _a) })), of7(showFileUploadPopup({ widgetName: action.payload.widgetName })));
1656
1714
  })); };
1657
1715
  // src/epics/view/sendOperationAssociateEpic.ts
1658
1716
  import { filter as filter6, map } from "rxjs";
@@ -1667,31 +1725,31 @@ var sendOperationAssociateEpic = function (action$, state$) { return action$.pip
1667
1725
  });
1668
1726
  })); };
1669
1727
  // src/epics/view/getRowMetaByForceActiveEpic.ts
1670
- import { EMPTY as EMPTY3, concat as concat5, filter as filter7, mergeMap as mergeMap6, of as of7, catchError as catchError2 } from "rxjs";
1671
- import { WidgetTypes as WidgetTypes3 } from "@cxbox-ui/schema";
1728
+ import { EMPTY as EMPTY4, concat as concat5, filter as filter7, mergeMap as mergeMap6, of as of8, catchError as catchError3 } from "rxjs";
1729
+ import { WidgetTypes as WidgetTypes4 } from "@cxbox-ui/schema";
1672
1730
  import { nanoid } from "@reduxjs/toolkit";
1673
1731
  var getRowMetaByForceActiveEpic = function (action$, state$, _a) {
1674
1732
  var api = _a.api;
1675
1733
  return action$.pipe(filter7(changeDataItem.match), mergeMap6(function (action) {
1676
- var _a, _b, _c, _d;
1734
+ var _a, _b, _c, _d, _e;
1677
1735
  var state = state$.value;
1678
1736
  var initUrl = state.view.url;
1679
- var _e = action.payload, bcName = _e.bcName, cursor = _e.cursor, disableRetry = _e.disableRetry;
1737
+ var _f = action.payload, bcName = _f.bcName, cursor = _f.cursor, disableRetry = _f.disableRetry;
1680
1738
  var isBcHierarchy = state.view.widgets.some(function (widget) {
1681
1739
  var _a, _b;
1682
- return widget.bcName === bcName && widget.type === WidgetTypes3.AssocListPopup && (((_a = widget.options) === null || _a === void 0 ? void 0 : _a.hierarchySameBc) || ((_b = widget.options) === null || _b === void 0 ? void 0 : _b.hierarchyFull));
1740
+ return widget.bcName === bcName && widget.type === WidgetTypes4.AssocListPopup && (((_a = widget.options) === null || _a === void 0 ? void 0 : _a.hierarchySameBc) || ((_b = widget.options) === null || _b === void 0 ? void 0 : _b.hierarchyFull));
1683
1741
  });
1684
1742
  if (isBcHierarchy) {
1685
- return EMPTY3;
1686
- }
1687
- 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) && [WidgetTypes3.PickListPopup, WidgetTypes3.FlatTreePopup].includes(item.type); });
1688
- var bcUrl = buildBcUrl(bcName, true);
1689
- var pendingChanges = state.view.pendingDataChanges[bcName][cursor];
1690
- var handledForceActive = ((_a = state.view.handledForceActive[bcName]) === null || _a === void 0 ? void 0 : _a[cursor]) || {};
1691
- var currentRecordData = (_b = state.data[bcName]) === null || _b === void 0 ? void 0 : _b.find(function (record) { return record.id === cursor; });
1692
- var fieldsRowMeta = (_d = (_c = state.view.rowMeta[bcName]) === null || _c === void 0 ? void 0 : _c[bcUrl]) === null || _d === void 0 ? void 0 : _d.fields;
1743
+ return EMPTY4;
1744
+ }
1745
+ 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) && [WidgetTypes4.PickListPopup, WidgetTypes4.FlatTreePopup].includes(item.type); });
1746
+ var bcUrl = buildBcUrl(bcName, true, state);
1747
+ var pendingChanges = (_a = state.view.pendingDataChanges[bcName]) === null || _a === void 0 ? void 0 : _a[cursor];
1748
+ var handledForceActive = ((_b = state.view.handledForceActive[bcName]) === null || _b === void 0 ? void 0 : _b[cursor]) || {};
1749
+ var currentRecordData = (_c = state.data[bcName]) === null || _c === void 0 ? void 0 : _c.find(function (record) { return record.id === cursor; });
1750
+ var fieldsRowMeta = (_e = (_d = state.view.rowMeta[bcName]) === null || _d === void 0 ? void 0 : _d[bcUrl]) === null || _e === void 0 ? void 0 : _e.fields;
1693
1751
  var changedFiledKey = null;
1694
- var closePopup = concat5(of7(viewClearPickMap(null)), of7(closeViewPopup(null)), of7(bcRemoveAllFilters({ bcName: bcName })));
1752
+ var closePopup = concat5(of8(closeViewPopup(null)), of8(viewClearPickMap(null)), of8(bcRemoveAllFilters({ bcName: bcName })));
1695
1753
  var someForceActiveChanged = fieldsRowMeta === null || fieldsRowMeta === void 0 ? void 0 : fieldsRowMeta.filter(function (field) { return field.forceActive && pendingChanges[field.key] !== void 0; }).some(function (field) {
1696
1754
  var result = pendingChanges[field.key] !== handledForceActive[field.key];
1697
1755
  if (result) {
@@ -1701,10 +1759,10 @@ var getRowMetaByForceActiveEpic = function (action$, state$, _a) {
1701
1759
  });
1702
1760
  var requestId = nanoid();
1703
1761
  if (someForceActiveChanged && !disableRetry) {
1704
- return concat5(of7(addPendingRequest({ request: { requestId: requestId, type: "force-active" } })), api.getRmByForceActive(state.screen.screenName, bcUrl, __assign(__assign({}, pendingChanges), { vstamp: currentRecordData.vstamp })).pipe(mergeMap6(function (data) {
1705
- var result = [of7(removePendingRequest({ requestId: requestId }))];
1762
+ return concat5(of8(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(mergeMap6(function (data) {
1763
+ var result = [of8(removePendingRequest({ requestId: requestId }))];
1706
1764
  if (state.view.url === initUrl) {
1707
- result.push(of7(forceActiveRmUpdate({
1765
+ result.push(of8(forceActiveRmUpdate({
1708
1766
  rowMeta: data,
1709
1767
  currentRecordData: currentRecordData,
1710
1768
  bcName: bcName,
@@ -1716,7 +1774,7 @@ var getRowMetaByForceActiveEpic = function (action$, state$, _a) {
1716
1774
  result.push(closePopup);
1717
1775
  }
1718
1776
  return concat5.apply(void 0, result);
1719
- }), catchError2(function (e) {
1777
+ }), catchError3(function (e) {
1720
1778
  var _a;
1721
1779
  var _b, _c, _d, _e, _f, _g;
1722
1780
  console.error(e);
@@ -1727,29 +1785,35 @@ var getRowMetaByForceActiveEpic = function (action$, state$, _a) {
1727
1785
  entityError = (_e = operationError === null || operationError === void 0 ? void 0 : operationError.error) === null || _e === void 0 ? void 0 : _e.entity;
1728
1786
  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];
1729
1787
  }
1730
- return concat5(of7(removePendingRequest({ requestId: requestId })), state.view.url === initUrl ? concat5(of7(changeDataItem({
1788
+ return concat5(of8(removePendingRequest({ requestId: requestId })), state.view.url === initUrl ? concat5(of8(changeDataItem({
1731
1789
  bcName: bcName,
1790
+ bcUrl: buildBcUrl(bcName, true, state),
1732
1791
  cursor: cursor,
1733
- dataItem: (_a = {}, _a[changedFiledKey] = currentRecordData[changedFiledKey], _a),
1792
+ dataItem: (_a = {}, _a[changedFiledKey] = currentRecordData === null || currentRecordData === void 0 ? void 0 : currentRecordData[changedFiledKey], _a),
1734
1793
  disableRetry: true
1735
- })), of7(forceActiveChangeFail({ bcName: bcName, bcUrl: bcUrl, viewError: viewError, entityError: entityError }))) : EMPTY3);
1794
+ })), of8(forceActiveChangeFail({ bcName: bcName, bcUrl: bcUrl, viewError: viewError, entityError: entityError }))) : EMPTY4, createApiErrorObservable(e));
1736
1795
  })));
1737
1796
  }
1738
- return isPickListPopup ? closePopup : EMPTY3;
1797
+ return isPickListPopup ? closePopup : EMPTY4;
1739
1798
  }));
1740
1799
  };
1741
1800
  // src/epics/view/showAllTableRecordsInitEpic.ts
1742
- import { concat as concat6, filter as filter8, mergeMap as mergeMap7, of as of8 } from "rxjs";
1801
+ import { concat as concat6, filter as filter8, mergeMap as mergeMap7, of as of9 } from "rxjs";
1743
1802
  var showAllTableRecordsInitEpic = function (action$, state$) { return action$.pipe(filter8(showAllTableRecordsInit.match), mergeMap7(function (action) {
1744
1803
  var _a;
1745
1804
  var resultObservables = [];
1746
- var bcName = action.payload.bcName;
1747
- resultObservables.push(of8(bcChangeCursors({ cursorsMap: (_a = {}, _a[bcName] = null, _a) })));
1748
- resultObservables.push(of8(bcForceUpdate({ bcName: bcName })));
1805
+ var _b = action.payload, bcName = _b.bcName, cursor = _b.cursor;
1806
+ var state = state$.value;
1807
+ var route = state.router;
1808
+ resultObservables.push(of9(bcChangeCursors({ cursorsMap: (_a = {}, _a[bcName] = null, _a) })));
1809
+ var bcPath = route.bcPath.slice(0, route.bcPath.indexOf("".concat(bcName, "/").concat(cursor)));
1810
+ var url = defaultBuildURL(__assign(__assign({}, route), { bcPath: bcPath }));
1811
+ resultObservables.push(of9(bcForceUpdate({ bcName: bcName })));
1812
+ resultObservables.push(of9(changeLocation({ location: defaultParseURL(new URL(url, window.location.origin)) })));
1749
1813
  return concat6.apply(void 0, resultObservables);
1750
1814
  })); };
1751
1815
  // src/epics/view/clearPendingDataChangesAfterCursorChangeEpic.ts
1752
- import { EMPTY as EMPTY4, filter as filter9, mergeMap as mergeMap8, of as of9 } from "rxjs";
1816
+ import { EMPTY as EMPTY5, filter as filter9, mergeMap as mergeMap8, of as of10 } from "rxjs";
1753
1817
  var clearPendingDataChangesAfterCursorChangeEpic = function (action$, state$) { return action$.pipe(filter9(bcChangeCursors.match), mergeMap8(function (action) {
1754
1818
  var state = state$.value;
1755
1819
  var nextCursors = parseBcCursors(state.router.bcPath) || {};
@@ -1762,28 +1826,128 @@ var clearPendingDataChangesAfterCursorChangeEpic = function (action$, state$) {
1762
1826
  }
1763
1827
  });
1764
1828
  if (Object.keys(cursorsDiffMap).length) {
1765
- return of9(bcChangeCursors({ cursorsMap: cursorsDiffMap }));
1829
+ return of10(bcChangeCursors({ cursorsMap: cursorsDiffMap }));
1766
1830
  }
1767
- return EMPTY4;
1831
+ return EMPTY5;
1768
1832
  })); };
1769
1833
  // src/epics/router/drilldownEpic.ts
1770
- import { EMPTY as EMPTY5, filter as filter10, switchMap } from "rxjs";
1834
+ import { concat as concat7, EMPTY as EMPTY6, filter as filter10, switchMap } from "rxjs";
1771
1835
  var drillDownEpic = function (action$, state$) { return action$.pipe(filter10(drillDown.match), switchMap(function (action) {
1772
- return EMPTY5;
1836
+ var _a, _b;
1837
+ var state = state$.value;
1838
+ var url = action.payload.url;
1839
+ var result = [];
1840
+ switch (action.payload.drillDownType) {
1841
+ case DrillDownType.external:
1842
+ window.location.href = url;
1843
+ break;
1844
+ case DrillDownType.externalNew:
1845
+ if (/^[a-z0-9]+:\/\//i.test(url)) {
1846
+ window.open(url);
1847
+ }
1848
+ break;
1849
+ case DrillDownType.relative:
1850
+ window.location.href = "".concat(window.location.origin, "/").concat(url);
1851
+ break;
1852
+ case DrillDownType.relativeNew:
1853
+ window.open("".concat(window.location.origin, "/").concat(url), "_blank");
1854
+ break;
1855
+ case DrillDownType.inner:
1856
+ default:
1857
+ var urlBase = url.split("?")[0];
1858
+ var urlObject = new URL(url, window.location.origin);
1859
+ var urlFilters = urlObject.searchParams.get("filters");
1860
+ var urlSorters = urlObject.searchParams.get("sorters");
1861
+ var newFilters_1 = {};
1862
+ var newSorters = {};
1863
+ try {
1864
+ newFilters_1 = (_a = JSON.parse(urlFilters)) !== null && _a !== void 0 ? _a : newFilters_1;
1865
+ }
1866
+ catch (_c) {
1867
+ urlFilters && console.warn("Failed to parse filters on drilldown");
1868
+ newFilters_1 = {};
1869
+ }
1870
+ try {
1871
+ newSorters = (_b = JSON.parse(urlSorters)) !== null && _b !== void 0 ? _b : newSorters;
1872
+ }
1873
+ catch (_d) {
1874
+ urlSorters && console.warn("Failed to parse sorters on drilldown");
1875
+ newSorters = {};
1876
+ }
1877
+ var bcToUpdate_1 = {};
1878
+ Object.keys(state.screen.filters).forEach(function (bcName) {
1879
+ if (newFilters_1[bcName] === "" || newFilters_1[bcName]) {
1880
+ bcToUpdate_1[bcName] = true;
1881
+ result.push(bcRemoveAllFilters({ bcName: bcName }));
1882
+ }
1883
+ });
1884
+ var nextState = defaultParseURL(urlObject);
1885
+ var viewName_1 = nextState.viewName;
1886
+ Object.entries(newFilters_1).forEach(function (_a) {
1887
+ var _b;
1888
+ var bcName = _a[0], filterExpression = _a[1];
1889
+ var parsedFilters = (_b = parseFilters(filterExpression)) === null || _b === void 0 ? void 0 : _b.map(function (item) { return (__assign(__assign({}, item), { viewName: viewName_1 })); });
1890
+ parsedFilters === null || parsedFilters === void 0 ? void 0 : parsedFilters.forEach(function (parsedFilter) {
1891
+ bcToUpdate_1[bcName] = true;
1892
+ result.push(bcAddFilter({ bcName: bcName, filter: parsedFilter }));
1893
+ });
1894
+ });
1895
+ Object.entries(newSorters).forEach(function (_a) {
1896
+ var bcName = _a[0], sortExpression = _a[1];
1897
+ var sorter = parseSorters(sortExpression);
1898
+ result.push(bcAddSorter({ bcName: bcName, sorter: sorter }));
1899
+ bcToUpdate_1[bcName] = true;
1900
+ });
1901
+ var prevState = state.router;
1902
+ var willUpdateAnyway = shallowCompare(prevState, nextState, ["params"]).length > 0;
1903
+ if (!willUpdateAnyway) {
1904
+ Object.keys(bcToUpdate_1).forEach(function (bcName) {
1905
+ result.push(bcForceUpdate({ bcName: bcName }));
1906
+ });
1907
+ }
1908
+ result.push(changeLocation({ location: defaultParseURL(new URL(makeRelativeUrl(urlBase), window.location.origin)) }));
1909
+ break;
1910
+ }
1911
+ return result.length ? concat7(result) : EMPTY6;
1773
1912
  })); };
1913
+ function shallowCompare(prevProps, nextProps, ignore) {
1914
+ if (ignore === void 0) { ignore = []; }
1915
+ var diffProps = [];
1916
+ if (!prevProps && !nextProps) {
1917
+ return null;
1918
+ }
1919
+ if (!prevProps) {
1920
+ return Object.keys(nextProps);
1921
+ }
1922
+ if (!nextProps) {
1923
+ return Object.keys(prevProps);
1924
+ }
1925
+ var newKeys = Object.keys(nextProps);
1926
+ newKeys.forEach(function (key) {
1927
+ if (prevProps[key] !== nextProps[key] && !ignore.includes(key)) {
1928
+ diffProps.push(key);
1929
+ }
1930
+ });
1931
+ Object.keys(prevProps).forEach(function (key) {
1932
+ if (!newKeys.includes(key)) {
1933
+ diffProps.push(key);
1934
+ }
1935
+ });
1936
+ return diffProps;
1937
+ }
1774
1938
  // src/epics/router/loginDoneEpic.ts
1775
- import { filter as filter11, of as of10, switchMap as switchMap2 } from "rxjs";
1939
+ import { filter as filter11, of as of11, switchMap as switchMap2 } from "rxjs";
1776
1940
  var loginDoneEpic = function (action$, state$) { return action$.pipe(filter11(loginDone.match), switchMap2(function (action) {
1777
1941
  var state = state$.value;
1778
1942
  if (state.router.type === "router" /* router */) {
1779
- return of10(handleRouter(state.router));
1943
+ return of11(handleRouter(state.router));
1780
1944
  }
1781
1945
  var nextScreenName = state.router.screenName;
1782
1946
  var nextScreen = state.session.screens.find(function (item) { return nextScreenName ? item.name === nextScreenName : item.defaultScreen; }) || state.session.screens[0];
1783
- return nextScreen ? of10(selectScreen({ screen: nextScreen })) : of10(selectScreenFail({ screenName: nextScreenName }));
1947
+ return nextScreen ? of11(selectScreen({ screen: nextScreen })) : of11(selectScreenFail({ screenName: nextScreenName }));
1784
1948
  })); };
1785
1949
  // src/epics/router/selectViewEpic.ts
1786
- import { EMPTY as EMPTY6, filter as filter12, of as of11, switchMap as switchMap3 } from "rxjs";
1950
+ import { EMPTY as EMPTY7, filter as filter12, of as of12, switchMap as switchMap3 } from "rxjs";
1787
1951
  var changeViewEpic = function (action$, state$) { return action$.pipe(filter12(selectView.match), switchMap3(function (action) {
1788
1952
  var state = state$.value;
1789
1953
  var nextCursors = parseBcCursors(state.router.bcPath) || {};
@@ -1796,77 +1960,77 @@ var changeViewEpic = function (action$, state$) { return action$.pipe(filter12(s
1796
1960
  }
1797
1961
  });
1798
1962
  if (Object.keys(cursorsDiffMap).length) {
1799
- return of11(bcChangeCursors({ cursorsMap: cursorsDiffMap }));
1963
+ return of12(bcChangeCursors({ cursorsMap: cursorsDiffMap }));
1800
1964
  }
1801
- return EMPTY6;
1965
+ return EMPTY7;
1802
1966
  })); };
1803
1967
  // src/epics/router/handleRouterEpic.ts
1804
- import { catchError as catchError3, EMPTY as EMPTY7, filter as filter13, mergeMap as mergeMap9, switchMap as switchMap4 } from "rxjs";
1968
+ import { catchError as catchError4, EMPTY as EMPTY8, filter as filter13, mergeMap as mergeMap9, switchMap as switchMap4 } from "rxjs";
1805
1969
  var handleRouterEpic = function (action$, state$, _a) {
1806
1970
  var api = _a.api;
1807
1971
  return action$.pipe(filter13(handleRouter.match), switchMap4(function (action) {
1808
1972
  var path = action.payload.path;
1809
1973
  var params = action.payload.params;
1810
1974
  return api.routerRequest(path, params).pipe(mergeMap9(function () {
1811
- return EMPTY7;
1812
- }), catchError3(function (error) {
1975
+ return EMPTY8;
1976
+ }), catchError4(function (error) {
1813
1977
  console.error(error);
1814
- return EMPTY7;
1978
+ return createApiErrorObservable(error);
1815
1979
  }));
1816
1980
  }));
1817
1981
  };
1818
1982
  // src/epics/router/selectScreenEpic.ts
1819
- import { filter as filter14, of as of12, switchMap as switchMap5 } from "rxjs";
1983
+ import { filter as filter14, of as of13, switchMap as switchMap5 } from "rxjs";
1820
1984
  var changeScreen = function (action$, state$) { return action$.pipe(filter14(selectScreen.match), switchMap5(function (action) {
1821
1985
  var state = state$.value;
1822
1986
  var nextViewName = state.router.viewName;
1823
1987
  var requestedView = state.screen.views.find(function (item) { return item.name === nextViewName; });
1824
1988
  var defaultView = !nextViewName && state.screen.primaryView && state.screen.views.find(function (item) { return item.name === state.screen.primaryView; });
1825
1989
  var nextView = requestedView || defaultView || state.screen.views[0];
1826
- return nextView ? of12(selectView(nextView)) : of12(selectViewFail({ viewName: nextViewName }));
1990
+ return nextView ? of13(selectView(nextView)) : of13(selectViewFail({ viewName: nextViewName }));
1827
1991
  })); };
1828
1992
  // src/epics/router/userDrillDownEpic.ts
1829
- import { catchError as catchError4, concat as concat7, EMPTY as EMPTY8, filter as filter15, mergeMap as mergeMap10, of as of13, switchMap as switchMap6 } from "rxjs";
1993
+ import { catchError as catchError5, concat as concat8, EMPTY as EMPTY9, filter as filter15, mergeMap as mergeMap10, of as of14, switchMap as switchMap6 } from "rxjs";
1830
1994
  var userDrillDownEpic = function (action$, state$, _a) {
1831
1995
  var api = _a.api;
1832
1996
  return action$.pipe(filter15(userDrillDown.match), switchMap6(function (action) {
1833
1997
  var state = state$.value;
1834
1998
  var _a = action.payload, bcName = _a.bcName, fieldKey = _a.fieldKey, cursor = _a.cursor;
1835
- var bcUrl = buildBcUrl(bcName, true);
1999
+ var bcUrl = buildBcUrl(bcName, true, state);
1836
2000
  return api.fetchRowMeta(state.screen.screenName, bcUrl).pipe(mergeMap10(function (rowMeta) {
1837
2001
  var _a, _b, _c, _d;
1838
2002
  var drillDownField = rowMeta.fields.find(function (field) { return field.key === fieldKey; });
1839
2003
  var route = state.router;
1840
2004
  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;
1841
2005
  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];
1842
- return customDrillDownUrl || (drillDownField === null || drillDownField === void 0 ? void 0 : drillDownField.drillDown) || (drillDownField === null || drillDownField === void 0 ? void 0 : drillDownField.drillDown) !== route.path ? concat7(drillDownField.drillDownType !== DrillDownType.inner ? of13(bcFetchRowMetaSuccess({ bcName: bcName, rowMeta: rowMeta, bcUrl: bcUrl, cursor: cursor })) : EMPTY8, of13(userDrillDownSuccess({ bcName: bcName, bcUrl: bcUrl, cursor: cursor })), of13(drillDown({
2006
+ return customDrillDownUrl || (drillDownField === null || drillDownField === void 0 ? void 0 : drillDownField.drillDown) || (drillDownField === null || drillDownField === void 0 ? void 0 : drillDownField.drillDown) !== route.path ? concat8((drillDownField === null || drillDownField === void 0 ? void 0 : drillDownField.drillDownType) !== DrillDownType.inner ? of14(bcFetchRowMetaSuccess({ bcName: bcName, rowMeta: rowMeta, bcUrl: bcUrl, cursor: cursor })) : EMPTY9, of14(userDrillDownSuccess({ bcName: bcName, bcUrl: bcUrl, cursor: cursor })), of14(drillDown({
1843
2007
  url: customDrillDownUrl || drillDownField.drillDown,
1844
2008
  drillDownType: drillDownField.drillDownType,
1845
2009
  route: route
1846
- }))) : EMPTY8;
1847
- }), catchError4(function (error) {
2010
+ }))) : EMPTY9;
2011
+ }), catchError5(function (error) {
1848
2012
  console.error(error);
1849
- return EMPTY8;
2013
+ return createApiErrorObservable(error);
1850
2014
  }));
1851
2015
  }));
1852
2016
  };
1853
2017
  // src/epics/router/changeLocationEpic.ts
1854
- import { concat as concat8, EMPTY as EMPTY9, filter as filter16, mergeMap as mergeMap11, of as of14 } from "rxjs";
2018
+ import { concat as concat9, EMPTY as EMPTY10, filter as filter16, mergeMap as mergeMap11, of as of15 } from "rxjs";
1855
2019
  var changeLocationEpic = function (action$, state$) { return action$.pipe(filter16(changeLocation.match), mergeMap11(function (action) {
1856
2020
  var _a, _b;
1857
2021
  var state = state$.value;
1858
2022
  if (!state.session.active) {
1859
- return EMPTY9;
2023
+ return EMPTY10;
1860
2024
  }
1861
2025
  if (state.router.type === "router" /* router */) {
1862
- return of14(handleRouter(state.router));
2026
+ return of15(handleRouter(state.router));
1863
2027
  }
1864
2028
  var currentScreenName = state.screen.screenName;
1865
2029
  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);
1866
2030
  var nextScreenName = state.router.type === "default" /* default */ ? defaultScreenName : state.router.screenName;
1867
2031
  if (nextScreenName !== currentScreenName) {
1868
2032
  var nextScreen = state.session.screens.find(function (item) { return item.name === nextScreenName; });
1869
- return nextScreen ? of14(selectScreen({ screen: nextScreen })) : of14(selectScreenFail({ screenName: nextScreenName }));
2033
+ return nextScreen ? of15(selectScreen({ screen: nextScreen })) : of15(selectScreenFail({ screenName: nextScreenName }));
1870
2034
  }
1871
2035
  var currentViewName = state.view.name;
1872
2036
  var nextViewName = state.router.viewName;
@@ -1883,21 +2047,21 @@ var changeLocationEpic = function (action$, state$) { return action$.pipe(filter
1883
2047
  var needUpdateViews = nextViewName !== currentViewName;
1884
2048
  var resultObservables = [];
1885
2049
  if (needUpdateCursors) {
1886
- resultObservables.push(of14(bcChangeCursors({ cursorsMap: cursorsDiffMap })));
2050
+ resultObservables.push(of15(bcChangeCursors({ cursorsMap: cursorsDiffMap })));
1887
2051
  }
1888
2052
  if (needUpdateViews) {
1889
2053
  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];
1890
- resultObservables.push(nextView ? of14(selectView(nextView)) : of14(selectViewFail({ viewName: nextViewName })));
2054
+ resultObservables.push(nextView ? of15(selectView(nextView)) : of15(selectViewFail({ viewName: nextViewName })));
1891
2055
  }
1892
2056
  if (needUpdateCursors && !needUpdateViews) {
1893
2057
  Object.entries(nextCursors).forEach(function (entry) {
1894
2058
  var bcName = entry[0], cursor = entry[1];
1895
2059
  if (!state.data[bcName].find(function (item) { return item.id === cursor; })) {
1896
- resultObservables.push(of14(bcForceUpdate({ bcName: bcName })));
2060
+ resultObservables.push(of15(bcForceUpdate({ bcName: bcName })));
1897
2061
  }
1898
2062
  });
1899
2063
  }
1900
- return concat8.apply(void 0, resultObservables);
2064
+ return concat9.apply(void 0, resultObservables);
1901
2065
  })); };
1902
2066
  // src/epics/router/selectViewFailEpic.ts
1903
2067
  import { filter as filter17, map as map2 } from "rxjs";
@@ -1930,43 +2094,44 @@ var userDrillDownChangeCursorsEpic = function (action$, state$) { return action$
1930
2094
  if (cursor !== action.payload.cursor) {
1931
2095
  return bcChangeCursors({ cursorsMap: (_a = {}, _a[action.payload.bcName] = action.payload.cursor, _a) });
1932
2096
  }
1933
- return void 0;
2097
+ return emptyAction;
1934
2098
  })); };
1935
2099
  // src/epics/screen/apiErrorEpic.ts
1936
2100
  import axios from "axios";
1937
- import { EMPTY as EMPTY10, filter as filter20, mergeMap as mergeMap12, of as of15 } from "rxjs";
1938
- var knownHttpErrors = [401, 409, 418, 500];
2101
+ import { EMPTY as EMPTY11, filter as filter20, mergeMap as mergeMap12, of as of16 } from "rxjs";
1939
2102
  var apiErrorEpic = function (action$) { return action$.pipe(filter20(apiError.match), mergeMap12(function (action) {
1940
2103
  var _a = action.payload, error = _a.error, callContext = _a.callContext;
1941
2104
  if (error.response) {
1942
- return of15(httpError({
2105
+ return of16(httpError({
1943
2106
  statusCode: error.response.status,
1944
2107
  error: error,
1945
2108
  callContext: callContext
1946
2109
  }));
1947
2110
  }
1948
2111
  else if (!axios.isCancel(error)) {
1949
- return of15(showViewError({
2112
+ return of16(showViewError({
1950
2113
  error: {
1951
2114
  type: 2 /* NetworkError */
1952
2115
  }
1953
2116
  }));
1954
2117
  }
1955
- return EMPTY10;
2118
+ return EMPTY11;
1956
2119
  })); };
1957
2120
  // src/epics/screen/downloadFileEpic.ts
1958
- import { EMPTY as EMPTY11, filter as filter21, mergeMap as mergeMap13, tap } from "rxjs";
2121
+ import { EMPTY as EMPTY12, filter as filter21, mergeMap as mergeMap13, tap } from "rxjs";
1959
2122
  var downloadFileEpic = function (action$, state$, _a) {
1960
2123
  var api = _a.api;
1961
2124
  return action$.pipe(filter21(downloadFile.match), tap(function (action) {
2125
+ var fileId = action.payload.fileId;
1962
2126
  var anchor = document.createElement("a");
2127
+ anchor.href = "".concat(api.fileUploadEndpoint, "?id=").concat(encodeURIComponent(fileId));
1963
2128
  anchor.style.display = "none";
1964
2129
  document.body.appendChild(anchor);
1965
2130
  setTimeout(function () {
1966
2131
  anchor.click();
1967
2132
  document.body.removeChild(anchor);
1968
2133
  }, 100);
1969
- }), mergeMap13(function () { return EMPTY11; }));
2134
+ }), mergeMap13(function () { return EMPTY12; }));
1970
2135
  };
1971
2136
  // src/epics/screen/httpError401Epic.ts
1972
2137
  import { filter as filter22, map as map5 } from "rxjs";
@@ -1976,8 +2141,8 @@ var httpError401Epic = function (action$) { return action$.pipe(filter22(httpErr
1976
2141
  // src/epics/screen/httpError409Epic.ts
1977
2142
  import { filter as filter23, map as map6 } from "rxjs";
1978
2143
  var httpError409Epic = function (action$, state$) { return action$.pipe(filter23(httpError.match), filter23(function (action) { return action.payload.statusCode === 409; }), map6(function (action) {
1979
- var _a, _b;
1980
- 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]) || "";
2144
+ var _a, _b, _c;
2145
+ 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]) || "";
1981
2146
  return addNotification({
1982
2147
  key: "action_edit_error",
1983
2148
  message: notificationMessage,
@@ -1991,30 +2156,30 @@ var httpError409Epic = function (action$, state$) { return action$.pipe(filter23
1991
2156
  });
1992
2157
  })); };
1993
2158
  // src/epics/screen/httpError418Epic.ts
1994
- import { concat as concat9, EMPTY as EMPTY12, filter as filter24, mergeMap as mergeMap14, of as of16 } from "rxjs";
2159
+ import { concat as concat10, EMPTY as EMPTY13, filter as filter24, mergeMap as mergeMap14, of as of17 } from "rxjs";
1995
2160
  var httpError418Epic = function (action$, state$) { return action$.pipe(filter24(httpError.match), filter24(function (action) { return action.payload.statusCode === 418; }), mergeMap14(function (action) {
1996
- var _a;
1997
- var _b = action.payload, error = _b.error, callContext = _b.callContext;
2161
+ var _a, _b;
2162
+ var _c = action.payload, error = _c.error, callContext = _c.callContext;
1998
2163
  var result = [];
1999
- var typedError = error.response.data;
2164
+ var typedError = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data;
2000
2165
  if (!typedError.error.popup) {
2001
- return EMPTY12;
2166
+ return EMPTY13;
2002
2167
  }
2003
2168
  var businessError = {
2004
2169
  type: 0 /* BusinessError */,
2005
2170
  message: typedError.error.popup[0]
2006
2171
  };
2007
- result.push(of16(showViewError({ error: businessError })));
2008
- if ((_a = typedError.error.postActions) === null || _a === void 0 ? void 0 : _a[0]) {
2172
+ result.push(of17(showViewError({ error: businessError })));
2173
+ if ((_b = typedError.error.postActions) === null || _b === void 0 ? void 0 : _b[0]) {
2009
2174
  var widget = state$.value.view.widgets.find(function (item) { return item.name === callContext.widgetName; });
2010
- var bcName = widget.bcName;
2011
- result.push(of16(processPostInvoke({
2175
+ var bcName = widget === null || widget === void 0 ? void 0 : widget.bcName;
2176
+ result.push(of17(processPostInvoke({
2012
2177
  bcName: bcName,
2013
2178
  postInvoke: typedError.error.postActions[0],
2014
- widgetName: widget.name
2179
+ widgetName: widget === null || widget === void 0 ? void 0 : widget.name
2015
2180
  })));
2016
2181
  }
2017
- return concat9.apply(void 0, result);
2182
+ return concat10.apply(void 0, result);
2018
2183
  })); };
2019
2184
  // src/epics/screen/httpError500Epic.ts
2020
2185
  import { filter as filter25, map as map7 } from "rxjs";
@@ -2029,16 +2194,18 @@ var httpError500Epic = function (action$, state$) { return action$.pipe(filter25
2029
2194
  })); };
2030
2195
  // src/epics/screen/httpErrorDefaultEpic.ts
2031
2196
  import { filter as filter26, map as map8 } from "rxjs";
2032
- var httpErrorDefaultEpic = function (action$, store) { return action$.pipe(filter26(httpError.match), filter26(function (action) { return !knownHttpErrors.includes(action.payload.statusCode); }), map8(function (action) {
2197
+ var knownHttpErrors = [401, 409, 418, 500];
2198
+ var httpErrorDefaultEpic = function (action$, state$) { return action$.pipe(filter26(httpError.match), filter26(function (action) { return !knownHttpErrors.includes(action.payload.statusCode); }), map8(function (action) {
2199
+ var _a, _b;
2033
2200
  var businessError = {
2034
2201
  type: 0 /* BusinessError */,
2035
- code: action.payload.error.response.status,
2036
- details: action.payload.error.response.data
2202
+ code: (_a = action.payload.error.response) === null || _a === void 0 ? void 0 : _a.status,
2203
+ details: (_b = action.payload.error.response) === null || _b === void 0 ? void 0 : _b.data
2037
2204
  };
2038
2205
  return showViewError({ error: businessError });
2039
2206
  })); };
2040
2207
  // src/epics/screen/downloadFileByUrlEpic.ts
2041
- import { EMPTY as EMPTY13, filter as filter27, mergeMap as mergeMap15, tap as tap2 } from "rxjs";
2208
+ import { EMPTY as EMPTY14, filter as filter27, mergeMap as mergeMap15, tap as tap2 } from "rxjs";
2042
2209
  var downloadFileByUrlEpic = function (action$, state$) { return action$.pipe(filter27(downloadFileByUrl.match), tap2(function (action) {
2043
2210
  var url = action.payload.url;
2044
2211
  var anchor = document.createElement("a");
@@ -2049,19 +2216,23 @@ var downloadFileByUrlEpic = function (action$, state$) { return action$.pipe(fil
2049
2216
  anchor.click();
2050
2217
  document.body.removeChild(anchor);
2051
2218
  }, 100);
2052
- }), mergeMap15(function () { return EMPTY13; })); };
2219
+ }), mergeMap15(function () { return EMPTY14; })); };
2053
2220
  // src/epics/screen/processPostInvokeEpic.ts
2054
- import { EMPTY as EMPTY14, filter as filter28, mergeMap as mergeMap16, of as of17 } from "rxjs";
2221
+ import { EMPTY as EMPTY15, filter as filter28, mergeMap as mergeMap16, of as of18 } from "rxjs";
2055
2222
  var processPostInvokeEpic = function (action$, state$) { return action$.pipe(filter28(processPostInvoke.match), mergeMap16(function (action) {
2056
2223
  var _a;
2224
+ var _b;
2057
2225
  var state = state$.value;
2058
2226
  switch (action.payload.postInvoke.type) {
2059
2227
  case "drillDown" /* drillDown */:
2060
- return of17(drillDown(__assign(__assign({}, action.payload.postInvoke), { route: state.router, widgetName: action.payload.widgetName })));
2228
+ return of18(drillDown(__assign(__assign({}, action.payload.postInvoke), { route: state.router, widgetName: action.payload.widgetName })));
2061
2229
  case "postDelete" /* postDelete */: {
2062
2230
  var cursorsMap = (_a = {}, _a[action.payload.bcName] = null, _a);
2063
2231
  var result = [bcChangeCursors({ cursorsMap: cursorsMap })];
2064
- if (state.router.bcPath.includes("".concat(action.payload.bcName, "/"))) {
2232
+ if ((_b = state.router.bcPath) === null || _b === void 0 ? void 0 : _b.includes("".concat(action.payload.bcName, "/"))) {
2233
+ var newBcUrl = state.router.bcPath.split(action.payload.bcName)[0] || "";
2234
+ var newUrl = "/screen/".concat(state.router.screenName, "/view/").concat(state.router.viewName, "/").concat(newBcUrl);
2235
+ result.push(changeLocation({ location: defaultParseURL(new URL(newUrl, window.location.origin)) }));
2065
2236
  }
2066
2237
  else {
2067
2238
  result.push(bcFetchDataRequest({
@@ -2069,7 +2240,7 @@ var processPostInvokeEpic = function (action$, state$) { return action$.pipe(fil
2069
2240
  widgetName: action.payload.widgetName
2070
2241
  }));
2071
2242
  }
2072
- return of17.apply(void 0, result);
2243
+ return of18.apply(void 0, result);
2073
2244
  }
2074
2245
  case "refreshBC" /* refreshBC */: {
2075
2246
  var bo = state.screen.bo;
@@ -2079,34 +2250,34 @@ var processPostInvokeEpic = function (action$, state$) { return action$.pipe(fil
2079
2250
  var widgetName = action.payload.widgetName || "";
2080
2251
  var infiniteWidgets_1 = state.view.infiniteWidgets || [];
2081
2252
  var infinitePagination = state.view.widgets.some(function (item) { return item.bcName === postInvokeBC_1 && infiniteWidgets_1.includes(item.name); });
2082
- return infinitePagination ? of17(bcFetchDataPages({
2253
+ return infinitePagination ? of18(bcFetchDataPages({
2083
2254
  bcName: postInvokeBCItem.name,
2084
2255
  widgetName: widgetName,
2085
2256
  from: 1,
2086
2257
  to: postInvokeBCItem.page
2087
- })) : of17(bcFetchDataRequest({
2258
+ })) : of18(bcFetchDataRequest({
2088
2259
  bcName: postInvokeBCItem.name,
2089
2260
  widgetName: widgetName
2090
2261
  }));
2091
2262
  }
2092
2263
  case "showMessage" /* showMessage */: {
2093
2264
  var postInvoke = action.payload.postInvoke;
2094
- return of17(showNotification({ type: postInvoke.messageType, message: postInvoke.messageText }));
2265
+ return of18(showNotification({ type: postInvoke.messageType, message: postInvoke.messageText }));
2095
2266
  }
2096
2267
  case "downloadFile" /* downloadFile */: {
2097
2268
  var postInvoke = action.payload.postInvoke;
2098
- return of17(downloadFile({ fileId: postInvoke.fileId }));
2269
+ return of18(downloadFile({ fileId: postInvoke.fileId }));
2099
2270
  }
2100
2271
  case "downloadFileByUrl" /* downloadFileByUrl */: {
2101
2272
  var postInvoke = action.payload.postInvoke;
2102
- return of17(downloadFileByUrl({ url: postInvoke.url }));
2273
+ return of18(downloadFileByUrl({ url: postInvoke.url }));
2103
2274
  }
2104
2275
  default:
2105
- return EMPTY14;
2276
+ return EMPTY15;
2106
2277
  }
2107
2278
  })); };
2108
2279
  // src/epics/screen/processPostInvokeConfirmEpic.ts
2109
- import { EMPTY as EMPTY15, filter as filter29, mergeMap as mergeMap17, of as of18 } from "rxjs";
2280
+ import { EMPTY as EMPTY16, filter as filter29, mergeMap as mergeMap17, of as of19 } from "rxjs";
2110
2281
  import { isAnyOf } from "@reduxjs/toolkit";
2111
2282
  var processPostInvokeConfirmEpic = function (action$, state$) { return action$.pipe(filter29(isAnyOf(processPostInvokeConfirm, processPreInvoke)), mergeMap17(function (action) {
2112
2283
  var _a = action.payload, bcName = _a.bcName, operationType = _a.operationType, widgetName = _a.widgetName;
@@ -2116,7 +2287,7 @@ var processPostInvokeConfirmEpic = function (action$, state$) { return action$.p
2116
2287
  case "info" /* info */:
2117
2288
  case "error" /* error */:
2118
2289
  case "confirmText" /* confirmText */: {
2119
- return of18(operationConfirmation({
2290
+ return of19(operationConfirmation({
2120
2291
  operation: {
2121
2292
  bcName: bcName,
2122
2293
  operationType: operationType,
@@ -2126,37 +2297,37 @@ var processPostInvokeConfirmEpic = function (action$, state$) { return action$.p
2126
2297
  }));
2127
2298
  }
2128
2299
  default:
2129
- return EMPTY15;
2300
+ return EMPTY16;
2130
2301
  }
2131
2302
  })); };
2132
2303
  // src/epics/session/switchRoleEpic.ts
2133
- import { concat as concat10, filter as filter30, switchMap as switchMap7 } from "rxjs";
2304
+ import { concat as concat11, filter as filter30, switchMap as switchMap7 } from "rxjs";
2134
2305
  var switchRoleEpic = function (action$, state$) { return action$.pipe(filter30(switchRole.match), switchMap7(function (action) {
2135
- return concat10([logoutDone(null), login({ login: "", password: "", role: action.payload.role })]);
2306
+ return concat11([logoutDone(null), login({ login: "", password: "", role: action.payload.role })]);
2136
2307
  })); };
2137
2308
  // src/epics/session/refreshMetaEpic.ts
2138
- import { catchError as catchError5, concat as concat11, filter as filter31, mergeMap as mergeMap18, of as of19, switchMap as switchMap8 } from "rxjs";
2309
+ import { catchError as catchError6, concat as concat12, filter as filter31, mergeMap as mergeMap18, switchMap as switchMap8 } from "rxjs";
2139
2310
  var refreshMetaEpic = function (action$, state$, _a) {
2140
2311
  var api = _a.api;
2141
2312
  return action$.pipe(filter31(refreshMeta.match), mergeMap18(function () {
2142
2313
  var state = state$.value;
2143
2314
  var router = state.router;
2144
2315
  var activeRole = state.session.activeRole;
2145
- return api.refreshMeta().pipe(switchMap8(function () { return concat11([
2316
+ return api.refreshMeta().pipe(switchMap8(function () { return concat12([
2317
+ refreshMetaDone(),
2146
2318
  logoutDone(null),
2147
2319
  login({ login: "", password: "", role: activeRole }),
2148
2320
  changeLocation({
2149
- route: router,
2150
- action: "PUSH"
2321
+ location: router
2151
2322
  })
2152
- ]); }), catchError5(function (error) { return of19(loginFail(error)); }));
2323
+ ]); }), catchError6(function (error) { return concat12([loginFail(error), refreshMetaFail(), createApiError(error)]); }));
2153
2324
  }));
2154
2325
  };
2155
2326
  // src/epics/session/loginDoneEpic.ts
2156
- import { EMPTY as EMPTY16, filter as filter32, switchMap as switchMap9 } from "rxjs";
2157
- var loginDoneSessionEpic = function (action$, store) { return action$.pipe(filter32(login.match), switchMap9(function (action) { return EMPTY16; })); };
2327
+ import { EMPTY as EMPTY17, filter as filter32, switchMap as switchMap9 } from "rxjs";
2328
+ var loginDoneSessionEpic = function (action$, store) { return action$.pipe(filter32(login.match), switchMap9(function (action) { return EMPTY17; })); };
2158
2329
  // src/epics/session/loginByAnotherRoleEpic.ts
2159
- import { catchError as catchError6, EMPTY as EMPTY17, filter as filter33, mergeMap as mergeMap19, of as of20, switchMap as switchMap10 } from "rxjs";
2330
+ import { catchError as catchError7, concat as concat13, filter as filter33, mergeMap as mergeMap19, of as of20, switchMap as switchMap10 } from "rxjs";
2160
2331
  var responseStatusMessages = {
2161
2332
  401: "Invalid credentials",
2162
2333
  403: "Access denied"
@@ -2168,53 +2339,73 @@ var loginByAnotherRoleEpic = function (action$, state$, _a) {
2168
2339
  var role = (_a = action.payload.role) !== null && _a !== void 0 ? _a : "";
2169
2340
  var isSwitchRole = role && role !== state$.value.session.activeRole;
2170
2341
  return api.loginByRoleRequest(role).pipe(mergeMap19(function (data) {
2342
+ var _a;
2343
+ var result = [];
2171
2344
  if (isSwitchRole) {
2345
+ var defaultScreen = data.screens.find(function (screen) { return screen.defaultScreen; }) || data.screens[0];
2346
+ var defaultViewName_1 = (_a = defaultScreen === null || defaultScreen === void 0 ? void 0 : defaultScreen.primary) !== null && _a !== void 0 ? _a : defaultScreen.meta.views[0].name;
2347
+ var defaultView = defaultScreen === null || defaultScreen === void 0 ? void 0 : defaultScreen.meta.views.find(function (view) { return defaultViewName_1 === view.name; });
2348
+ if (defaultView)
2349
+ result.push(changeLocation({ location: defaultParseURL(new URL(defaultView.url, window.location.origin)) }));
2172
2350
  }
2173
- return EMPTY17;
2174
- }), catchError6(function (error) {
2351
+ return concat13(__spreadArray(__spreadArray([], result, true), [
2352
+ loginDone({
2353
+ devPanelEnabled: data.devPanelEnabled,
2354
+ activeRole: data.activeRole,
2355
+ roles: data.roles,
2356
+ screens: data.screens,
2357
+ firstName: data.firstName,
2358
+ lastName: data.lastName,
2359
+ login: data.login
2360
+ })
2361
+ ], false));
2362
+ }), catchError7(function (error) {
2175
2363
  console.error(error);
2176
2364
  var errorMsg = error.response ? responseStatusMessages[error.response.status] || "Server application unavailable" : "Empty server response";
2177
- return of20(loginFail({ errorMsg: errorMsg }));
2365
+ return concat13(of20(loginFail({ errorMsg: errorMsg })), createApiErrorObservable(error));
2178
2366
  }));
2179
2367
  }));
2180
2368
  };
2181
2369
  // src/epics/session/refreshMetaAndReloadPageEpic.ts
2182
- import { concat as concat12, EMPTY as EMPTY18, filter as filter34, of as of21, switchMap as switchMap11, take, tap as tap3 } from "rxjs";
2183
- var refreshMetaAndReloadPageEpic = function (action$, state$) { return action$.pipe(filter34(refreshMetaAndReloadPage.match), switchMap11(function () { return concat12(of21(refreshMeta(null)), action$.pipe(filter34(loginDone.match), take(1), tap3(function () { return location.reload(); }), switchMap11(function () { return EMPTY18; }))); })); };
2370
+ import { concat as concat14, EMPTY as EMPTY18, filter as filter34, of as of21, switchMap as switchMap11, take, tap as tap3 } from "rxjs";
2371
+ var refreshMetaAndReloadPageEpic = function (action$, state$) { return action$.pipe(filter34(refreshMetaAndReloadPage.match), switchMap11(function () { return concat14(of21(refreshMeta()), action$.pipe(filter34(loginDone.match), take(1), tap3(function () { return location.reload(); }), switchMap11(function () { return EMPTY18; }))); })); };
2184
2372
  // src/epics/data/bcNewDataEpic.ts
2185
- import { catchError as catchError7, concat as concat13, EMPTY as EMPTY19, filter as filter35, mergeMap as mergeMap20, of as of22 } from "rxjs";
2373
+ import { catchError as catchError8, concat as concat15, EMPTY as EMPTY19, filter as filter35, mergeMap as mergeMap20, of as of22 } from "rxjs";
2186
2374
  import { OperationTypeCrud as OperationTypeCrud8 } from "@cxbox-ui/schema";
2187
2375
  var bcNewDataEpic = function (action$, state$, _a) {
2188
2376
  var api = _a.api;
2189
2377
  return action$.pipe(filter35(sendOperation.match), filter35(function (action) { return matchOperationRole(OperationTypeCrud8.create, action.payload, state$.value); }), mergeMap20(function (action) {
2378
+ var _a;
2190
2379
  var state = state$.value;
2191
2380
  var bcName = action.payload.bcName;
2192
- var bcUrl = buildBcUrl(bcName);
2381
+ var bcUrl = (_a = buildBcUrl(bcName, false, state)) !== null && _a !== void 0 ? _a : "";
2193
2382
  var context = { widgetName: action.payload.widgetName };
2194
2383
  var params = { _action: action.payload.operationType };
2195
2384
  return api.newBcData(state.screen.screenName, bcUrl, context, params).pipe(mergeMap20(function (data) {
2385
+ var _a, _b;
2196
2386
  var rowMeta = data.row;
2197
2387
  var dataItem = { id: null, vstamp: -1 };
2198
2388
  data.row.fields.forEach(function (field) {
2199
2389
  dataItem[field.key] = field.currentValue;
2200
2390
  });
2201
- var postInvoke = data.postActions[0];
2391
+ var postInvoke = (_a = data.postActions) === null || _a === void 0 ? void 0 : _a[0];
2202
2392
  var cursor = dataItem.id;
2203
- return concat13(of22(bcNewDataSuccess({ bcName: bcName, dataItem: dataItem, bcUrl: bcUrl })), of22(bcFetchRowMetaSuccess({ bcName: bcName, bcUrl: "".concat(bcUrl, "/").concat(cursor), rowMeta: rowMeta, cursor: cursor })), of22(changeDataItem({
2204
- bcName: action.payload.bcName,
2393
+ return concat15(of22(bcNewDataSuccess({ bcName: bcName, dataItem: dataItem, bcUrl: bcUrl })), of22(bcFetchRowMetaSuccess({ bcName: bcName, bcUrl: "".concat(bcUrl, "/").concat(cursor), rowMeta: rowMeta, cursor: cursor })), of22(changeDataItem({
2394
+ bcName: bcName,
2395
+ bcUrl: (_b = buildBcUrl(bcName, true, state)) !== null && _b !== void 0 ? _b : "",
2205
2396
  cursor: cursor,
2206
2397
  dataItem: {
2207
2398
  id: cursor
2208
2399
  }
2209
2400
  })), postInvoke ? of22(processPostInvoke({ bcName: bcName, postInvoke: postInvoke, cursor: cursor, widgetName: action.payload.widgetName })) : EMPTY19);
2210
- }), catchError7(function (error) {
2401
+ }), catchError8(function (error) {
2211
2402
  console.error(error);
2212
- return of22(bcNewDataFail({ bcName: bcName }));
2403
+ return concat15(of22(bcNewDataFail({ bcName: bcName })), createApiErrorObservable(error, context));
2213
2404
  }));
2214
2405
  }));
2215
2406
  };
2216
2407
  // src/epics/data/bcLoadMoreEpic.ts
2217
- import { catchError as catchError8, filter as filter37, mergeMap as mergeMap22, of as of24, race } from "rxjs";
2408
+ import { catchError as catchError9, concat as concat16, filter as filter37, mergeMap as mergeMap22, of as of24, race } from "rxjs";
2218
2409
  // src/utils/cancelRequestEpic.ts
2219
2410
  import { filter as filter36, mergeMap as mergeMap21, of as of23, take as take2 } from "rxjs";
2220
2411
  import { isAnyOf as isAnyOf2 } from "@reduxjs/toolkit";
@@ -2224,7 +2415,7 @@ function cancelRequestEpic(action$, actionTypes, cancelFn, cancelActionCreator,
2224
2415
  return true;
2225
2416
  }; }
2226
2417
  return action$.pipe(filter36(isAnyOf2.apply(void 0, actionTypes)), filter36(filterFn), mergeMap21(function () {
2227
- cancelFn();
2418
+ cancelFn === null || cancelFn === void 0 ? void 0 : cancelFn();
2228
2419
  return of23(cancelActionCreator);
2229
2420
  }), take2(1));
2230
2421
  }
@@ -2239,7 +2430,7 @@ var bcLoadMoreEpic = function (action$, state$, _a) {
2239
2430
  var cursor = bc.cursor, page = bc.page;
2240
2431
  var limit = ((_a = state.view.widgets.find(function (i) { return i.bcName === bcName; })) === null || _a === void 0 ? void 0 : _a.limit) || bc.limit;
2241
2432
  var limitBySelfCursor = (_b = state.router.bcPath) === null || _b === void 0 ? void 0 : _b.includes("".concat(bcName, "/").concat(cursor));
2242
- var bcUrl = buildBcUrl(bcName, limitBySelfCursor);
2433
+ var bcUrl = buildBcUrl(bcName, limitBySelfCursor, state);
2243
2434
  var filters = state.screen.filters[bcName] || [];
2244
2435
  var sorters = state.screen.sorters[bcName];
2245
2436
  var fetchParams = __assign(__assign({ _page: page, _limit: limit }, getFilters(filters)), getSorters(sorters));
@@ -2255,28 +2446,28 @@ var bcLoadMoreEpic = function (action$, state$, _a) {
2255
2446
  bcUrl: bcUrl,
2256
2447
  hasNext: data.hasNext
2257
2448
  }));
2258
- }), catchError8(function (error) {
2449
+ }), catchError9(function (error) {
2259
2450
  console.error(error);
2260
- return of24(bcFetchDataFail({ bcName: bcName, bcUrl: bcUrl }));
2451
+ return concat16(of24(bcFetchDataFail({ bcName: bcName, bcUrl: bcUrl })), createApiErrorObservable(error));
2261
2452
  }));
2262
2453
  return race(cancelFlow, normalFlow);
2263
2454
  }));
2264
2455
  };
2265
2456
  // src/epics/data/bcSaveDataEpic.ts
2266
- import { catchError as catchError9, concat as concat14, EMPTY as EMPTY20, filter as filter38, mergeMap as mergeMap23, of as of25 } from "rxjs";
2457
+ import { catchError as catchError10, concat as concat17, EMPTY as EMPTY20, filter as filter38, mergeMap as mergeMap23, of as of25 } from "rxjs";
2267
2458
  var bcSaveDataEpic = function (action$, state$, _a) {
2268
2459
  var api = _a.api;
2269
2460
  return action$.pipe(filter38(sendOperation.match), filter38(function (action) { return matchOperationRole(OperationTypeCrud.save, action.payload, state$.value); }), mergeMap23(function (action) {
2270
- var _a, _b, _c;
2461
+ var _a, _b, _c, _d;
2271
2462
  var state = state$.value;
2272
2463
  var bcName = action.payload.bcName;
2273
- var bcUrl = buildBcUrl(bcName, true);
2464
+ var bcUrl = (_a = buildBcUrl(bcName, true, state)) !== null && _a !== void 0 ? _a : "";
2274
2465
  var widgetName = action.payload.widgetName;
2275
2466
  var cursor = state.screen.bo.bc[bcName].cursor;
2276
2467
  var dataItem = state.data[bcName].find(function (item) { return item.id === cursor; });
2277
- var pendingChanges = (_a = state.view.pendingDataChanges[bcName]) === null || _a === void 0 ? void 0 : _a[cursor];
2278
- var rowMeta = bcUrl && ((_b = state.view.rowMeta[bcName]) === null || _b === void 0 ? void 0 : _b[bcUrl]);
2279
- var options = (_c = state.view.widgets.find(function (widget) { return widget.name === widgetName; })) === null || _c === void 0 ? void 0 : _c.options;
2468
+ var pendingChanges = __assign({}, (_b = state.view.pendingDataChanges[bcName]) === null || _b === void 0 ? void 0 : _b[cursor]);
2469
+ var rowMeta = bcUrl && ((_c = state.view.rowMeta[bcName]) === null || _c === void 0 ? void 0 : _c[bcUrl]);
2470
+ var options = (_d = state.view.widgets.find(function (widget) { return widget.name === widgetName; })) === null || _d === void 0 ? void 0 : _d.options;
2280
2471
  if (rowMeta) {
2281
2472
  var fields = rowMeta.fields;
2282
2473
  var _loop_2 = function (key) {
@@ -2293,17 +2484,18 @@ var bcSaveDataEpic = function (action$, state$, _a) {
2293
2484
  return bcFetchDataRequest({ bcName: childBcName, widgetName: widgetNames[0] });
2294
2485
  });
2295
2486
  var context = { widgetName: action.payload.widgetName };
2296
- return api.saveBcData(state.screen.screenName, bcUrl, __assign(__assign({}, pendingChanges), { vstamp: dataItem.vstamp }), context).pipe(mergeMap23(function (data) {
2297
- var postInvoke = data.postActions[0];
2487
+ return api.saveBcData(state.screen.screenName, bcUrl, __assign(__assign({}, pendingChanges), { vstamp: dataItem === null || dataItem === void 0 ? void 0 : dataItem.vstamp }), context).pipe(mergeMap23(function (data) {
2488
+ var _a;
2489
+ var postInvoke = (_a = data.postActions) === null || _a === void 0 ? void 0 : _a[0];
2298
2490
  var responseDataItem = data.record;
2299
- return concat14(of25(bcSaveDataSuccess({ bcName: bcName, cursor: cursor, dataItem: responseDataItem })), of25(bcFetchRowMeta({ widgetName: widgetName, bcName: bcName })), of25.apply(void 0, fetchChildrenBcData), postInvoke ? of25(processPostInvoke({
2491
+ return concat17(of25(bcSaveDataSuccess({ bcName: bcName, cursor: cursor, dataItem: responseDataItem })), of25(bcFetchRowMeta({ widgetName: widgetName, bcName: bcName })), of25.apply(void 0, fetchChildrenBcData), postInvoke ? of25(processPostInvoke({
2300
2492
  bcName: bcName,
2301
2493
  widgetName: widgetName,
2302
2494
  postInvoke: postInvoke,
2303
2495
  cursor: responseDataItem.id
2304
2496
  })) : EMPTY20, action.payload.onSuccessAction ? of25(action.payload.onSuccessAction) : EMPTY20);
2305
- }), catchError9(function (e) {
2306
- var _a, _b, _c, _d, _e, _f;
2497
+ }), catchError10(function (e) {
2498
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2307
2499
  console.error(e);
2308
2500
  var notification$ = EMPTY20;
2309
2501
  if (action.payload.onSuccessAction && !(options === null || options === void 0 ? void 0 : options.disableNotification)) {
@@ -2324,10 +2516,10 @@ var bcSaveDataEpic = function (action$, state$, _a) {
2324
2516
  var entityError = null;
2325
2517
  var operationError = (_a = e.response) === null || _a === void 0 ? void 0 : _a.data;
2326
2518
  if (((_b = e.response) === null || _b === void 0 ? void 0 : _b.data) === Object((_c = e.response) === null || _c === void 0 ? void 0 : _c.data)) {
2327
- entityError = (_d = operationError === null || operationError === void 0 ? void 0 : operationError.error) === null || _d === void 0 ? void 0 : _d.entity;
2328
- 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];
2519
+ 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;
2520
+ 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;
2329
2521
  }
2330
- return concat14(of25(bcSaveDataFail({ bcName: bcName, bcUrl: bcUrl, viewError: viewError, entityError: entityError })), notification$);
2522
+ return concat17(of25(bcSaveDataFail({ bcName: bcName, bcUrl: bcUrl, viewError: viewError, entityError: entityError })), notification$, createApiErrorObservable(e, context));
2331
2523
  }));
2332
2524
  }));
2333
2525
  };
@@ -2362,8 +2554,8 @@ var selectViewEpic = function (action$, state$) { return action$.pipe(filter39(s
2362
2554
  }
2363
2555
  })); };
2364
2556
  // src/epics/data/bcFetchDataEpic.ts
2365
- import { catchError as catchError10, concat as concat15, EMPTY as EMPTY22, filter as filter40, mergeMap as mergeMap25, of as of26, race as race2 } from "rxjs";
2366
- import { WidgetTypes as WidgetTypes4 } from "@cxbox-ui/schema";
2557
+ import { catchError as catchError11, concat as concat18, EMPTY as EMPTY22, filter as filter40, mergeMap as mergeMap25, of as of26, race as race2 } from "rxjs";
2558
+ import { WidgetTypes as WidgetTypes5 } from "@cxbox-ui/schema";
2367
2559
  import { isAnyOf as isAnyOf3 } from "@reduxjs/toolkit";
2368
2560
  var bcFetchDataEpic = function (action$, state$, _a) {
2369
2561
  var api = _a.api;
@@ -2384,7 +2576,7 @@ var bcFetchDataEpic = function (action$, state$, _a) {
2384
2576
  var getChildrenData = function (widgets, bcDictionary, isHierarchy, showConditionCheck) {
2385
2577
  var bcName = action.payload.bcName;
2386
2578
  var _a = bcFetchDataRequest.match(action) ? action.payload : { ignorePageLimit: void 0, keepDelta: void 0 }, ignorePageLimit = _a.ignorePageLimit, keepDelta = _a.keepDelta;
2387
- return concat15.apply(void 0, Object.entries(getBcChildren(bcName, widgets, bcDictionary)).filter(function (_a) {
2579
+ return concat18.apply(void 0, Object.entries(getBcChildren(bcName, widgets, bcDictionary)).filter(function (_a) {
2388
2580
  var childBcName = _a[0], widgetNames = _a[1];
2389
2581
  var nonLazyWidget = widgets.find(function (item) {
2390
2582
  return widgetNames.includes(item.name) && !PopupWidgetTypes.includes(item.type) && showConditionCheck(item);
@@ -2401,41 +2593,41 @@ var bcFetchDataEpic = function (action$, state$, _a) {
2401
2593
  });
2402
2594
  return of26(bcFetchDataRequest({
2403
2595
  bcName: childBcName,
2404
- widgetName: nonLazyWidget.name,
2596
+ widgetName: nonLazyWidget === null || nonLazyWidget === void 0 ? void 0 : nonLazyWidget.name,
2405
2597
  ignorePageLimit: ignorePageLimit || showViewPopup.match(action),
2406
2598
  keepDelta: isHierarchy || keepDelta
2407
2599
  }));
2408
2600
  }));
2409
2601
  };
2410
2602
  var bcFetchDataImpl = function () {
2411
- var _a, _b, _c, _d, _e, _f;
2603
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2412
2604
  var state = state$.value;
2413
- var widgetName = action.payload.widgetName;
2414
- var _g = state.view, widgets = _g.widgets, infiniteWidgets = _g.infiniteWidgets;
2415
- 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; });
2605
+ var _j = action.payload.widgetName, widgetName = _j === void 0 ? "" : _j;
2606
+ var _k = state.view, widgets = _k.widgets, infiniteWidgets = _k.infiniteWidgets;
2607
+ 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; });
2416
2608
  if (!widget) {
2417
2609
  return [EMPTY22];
2418
2610
  }
2419
2611
  var bcName = action.payload.bcName;
2420
2612
  var bc = state.screen.bo.bc[bcName];
2421
- var cursor = bc.cursor, page = bc.page;
2422
- var limit = ((_b = widgets.find(function (i) { return i.bcName === bcName; })) === null || _b === void 0 ? void 0 : _b.limit) || bc.limit;
2613
+ var cursor = bc.cursor, _l = bc.page, page = _l === void 0 ? 1 : _l;
2614
+ 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;
2423
2615
  var sorters = state.screen.sorters[bcName];
2424
2616
  if (showViewPopup.match(action) && bcName === action.payload.calleeBCName) {
2425
2617
  return [EMPTY22];
2426
2618
  }
2427
- var anyHierarchyWidget = widgets.find(function (item) {
2428
- return item.bcName === widget.bcName && item.type === WidgetTypes4.AssocListPopup && isHierarchyWidget(item);
2619
+ var anyHierarchyWidget = widgets === null || widgets === void 0 ? void 0 : widgets.find(function (item) {
2620
+ return item.bcName === widget.bcName && item.type === WidgetTypes5.AssocListPopup && isHierarchyWidget(item);
2429
2621
  });
2430
- var fullHierarchyWidget = state.view.widgets.find(function (item) {
2622
+ var fullHierarchyWidget = (_d = state.view.widgets) === null || _d === void 0 ? void 0 : _d.find(function (item) {
2431
2623
  var _a;
2432
- return item.bcName === widget.bcName && item.type === WidgetTypes4.AssocListPopup && ((_a = item.options) === null || _a === void 0 ? void 0 : _a.hierarchyFull);
2624
+ return item.bcName === widget.bcName && item.type === WidgetTypes5.AssocListPopup && ((_a = item.options) === null || _a === void 0 ? void 0 : _a.hierarchyFull);
2433
2625
  });
2434
- var limitBySelfCursor = (_c = state.router.bcPath) === null || _c === void 0 ? void 0 : _c.includes("".concat(bcName, "/").concat(cursor));
2435
- var bcUrl = buildBcUrl(bcName, limitBySelfCursor);
2626
+ var limitBySelfCursor = (_e = state.router.bcPath) === null || _e === void 0 ? void 0 : _e.includes("".concat(bcName, "/").concat(cursor));
2627
+ var bcUrl = buildBcUrl(bcName, limitBySelfCursor, state);
2436
2628
  var fetchParams = __assign(__assign({ _page: page, _limit: limit }, getFilters(fullHierarchyWidget ? [] : state.screen.filters[bcName] || [])), getSorters(sorters));
2437
2629
  if (bcForceUpdate.match(action)) {
2438
- 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);
2630
+ 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);
2439
2631
  if (infinityPaginationWidget) {
2440
2632
  fetchParams._page = 1;
2441
2633
  fetchParams._limit = limit * page;
@@ -2445,7 +2637,7 @@ var bcFetchDataEpic = function (action$, state$, _a) {
2445
2637
  fetchParams._page = action.payload.from || 1;
2446
2638
  fetchParams._limit = (action.payload.to || page - fetchParams._page) * limit;
2447
2639
  }
2448
- 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)) {
2640
+ 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)) {
2449
2641
  fetchParams._limit = 0;
2450
2642
  }
2451
2643
  var canceler = api.createCanceler();
@@ -2457,7 +2649,7 @@ var bcFetchDataEpic = function (action$, state$, _a) {
2457
2649
  var normalFlow = api.fetchBcData(state.screen.screenName, bcUrl, fetchParams, canceler.cancelToken).pipe(mergeMap25(function (response) {
2458
2650
  var _a, _b;
2459
2651
  var cursorChange = getCursorChange(response.data, cursor, !!anyHierarchyWidget);
2460
- var parentOfNotLazyWidget = widgets.some(function (item) {
2652
+ var parentOfNotLazyWidget = widgets === null || widgets === void 0 ? void 0 : widgets.some(function (item) {
2461
2653
  var _a;
2462
2654
  return ((_a = state.screen.bo.bc[item.bcName]) === null || _a === void 0 ? void 0 : _a.parentName) === bcName && !PopupWidgetTypes.includes(item.type);
2463
2655
  });
@@ -2484,15 +2676,15 @@ var bcFetchDataEpic = function (action$, state$, _a) {
2484
2676
  }
2485
2677
  var fetchChildren = ((_b = response.data) === null || _b === void 0 ? void 0 : _b.length) ? getChildrenData(widgets, state.screen.bo.bc, !!anyHierarchyWidget, isWidgetVisible) : EMPTY22;
2486
2678
  var fetchRowMeta = of26(bcFetchRowMeta({ widgetName: widgetName, bcName: bcName }));
2487
- return concat15(cursorChange, of26(bcFetchDataSuccess({
2679
+ return concat18(cursorChange, of26(bcFetchDataSuccess({
2488
2680
  bcName: bcName,
2489
2681
  data: response.data,
2490
2682
  bcUrl: bcUrl,
2491
2683
  hasNext: response.hasNext
2492
2684
  })), fetchRowMeta, fetchChildren);
2493
- }), catchError10(function (error) {
2685
+ }), catchError11(function (error) {
2494
2686
  console.error(error);
2495
- return of26(bcFetchDataFail({ bcName: action.payload.bcName, bcUrl: bcUrl }));
2687
+ return concat18(of26(bcFetchDataFail({ bcName: action.payload.bcName, bcUrl: bcUrl })), createApiErrorObservable(error));
2496
2688
  }));
2497
2689
  return [cancelFlow, cancelByParentBc, normalFlow];
2498
2690
  };
@@ -2504,7 +2696,7 @@ function isHierarchyWidget(widget) {
2504
2696
  return ((_a = widget.options) === null || _a === void 0 ? void 0 : _a.hierarchy) || ((_b = widget.options) === null || _b === void 0 ? void 0 : _b.hierarchyFull);
2505
2697
  }
2506
2698
  // src/epics/data/bcDeleteDataEpic.ts
2507
- import { catchError as catchError11, concat as concat16, EMPTY as EMPTY23, filter as filter41, mergeMap as mergeMap26, of as of27 } from "rxjs";
2699
+ import { catchError as catchError12, concat as concat19, EMPTY as EMPTY23, filter as filter41, mergeMap as mergeMap26, of as of27 } from "rxjs";
2508
2700
  import { OperationTypeCrud as OperationTypeCrud9 } from "@cxbox-ui/schema";
2509
2701
  var bcDeleteDataEpic = function (action$, store$, _a) {
2510
2702
  var api = _a.api;
@@ -2513,20 +2705,21 @@ var bcDeleteDataEpic = function (action$, store$, _a) {
2513
2705
  var state = store$.value;
2514
2706
  var bcName = action.payload.bcName;
2515
2707
  var cursor = state.screen.bo.bc[bcName].cursor;
2516
- var bcUrl = buildBcUrl(bcName, true);
2708
+ var bcUrl = buildBcUrl(bcName, true, state);
2517
2709
  var context = { widgetName: action.payload.widgetName };
2518
2710
  var isTargetFormatPVF = state.view.pendingValidationFailsFormat === "target" /* target */;
2519
2711
  return api.deleteBcData(state.screen.screenName, bcUrl, context).pipe(mergeMap26(function (data) {
2520
- var postInvoke = data.postActions[0];
2521
- return concat16(isTargetFormatPVF ? of27(bcCancelPendingChanges({ bcNames: [bcName] })) : EMPTY23, of27(bcFetchDataRequest({ bcName: bcName, widgetName: widgetName })), postInvoke ? of27(processPostInvoke({ bcName: bcName, postInvoke: postInvoke, cursor: cursor, widgetName: widgetName })) : EMPTY23);
2522
- }), catchError11(function (error) {
2712
+ var _a;
2713
+ var postInvoke = (_a = data.postActions) === null || _a === void 0 ? void 0 : _a[0];
2714
+ return concat19(isTargetFormatPVF ? of27(bcCancelPendingChanges({ bcNames: [bcName] })) : EMPTY23, of27(bcFetchDataRequest({ bcName: bcName, widgetName: widgetName })), postInvoke ? of27(processPostInvoke({ bcName: bcName, postInvoke: postInvoke, cursor: cursor, widgetName: widgetName })) : EMPTY23);
2715
+ }), catchError12(function (error) {
2523
2716
  console.error(error);
2524
- return of27(bcDeleteDataFail({ bcName: bcName }));
2717
+ return concat19(of27(bcDeleteDataFail({ bcName: bcName })), createApiErrorObservable(error, context));
2525
2718
  }));
2526
2719
  }));
2527
2720
  };
2528
2721
  // src/epics/data/bcSelectRecordEpic.ts
2529
- import { concat as concat17, filter as filter42, mergeMap as mergeMap27, of as of28 } from "rxjs";
2722
+ import { concat as concat20, filter as filter42, mergeMap as mergeMap27, of as of28 } from "rxjs";
2530
2723
  var bcSelectRecordEpic = function (action$, store$) { return action$.pipe(filter42(bcSelectRecord.match), mergeMap27(function (action) {
2531
2724
  var _a;
2532
2725
  var _b = action.payload, bcName = _b.bcName, cursor = _b.cursor;
@@ -2541,17 +2734,19 @@ var bcSelectRecordEpic = function (action$, store$) { return action$.pipe(filter
2541
2734
  keepDelta: action.payload.keepDelta
2542
2735
  });
2543
2736
  });
2544
- return concat17(of28(bcChangeCursors({ cursorsMap: (_a = {}, _a[bcName] = cursor, _a), keepDelta: action.payload.keepDelta })), of28(bcFetchRowMeta({ widgetName: "", bcName: bcName })), fetchChildrenBcData);
2737
+ return concat20(of28(bcChangeCursors({ cursorsMap: (_a = {}, _a[bcName] = cursor, _a), keepDelta: action.payload.keepDelta })), of28(bcFetchRowMeta({ widgetName: "", bcName: bcName })), fetchChildrenBcData);
2545
2738
  })); };
2546
2739
  // src/epics/data/changeAssociationEpic.ts
2547
- import { concat as concat18, filter as filter43, mergeMap as mergeMap28, of as of29 } from "rxjs";
2740
+ import { concat as concat21, filter as filter43, mergeMap as mergeMap28, of as of29 } from "rxjs";
2548
2741
  var changeAssociationEpic = function (action$, state$) { return action$.pipe(filter43(changeAssociation.match), mergeMap28(function (action) {
2549
2742
  var _a, _b, _c, _d, _e;
2550
2743
  var state = state$.value;
2551
2744
  var selected = action.payload.dataItem._associate;
2745
+ var bcName = action.payload.bcName;
2552
2746
  var result = [
2553
2747
  of29(changeDataItem({
2554
- bcName: action.payload.bcName,
2748
+ bcName: bcName,
2749
+ bcUrl: buildBcUrl(bcName, true, state),
2555
2750
  cursor: action.payload.dataItem.id,
2556
2751
  dataItem: action.payload.dataItem
2557
2752
  }))
@@ -2564,19 +2759,19 @@ var changeAssociationEpic = function (action$, state$) { return action$.pipe(fil
2564
2759
  fields: widget.fields
2565
2760
  };
2566
2761
  var hierarchy = (_b = widget.options) === null || _b === void 0 ? void 0 : _b.hierarchy;
2567
- var hierarchyDescriptor = isRoot ? rootHierarchyDescriptor : hierarchy.find(function (item) { return item.bcName === action.payload.bcName; });
2762
+ var hierarchyDescriptor = isRoot ? rootHierarchyDescriptor : hierarchy === null || hierarchy === void 0 ? void 0 : hierarchy.find(function (item) { return item.bcName === action.payload.bcName; });
2568
2763
  var hierarchyGroupSelection = (_c = widget.options) === null || _c === void 0 ? void 0 : _c.hierarchyGroupSelection;
2569
2764
  var hierarchyTraverse = (_d = widget.options) === null || _d === void 0 ? void 0 : _d.hierarchyTraverse;
2570
- var childrenBc = hierarchy.slice(hierarchy.findIndex(function (item) { return item.bcName === action.payload.bcName; }) + 1).map(function (item) { return item.bcName; });
2765
+ 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; });
2571
2766
  if (hierarchyGroupSelection && hierarchyDescriptor.radio && !selected) {
2572
2767
  result.push(of29(dropAllAssociations({
2573
2768
  bcNames: childrenBc
2574
2769
  })));
2575
2770
  }
2576
- var parent = isRoot ? null : hierarchy.find(function (item, index) {
2771
+ var parent = isRoot ? null : (hierarchy === null || hierarchy === void 0 ? void 0 : hierarchy.find(function (item, index) {
2577
2772
  var _a;
2578
2773
  return ((_a = hierarchy[index + 1]) === null || _a === void 0 ? void 0 : _a.bcName) === action.payload.bcName;
2579
- }) || rootHierarchyDescriptor;
2774
+ })) || rootHierarchyDescriptor;
2580
2775
  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; });
2581
2776
  if (parent && hierarchyTraverse && selected) {
2582
2777
  if (hierarchyDescriptor.radio) {
@@ -2587,7 +2782,7 @@ var changeAssociationEpic = function (action$, state$) { return action$.pipe(fil
2587
2782
  result.push(of29(changeAssociation({
2588
2783
  bcName: parent.bcName,
2589
2784
  widgetName: action.payload.widgetName,
2590
- dataItem: __assign(__assign({}, parentItem), { _associate: true, _value: parentItem[parent.assocValueKey || action.payload.assocValueKey] }),
2785
+ dataItem: __assign(__assign({}, parentItem), { _associate: true, _value: parentItem === null || parentItem === void 0 ? void 0 : parentItem[parent.assocValueKey || action.payload.assocValueKey] }),
2591
2786
  assocValueKey: action.payload.assocValueKey
2592
2787
  })));
2593
2788
  }
@@ -2609,10 +2804,10 @@ var changeAssociationEpic = function (action$, state$) { return action$.pipe(fil
2609
2804
  })));
2610
2805
  }
2611
2806
  }
2612
- return concat18.apply(void 0, result);
2807
+ return concat21.apply(void 0, result);
2613
2808
  })); };
2614
2809
  // src/epics/data/bcCancelCreateDataEpic.ts
2615
- import { catchError as catchError12, concat as concat19, EMPTY as EMPTY24, filter as filter44, mergeMap as mergeMap29, of as of30 } from "rxjs";
2810
+ import { catchError as catchError13, concat as concat22, EMPTY as EMPTY24, filter as filter44, mergeMap as mergeMap29, of as of30 } from "rxjs";
2616
2811
  import { OperationTypeCrud as OperationTypeCrud10 } from "@cxbox-ui/schema";
2617
2812
  import { isAnyOf as isAnyOf4 } from "@reduxjs/toolkit";
2618
2813
  var actionTypesMatcher = isAnyOf4(sendOperation);
@@ -2624,7 +2819,7 @@ var bcCancelCreateDataEpic = function (action$, state$, _a) {
2624
2819
  var state = state$.value;
2625
2820
  var screenName = state.screen.screenName;
2626
2821
  var bcName = action.payload.bcName;
2627
- var bcUrl = buildBcUrl(bcName, true);
2822
+ var bcUrl = buildBcUrl(bcName, true, state);
2628
2823
  var bc = state.screen.bo.bc[bcName];
2629
2824
  var cursor = bc === null || bc === void 0 ? void 0 : bc.cursor;
2630
2825
  var context = { widgetName: action.payload.widgetName };
@@ -2634,19 +2829,20 @@ var bcCancelCreateDataEpic = function (action$, state$, _a) {
2634
2829
  var params = { _action: action.payload.operationType };
2635
2830
  var cursorsMap = (_a = {}, _a[action.payload.bcName] = null, _a);
2636
2831
  return api.customAction(screenName, bcUrl, data, context, params).pipe(mergeMap29(function (response) {
2637
- var postInvoke = response.postActions[0];
2638
- return concat19(of30(sendOperationSuccess({ bcName: bcName, cursor: cursor })), of30(bcChangeCursors({ cursorsMap: cursorsMap })), postInvoke ? of30(processPostInvoke({ bcName: bcName, postInvoke: postInvoke, cursor: cursor, widgetName: context.widgetName })) : EMPTY24);
2639
- }), catchError12(function (error) {
2832
+ var _a;
2833
+ var postInvoke = (_a = response.postActions) === null || _a === void 0 ? void 0 : _a[0];
2834
+ return concat22(of30(sendOperationSuccess({ bcName: bcName, cursor: cursor })), of30(bcChangeCursors({ cursorsMap: cursorsMap })), postInvoke ? of30(processPostInvoke({ bcName: bcName, postInvoke: postInvoke, cursor: cursor, widgetName: context.widgetName })) : EMPTY24);
2835
+ }), catchError13(function (error) {
2640
2836
  console.error(error);
2641
- return of30(bcDeleteDataFail({ bcName: bcName }));
2837
+ return concat22(of30(bcDeleteDataFail({ bcName: bcName })), createApiErrorObservable(error, context));
2642
2838
  }));
2643
2839
  }));
2644
2840
  };
2645
2841
  // src/epics/data/bcSelectDepthRecordEpic.ts
2646
- import { concat as concat20, filter as filter45, mergeMap as mergeMap30, of as of31 } from "rxjs";
2842
+ import { concat as concat23, filter as filter45, mergeMap as mergeMap30, of as of31 } from "rxjs";
2647
2843
  var bcSelectDepthRecordEpic = function (action$) { return action$.pipe(filter45(bcSelectDepthRecord.match), mergeMap30(function (action) {
2648
2844
  var _a = action.payload, bcName = _a.bcName, cursor = _a.cursor, depth = _a.depth;
2649
- return concat20(of31(bcChangeDepthCursor({ bcName: bcName, depth: depth, cursor: cursor })), of31(bcFetchDataRequest({
2845
+ return concat23(of31(bcChangeDepthCursor({ bcName: bcName, depth: depth, cursor: cursor })), of31(bcFetchDataRequest({
2650
2846
  bcName: bcName,
2651
2847
  depth: depth + 1,
2652
2848
  widgetName: "",
@@ -2654,7 +2850,7 @@ var bcSelectDepthRecordEpic = function (action$) { return action$.pipe(filter45(
2654
2850
  })));
2655
2851
  })); };
2656
2852
  // src/epics/data/removeMultivalueTagEpic.ts
2657
- import { concat as concat21, filter as filter46, mergeMap as mergeMap31, of as of32 } from "rxjs";
2853
+ import { concat as concat24, filter as filter46, mergeMap as mergeMap31, of as of32 } from "rxjs";
2658
2854
  var removeMultivalueTagEpic = function (action$, state$) { return action$.pipe(filter46(removeMultivalueTag.match), mergeMap31(function (action) {
2659
2855
  var _a, _b, _c;
2660
2856
  var _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
@@ -2670,28 +2866,28 @@ var removeMultivalueTagEpic = function (action$, state$) { return action$.pipe(f
2670
2866
  var removedItem = data.find(function (item) { return item.id === action.payload.removedItem.id; });
2671
2867
  var associated = action.payload.dataItem.map(function (item) { return item.id; });
2672
2868
  var removedNodes = [];
2673
- if ((_d = widget.options) === null || _d === void 0 ? void 0 : _d.hierarchyGroupDeselection) {
2674
- if ((_e = widget.options) === null || _e === void 0 ? void 0 : _e.hierarchyTraverse) {
2869
+ if ((_d = widget === null || widget === void 0 ? void 0 : widget.options) === null || _d === void 0 ? void 0 : _d.hierarchyGroupDeselection) {
2870
+ if ((_e = widget === null || widget === void 0 ? void 0 : widget.options) === null || _e === void 0 ? void 0 : _e.hierarchyTraverse) {
2675
2871
  data = assignTreeLinks(data);
2676
2872
  }
2677
- var removedItemChildren = data.filter(function (item) { return item.parentId === removedItem.id; });
2678
- removedNodes = __spreadArray([removedItem.id], removedItemChildren.filter(function (item) { return associated.includes(item.id); }).map(function (item) { return item.id; }), true);
2679
- if ((_f = widget.options) === null || _f === void 0 ? void 0 : _f.hierarchyTraverse) {
2873
+ var removedItemChildren = data.filter(function (item) { return item.parentId === (removedItem === null || removedItem === void 0 ? void 0 : removedItem.id); });
2874
+ 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);
2875
+ if ((_f = widget === null || widget === void 0 ? void 0 : widget.options) === null || _f === void 0 ? void 0 : _f.hierarchyTraverse) {
2680
2876
  getDescendants(removedItemChildren, removedNodes);
2681
2877
  removedNodes = data.filter(function (item) { return removedNodes.includes(item.id) && associated.includes(item.id); }).map(function (item) { return item.id; });
2682
2878
  }
2683
- var parent_1 = data.find(function (item) { return item.id === removedItem.parentId; });
2879
+ var parent_1 = data.find(function (item) { return item.id === (removedItem === null || removedItem === void 0 ? void 0 : removedItem.parentId); });
2684
2880
  var siblings = data.filter(function (item) { return item.parentId === (parent_1 === null || parent_1 === void 0 ? void 0 : parent_1.id); });
2685
2881
  var parentEmpty = siblings.every(function (child) { return removedNodes.includes(child.id) || !associated.includes(child.id); });
2686
2882
  if (parent_1 && parentEmpty) {
2687
- if ((_g = widget.options) === null || _g === void 0 ? void 0 : _g.hierarchyTraverse) {
2883
+ if ((_g = widget === null || widget === void 0 ? void 0 : widget.options) === null || _g === void 0 ? void 0 : _g.hierarchyTraverse) {
2688
2884
  var parentDescendants = [];
2689
2885
  getDescendants(siblings, parentDescendants);
2690
2886
  var parentDeepEmpty = parentDescendants.every(function (descendant) {
2691
2887
  return removedNodes.includes(descendant) || !associated.includes(descendant);
2692
2888
  });
2693
2889
  if (parentDeepEmpty) {
2694
- return concat21(of32(removeMultivalueTag(__assign(__assign({}, action.payload), { removedItem: { id: parent_1.id, value: null } }))));
2890
+ return concat24(of32(removeMultivalueTag(__assign(__assign({}, action.payload), { removedItem: { id: parent_1.id, value: null } }))));
2695
2891
  }
2696
2892
  }
2697
2893
  else {
@@ -2699,53 +2895,60 @@ var removeMultivalueTagEpic = function (action$, state$) { return action$.pipe(f
2699
2895
  }
2700
2896
  }
2701
2897
  }
2702
- if ((_h = widget.options) === null || _h === void 0 ? void 0 : _h.hierarchyFull) {
2898
+ if ((_h = widget === null || widget === void 0 ? void 0 : widget.options) === null || _h === void 0 ? void 0 : _h.hierarchyFull) {
2703
2899
  return of32(changeDataItem({
2704
2900
  bcName: bcName,
2901
+ bcUrl: buildBcUrl(bcName, true, state),
2705
2902
  cursor: cursor,
2706
2903
  dataItem: (_a = {}, _a[associateFieldKey] = action.payload.dataItem.filter(function (item) { return !removedNodes.includes(item.id); }), _a)
2707
2904
  }));
2708
2905
  }
2709
- if ((_j = widget.options) === null || _j === void 0 ? void 0 : _j.hierarchy) {
2710
- return concat21(of32(changeDataItem({
2906
+ if ((_j = widget === null || widget === void 0 ? void 0 : widget.options) === null || _j === void 0 ? void 0 : _j.hierarchy) {
2907
+ 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) {
2908
+ var _a;
2909
+ return (_a = state.view.pendingDataChanges[hierarchyData.bcName]) === null || _a === void 0 ? void 0 : _a[action.payload.removedItem.id];
2910
+ })) === null || _m === void 0 ? void 0 : _m.bcName) !== null && _o !== void 0 ? _o : bcName;
2911
+ return concat24(of32(changeDataItem({
2711
2912
  /**
2712
2913
  * This is incorrect and will break if different BC has records with
2713
2914
  * identical ids.
2714
2915
  *
2715
2916
  * TODO: Record `level` should be mapped to hierarchyData index instead
2716
2917
  */
2717
- 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) {
2718
- var _a;
2719
- return (_a = state.view.pendingDataChanges[hierarchyData.bcName]) === null || _a === void 0 ? void 0 : _a[action.payload.removedItem.id];
2720
- })) === null || _m === void 0 ? void 0 : _m.bcName) !== null && _o !== void 0 ? _o : bcName,
2918
+ bcName: hierarchyBcName,
2919
+ bcUrl: buildBcUrl(hierarchyBcName, true, state),
2721
2920
  cursor: action.payload.removedItem.id,
2722
2921
  dataItem: __assign(__assign({}, action.payload.removedItem), { _associate: false })
2723
2922
  })), of32(changeDataItem({
2724
2923
  bcName: bcName,
2924
+ bcUrl: buildBcUrl(bcName, true, state),
2725
2925
  cursor: cursor,
2726
2926
  dataItem: (_b = {}, _b[associateFieldKey] = action.payload.dataItem, _b)
2727
2927
  })));
2728
2928
  }
2729
- return concat21(of32(changeDataItem({
2929
+ return concat24(of32(changeDataItem({
2730
2930
  bcName: popupBcName,
2931
+ bcUrl: buildBcUrl(popupBcName, true, state),
2731
2932
  cursor: action.payload.removedItem.id,
2732
2933
  dataItem: __assign(__assign({}, action.payload.removedItem), { _associate: false })
2733
2934
  })), of32(changeDataItem({
2734
2935
  bcName: bcName,
2936
+ bcUrl: buildBcUrl(bcName, true, state),
2735
2937
  cursor: cursor,
2736
2938
  dataItem: (_c = {}, _c[associateFieldKey] = action.payload.dataItem, _c)
2737
2939
  })));
2738
2940
  })); };
2739
2941
  // src/epics/data/bcFetchRowMetaRequestEpic.ts
2740
- import { catchError as catchError13, filter as filter47, map as map9, mergeMap as mergeMap32, of as of33, race as race3 } from "rxjs";
2942
+ import { catchError as catchError14, concat as concat25, filter as filter47, map as map9, mergeMap as mergeMap32, of as of33, race as race3 } from "rxjs";
2741
2943
  var bcFetchRowMetaRequestEpic = function (action$, state$, _a) {
2742
2944
  var api = _a.api;
2743
2945
  return action$.pipe(filter47(bcFetchRowMeta.match), mergeMap32(function (action) {
2946
+ var _a, _b;
2744
2947
  var state = state$.value;
2745
2948
  var screenName = state.screen.screenName;
2746
2949
  var bcName = action.payload.bcName;
2747
- var cursor = state.screen.bo.bc[bcName].cursor;
2748
- var bcUrl = buildBcUrl(bcName, true);
2950
+ var cursor = (_a = state.screen.bo.bc[bcName].cursor) !== null && _a !== void 0 ? _a : "";
2951
+ var bcUrl = (_b = buildBcUrl(bcName, true, state)) !== null && _b !== void 0 ? _b : "";
2749
2952
  var canceler = api.createCanceler();
2750
2953
  var cancelFlow = cancelRequestEpic(action$, cancelRequestActionTypes, canceler.cancel, bcFetchRowMetaFail({ bcName: bcName }));
2751
2954
  var cancelByParentBc = cancelRequestEpic(action$, [bcSelectRecord], canceler.cancel, bcFetchRowMetaFail({ bcName: bcName }), function (filteredAction) {
@@ -2754,15 +2957,15 @@ var bcFetchRowMetaRequestEpic = function (action$, state$, _a) {
2754
2957
  });
2755
2958
  var normalFlow = api.fetchRowMeta(screenName, bcUrl, void 0, canceler.cancelToken).pipe(map9(function (rowMeta) {
2756
2959
  return bcFetchRowMetaSuccess({ bcName: bcName, rowMeta: rowMeta, bcUrl: bcUrl, cursor: cursor });
2757
- }), catchError13(function (error) {
2960
+ }), catchError14(function (error) {
2758
2961
  console.error(error);
2759
- return of33(bcFetchRowMetaFail({ bcName: bcName }));
2962
+ return concat25(of33(bcFetchRowMetaFail({ bcName: bcName })), createApiErrorObservable(error));
2760
2963
  }));
2761
2964
  return race3(cancelFlow, cancelByParentBc, normalFlow);
2762
2965
  }));
2763
2966
  };
2764
2967
  // src/epics/data/changeAssociationFullEpic.ts
2765
- import { concat as concat22, filter as filter48, mergeMap as mergeMap33, of as of34 } from "rxjs";
2968
+ import { concat as concat26, filter as filter48, mergeMap as mergeMap33, of as of34 } from "rxjs";
2766
2969
  var changeAssociationFullEpic = function (action$, state$) { return action$.pipe(filter48(changeAssociationFull.match), mergeMap33(function (action) {
2767
2970
  var _a, _b, _c, _d, _e;
2768
2971
  var state = state$.value;
@@ -2813,6 +3016,7 @@ var changeAssociationFullEpic = function (action$, state$) { return action$.pipe
2813
3016
  }
2814
3017
  result.push(of34(changeDataItem({
2815
3018
  bcName: action.payload.bcName,
3019
+ bcUrl: buildBcUrl(action.payload.bcName, true, state),
2816
3020
  cursor: action.payload.dataItem.id,
2817
3021
  dataItem: action.payload.dataItem
2818
3022
  })));
@@ -2821,7 +3025,7 @@ var changeAssociationFullEpic = function (action$, state$) { return action$.pipe
2821
3025
  bcName: bcName,
2822
3026
  depth: parentDepth,
2823
3027
  widgetName: action.payload.widgetName,
2824
- dataItem: __assign(__assign({}, parentItem), { _associate: true, _value: parentItem[assocValueKey] }),
3028
+ dataItem: __assign(__assign({}, parentItem), { _associate: true, _value: parentItem === null || parentItem === void 0 ? void 0 : parentItem[assocValueKey] }),
2825
3029
  assocValueKey: assocValueKey
2826
3030
  })));
2827
3031
  }
@@ -2842,59 +3046,62 @@ var changeAssociationFullEpic = function (action$, state$) { return action$.pipe
2842
3046
  })));
2843
3047
  }
2844
3048
  }
2845
- return concat22.apply(void 0, result);
3049
+ return concat26.apply(void 0, result);
2846
3050
  })); };
2847
3051
  // src/epics/data/saveAssociationsActiveEpic.ts
2848
- import { catchError as catchError14, concat as concat23, EMPTY as EMPTY25, filter as filter49, mergeMap as mergeMap34, of as of35, switchMap as switchMap12 } from "rxjs";
3052
+ import { catchError as catchError15, concat as concat27, EMPTY as EMPTY25, filter as filter49, mergeMap as mergeMap34, of as of35, switchMap as switchMap12 } from "rxjs";
2849
3053
  var saveAssociationsActiveEpic = function (action$, state$, _a) {
2850
3054
  var api = _a.api;
2851
3055
  return action$.pipe(filter49(saveAssociations.match), filter49(function (action) {
2852
- return state$.value.view.popupData.active;
3056
+ var _a;
3057
+ return (_a = state$.value.view.popupData) === null || _a === void 0 ? void 0 : _a.active;
2853
3058
  }), switchMap12(function (action) {
3059
+ var _a, _b;
2854
3060
  var state = state$.value;
2855
- var calleeBCName = state.view.popupData.calleeBCName;
2856
- var calleeWidgetName = state.view.popupData.calleeWidgetName;
3061
+ var calleeBCName = (_a = state.view.popupData) === null || _a === void 0 ? void 0 : _a.calleeBCName;
3062
+ var calleeWidgetName = (_b = state.view.popupData) === null || _b === void 0 ? void 0 : _b.calleeWidgetName;
2857
3063
  var bcNames = action.payload.bcNames;
2858
- var bcUrl = buildBcUrl(calleeBCName, true);
3064
+ var bcUrl = buildBcUrl(calleeBCName, true, state);
2859
3065
  var pendingChanges = state.view.pendingDataChanges[bcNames[0]] || {};
2860
3066
  var params = bcNames.length ? { _bcName: bcNames[bcNames.length - 1] } : {};
2861
3067
  return api.associate(state.screen.screenName, bcUrl, Object.values(pendingChanges).filter(function (i) { return i._associate; }), params).pipe(mergeMap34(function (response) {
2862
3068
  var postInvoke = response.postActions[0];
2863
3069
  var calleeWidget = state.view.widgets.find(function (widgetItem) { return widgetItem.bcName === calleeBCName; });
2864
- return concat23(postInvoke ? of35(processPostInvoke({ bcName: calleeBCName, postInvoke: postInvoke, widgetName: calleeWidget.name })) : EMPTY25, of35(bcCancelPendingChanges({ bcNames: bcNames })), of35(bcForceUpdate({ bcName: calleeBCName, widgetName: calleeWidgetName })));
2865
- }), catchError14(function (err) {
3070
+ return concat27(postInvoke ? of35(processPostInvoke({ bcName: calleeBCName, postInvoke: postInvoke, widgetName: calleeWidget === null || calleeWidget === void 0 ? void 0 : calleeWidget.name })) : EMPTY25, of35(bcCancelPendingChanges({ bcNames: bcNames })), of35(bcForceUpdate({ bcName: calleeBCName, widgetName: calleeWidgetName })));
3071
+ }), catchError15(function (err) {
2866
3072
  console.error(err);
2867
3073
  return EMPTY25;
2868
3074
  }));
2869
3075
  }));
2870
3076
  };
2871
3077
  // src/epics/data/changeAssociationSameBcEpic.ts
2872
- import { concat as concat24, filter as filter50, mergeMap as mergeMap35, of as of36 } from "rxjs";
3078
+ import { concat as concat28, filter as filter50, mergeMap as mergeMap35, of as of36 } from "rxjs";
2873
3079
  var changeAssociationSameBcEpic = function (action$, state$) { return action$.pipe(filter50(changeAssociationSameBc.match), mergeMap35(function (action) {
2874
- var _a, _b, _c, _d, _e;
3080
+ var _a, _b, _c, _d, _e, _f;
3081
+ var state = state$.value;
2875
3082
  var bcName = action.payload.bcName;
2876
3083
  var result = [
2877
3084
  of36(changeDataItem({
2878
3085
  bcName: bcName,
3086
+ bcUrl: buildBcUrl(bcName, true, state),
2879
3087
  cursor: action.payload.dataItem.id,
2880
3088
  dataItem: action.payload.dataItem
2881
3089
  }))
2882
3090
  ];
2883
- var state = state$.value;
2884
3091
  var selected = action.payload.dataItem._associate;
2885
3092
  var depth = action.payload.depth || 1;
2886
3093
  var parentDepth = depth - 1;
2887
3094
  var widget = state.view.widgets.find(function (item) { return item.name === action.payload.widgetName; });
2888
3095
  var hierarchyTraverse = (_a = widget.options) === null || _a === void 0 ? void 0 : _a.hierarchyTraverse;
2889
3096
  var currentData = depth > 1 ? (_b = state.depthData[depth]) === null || _b === void 0 ? void 0 : _b[bcName] : state.data[bcName];
2890
- 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;
2891
- 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;
3097
+ 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;
3098
+ 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;
2892
3099
  if (parentDepth && hierarchyTraverse && selected) {
2893
3100
  result.push(of36(changeAssociationSameBc({
2894
3101
  bcName: bcName,
2895
3102
  depth: parentDepth,
2896
3103
  widgetName: action.payload.widgetName,
2897
- dataItem: __assign(__assign({}, parentItem), { _associate: true, _value: parentItem[action.payload.assocValueKey] }),
3104
+ dataItem: __assign(__assign({}, parentItem), { _associate: true, _value: parentItem === null || parentItem === void 0 ? void 0 : parentItem[action.payload.assocValueKey] }),
2898
3105
  assocValueKey: action.payload.assocValueKey
2899
3106
  })));
2900
3107
  }
@@ -2910,21 +3117,22 @@ var changeAssociationSameBcEpic = function (action$, state$) { return action$.pi
2910
3117
  })));
2911
3118
  }
2912
3119
  }
2913
- return concat24.apply(void 0, result);
3120
+ return concat28.apply(void 0, result);
2914
3121
  })); };
2915
3122
  // src/epics/data/inlinePickListFetchDataEpic.ts
2916
- import { catchError as catchError15, filter as filter51, mergeMap as mergeMap36, of as of37, race as race4 } from "rxjs";
3123
+ import { catchError as catchError16, filter as filter51, mergeMap as mergeMap36, of as of37, race as race4 } from "rxjs";
2917
3124
  var inlinePickListFetchDataEpic = function (action$, state$, _a) {
2918
3125
  var api = _a.api;
2919
3126
  return action$.pipe(filter51(inlinePickListFetchDataRequest.match), mergeMap36(function (action) {
2920
3127
  var _a;
2921
3128
  var _b = action.payload, bcName = _b.bcName, searchSpec = _b.searchSpec, searchString = _b.searchString;
2922
- var bcUrl = buildBcUrl(bcName, false);
3129
+ var state = state$.value;
3130
+ var bcUrl = buildBcUrl(bcName, false, state);
2923
3131
  var canceler = api.createCanceler();
2924
3132
  var cancelFlow = cancelRequestEpic(action$, cancelRequestActionTypes, canceler.cancel, bcFetchDataFail({ bcName: bcName, bcUrl: bcUrl }));
2925
3133
  var normalFlow = api.fetchBcData(state$.value.screen.screenName, bcUrl, (_a = {}, _a[searchSpec + ".contains"] = searchString, _a), canceler.cancelToken).pipe(mergeMap36(function (data) {
2926
3134
  return of37(bcFetchDataSuccess({ bcName: bcName, data: data.data, bcUrl: bcUrl }));
2927
- }), catchError15(function (error) {
3135
+ }), catchError16(function (error) {
2928
3136
  console.error(error);
2929
3137
  return of37(bcFetchDataFail({ bcName: action.payload.bcName, bcUrl: bcUrl }));
2930
3138
  }));
@@ -2934,14 +3142,15 @@ var inlinePickListFetchDataEpic = function (action$, state$, _a) {
2934
3142
  // src/epics/data/saveAssociationsPassiveEpic.ts
2935
3143
  import { filter as filter52, of as of38, switchMap as switchMap13 } from "rxjs";
2936
3144
  var saveAssociationsPassiveEpic = function (action$, state$) { return action$.pipe(filter52(saveAssociations.match), filter52(function () {
2937
- return !state$.value.view.popupData.active;
3145
+ var _a;
3146
+ return !((_a = state$.value.view.popupData) === null || _a === void 0 ? void 0 : _a.active);
2938
3147
  }), switchMap13(function (action) {
2939
3148
  var _a, _b;
2940
- var _c;
3149
+ var _c, _d;
2941
3150
  var state = state$.value;
2942
- 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;
3151
+ 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;
2943
3152
  var cursor = state.screen.bo.bc[calleeBCName].cursor;
2944
- var recordPrevData = (_c = state.data[calleeBCName].find(function (dataStateRecord) { return dataStateRecord.id === cursor; })[associateFieldKey]) !== null && _c !== void 0 ? _c : [];
3153
+ var recordPrevData = (_d = state.data[calleeBCName].find(function (dataStateRecord) { return dataStateRecord.id === cursor; })[associateFieldKey]) !== null && _d !== void 0 ? _d : [];
2945
3154
  var newValues = [];
2946
3155
  action.payload.bcNames.forEach(function (pendingBc) {
2947
3156
  var pendingChanges = state.view.pendingDataChanges[pendingBc] || {};
@@ -2967,6 +3176,7 @@ var saveAssociationsPassiveEpic = function (action$, state$) { return action$.pi
2967
3176
  })).concat.apply(_a, addedItems);
2968
3177
  return of38(changeDataItem({
2969
3178
  bcName: calleeBCName,
3179
+ bcUrl: buildBcUrl(calleeBCName, true, state),
2970
3180
  cursor: cursor,
2971
3181
  dataItem: (_b = {},
2972
3182
  _b[associateFieldKey] = result,
@@ -3000,7 +3210,7 @@ var changeChildrenAssociationsSameBcEpic = function (action$, state$) { return a
3000
3210
  }));
3001
3211
  })); };
3002
3212
  // src/epics/data/changeDescendantsAssociationsFullEpic.ts
3003
- import { concat as concat25, filter as filter55, mergeMap as mergeMap39, of as of41 } from "rxjs";
3213
+ import { concat as concat29, filter as filter55, mergeMap as mergeMap39, of as of41 } from "rxjs";
3004
3214
  var changeDescendantsAssociationsFullEpic = function (action$, state$) { return action$.pipe(filter55(changeDescendantsAssociationsFull.match), mergeMap39(function (action) {
3005
3215
  var state = state$.value;
3006
3216
  var depth = action.payload.depth;
@@ -3018,7 +3228,7 @@ var changeDescendantsAssociationsFullEpic = function (action$, state$) { return
3018
3228
  result.push(of41(changeDescendantsAssociationsFull(__assign(__assign({}, action.payload), { parentId: targetDataItem.id, depth: depth + 1 }))));
3019
3229
  }
3020
3230
  });
3021
- return concat25.apply(void 0, result);
3231
+ return concat29.apply(void 0, result);
3022
3232
  })); };
3023
3233
  // src/api/ObservableApiWrapper.ts
3024
3234
  import axios2 from "axios";
@@ -3047,7 +3257,6 @@ var ObservableApiWrapper = /** @class */ (function () {
3047
3257
  this.instance = instance;
3048
3258
  }
3049
3259
  class_2.prototype.get = function (path, config, callContext) {
3050
- if (config === void 0) { config = {}; }
3051
3260
  return from(this.instance.get(path, config)).pipe(takeWhile(redirectOccurred), map10(function (response) { return response.data; }));
3052
3261
  };
3053
3262
  class_2.prototype.put = function (path, data, callContext) {
@@ -3066,7 +3275,6 @@ import axios3 from "axios";
3066
3275
  import { EMPTY as EMPTY26, expand, map as map11, reduce } from "rxjs";
3067
3276
  var Api = /** @class */ (function () {
3068
3277
  function class_3(instance) {
3069
- this.api$ = new ObservableApiWrapper();
3070
3278
  this.api$ = new ObservableApiWrapper(instance);
3071
3279
  }
3072
3280
  class_3.prototype.routerRequest = function (path, params) {
@@ -3091,23 +3299,24 @@ var Api = /** @class */ (function () {
3091
3299
  };
3092
3300
  class_3.prototype.fetchRowMeta = function (screenName, bcUrl, params, cancelToken) {
3093
3301
  var url = applyParams(buildUrl(templateObject_2 || (templateObject_2 = __makeTemplateObject(["row-meta/", "/"], ["row-meta/", "/"])), screenName) + bcUrl, params);
3094
- return this.api$.get(url, { cancelToken: cancelToken }).pipe(map11(function (response) { return response.data.row; }));
3302
+ return this.api$.get(url, { cancelToken: cancelToken }).pipe(map11(function (response) { var _a; return (_a = response.data) === null || _a === void 0 ? void 0 : _a.row; }));
3095
3303
  };
3096
3304
  class_3.prototype.newBcData = function (screenName, bcUrl, context, params) {
3097
3305
  var url = applyParams(buildUrl(templateObject_3 || (templateObject_3 = __makeTemplateObject(["row-meta-new/", "/"], ["row-meta-new/", "/"])), screenName) + bcUrl, params);
3098
- return this.api$.get(url, null, context).pipe(map11(function (response) { return response.data; }));
3306
+ return this.api$.get(url, void 0, context).pipe(map11(function (response) { return response.data; }));
3099
3307
  };
3100
3308
  class_3.prototype.saveBcData = function (screenName, bcUrl, data, context, params) {
3101
3309
  var url = applyParams(buildUrl(templateObject_4 || (templateObject_4 = __makeTemplateObject(["data/", "/"], ["data/", "/"])), screenName) + bcUrl, params);
3102
3310
  return this.api$.put(url, { data: data }, context).pipe(map11(function (response) { return response.data; }));
3103
3311
  };
3104
3312
  class_3.prototype.deleteBcData = function (screenName, bcUrl, context, params) {
3313
+ if (bcUrl === void 0) { bcUrl = ""; }
3105
3314
  var url = applyParams(buildUrl(templateObject_5 || (templateObject_5 = __makeTemplateObject(["data/", "/"], ["data/", "/"])), screenName) + bcUrl, params);
3106
3315
  return this.api$.delete(url, context).pipe(map11(function (response) { return response.data; }));
3107
3316
  };
3108
3317
  class_3.prototype.customAction = function (screenName, bcUrl, data, context, params) {
3109
3318
  var url = applyParams(buildUrl(templateObject_6 || (templateObject_6 = __makeTemplateObject(["custom-action/", "/"], ["custom-action/", "/"])), screenName) + bcUrl, params);
3110
- return this.api$.post(url, { data: data || {} }, null, context).pipe(map11(function (response) { return response.data; }));
3319
+ return this.api$.post(url, { data: data || {} }, void 0, context).pipe(map11(function (response) { return response.data; }));
3111
3320
  };
3112
3321
  class_3.prototype.associate = function (screenName, bcUrl, data, params) {
3113
3322
  var processedData = Array.isArray(data) ? data.map(function (item) { return ({
@@ -3119,9 +3328,27 @@ var Api = /** @class */ (function () {
3119
3328
  return this.api$.post(url, processedData).pipe(map11(function (response) { return response.data; }));
3120
3329
  };
3121
3330
  class_3.prototype.getRmByForceActive = function (screenName, bcUrl, data, params) {
3122
- var url = applyParams(buildUrl(templateObject_8 || (templateObject_8 = __makeTemplateObject(["row-meta/", "/"], ["row-meta/", "/"])), screenName) + bcUrl, params);
3331
+ var url = applyParams(buildUrl(templateObject_8 || (templateObject_8 = __makeTemplateObject(["row-meta/", "/"], ["row-meta/", "/"])), screenName) + (bcUrl !== null && bcUrl !== void 0 ? bcUrl : ""), params);
3123
3332
  return this.api$.post(url, { data: data }).pipe(map11(function (response) { return response.data.row; }));
3124
3333
  };
3334
+ Object.defineProperty(class_3.prototype, "fileUploadEndpoint", {
3335
+ /**
3336
+ * Get Cxbox API file upload endpoint based on baseURL of axios instance
3337
+ *
3338
+ * Handles empty baseURL and trailing slash
3339
+ *
3340
+ * @returns File upload endpoint
3341
+ */
3342
+ get: function () {
3343
+ var instance = this.api$.instance;
3344
+ if (!instance.defaults.baseURL) {
3345
+ return "/file";
3346
+ }
3347
+ return instance.defaults.baseURL.endsWith("/") ? "".concat(instance.defaults.baseURL, "file") : "".concat(instance.defaults.baseURL, "/file");
3348
+ },
3349
+ enumerable: false,
3350
+ configurable: true
3351
+ });
3125
3352
  class_3.prototype.refreshMeta = function () {
3126
3353
  return this.api$.get(buildUrl(templateObject_9 || (templateObject_9 = __makeTemplateObject(["bc-registry/refresh-meta"], ["bc-registry/refresh-meta"]))));
3127
3354
  };
@@ -3140,6 +3367,243 @@ var Api = /** @class */ (function () {
3140
3367
  };
3141
3368
  return class_3;
3142
3369
  }());
3143
- export { Api, actions_exports as actions, epics_exports as epics, interfaces_exports as interfaces, reducers_exports as reducers, utils_exports as utils };
3370
+ // src/utils/autosave.ts
3371
+ function autosaveRoutine(action, store, next) {
3372
+ var _a, _b, _c;
3373
+ var state = store.getState();
3374
+ var dispatch = store.dispatch;
3375
+ var pendingDataChanges = state.view.pendingDataChanges;
3376
+ var bcList = Object.keys(pendingDataChanges);
3377
+ 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); });
3378
+ var baseBcName = bcList[baseBcNameIndex];
3379
+ if (baseBcNameIndex > -1) {
3380
+ bcList.splice(baseBcNameIndex, 1);
3381
+ }
3382
+ if (baseBcName) {
3383
+ bcList.forEach(function (bcName) {
3384
+ var _a, _b;
3385
+ var widget = (_a = state.view.widgets) === null || _a === void 0 ? void 0 : _a.find(function (v) { return v.bcName === bcName; });
3386
+ var cursor = (_b = state.screen.bo.bc[bcName]) === null || _b === void 0 ? void 0 : _b.cursor;
3387
+ if (bcHasPendingAutosaveChanges(state, bcName, cursor)) {
3388
+ dispatch(sendOperation({
3389
+ bcName: bcName,
3390
+ operationType: OperationTypeCrud.save,
3391
+ widgetName: widget === null || widget === void 0 ? void 0 : widget.name
3392
+ }));
3393
+ }
3394
+ });
3395
+ var baseWidget = (_c = state.view.widgets) === null || _c === void 0 ? void 0 : _c.find(function (v) { return v.bcName === baseBcName; });
3396
+ return next(sendOperation({
3397
+ bcName: baseBcName,
3398
+ operationType: OperationTypeCrud.save,
3399
+ widgetName: baseWidget === null || baseWidget === void 0 ? void 0 : baseWidget.name,
3400
+ onSuccessAction: action
3401
+ }));
3402
+ }
3403
+ return next(action);
3404
+ }
3405
+ function bcHasPendingAutosaveChanges(store, bcName, cursor) {
3406
+ var _a;
3407
+ var pendingChanges = store.view.pendingDataChanges;
3408
+ var cursorChanges = (_a = pendingChanges[bcName]) === null || _a === void 0 ? void 0 : _a[cursor];
3409
+ var result = cursorChanges && !Object.keys(cursorChanges).includes("_associate") && Object.values(cursorChanges).length > 0;
3410
+ return result;
3411
+ }
3412
+ function checkUnsavedChangesOfBc(store, bcName) {
3413
+ var _a, _b;
3414
+ var pendingCursors = Object.keys((_b = (_a = store.view.pendingDataChanges) === null || _a === void 0 ? void 0 : _a[bcName]) !== null && _b !== void 0 ? _b : {});
3415
+ return pendingCursors.some(function (cursor) { return bcHasPendingAutosaveChanges(store, bcName, cursor); });
3416
+ }
3417
+ // src/middlewares/autosaveMiddleware.ts
3418
+ var saveFormMiddleware = function (_a) {
3419
+ var getState = _a.getState, dispatch = _a.dispatch;
3420
+ return function (next) { return function (action) {
3421
+ var _a, _b, _c, _d, _e, _f, _g;
3422
+ var state = getState();
3423
+ var isSendOperation = sendOperation.match(action);
3424
+ var isCoreSendOperation = isSendOperation && coreOperations.includes(action.payload.operationType);
3425
+ var isSelectTableCellInit = selectTableCellInit.match(action);
3426
+ var isSaveAction = isSendOperation && action.payload.operationType === OperationTypeCrud.save;
3427
+ var isNotSaveAction = !isSaveAction;
3428
+ var actionBcName = isSendOperation && action.payload.bcName;
3429
+ var hasAnotherUnsavedBc = Object.keys(state.view.pendingDataChanges).filter(function (key) { return key !== actionBcName; }).filter(function (key) { return checkUnsavedChangesOfBc(state, key); }).length > 0;
3430
+ var isSendOperationForAnotherBc = isCoreSendOperation && hasAnotherUnsavedBc;
3431
+ var selectedCell = state.view.selectedCell;
3432
+ var isSelectTableCellInitOnAnotherRowOrWidget = selectedCell && isSelectTableCellInit && (selectedCell.widgetName !== action.payload.widgetName || selectedCell.rowId !== action.payload.rowId);
3433
+ 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; });
3434
+ 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;
3435
+ 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];
3436
+ var isChangeLocation = defaultSaveWidget && changeLocation.match(action) && Object.keys(pendingData || {}).length > 0;
3437
+ if (isChangeLocation) {
3438
+ return next(sendOperation({
3439
+ bcName: defaultSaveWidget.bcName,
3440
+ operationType: ((_g = defaultSaveWidget.options) === null || _g === void 0 ? void 0 : _g.actionGroups).defaultSave,
3441
+ widgetName: defaultSaveWidget.name,
3442
+ onSuccessAction: action
3443
+ }));
3444
+ }
3445
+ var isNeedSaveCondition = isNotSaveAction && (isSendOperationForAnotherBc || isSelectTableCellInitOnAnotherRowOrWidget);
3446
+ if (isNeedSaveCondition) {
3447
+ return autosaveRoutine(action, { getState: getState, dispatch: dispatch }, next);
3448
+ }
3449
+ return next(action);
3450
+ }; };
3451
+ };
3452
+ // src/middlewares/requiredFieldsMiddleware.ts
3453
+ var requiredFields = function (_a) {
3454
+ var getState = _a.getState, dispatch = _a.dispatch;
3455
+ return function (next) { return function (action) {
3456
+ var _a, _b, _c, _d;
3457
+ var state = getState();
3458
+ if (sendOperation.match(action)) {
3459
+ var _e = action.payload, bcName = _e.bcName, operationType = _e.operationType, widgetName_1 = _e.widgetName;
3460
+ var cursor_1 = (_a = state.screen.bo.bc[bcName]) === null || _a === void 0 ? void 0 : _a.cursor;
3461
+ if (cursor_1) {
3462
+ var bcUrl = buildBcUrl(bcName, true, state);
3463
+ var record = (_b = state.data[bcName]) === null || _b === void 0 ? void 0 : _b.find(function (item) { return item.id === cursor_1; });
3464
+ var rowMeta_1 = bcUrl && ((_c = state.view.rowMeta[bcName]) === null || _c === void 0 ? void 0 : _c[bcUrl]);
3465
+ var pendingValues = (_d = state.view.pendingDataChanges[bcName]) === null || _d === void 0 ? void 0 : _d[cursor_1];
3466
+ var widget_1 = state.view.widgets.find(function (item) { return item.name === widgetName_1; });
3467
+ if (operationRequiresAutosave(operationType, rowMeta_1 === null || rowMeta_1 === void 0 ? void 0 : rowMeta_1.actions)) {
3468
+ var fieldsToCheck_1 = {};
3469
+ state.view.widgets.filter(function (item) { return item.bcName === (widget_1 === null || widget_1 === void 0 ? void 0 : widget_1.bcName); }).forEach(function (item) {
3470
+ var itemFieldsCalc = item.fields;
3471
+ if (item.fields) {
3472
+ item.fields.forEach(function (block) {
3473
+ if (isWidgetFieldBlock(block)) {
3474
+ block.fields.forEach(function (field) { return itemFieldsCalc.push(field); });
3475
+ }
3476
+ });
3477
+ }
3478
+ itemFieldsCalc.forEach(function (widgetField) {
3479
+ var _a;
3480
+ 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; });
3481
+ if (!fieldsToCheck_1[widgetField.key] && matchingRowMeta && !matchingRowMeta.hidden) {
3482
+ fieldsToCheck_1[widgetField.key] = matchingRowMeta;
3483
+ }
3484
+ });
3485
+ });
3486
+ var dataItem = getRequiredFieldsMissing(record, pendingValues, Object.values(fieldsToCheck_1));
3487
+ if (dataItem && TableLikeWidgetTypes.includes(widget_1 === null || widget_1 === void 0 ? void 0 : widget_1.type)) {
3488
+ dispatch(selectTableCellInit({ widgetName: widgetName_1, rowId: cursor_1, fieldKey: Object.keys(dataItem)[0] }));
3489
+ }
3490
+ return dataItem ? next(changeDataItem({ bcName: bcName, bcUrl: buildBcUrl(bcName, true, state), cursor: cursor_1, dataItem: dataItem })) : next(action);
3491
+ }
3492
+ if (hasPendingValidationFails(state, bcName)) {
3493
+ return addNotification({
3494
+ key: "requiredFieldsMissing",
3495
+ type: "buttonWarningNotification",
3496
+ message: "Required fields are missing",
3497
+ duration: 0,
3498
+ options: {
3499
+ buttonWarningNotificationOptions: {
3500
+ buttonText: "Cancel changes",
3501
+ actionsForClick: [bcCancelPendingChanges(null), clearValidationFails(null)]
3502
+ }
3503
+ }
3504
+ });
3505
+ }
3506
+ }
3507
+ }
3508
+ return next(action);
3509
+ }; };
3510
+ };
3511
+ function operationRequiresAutosave(operationType, actions2) {
3512
+ var result = false;
3513
+ if (!actions2) {
3514
+ console.error('rowMeta is missing in the middle of "sendOperation" action');
3515
+ return result;
3516
+ }
3517
+ result = flattenOperations(actions2).some(function (action) { return action.type === operationType && action.autoSaveBefore; });
3518
+ return result;
3519
+ }
3520
+ function getRequiredFieldsMissing(record, pendingChanges, fieldsMeta) {
3521
+ var result = {};
3522
+ fieldsMeta.forEach(function (field) {
3523
+ var value = record === null || record === void 0 ? void 0 : record[field.key];
3524
+ var pendingValue = pendingChanges === null || pendingChanges === void 0 ? void 0 : pendingChanges[field.key];
3525
+ var effectiveValue = pendingValue !== void 0 ? pendingValue : value;
3526
+ var falsyValue = false;
3527
+ if (effectiveValue === null || effectiveValue === void 0 || effectiveValue === "") {
3528
+ falsyValue = true;
3529
+ }
3530
+ else if (Array.isArray(effectiveValue) && !effectiveValue.length) {
3531
+ falsyValue = true;
3532
+ }
3533
+ else if (effectiveValue && typeof effectiveValue === "object" && !Object.keys(effectiveValue).length) {
3534
+ falsyValue = true;
3535
+ }
3536
+ if (field.required && falsyValue) {
3537
+ result[field.key] = Array.isArray(effectiveValue) ? [] : null;
3538
+ }
3539
+ });
3540
+ return Object.keys(result).length > 0 ? result : null;
3541
+ }
3542
+ function hasPendingValidationFails(store, bcName) {
3543
+ var _a;
3544
+ if (store.view.pendingValidationFailsFormat !== "target" /* target */ && store.view.pendingValidationFails && Object.keys(store.view.pendingValidationFails).length) {
3545
+ return true;
3546
+ }
3547
+ var checkResult = false;
3548
+ var bcPendingValidations = (_a = store.view.pendingValidationFails) === null || _a === void 0 ? void 0 : _a[bcName];
3549
+ var cursorsList = bcPendingValidations && Object.keys(bcPendingValidations);
3550
+ if (!cursorsList) {
3551
+ return false;
3552
+ }
3553
+ var i = 0;
3554
+ for (; i < cursorsList.length; i++) {
3555
+ if (Object.keys(bcPendingValidations[cursorsList[i]]).length) {
3556
+ checkResult = true;
3557
+ break;
3558
+ }
3559
+ }
3560
+ return checkResult;
3561
+ }
3562
+ // src/middlewares/preInvokeMiddleware.ts
3563
+ var preInvokeAction = function (_a) {
3564
+ var getState = _a.getState;
3565
+ return function (next) { return function (action) {
3566
+ var _a, _b, _c;
3567
+ if (sendOperation.match(action)) {
3568
+ var state = getState();
3569
+ var _d = action.payload, operationType_1 = _d.operationType, widgetName_2 = _d.widgetName, confirm = _d.confirm;
3570
+ var bcName = (_a = state.view.widgets.find(function (widgetItem) { return widgetItem.name === widgetName_2; })) === null || _a === void 0 ? void 0 : _a.bcName;
3571
+ var bcUrl = buildBcUrl(bcName, true, state);
3572
+ var rowMeta = bcUrl && ((_b = state.view.rowMeta[bcName]) === null || _b === void 0 ? void 0 : _b[bcUrl]);
3573
+ var actions2 = rowMeta && flattenOperations(rowMeta.actions);
3574
+ 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;
3575
+ return preInvoke && !confirm ? next(processPreInvoke({
3576
+ bcName: bcName,
3577
+ operationType: operationType_1,
3578
+ widgetName: widgetName_2,
3579
+ preInvoke: preInvoke
3580
+ })) : next(action);
3581
+ }
3582
+ return next(action);
3583
+ }; };
3584
+ };
3585
+ // src/middlewares/popupMiddleware.ts
3586
+ var popupMiddleware = function (_a) {
3587
+ var getState = _a.getState;
3588
+ return function (next) { return function (action) {
3589
+ var _a, _b, _c;
3590
+ if (showViewPopup.match(action)) {
3591
+ var state = getState();
3592
+ var bcName_1 = action.payload.bcName;
3593
+ 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;
3594
+ var assocValueKey = (_c = action.payload.assocValueKey) !== null && _c !== void 0 ? _c : widgetValueKey;
3595
+ return widgetValueKey ? next(showViewPopup(__assign(__assign({}, action.payload), { assocValueKey: assocValueKey }))) : next(action);
3596
+ }
3597
+ return next(action);
3598
+ }; };
3599
+ };
3600
+ // src/middlewares/index.ts
3601
+ var middlewares = {
3602
+ autosave: saveFormMiddleware,
3603
+ requiredFields: requiredFields,
3604
+ preInvoke: preInvokeAction,
3605
+ popup: popupMiddleware
3606
+ };
3607
+ export { Api, actions_exports as actions, epics_exports as epics, interfaces_exports as interfaces, middlewares, reducers_exports as reducers, utils_exports as utils };
3144
3608
  var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10;
3145
3609
  //# sourceMappingURL=cxbox-ui-core.esm.js.map