@cxbox-ui/core 2.0.0-alpha.8 → 2.0.0

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.
Files changed (127) hide show
  1. package/README.md +261 -28
  2. package/dist/core.d.ts +4274 -0
  3. package/dist/index.js +2 -6
  4. package/dist/index.js.map +1 -0
  5. package/package.json +20 -30
  6. package/dist/actions/index.d.ts +0 -1081
  7. package/dist/api/ObservableApi.d.ts +0 -53
  8. package/dist/api/ObservableApiWrapper.d.ts +0 -11
  9. package/dist/api/index.d.ts +0 -1
  10. package/dist/cxbox-ui-core.cjs.development.js +0 -3692
  11. package/dist/cxbox-ui-core.cjs.production.min.js +0 -2
  12. package/dist/cxbox-ui-core.esm.js +0 -3656
  13. package/dist/cxbox-ui-core.modern.development.js +0 -3586
  14. package/dist/cxbox-ui-core.modern.js +0 -3586
  15. package/dist/cxbox-ui-core.modern.production.min.js +0 -2
  16. package/dist/epics/data/bcCancelCreateDataEpic.d.ts +0 -9
  17. package/dist/epics/data/bcDeleteDataEpic.d.ts +0 -2
  18. package/dist/epics/data/bcFetchDataEpic.d.ts +0 -15
  19. package/dist/epics/data/bcFetchRowMetaRequestEpic.d.ts +0 -17
  20. package/dist/epics/data/bcLoadMoreEpic.d.ts +0 -2
  21. package/dist/epics/data/bcNewDataEpic.d.ts +0 -14
  22. package/dist/epics/data/bcSaveDataEpic.d.ts +0 -24
  23. package/dist/epics/data/bcSelectDepthRecordEpic.d.ts +0 -2
  24. package/dist/epics/data/bcSelectRecordEpic.d.ts +0 -2
  25. package/dist/epics/data/changeAssociationEpic.d.ts +0 -2
  26. package/dist/epics/data/changeAssociationFullEpic.d.ts +0 -5
  27. package/dist/epics/data/changeAssociationSameBcEpic.d.ts +0 -5
  28. package/dist/epics/data/changeChildrenAssociationsEpic.d.ts +0 -2
  29. package/dist/epics/data/changeChildrenAssociationsSameBcEpic.d.ts +0 -2
  30. package/dist/epics/data/changeDescendantsAssociationsFullEpic.d.ts +0 -5
  31. package/dist/epics/data/index.d.ts +0 -20
  32. package/dist/epics/data/inlinePickListFetchDataEpic.d.ts +0 -2
  33. package/dist/epics/data/removeMultivalueTagEpic.d.ts +0 -17
  34. package/dist/epics/data/saveAssociationsActiveEpic.d.ts +0 -7
  35. package/dist/epics/data/saveAssociationsPassiveEpic.d.ts +0 -7
  36. package/dist/epics/data/selectViewEpic.d.ts +0 -11
  37. package/dist/epics/index.d.ts +0 -6
  38. package/dist/epics/router/changeLocationEpic.d.ts +0 -10
  39. package/dist/epics/router/drilldownEpic.d.ts +0 -2
  40. package/dist/epics/router/handleRouterEpic.d.ts +0 -2
  41. package/dist/epics/router/index.d.ts +0 -10
  42. package/dist/epics/router/loginDoneEpic.d.ts +0 -9
  43. package/dist/epics/router/selectScreenEpic.d.ts +0 -7
  44. package/dist/epics/router/selectScreenFailEpic.d.ts +0 -7
  45. package/dist/epics/router/selectViewEpic.d.ts +0 -7
  46. package/dist/epics/router/selectViewFailEpic.d.ts +0 -6
  47. package/dist/epics/router/userDrillDownEpic.d.ts +0 -6
  48. package/dist/epics/router/userDrilldownChangeCursorsEpic.d.ts +0 -2
  49. package/dist/epics/screen/apiErrorEpic.d.ts +0 -2
  50. package/dist/epics/screen/downloadFileByUrlEpic.d.ts +0 -2
  51. package/dist/epics/screen/downloadFileEpic.d.ts +0 -2
  52. package/dist/epics/screen/httpError401Epic.d.ts +0 -2
  53. package/dist/epics/screen/httpError409Epic.d.ts +0 -2
  54. package/dist/epics/screen/httpError418Epic.d.ts +0 -2
  55. package/dist/epics/screen/httpError500Epic.d.ts +0 -2
  56. package/dist/epics/screen/httpErrorDefaultEpic.d.ts +0 -2
  57. package/dist/epics/screen/index.d.ts +0 -10
  58. package/dist/epics/screen/processPostInvokeConfirmEpic.d.ts +0 -2
  59. package/dist/epics/screen/processPostInvokeEpic.d.ts +0 -2
  60. package/dist/epics/session/index.d.ts +0 -5
  61. package/dist/epics/session/loginByAnotherRoleEpic.d.ts +0 -5
  62. package/dist/epics/session/loginDoneEpic.d.ts +0 -6
  63. package/dist/epics/session/refreshMetaAndReloadPageEpic.d.ts +0 -2
  64. package/dist/epics/session/refreshMetaEpic.d.ts +0 -5
  65. package/dist/epics/session/switchRoleEpic.d.ts +0 -5
  66. package/dist/epics/utils/postOperationRoutine.d.ts +0 -13
  67. package/dist/epics/view/clearPendingDataChangesAfterCursorChangeEpic.d.ts +0 -7
  68. package/dist/epics/view/fileUploadConfirmEpic.d.ts +0 -11
  69. package/dist/epics/view/getRowMetaByForceActiveEpic.d.ts +0 -5
  70. package/dist/epics/view/index.d.ts +0 -9
  71. package/dist/epics/view/selectTableCellInitEpic.d.ts +0 -2
  72. package/dist/epics/view/sendOperationAssociateEpic.d.ts +0 -5
  73. package/dist/epics/view/sendOperationEpic.d.ts +0 -10
  74. package/dist/epics/view/showAllTableRecordsInitEpic.d.ts +0 -2
  75. package/dist/epics/view/showAssocPopupEpic.d.ts +0 -2
  76. package/dist/epics/view/showFileUploadPopupEpic.d.ts +0 -5
  77. package/dist/index.d.ts +0 -7
  78. package/dist/interfaces/bc.d.ts +0 -79
  79. package/dist/interfaces/customEpics.d.ts +0 -15
  80. package/dist/interfaces/customMiddlewares.d.ts +0 -35
  81. package/dist/interfaces/data.d.ts +0 -48
  82. package/dist/interfaces/filters.d.ts +0 -32
  83. package/dist/interfaces/index.d.ts +0 -27
  84. package/dist/interfaces/navigation.d.ts +0 -48
  85. package/dist/interfaces/objectMap.d.ts +0 -36
  86. package/dist/interfaces/operation.d.ts +0 -336
  87. package/dist/interfaces/router.d.ts +0 -17
  88. package/dist/interfaces/rowMeta.d.ts +0 -74
  89. package/dist/interfaces/screen.d.ts +0 -28
  90. package/dist/interfaces/session.d.ts +0 -83
  91. package/dist/interfaces/store.d.ts +0 -14
  92. package/dist/interfaces/tree.d.ts +0 -66
  93. package/dist/interfaces/view.d.ts +0 -202
  94. package/dist/interfaces/widget.d.ts +0 -209
  95. package/dist/middlewares/autosaveMiddleware.d.ts +0 -2
  96. package/dist/middlewares/index.d.ts +0 -6
  97. package/dist/middlewares/popupMiddleware.d.ts +0 -2
  98. package/dist/middlewares/preInvokeMiddleware.d.ts +0 -5
  99. package/dist/middlewares/requiredFieldsMiddleware.d.ts +0 -30
  100. package/dist/reducers/ReducerBuilderManager.d.ts +0 -19
  101. package/dist/reducers/data.d.ts +0 -4
  102. package/dist/reducers/depthData.d.ts +0 -4
  103. package/dist/reducers/index.d.ts +0 -6
  104. package/dist/reducers/router.d.ts +0 -9
  105. package/dist/reducers/screen.d.ts +0 -10
  106. package/dist/reducers/session.d.ts +0 -10
  107. package/dist/reducers/view.d.ts +0 -10
  108. package/dist/utils/api.d.ts +0 -25
  109. package/dist/utils/apiError.d.ts +0 -19
  110. package/dist/utils/autosave.d.ts +0 -37
  111. package/dist/utils/bc.d.ts +0 -27
  112. package/dist/utils/breadthFirst.d.ts +0 -21
  113. package/dist/utils/cancelRequestEpic.d.ts +0 -27
  114. package/dist/utils/combineMiddlewares.d.ts +0 -3
  115. package/dist/utils/deleteUndefinedFromObject.d.ts +0 -1
  116. package/dist/utils/exportState.d.ts +0 -0
  117. package/dist/utils/extendPopupWidgetTypes.d.ts +0 -8
  118. package/dist/utils/filters.d.ts +0 -63
  119. package/dist/utils/hierarchy.d.ts +0 -17
  120. package/dist/utils/highlightJson.d.ts +0 -12
  121. package/dist/utils/history.d.ts +0 -50
  122. package/dist/utils/index.d.ts +0 -10
  123. package/dist/utils/operations.d.ts +0 -21
  124. package/dist/utils/others.d.ts +0 -6
  125. package/dist/utils/strings.d.ts +0 -44
  126. package/dist/utils/tree.d.ts +0 -43
  127. package/dist/utils/viewTabs.d.ts +0 -20
@@ -1,3586 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __export = (target, all) => {
21
- for (var name in all)
22
- __defProp(target, name, { get: all[name], enumerable: true });
23
- };
24
- var __publicField = (obj, key, value) => {
25
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
26
- return value;
27
- };
28
- // src/reducers/index.ts
29
- var reducers_exports = {};
30
- __export(reducers_exports, {
31
- createDataReducerBuilderManager: () => createDataReducerBuilderManager,
32
- createDepthDataReducerBuilderManager: () => createDepthDataReducerBuilderManager,
33
- createRouterReducerBuilderManager: () => createRouterReducerBuilderManager,
34
- createScreenReducerBuilderManager: () => createScreenReducerBuilderManager,
35
- createSessionReducerBuilderManager: () => createSessionReducerBuilderManager,
36
- createViewReducerBuilderManager: () => createViewReducerBuilderManager,
37
- dataInitialState: () => dataInitialState,
38
- initialDepthDataState: () => initialDepthDataState,
39
- initialRouterState: () => initialRouterState,
40
- initialScreenState: () => initialScreenState,
41
- initialSessionState: () => initialSessionState,
42
- initialViewState: () => initialViewState
43
- });
44
- // src/actions/index.ts
45
- var actions_exports = {};
46
- __export(actions_exports, {
47
- addNotification: () => addNotification,
48
- addPendingRequest: () => addPendingRequest,
49
- apiError: () => apiError,
50
- bcAddFilter: () => bcAddFilter,
51
- bcAddSorter: () => bcAddSorter,
52
- bcCancelPendingChanges: () => bcCancelPendingChanges,
53
- bcChangeCursors: () => bcChangeCursors,
54
- bcChangeDepthCursor: () => bcChangeDepthCursor,
55
- bcChangePage: () => bcChangePage,
56
- bcDeleteDataFail: () => bcDeleteDataFail,
57
- bcFetchDataFail: () => bcFetchDataFail,
58
- bcFetchDataPages: () => bcFetchDataPages,
59
- bcFetchDataRequest: () => bcFetchDataRequest,
60
- bcFetchDataSuccess: () => bcFetchDataSuccess,
61
- bcFetchRowMeta: () => bcFetchRowMeta,
62
- bcFetchRowMetaFail: () => bcFetchRowMetaFail,
63
- bcFetchRowMetaSuccess: () => bcFetchRowMetaSuccess,
64
- bcForceUpdate: () => bcForceUpdate,
65
- bcLoadMore: () => bcLoadMore,
66
- bcNewData: () => bcNewData,
67
- bcNewDataFail: () => bcNewDataFail,
68
- bcNewDataSuccess: () => bcNewDataSuccess,
69
- bcRemoveAllFilters: () => bcRemoveAllFilters,
70
- bcRemoveFilter: () => bcRemoveFilter,
71
- bcRemoveSorter: () => bcRemoveSorter,
72
- bcSaveDataFail: () => bcSaveDataFail,
73
- bcSaveDataSuccess: () => bcSaveDataSuccess,
74
- bcSelectDepthRecord: () => bcSelectDepthRecord,
75
- bcSelectRecord: () => bcSelectRecord,
76
- bulkUploadFiles: () => bulkUploadFiles,
77
- changeAssociation: () => changeAssociation,
78
- changeAssociationFull: () => changeAssociationFull,
79
- changeAssociationSameBc: () => changeAssociationSameBc,
80
- changeAssociations: () => changeAssociations,
81
- changeChildrenAssociations: () => changeChildrenAssociations,
82
- changeChildrenAssociationsSameBc: () => changeChildrenAssociationsSameBc,
83
- changeDataItem: () => changeDataItem,
84
- changeDataItems: () => changeDataItems,
85
- changeDescendantsAssociationsFull: () => changeDescendantsAssociationsFull,
86
- changeLocation: () => changeLocation,
87
- clearValidationFails: () => clearValidationFails,
88
- closeConfirmModal: () => closeConfirmModal,
89
- closeNotification: () => closeNotification,
90
- closeViewError: () => closeViewError,
91
- closeViewPopup: () => closeViewPopup,
92
- downloadFile: () => downloadFile,
93
- downloadFileByUrl: () => downloadFileByUrl,
94
- drillDown: () => drillDown,
95
- dropAllAssociations: () => dropAllAssociations,
96
- dropAllAssociationsFull: () => dropAllAssociationsFull,
97
- dropAllAssociationsSameBc: () => dropAllAssociationsSameBc,
98
- emptyAction: () => emptyAction,
99
- exportState: () => exportState,
100
- forceActiveChangeFail: () => forceActiveChangeFail,
101
- forceActiveRmUpdate: () => forceActiveRmUpdate,
102
- handleRouter: () => handleRouter,
103
- httpError: () => httpError,
104
- inlinePickListFetchDataRequest: () => inlinePickListFetchDataRequest,
105
- login: () => login,
106
- loginDone: () => loginDone,
107
- loginFail: () => loginFail,
108
- logout: () => logout,
109
- logoutDone: () => logoutDone,
110
- operationConfirmation: () => operationConfirmation,
111
- processPostInvoke: () => processPostInvoke,
112
- processPostInvokeConfirm: () => processPostInvokeConfirm,
113
- processPreInvoke: () => processPreInvoke,
114
- refreshMeta: () => refreshMeta,
115
- refreshMetaAndReloadPage: () => refreshMetaAndReloadPage,
116
- refreshMetaDone: () => refreshMetaDone,
117
- refreshMetaFail: () => refreshMetaFail,
118
- removeMultivalueTag: () => removeMultivalueTag,
119
- removeNotifications: () => removeNotifications,
120
- removePendingRequest: () => removePendingRequest,
121
- saveAssociations: () => saveAssociations,
122
- selectScreen: () => selectScreen,
123
- selectScreenFail: () => selectScreenFail,
124
- selectTableCell: () => selectTableCell,
125
- selectTableCellInit: () => selectTableCellInit,
126
- selectView: () => selectView,
127
- selectViewFail: () => selectViewFail,
128
- sendOperation: () => sendOperation,
129
- sendOperationFail: () => sendOperationFail,
130
- sendOperationSuccess: () => sendOperationSuccess,
131
- showAllTableRecordsInit: () => showAllTableRecordsInit,
132
- showFileUploadPopup: () => showFileUploadPopup,
133
- showNotification: () => showNotification,
134
- showViewError: () => showViewError,
135
- showViewPopup: () => showViewPopup,
136
- switchDebugMode: () => switchDebugMode,
137
- switchRole: () => switchRole,
138
- uploadFile: () => uploadFile,
139
- uploadFileDone: () => uploadFileDone,
140
- uploadFileFailed: () => uploadFileFailed,
141
- userDrillDown: () => userDrillDown,
142
- userDrillDownSuccess: () => userDrillDownSuccess,
143
- viewClearPickMap: () => viewClearPickMap,
144
- viewPutPickMap: () => viewPutPickMap
145
- });
146
- import { createAction } from "@reduxjs/toolkit";
147
- var changeLocation = createAction("changeLocation");
148
- var login = createAction("login");
149
- var loginDone = createAction("loginDone");
150
- var loginFail = createAction("loginFail");
151
- var logout = createAction("logout");
152
- var logoutDone = createAction("logoutDone");
153
- var selectScreen = createAction("selectScreen");
154
- var selectScreenFail = createAction("selectScreenFail");
155
- var selectView = createAction("selectView");
156
- var selectViewFail = createAction("selectViewFail");
157
- var bcFetchDataRequest = createAction("bcFetchDataRequest");
158
- var bcFetchDataPages = createAction("bcFetchDataPages");
159
- var inlinePickListFetchDataRequest = createAction("inlinePickListFetchDataRequest");
160
- var bcFetchDataSuccess = createAction("bcFetchDataSuccess");
161
- var bcFetchDataFail = createAction("bcFetchDataFail");
162
- var bcLoadMore = createAction("bcLoadMore");
163
- var bcFetchRowMeta = createAction("bcFetchRowMeta");
164
- var bcFetchRowMetaSuccess = createAction("bcFetchRowMetaSuccess");
165
- var bcFetchRowMetaFail = createAction("bcFetchRowMetaFail");
166
- var bcNewData = createAction("bcNewData");
167
- var bcNewDataSuccess = createAction("bcNewDataSuccess");
168
- var bcNewDataFail = createAction("bcNewDataFail");
169
- var bcDeleteDataFail = createAction("bcDeleteDataFail");
170
- var forceActiveChangeFail = createAction("forceActiveChangeFail");
171
- var sendOperation = createAction("sendOperation");
172
- var sendOperationFail = createAction("sendOperationFail");
173
- var sendOperationSuccess = createAction("sendOperationSuccess");
174
- var processPostInvoke = createAction("processPostInvoke");
175
- var processPreInvoke = createAction("processPreInvoke");
176
- var processPostInvokeConfirm = createAction("processPostInvokeConfirm");
177
- var userDrillDown = createAction("userDrillDown");
178
- var userDrillDownSuccess = createAction("userDrillDownSuccess");
179
- var drillDown = createAction("drillDown");
180
- var bcChangeCursors = createAction("bcChangeCursors");
181
- var bcChangeDepthCursor = createAction("bcChangeDepthCursor");
182
- var changeDataItem = createAction("changeDataItem");
183
- var changeDataItems = createAction("changeDataItems");
184
- var forceActiveRmUpdate = createAction("forceActiveRmUpdate");
185
- var showViewPopup = createAction("showViewPopup");
186
- var showFileUploadPopup = createAction("showFileUploadPopup");
187
- var closeViewPopup = createAction("closeViewPopup");
188
- var viewPutPickMap = createAction("viewPutPickMap");
189
- var viewClearPickMap = createAction("viewClearPickMap");
190
- var saveAssociations = createAction("saveAssociations");
191
- var changeAssociations = createAction("cnangeAssociations");
192
- var removeMultivalueTag = createAction("removeMultivalueTag");
193
- var bcSaveDataSuccess = createAction("bcSaveDataSuccess");
194
- var bcSaveDataFail = createAction("bcSaveDataFail");
195
- var operationConfirmation = createAction("operationConfirmation");
196
- var bcForceUpdate = createAction("bcForceUpdate");
197
- var uploadFile = createAction("uploadFile");
198
- var uploadFileDone = createAction("uploadFileDone");
199
- var uploadFileFailed = createAction("uploadFileFailed");
200
- var bcCancelPendingChanges = createAction("bcCancelPendingChanges");
201
- var bcSelectRecord = createAction("bcSelectRecord");
202
- var bcSelectDepthRecord = createAction("bcSelectDepthRecord");
203
- var changeAssociation = createAction("changeAssociations");
204
- var changeAssociationSameBc = createAction("changeAssociationsSameBc");
205
- var changeAssociationFull = createAction("changeAssociationFull");
206
- var changeChildrenAssociations = createAction("changeChildrenAssociations");
207
- var changeChildrenAssociationsSameBc = createAction("changeChildrenAssociationsSameBc");
208
- var changeDescendantsAssociationsFull = createAction("changeDescendantsAssociationsFull");
209
- var dropAllAssociations = createAction("dropAllAssociations");
210
- var dropAllAssociationsSameBc = createAction("dropAllAssociationsSameBc");
211
- var dropAllAssociationsFull = createAction("dropAllAssociationsFull");
212
- var handleRouter = createAction("handleRouter");
213
- var selectTableCellInit = createAction("selectTableCellInit");
214
- var selectTableCell = createAction("selectTableCell");
215
- var showAllTableRecordsInit = createAction("showAllTableRecordsInit");
216
- var showNotification = createAction("showNotification");
217
- var closeNotification = createAction("closeNotification");
218
- var bcAddFilter = createAction("bcAddFilter");
219
- var bcRemoveFilter = createAction("bcRemoveFilter");
220
- var bcRemoveAllFilters = createAction("bcRemoveAllFilters");
221
- var bcAddSorter = createAction("bcAddSorter");
222
- var bcRemoveSorter = createAction("bcRemoveSorter");
223
- var bcChangePage = createAction("bcChangePage");
224
- var showViewError = createAction("showViewError");
225
- var closeViewError = createAction("closeViewError");
226
- var closeConfirmModal = createAction("closeConfirmModal");
227
- var clearValidationFails = createAction("clearValidationFails");
228
- var downloadFile = createAction("downloadFile");
229
- var downloadFileByUrl = createAction("downloadFileByUrl");
230
- var bulkUploadFiles = createAction("bulkUploadFiles");
231
- var apiError = createAction("apiError");
232
- var httpError = createAction("httpError");
233
- var switchDebugMode = createAction("switchDebugMode");
234
- var exportState = createAction("exportState");
235
- var emptyAction = createAction("emptyAction");
236
- var refreshMeta = createAction("refreshMeta");
237
- var refreshMetaDone = createAction("refreshMetaDone");
238
- var refreshMetaFail = createAction("refreshMetaFail");
239
- var refreshMetaAndReloadPage = createAction("refreshMetaAndReloadPage");
240
- var switchRole = createAction("switchRole");
241
- var addPendingRequest = createAction("addPendingRequest");
242
- var removePendingRequest = createAction("removePendingRequest");
243
- var addNotification = createAction("addNotification");
244
- var removeNotifications = createAction("removeNotifications");
245
- // src/reducers/ReducerBuilderManager.ts
246
- var ReducerBuilderManager = class {
247
- constructor() {
248
- __publicField(this, "reducers", []);
249
- __publicField(this, "matchers", []);
250
- __publicField(this, "defaultCaseReducer");
251
- }
252
- addCase(action, reducer) {
253
- this.reducers.push([action, reducer]);
254
- return this;
255
- }
256
- removeCase(action) {
257
- this.reducers = this.reducers.filter((reducer) => reducer[0].type !== action.type);
258
- return this;
259
- }
260
- replaceCase(action, reducer) {
261
- this.removeCase(action).addCase(action, reducer);
262
- return this;
263
- }
264
- addMatcher(matcher, reducer) {
265
- this.matchers.push([matcher, reducer]);
266
- return this;
267
- }
268
- addDefaultCase(reducer) {
269
- this.defaultCaseReducer = reducer;
270
- return this;
271
- }
272
- get builder() {
273
- return (builder) => {
274
- const builderWithCases = this.reducers.reduce((acc, args) => acc.addCase(...args), builder);
275
- const builderWithMatchers = this.matchers.reduce((acc, args) => acc.addMatcher(...args), builderWithCases);
276
- return this.defaultCaseReducer !== void 0 ? builderWithMatchers.addDefaultCase(this.defaultCaseReducer) : builderWithMatchers;
277
- };
278
- }
279
- };
280
- // src/reducers/data.ts
281
- var emptyData = [];
282
- var dataInitialState = {};
283
- var createDataReducerBuilderManager = (initialState) => new ReducerBuilderManager().addCase(bcFetchDataSuccess, (state, action) => {
284
- state[action.payload.bcName] = action.payload.data;
285
- }).addCase(bcNewDataSuccess, (state, action) => {
286
- state[action.payload.bcName] = [...state[action.payload.bcName] || emptyData, action.payload.dataItem];
287
- }).addCase(bcSaveDataSuccess, (state, action) => {
288
- const nextDataItem = action.payload.dataItem;
289
- const index = state[action.payload.bcName].findIndex((item) => item.id === nextDataItem.id);
290
- state[action.payload.bcName][index] = nextDataItem;
291
- }).addCase(bcFetchRowMetaSuccess, (state, action) => {
292
- const cursor = action.payload.cursor;
293
- if (!cursor) {
294
- return;
295
- }
296
- const prevDataItem = (state[action.payload.bcName] || emptyData).find((item) => item.id === cursor);
297
- const nextDataItem = __spreadProps(__spreadValues({}, prevDataItem), {
298
- id: cursor,
299
- vstamp: -1,
300
- _associate: prevDataItem && prevDataItem._associate
301
- });
302
- const valueUpdateUnsupported = action.payload.rowMeta.fields.find((item) => item.key === "id" && !item.currentValue);
303
- if (valueUpdateUnsupported) {
304
- return;
305
- }
306
- action.payload.rowMeta.fields.filter((field) => {
307
- return field.key !== "_associate";
308
- }).forEach((field) => nextDataItem[field.key] = field.currentValue);
309
- if (!prevDataItem) {
310
- state[action.payload.bcName] = [...state[action.payload.bcName] || emptyData, nextDataItem];
311
- return;
312
- }
313
- state[action.payload.bcName] = state[action.payload.bcName].map((item) => item === prevDataItem ? nextDataItem : item);
314
- }).addCase(changeAssociations, (state, action) => {
315
- state[`${action.payload.bcName}Delta`] = action.payload.records || [];
316
- }).addCase(selectView, (state) => {
317
- return initialState;
318
- });
319
- // src/reducers/depthData.ts
320
- var initialDepthDataState = {};
321
- var createDepthDataReducerBuilderManager = (initialState) => {
322
- return new ReducerBuilderManager().addCase(bcFetchDataSuccess, (state, action) => {
323
- var _a;
324
- if (!action.payload.depth || action.payload.depth < 2) {
325
- return;
326
- }
327
- state[action.payload.depth] = (_a = state[action.payload.depth]) != null ? _a : {};
328
- state[action.payload.depth][action.payload.bcName] = action.payload.data;
329
- }).addCase(selectView, (state) => {
330
- return initialState;
331
- });
332
- };
333
- // src/interfaces/index.ts
334
- var interfaces_exports = {};
335
- __export(interfaces_exports, {
336
- AppNotificationType: () => AppNotificationType,
337
- ApplicationErrorType: () => ApplicationErrorType,
338
- DrillDownType: () => DrillDownType,
339
- FieldType: () => FieldType,
340
- FilterType: () => FilterType,
341
- OperationPostInvokeConfirmType: () => OperationPostInvokeConfirmType,
342
- OperationPostInvokeType: () => OperationPostInvokeType,
343
- OperationPreInvokeType: () => OperationPreInvokeType,
344
- OperationTypeCrud: () => OperationTypeCrud,
345
- PaginationMode: () => PaginationMode,
346
- PendingValidationFailsFormat: () => PendingValidationFailsFormat,
347
- PopupWidgetTypes: () => PopupWidgetTypes,
348
- PositionTypes: () => PositionTypes,
349
- RouteType: () => RouteType,
350
- TableLikeWidgetTypes: () => TableLikeWidgetTypes,
351
- WidgetTypes: () => WidgetTypes2,
352
- coreOperations: () => coreOperations,
353
- isCustomWidget: () => isCustomWidget,
354
- isCustomWidgetConfiguration: () => isCustomWidgetConfiguration,
355
- isOperationGroup: () => isOperationGroup,
356
- isViewNavigationCategory: () => isViewNavigationCategory,
357
- isViewNavigationGroup: () => isViewNavigationGroup,
358
- isViewNavigationItem: () => isViewNavigationItem,
359
- isWidgetFieldBlock: () => isWidgetFieldBlock
360
- });
361
- // src/interfaces/objectMap.ts
362
- var AppNotificationType = /* @__PURE__ */ ((AppNotificationType2) => {
363
- AppNotificationType2["success"] = "success";
364
- AppNotificationType2["info"] = "info";
365
- AppNotificationType2["warning"] = "warning";
366
- AppNotificationType2["error"] = "error";
367
- return AppNotificationType2;
368
- })(AppNotificationType || {});
369
- // src/interfaces/router.ts
370
- import { DrillDownType } from "@cxbox-ui/schema";
371
- var RouteType = /* @__PURE__ */ ((RouteType2) => {
372
- RouteType2["screen"] = "screen";
373
- RouteType2["default"] = "default";
374
- RouteType2["router"] = "router";
375
- RouteType2["invalid"] = "invalid";
376
- RouteType2["unknown"] = "unknown";
377
- return RouteType2;
378
- })(RouteType || {});
379
- // src/interfaces/view.ts
380
- import { FieldType } from "@cxbox-ui/schema";
381
- var PendingValidationFailsFormat = /* @__PURE__ */ ((PendingValidationFailsFormat2) => {
382
- PendingValidationFailsFormat2["old"] = "old";
383
- PendingValidationFailsFormat2["target"] = "target";
384
- return PendingValidationFailsFormat2;
385
- })(PendingValidationFailsFormat || {});
386
- var ApplicationErrorType = /* @__PURE__ */ ((ApplicationErrorType2) => {
387
- ApplicationErrorType2[ApplicationErrorType2["BusinessError"] = 0] = "BusinessError";
388
- ApplicationErrorType2[ApplicationErrorType2["SystemError"] = 1] = "SystemError";
389
- ApplicationErrorType2[ApplicationErrorType2["NetworkError"] = 2] = "NetworkError";
390
- return ApplicationErrorType2;
391
- })(ApplicationErrorType || {});
392
- // src/interfaces/widget.ts
393
- import { WidgetTypes } from "@cxbox-ui/schema";
394
- import { WidgetTypes as WidgetTypes2, PositionTypes } from "@cxbox-ui/schema";
395
- var TableLikeWidgetTypes = [
396
- WidgetTypes.List,
397
- WidgetTypes.DataGrid,
398
- WidgetTypes.AssocListPopup,
399
- WidgetTypes.PickListPopup,
400
- WidgetTypes.FlatTree,
401
- WidgetTypes.FlatTreePopup
402
- ];
403
- var PopupWidgetTypes = [WidgetTypes.PickListPopup, WidgetTypes.AssocListPopup, WidgetTypes.FlatTreePopup];
404
- function isCustomWidget(descriptor) {
405
- return !!descriptor && !("component" in descriptor);
406
- }
407
- function isCustomWidgetConfiguration(descriptor) {
408
- return descriptor && "component" in descriptor;
409
- }
410
- function isWidgetFieldBlock(item) {
411
- return !!item && "blockId" in item;
412
- }
413
- var PaginationMode = /* @__PURE__ */ ((PaginationMode2) => {
414
- PaginationMode2["page"] = "page";
415
- PaginationMode2["loadMore"] = "loadMore";
416
- return PaginationMode2;
417
- })(PaginationMode || {});
418
- // src/interfaces/operation.ts
419
- import { OperationTypeCrud } from "@cxbox-ui/schema";
420
- var coreOperations = [
421
- OperationTypeCrud.create,
422
- OperationTypeCrud.save,
423
- OperationTypeCrud.delete,
424
- OperationTypeCrud.associate,
425
- OperationTypeCrud.cancelCreate,
426
- OperationTypeCrud.fileUpload
427
- ];
428
- function isOperationGroup(operation) {
429
- return Array.isArray(operation.actions);
430
- }
431
- var OperationPreInvokeType = /* @__PURE__ */ ((OperationPreInvokeType2) => {
432
- OperationPreInvokeType2["confirm"] = "confirm";
433
- OperationPreInvokeType2["info"] = "info";
434
- OperationPreInvokeType2["error"] = "error";
435
- return OperationPreInvokeType2;
436
- })(OperationPreInvokeType || {});
437
- var OperationPostInvokeType = /* @__PURE__ */ ((OperationPostInvokeType2) => {
438
- OperationPostInvokeType2["refreshBC"] = "refreshBC";
439
- OperationPostInvokeType2["downloadFile"] = "downloadFile";
440
- OperationPostInvokeType2["downloadFileByUrl"] = "downloadFileByUrl";
441
- OperationPostInvokeType2["drillDown"] = "drillDown";
442
- OperationPostInvokeType2["openPickList"] = "openPickList";
443
- OperationPostInvokeType2["showMessage"] = "showMessage";
444
- OperationPostInvokeType2["postDelete"] = "postDelete";
445
- return OperationPostInvokeType2;
446
- })(OperationPostInvokeType || {});
447
- var OperationPostInvokeConfirmType = /* @__PURE__ */ ((OperationPostInvokeConfirmType2) => {
448
- OperationPostInvokeConfirmType2["confirm"] = "confirm";
449
- OperationPostInvokeConfirmType2["confirmText"] = "confirmText";
450
- return OperationPostInvokeConfirmType2;
451
- })(OperationPostInvokeConfirmType || {});
452
- // src/interfaces/filters.ts
453
- var FilterType = /* @__PURE__ */ ((FilterType2) => {
454
- FilterType2["range"] = "range";
455
- FilterType2["equals"] = "equals";
456
- FilterType2["greaterThan"] = "greaterThan";
457
- FilterType2["lessThan"] = "lessThan";
458
- FilterType2["greaterOrEqualThan"] = "greaterOrEqualThan";
459
- FilterType2["lessOrEqualThan"] = "lessOrEqualThan";
460
- FilterType2["contains"] = "contains";
461
- FilterType2["specified"] = "specified";
462
- FilterType2["specifiedBooleanSql"] = "specifiedBooleanSql";
463
- FilterType2["equalsOneOf"] = "equalsOneOf";
464
- FilterType2["containsOneOf"] = "containsOneOf";
465
- return FilterType2;
466
- })(FilterType || {});
467
- // src/interfaces/navigation.ts
468
- function isViewNavigationItem(item) {
469
- return !!item && "viewName" in item;
470
- }
471
- function isViewNavigationCategory(item) {
472
- return !!item && "categoryName" in item;
473
- }
474
- function isViewNavigationGroup(item) {
475
- return !!item && "child" in item && !("categoryName" in item);
476
- }
477
- // src/reducers/router.ts
478
- var initialRouterState = { type: "default" /* default */, path: "/", search: "", params: null, screenName: null };
479
- var createRouterReducerBuilderManager = (initialState) => new ReducerBuilderManager().addCase(changeLocation, (state, action) => {
480
- return action.payload.location;
481
- });
482
- // src/reducers/screen.ts
483
- import { OperationTypeCrud as OperationTypeCrud3 } from "@cxbox-ui/schema";
484
- // src/utils/index.ts
485
- var utils_exports = {};
486
- __export(utils_exports, {
487
- addTailControlSequences: () => addTailControlSequences,
488
- applyParams: () => applyParams,
489
- applyRawParams: () => applyRawParams,
490
- assignTreeLinks: () => assignTreeLinks,
491
- breadthFirstSearch: () => breadthFirstSearch,
492
- buildBcUrl: () => buildBcUrl,
493
- buildSearchResultTree: () => buildSearchResultTree,
494
- buildUrl: () => buildUrl,
495
- checkShowCondition: () => checkShowCondition,
496
- createApiError: () => createApiError,
497
- createApiErrorObservable: () => createApiErrorObservable,
498
- defaultBuildURL: () => defaultBuildURL,
499
- defaultParseURL: () => defaultParseURL,
500
- deleteUndefinedFromObject: () => deleteUndefinedFromObject,
501
- escapedSrc: () => escapedSrc,
502
- flattenOperations: () => flattenOperations,
503
- getBcChildren: () => getBcChildren,
504
- getDescendants: () => getDescendants,
505
- getFieldTitle: () => getFieldTitle,
506
- getFilterType: () => getFilterType,
507
- getFilters: () => getFilters,
508
- getRouteFromString: () => getRouteFromString,
509
- getSorters: () => getSorters,
510
- getTemplate: () => getTemplate,
511
- makeRelativeUrl: () => makeRelativeUrl,
512
- matchOperationRole: () => matchOperationRole,
513
- parseBcCursors: () => parseBcCursors,
514
- parseFilters: () => parseFilters,
515
- parseSorters: () => parseSorters,
516
- presort: () => presort,
517
- splitBcUrl: () => splitBcUrl,
518
- splitIntoTokens: () => splitIntoTokens
519
- });
520
- // src/utils/api.ts
521
- function dropEmptyOrWrongParams(qso) {
522
- const result = __spreadValues({}, qso);
523
- return Object.keys(result).reduce((prev, paramKey) => {
524
- if (!prev[paramKey] && typeof prev[paramKey] !== "number") {
525
- delete prev[paramKey];
526
- }
527
- return prev;
528
- }, result);
529
- }
530
- function addTailControlSequences(url) {
531
- return !url.includes("?") ? url + "?" : url + "&";
532
- }
533
- function applyParams(url, qso) {
534
- if (!qso) {
535
- return url;
536
- }
537
- return applyRawParams(url, dropEmptyOrWrongParams(qso));
538
- }
539
- function applyRawParams(url, qso) {
540
- if (!qso) {
541
- return url;
542
- }
543
- const result = new URLSearchParams(qso).toString();
544
- return `${addTailControlSequences(url)}${result && `${result}`}`;
545
- }
546
- // src/utils/apiError.ts
547
- import { actions } from "@cxbox-ui/core";
548
- import { EMPTY, of } from "rxjs";
549
- function createApiError(error, context = { widgetName: "unknown" }) {
550
- if (!error.isAxiosError)
551
- return void 0;
552
- return actions.apiError({ error, callContext: context });
553
- }
554
- function createApiErrorObservable(error, context) {
555
- const apiError2 = createApiError(error, context);
556
- return apiError2 ? of(apiError2) : EMPTY;
557
- }
558
- // src/utils/strings.ts
559
- function getTemplate(literals, ...placeholders) {
560
- let result = "";
561
- for (let i = 0; i < placeholders.length; i++) {
562
- result += literals[i];
563
- result += "${" + i + "}";
564
- }
565
- result += literals[literals.length - 1];
566
- return result;
567
- }
568
- function buildBcUrl(bcName, includeSelf = false, state) {
569
- var _a;
570
- const bcMap = state.screen.bo.bc;
571
- const bc = bcMap[bcName];
572
- if (!bc) {
573
- return null;
574
- }
575
- const url = [bc.cursor && includeSelf ? `${bc.name}/${bc.cursor}` : bc.name];
576
- let nextBc = bc;
577
- while (nextBc.parentName) {
578
- nextBc = bcMap[nextBc.parentName];
579
- url.push(`${nextBc.name}/${(_a = nextBc.cursor) != null ? _a : null}`);
580
- }
581
- const bcUrl = url.reverse().join("/");
582
- return bcUrl;
583
- }
584
- function splitBcUrl(bcUrl) {
585
- const bcUrlItems = bcUrl.split("/");
586
- const result = [];
587
- for (let i = 0; i < bcUrlItems.length; i += 2) {
588
- const bcName = bcUrlItems[i];
589
- const bcCursor = bcUrlItems[i + 1];
590
- const includeSelf = bcName && bcCursor;
591
- result.push(includeSelf ? `${bcName}/${bcCursor}` : bcName);
592
- }
593
- return result;
594
- }
595
- var TAG_PLACEHOLDER = /\${([^{}]+)}/g;
596
- var formatString = (templatedString, item) => {
597
- if (!templatedString) {
598
- return "";
599
- }
600
- return templatedString.replace(TAG_PLACEHOLDER, (token, varName) => {
601
- const [key, defaultValue] = varName.split(":");
602
- const result = String((item == null ? void 0 : item[key]) || defaultValue || "");
603
- return result;
604
- });
605
- };
606
- var isTemplate = (templatedString) => {
607
- if (!templatedString) {
608
- return false;
609
- }
610
- return templatedString.match(TAG_PLACEHOLDER) !== null;
611
- };
612
- function getFieldTitle(title, dataItem) {
613
- if (!isTemplate(title)) {
614
- return title;
615
- }
616
- else {
617
- return formatString(title, dataItem);
618
- }
619
- }
620
- function splitIntoTokens(source, search) {
621
- const tokenizer = search instanceof RegExp ? search : escapedSrc(search);
622
- return source.split(tokenizer);
623
- }
624
- function escapedSrc(str) {
625
- return new RegExp(`(${str == null ? void 0 : str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&")})`, "gi");
626
- }
627
- // src/utils/history.ts
628
- function makeRelativeUrl(absoluteUrl) {
629
- return absoluteUrl.startsWith("/") ? absoluteUrl : `/${absoluteUrl}`;
630
- }
631
- function parseBcCursors(bcPath) {
632
- if (!bcPath) {
633
- return null;
634
- }
635
- const cursors = {};
636
- const tokens = bcPath.split("/");
637
- for (let i = 0; i < tokens.length; i = i + 2) {
638
- if (tokens[i + 1]) {
639
- cursors[tokens[i]] = tokens[i + 1];
640
- }
641
- }
642
- return cursors;
643
- }
644
- function buildUrl(literals, ...placeholders) {
645
- let result = "";
646
- for (let i = 0; i < placeholders.length; i++) {
647
- result += literals[i];
648
- const placeholder = placeholders[i];
649
- if (typeof placeholder === "number") {
650
- result += placeholder.toString(10);
651
- }
652
- else if (typeof placeholder === "string") {
653
- result += encodeURIComponent(placeholder);
654
- }
655
- else {
656
- const template = getTemplate(literals, placeholders);
657
- throw new Error(`\u041D\u0435\u0432\u0435\u0440\u043D\u044B\u0439 \u0442\u0438\u043F \u043F\u043E\u0434\u0441\u0442\u0430\u043D\u043E\u0432\u043E\u0447\u043D\u043E\u0433\u043E \u0437\u043D\u0430\u043A\u0430 \u0432 ${template}, index: ${i}, value: ${JSON.stringify(placeholder)}`);
658
- }
659
- }
660
- result += literals[literals.length - 1];
661
- return result;
662
- }
663
- function defaultParseURL(url) {
664
- let path = url.pathname;
665
- if (path.startsWith("/")) {
666
- path = path.substring(1);
667
- }
668
- if (path.endsWith("/")) {
669
- path = path.substring(0, path.length - 1);
670
- }
671
- if ((path == null ? void 0 : path.includes("&")) && !(path == null ? void 0 : path.includes("?"))) {
672
- path = path.substring(0, path.indexOf("&"));
673
- }
674
- const params = {};
675
- url.searchParams.forEach((value, key) => params[key] = value);
676
- const tokens = path.split("/").map(decodeURIComponent);
677
- let type = "unknown" /* unknown */;
678
- let screenName = null;
679
- let viewName = null;
680
- let bcPath = null;
681
- if (tokens.length > 0 && tokens[0] === "router") {
682
- type = "router" /* router */;
683
- }
684
- else if (tokens.length === 1) {
685
- type = "default" /* default */;
686
- }
687
- else if (tokens.length >= 2 && tokens[0] === "screen") {
688
- let bcIndex = 2;
689
- type = "screen" /* screen */;
690
- screenName = tokens[1];
691
- if (tokens.length >= 4 && tokens[2] === "view") {
692
- bcIndex += 2;
693
- viewName = tokens[3];
694
- }
695
- bcPath = tokens.slice(bcIndex).map(encodeURIComponent).join("/");
696
- }
697
- return {
698
- type,
699
- path: path.length !== 0 && !path.startsWith("/") ? `/${path}` : path,
700
- search: url.search,
701
- params,
702
- screenName,
703
- viewName,
704
- bcPath
705
- };
706
- }
707
- function defaultBuildURL(route) {
708
- return `/screen/${route.screenName}/view/${route.viewName}/${route.bcPath}`;
709
- }
710
- var getRouteFromString = (ulrString) => {
711
- const url = new URL(ulrString, window.location.origin);
712
- return defaultParseURL(url);
713
- };
714
- // src/utils/filters.ts
715
- function getFilters(filters) {
716
- if (!filters || !filters.length) {
717
- return null;
718
- }
719
- const result = {};
720
- filters.forEach((item) => {
721
- if (item.type === "range" /* range */) {
722
- const values = item.value;
723
- if (values[0]) {
724
- result[`${item.fieldName}.${"greaterOrEqualThan" /* greaterOrEqualThan */}`] = String(values[0]);
725
- }
726
- if (values[1]) {
727
- result[`${item.fieldName}.${"lessOrEqualThan" /* lessOrEqualThan */}`] = String(values[1]);
728
- }
729
- }
730
- else {
731
- let value = String(item.value);
732
- if (Array.isArray(item.value)) {
733
- const values = item.value.map((val) => `"${val}"`);
734
- value = `[${values}]`;
735
- }
736
- const separator = item.fieldName ? "." : "";
737
- result[`${item.fieldName}${separator}${item.type}`] = value;
738
- }
739
- });
740
- return result;
741
- }
742
- function getSorters(sorters) {
743
- if (!sorters || !sorters.length) {
744
- return null;
745
- }
746
- const result = {};
747
- sorters.forEach((item, index) => {
748
- result[`_sort.${index}.${item.direction}`] = item.fieldName;
749
- });
750
- return result;
751
- }
752
- var jsonParse = (value) => {
753
- try {
754
- return JSON.parse(value);
755
- }
756
- catch (e) {
757
- console.warn(e);
758
- return null;
759
- }
760
- };
761
- function parseFilters(defaultFilters = "") {
762
- const result = [];
763
- const urlParams = new URLSearchParams(defaultFilters);
764
- const paramKeys = Object.keys(Object.fromEntries(urlParams));
765
- paramKeys.forEach((param) => {
766
- var _a, _b;
767
- const [fieldName, type] = param.split(".");
768
- const isStandardFilter = fieldName && type && urlParams.get(param);
769
- if (isStandardFilter) {
770
- let value = urlParams.getAll(param);
771
- if (type === "containsOneOf" /* containsOneOf */ || type === "equalsOneOf" /* equalsOneOf */) {
772
- if (value.length === 1) {
773
- value = (_a = jsonParse(value[0])) != null ? _a : value;
774
- }
775
- value = Array.isArray(value) ? value : [];
776
- }
777
- else {
778
- value = Array.isArray(value) ? value[0] : value;
779
- }
780
- result.push({
781
- fieldName,
782
- type,
783
- value
784
- });
785
- }
786
- else if (defaultFilters) {
787
- let value = urlParams.getAll(param);
788
- if (value.length === 1) {
789
- value = (_b = jsonParse(value[0])) != null ? _b : value[0];
790
- }
791
- result.push({
792
- fieldName: "",
793
- type: param,
794
- value
795
- });
796
- }
797
- });
798
- return result.length ? result : null;
799
- }
800
- function parseSorters(sorters) {
801
- if (!sorters || !sorters.length) {
802
- return null;
803
- }
804
- const result = [];
805
- const dictionary = new URLSearchParams(sorters);
806
- Array.from(dictionary.entries()).map(([sort, fieldKey]) => {
807
- const [order, direction] = sort.split(".").slice(1);
808
- return { fieldName: fieldKey, order: Number.parseInt(order, 10), direction };
809
- }).sort((a, b) => a.order - b.order).forEach((item) => {
810
- result.push({ fieldName: item.fieldName, direction: item.direction });
811
- });
812
- return result;
813
- }
814
- function getFilterType(fieldType) {
815
- switch (fieldType) {
816
- case FieldType.dictionary: {
817
- return "equalsOneOf" /* equalsOneOf */;
818
- }
819
- case FieldType.checkbox: {
820
- return "specified" /* specified */;
821
- }
822
- case FieldType.input:
823
- case FieldType.text: {
824
- return "contains" /* contains */;
825
- }
826
- default:
827
- return "equals" /* equals */;
828
- }
829
- }
830
- // src/utils/operations.ts
831
- function flattenOperations(operations) {
832
- const result = [];
833
- operations == null ? void 0 : operations.forEach((item) => {
834
- if (isOperationGroup(item)) {
835
- const currentOperation = item;
836
- currentOperation.actions.forEach((OperationItem) => {
837
- result.push(OperationItem);
838
- });
839
- }
840
- else {
841
- result.push(item);
842
- }
843
- });
844
- return result;
845
- }
846
- function matchOperationRole(role, payload, store) {
847
- var _a, _b;
848
- if (payload.operationType === role) {
849
- return true;
850
- }
851
- const bcUrl = buildBcUrl(payload.bcName, true, store);
852
- const operations = flattenOperations((_b = (_a = store.view.rowMeta[payload.bcName]) == null ? void 0 : _a[bcUrl]) == null ? void 0 : _b.actions);
853
- const operation = operations.find((item) => item.type === payload.operationType);
854
- if (role === "none") {
855
- return coreOperations.every((item) => item !== payload.operationType && item !== (operation == null ? void 0 : operation.actionRole));
856
- }
857
- return (operation == null ? void 0 : operation.actionRole) === role;
858
- }
859
- // src/utils/bc.ts
860
- function getBcChildren(originBcName, widgets, bcMap) {
861
- const childrenBcMap = {};
862
- widgets.filter((widget) => widget.bcName).forEach((widget) => {
863
- const widgetBcList = [];
864
- widgetBcList.push(widget.bcName);
865
- let parentName = bcMap[widget.bcName].parentName;
866
- while (parentName) {
867
- widgetBcList.push(parentName);
868
- parentName = bcMap[parentName].parentName;
869
- }
870
- widgetBcList.filter((expectedBcName) => bcMap[expectedBcName].parentName === originBcName).forEach((expectedBcName) => {
871
- childrenBcMap[expectedBcName] = [...childrenBcMap[expectedBcName] || [], widget.name];
872
- });
873
- });
874
- widgets.filter((item) => {
875
- var _a;
876
- return (_a = item.options) == null ? void 0 : _a.hierarchy;
877
- }).forEach((widget) => {
878
- const [hierarchyBcName, hierarchyWidgetName] = getHierarchyChildBc(originBcName, widget);
879
- if (hierarchyBcName) {
880
- childrenBcMap[hierarchyBcName] = [...childrenBcMap[hierarchyBcName] || [], hierarchyWidgetName];
881
- }
882
- });
883
- return childrenBcMap;
884
- }
885
- function getHierarchyChildBc(originBcName, hierarchyWidget) {
886
- var _a, _b;
887
- const nestedBcNames = (_b = (_a = hierarchyWidget == null ? void 0 : hierarchyWidget.options) == null ? void 0 : _a.hierarchy) == null ? void 0 : _b.map((nestedItem) => nestedItem.bcName);
888
- if (originBcName !== hierarchyWidget.bcName && !(nestedBcNames == null ? void 0 : nestedBcNames.includes(originBcName))) {
889
- return [];
890
- }
891
- const childHierarchyBcIndex = nestedBcNames == null ? void 0 : nestedBcNames.findIndex((item) => item === originBcName);
892
- const childHierarchyBcName = nestedBcNames == null ? void 0 : nestedBcNames[childHierarchyBcIndex + 1];
893
- return [childHierarchyBcName, hierarchyWidget.name];
894
- }
895
- function checkShowCondition(condition, cursor, data, pendingDataChanges) {
896
- var _a, _b;
897
- const { bcName, isDefault, params } = condition || {};
898
- const emptyCondition = !condition || Array.isArray(condition);
899
- if (emptyCondition || isDefault) {
900
- return true;
901
- }
902
- const record = cursor && (data == null ? void 0 : data.find((item) => item.id === cursor));
903
- if (!record) {
904
- return false;
905
- }
906
- const actualValue = record == null ? void 0 : record[params == null ? void 0 : params.fieldKey];
907
- const pendingValue = (_b = (_a = pendingDataChanges == null ? void 0 : pendingDataChanges[bcName]) == null ? void 0 : _a[cursor]) == null ? void 0 : _b[params == null ? void 0 : params.fieldKey];
908
- return pendingValue !== void 0 ? pendingValue === (params == null ? void 0 : params.value) : actualValue === (params == null ? void 0 : params.value);
909
- }
910
- // src/utils/tree.ts
911
- function assignTreeLinks(flat) {
912
- const result = flat.map((item) => __spreadValues({}, item));
913
- const map12 = {};
914
- const orphans = [];
915
- result.forEach((item) => {
916
- var _a, _b;
917
- if (!item.parentId || item.parentId === "0") {
918
- return;
919
- }
920
- let parentIndex = map12[item.parentId];
921
- if (typeof parentIndex !== "number") {
922
- parentIndex = flat.findIndex((el) => el.id === item.parentId);
923
- map12[item.parentId] = parentIndex;
924
- }
925
- if (parentIndex === -1) {
926
- orphans.push(item.parentId);
927
- console.warn(`Record with [id] = ${item.id} has [parentId] = ${item.parentId}, but no matching parent record exist. Check the service for this BC.`);
928
- return;
929
- }
930
- item.parent = result[parentIndex];
931
- if (!result[parentIndex].children) {
932
- result[parentIndex].children = [item];
933
- }
934
- else {
935
- (_b = (_a = result[parentIndex]) == null ? void 0 : _a.children) == null ? void 0 : _b.push(item);
936
- }
937
- });
938
- if (orphans.length) {
939
- return result.filter((item) => !orphans.includes(item.parentId));
940
- }
941
- return result;
942
- }
943
- function getDescendants(nodes, result) {
944
- nodes.forEach((child) => {
945
- result.push(child.id);
946
- if (child.children) {
947
- getDescendants(child.children, result);
948
- }
949
- });
950
- }
951
- function buildSearchResultTree(nodes, matchingNodes) {
952
- const result = {};
953
- nodes.forEach((item) => {
954
- var _a;
955
- if (!matchingNodes.includes(item.id)) {
956
- return;
957
- }
958
- let parent = item.parent;
959
- while (parent) {
960
- result[parent.id] = true;
961
- parent = parent.parent;
962
- }
963
- result[item.id] = true;
964
- (_a = item.children) == null ? void 0 : _a.forEach((child) => {
965
- result[child.id] = true;
966
- });
967
- });
968
- return nodes.filter((item) => result[item.id] === true);
969
- }
970
- function presort(data) {
971
- const result = [];
972
- data.filter((item) => item.level === 1).forEach((item) => {
973
- result.push(item.id);
974
- if (item.children) {
975
- getDescendants(item.children, result);
976
- }
977
- });
978
- return result.map((id) => data.find((match) => match.id === id));
979
- }
980
- // src/utils/breadthFirst.ts
981
- function breadthFirstSearch(root, predicate, depth = 1, childrenProperty = "child") {
982
- const rootMatch = predicate(root) && root;
983
- const rootChildren = root[childrenProperty];
984
- if (!rootMatch && !rootChildren) {
985
- return null;
986
- }
987
- if (rootMatch) {
988
- return { node: rootMatch, depth };
989
- }
990
- let simpleLeaf = rootChildren.filter((item) => !item[childrenProperty]).find((item) => predicate(item));
991
- if (simpleLeaf) {
992
- return { node: simpleLeaf, depth: depth + 1 };
993
- }
994
- let resultDepth = depth;
995
- rootChildren.some((item) => {
996
- const search = breadthFirstSearch(item, predicate, resultDepth + 1, childrenProperty != null ? childrenProperty : "child");
997
- simpleLeaf = search == null ? void 0 : search.node;
998
- resultDepth = search == null ? void 0 : search.depth;
999
- return search == null ? void 0 : search.node;
1000
- });
1001
- return simpleLeaf ? { node: simpleLeaf, depth: resultDepth } : null;
1002
- }
1003
- // src/utils/deleteUndefinedFromObject.ts
1004
- function deleteUndefinedFromObject(obj) {
1005
- Object.keys(obj).forEach((key) => {
1006
- if (obj[key] === void 0) {
1007
- delete obj[key];
1008
- }
1009
- });
1010
- }
1011
- // src/reducers/screen.ts
1012
- var initialScreenState = {
1013
- screenName: "",
1014
- bo: { activeBcName: "", bc: {} },
1015
- cachedBc: {},
1016
- views: [],
1017
- primaryView: "",
1018
- filters: {},
1019
- sorters: {}
1020
- };
1021
- var operationsHandledLocally = [OperationTypeCrud3.associate, OperationTypeCrud3.fileUpload];
1022
- var createScreenReducerBuilderManager = (initialState) => new ReducerBuilderManager().addCase(selectScreen, (state, action) => {
1023
- var _a, _b, _c, _d, _e;
1024
- const bcDictionary = {};
1025
- const bcSorters = {};
1026
- const bcFilters = {};
1027
- (_a = action.payload.screen.meta) == null ? void 0 : _a.bo.bc.forEach((item) => {
1028
- bcDictionary[item.name] = item;
1029
- const sorter = parseSorters(item.defaultSort);
1030
- const filter56 = parseFilters(item.defaultFilter);
1031
- if (sorter) {
1032
- bcSorters[item.name] = sorter;
1033
- }
1034
- if (filter56) {
1035
- bcFilters[item.name] = filter56;
1036
- }
1037
- });
1038
- state.screenName = action.payload.screen.name;
1039
- state.primaryView = (_c = (_b = action.payload.screen.meta) == null ? void 0 : _b.primary) != null ? _c : state.primaryView;
1040
- state.views = (_e = (_d = action.payload.screen.meta) == null ? void 0 : _d.views) != null ? _e : state.views;
1041
- state.bo = { activeBcName: null, bc: bcDictionary };
1042
- state.sorters = __spreadValues(__spreadValues({}, state.sorters), bcSorters);
1043
- state.filters = __spreadValues(__spreadValues({}, state.filters), bcFilters);
1044
- }).addCase(selectScreenFail, (state, action) => {
1045
- state.screenName = action.payload.screenName;
1046
- state.views = [];
1047
- }).addCase(bcFetchDataRequest, (state, action) => {
1048
- state.bo.bc[action.payload.bcName].loading = true;
1049
- }).addCase(bcLoadMore, (state, action) => {
1050
- var _a;
1051
- const currentBc = state.bo.bc[action.payload.bcName];
1052
- currentBc.page = ((_a = currentBc.page) != null ? _a : 1) + 1;
1053
- currentBc.loading = true;
1054
- }).addCase(selectView, (state, action) => {
1055
- var _a;
1056
- const newBcs = {};
1057
- Array.from(new Set((_a = action.payload.widgets) == null ? void 0 : _a.map((widget) => widget.bcName))
1058
- // БК которые есть на вьюхе
1059
- ).filter((bcName) => state.bo.bc[bcName]).forEach((bcName) => {
1060
- newBcs[bcName] = __spreadProps(__spreadValues({}, state.bo.bc[bcName]), { page: 1 });
1061
- });
1062
- state.bo.bc = __spreadValues(__spreadValues({}, state.bo.bc), newBcs);
1063
- }).addCase(bcFetchDataSuccess, (state, action) => {
1064
- const currentBc = state.bo.bc[action.payload.bcName];
1065
- currentBc.hasNext = action.payload.hasNext;
1066
- currentBc.loading = false;
1067
- state.cachedBc[action.payload.bcName] = action.payload.bcUrl;
1068
- }).addCase(bcFetchDataFail, (state, action) => {
1069
- const bcName = action.payload.bcName;
1070
- if (Object.values(state.bo.bc).some((bc) => bc.name === bcName)) {
1071
- state.bo.bc[bcName].loading = false;
1072
- state.cachedBc[bcName] = action.payload.bcUrl;
1073
- }
1074
- }).addCase(sendOperation, (state, action) => {
1075
- if (!operationsHandledLocally.includes(action.payload.operationType)) {
1076
- state.bo.bc[action.payload.bcName].loading = true;
1077
- }
1078
- }).addCase(bcNewDataSuccess, (state, action) => {
1079
- state.bo.bc[action.payload.bcName].loading = false;
1080
- state.bo.bc[action.payload.bcName].cursor = action.payload.dataItem.id;
1081
- state.cachedBc[action.payload.bcName] = action.payload.bcUrl;
1082
- }).addCase(bcChangeCursors, (state, action) => {
1083
- const newCursors = {};
1084
- const newCache = {};
1085
- Object.entries(action.payload.cursorsMap).forEach((entry) => {
1086
- const [bcName, cursor] = entry;
1087
- newCursors[bcName] = __spreadProps(__spreadValues({}, state.bo.bc[bcName]), { cursor });
1088
- newCache[bcName] = cursor;
1089
- });
1090
- const changedParents = Object.values(newCursors).map((bc) => `${bc.url}/:id`);
1091
- Object.values(state.bo.bc).forEach((bc) => {
1092
- if (changedParents.some((item) => bc.url.includes(item))) {
1093
- newCursors[bc.name] = __spreadProps(__spreadValues({}, state.bo.bc[bc.name]), { cursor: null });
1094
- newCache[bc.name] = null;
1095
- }
1096
- });
1097
- Object.assign(state.bo.bc, newCursors);
1098
- Object.assign(state.cachedBc, newCache);
1099
- }).addCase(bcChangeDepthCursor, (state, action) => {
1100
- var _a;
1101
- if (action.payload.depth === 1) {
1102
- state.bo.bc[action.payload.bcName].cursor = action.payload.cursor;
1103
- }
1104
- else {
1105
- state.bo.bc[action.payload.bcName].depthBc = (_a = state.bo.bc[action.payload.bcName].depthBc) != null ? _a : {};
1106
- state.bo.bc[action.payload.bcName].depthBc[action.payload.depth].cursor = action.payload.cursor;
1107
- }
1108
- }).addCase(bcSelectRecord, (state, action) => {
1109
- state.bo.bc[action.payload.bcName].cursor = action.payload.cursor;
1110
- }).addCase(bcForceUpdate, (state, action) => {
1111
- state.bo.bc[action.payload.bcName].loading = true;
1112
- state.cachedBc[action.payload.bcName] = null;
1113
- }).addCase(bcAddFilter, (state, action) => {
1114
- const { bcName, filter: filter56 } = action.payload;
1115
- const newFilter = filter56;
1116
- const prevFilters = state.filters[bcName] || [];
1117
- const prevFilter = prevFilters.find((item) => item.fieldName === filter56.fieldName && item.type === filter56.type);
1118
- const newFilters = prevFilter ? prevFilters.map((item) => item === prevFilter ? __spreadProps(__spreadValues({}, prevFilter), { value: newFilter.value }) : item) : [...prevFilters, newFilter];
1119
- state.bo.bc[bcName].page = 1;
1120
- state.filters[bcName] = newFilters;
1121
- }).addCase(bcRemoveFilter, (state, action) => {
1122
- const { bcName, filter: filter56 } = action.payload;
1123
- const prevBcFilters = state.filters[bcName] || [];
1124
- const newBcFilters = prevBcFilters.filter((item) => item.fieldName !== (filter56 == null ? void 0 : filter56.fieldName) || item.type !== filter56.type);
1125
- const newFilters = __spreadProps(__spreadValues({}, state.filters), { [bcName]: newBcFilters });
1126
- if (!newBcFilters.length) {
1127
- delete newFilters[bcName];
1128
- }
1129
- state.bo.bc[action.payload.bcName].page = 1;
1130
- state.filters = newFilters;
1131
- }).addCase(bcRemoveAllFilters, (state, action) => {
1132
- delete state.filters[action.payload.bcName];
1133
- state.bo.bc[action.payload.bcName].page = 1;
1134
- }).addCase(bcAddSorter, (state, action) => {
1135
- state.sorters[action.payload.bcName] = Array.isArray(action.payload.sorter) ? action.payload.sorter : [action.payload.sorter];
1136
- }).addCase(bcChangePage, (state, action) => {
1137
- state.bo.bc[action.payload.bcName].page = action.payload.page;
1138
- state.bo.bc[action.payload.bcName].loading = true;
1139
- }).addCase(showViewPopup, (state, action) => {
1140
- var _a, _b;
1141
- const currentPage = (_b = (_a = state.bo.bc[action.payload.bcName]) == null ? void 0 : _a.page) != null ? _b : 1;
1142
- state.bo.bc[action.payload.bcName].page = action.payload.bcName === action.payload.calleeBCName ? currentPage : 1;
1143
- state.bo.bc[action.payload.bcName].loading = action.payload.bcName !== action.payload.calleeBCName;
1144
- }).addCase(sendOperationSuccess, (state, action) => {
1145
- state.bo.bc[action.payload.bcName].loading = false;
1146
- }).addCase(bcDeleteDataFail, (state, action) => {
1147
- state.bo.bc[action.payload.bcName].loading = false;
1148
- }).addCase(sendOperationFail, (state, action) => {
1149
- state.bo.bc[action.payload.bcName].loading = false;
1150
- }).addCase(bcSaveDataSuccess, (state, action) => {
1151
- state.bo.bc[action.payload.bcName].loading = false;
1152
- }).addCase(bcSaveDataFail, (state, action) => {
1153
- state.bo.bc[action.payload.bcName].loading = false;
1154
- });
1155
- // src/reducers/session.ts
1156
- var initialSessionState = {
1157
- devPanelEnabled: false,
1158
- activeRole: null,
1159
- roles: null,
1160
- firstName: "",
1161
- lastName: "",
1162
- login: "",
1163
- debugMode: false,
1164
- exportStateEnabled: false,
1165
- active: false,
1166
- logout: false,
1167
- loginSpin: false,
1168
- errorMsg: null,
1169
- screens: [],
1170
- pendingRequests: [],
1171
- notifications: [],
1172
- isMetaRefreshing: false
1173
- };
1174
- var createSessionReducerBuilderManager = (initialState) => new ReducerBuilderManager().addCase(login, (state) => {
1175
- state.loginSpin = true;
1176
- state.errorMsg = null;
1177
- }).addCase(loginDone, (state, action) => {
1178
- state = Object.assign(state, action.payload);
1179
- state.loginSpin = false;
1180
- state.active = true;
1181
- state.logout = false;
1182
- }).addCase(loginFail, (state, action) => {
1183
- state.loginSpin = false;
1184
- state.errorMsg = action.payload.errorMsg;
1185
- }).addCase(logout, (state) => {
1186
- state.loginSpin = false;
1187
- state.active = false;
1188
- state.logout = true;
1189
- }).addCase(switchDebugMode, (state, action) => {
1190
- state.debugMode = action.payload;
1191
- }).addCase(addPendingRequest, (state, action) => {
1192
- var _a;
1193
- (_a = state.pendingRequests) == null ? void 0 : _a.push(action.payload.request);
1194
- }).addCase(removePendingRequest, (state, action) => {
1195
- var _a;
1196
- state.pendingRequests = (_a = state.pendingRequests) == null ? void 0 : _a.filter((item) => item.requestId !== action.payload.requestId);
1197
- }).addCase(addNotification, (state, action) => {
1198
- state.notifications.push(action.payload);
1199
- }).addCase(removeNotifications, (state, action) => {
1200
- const closingKeys = action.payload;
1201
- state.notifications = state.notifications.filter((notification) => !closingKeys.includes(notification.key));
1202
- }).addCase(refreshMeta, (state) => {
1203
- state.isMetaRefreshing = true;
1204
- }).addCase(refreshMetaDone, (state) => {
1205
- state.isMetaRefreshing = false;
1206
- }).addCase(refreshMetaFail, (state) => {
1207
- state.isMetaRefreshing = false;
1208
- });
1209
- // src/reducers/view.ts
1210
- import { OperationTypeCrud as OperationTypeCrud4 } from "@cxbox-ui/schema";
1211
- var initialViewState = {
1212
- id: void 0,
1213
- name: null,
1214
- url: null,
1215
- widgets: [],
1216
- columns: null,
1217
- readOnly: false,
1218
- rowHeight: null,
1219
- rowMeta: {},
1220
- metaInProgress: {},
1221
- popupData: { bcName: null },
1222
- pendingDataChanges: {},
1223
- infiniteWidgets: [],
1224
- pendingValidationFailsFormat: "old" /* old */,
1225
- pendingValidationFails: {},
1226
- handledForceActive: {},
1227
- selectedCell: null,
1228
- ignoreHistory: null,
1229
- systemNotifications: [],
1230
- error: null,
1231
- modalInvoke: null
1232
- };
1233
- var createViewReducerBuilderManager = (initialState) => new ReducerBuilderManager().addCase(selectView, (state, action) => {
1234
- state.rowMeta = initialViewState.rowMeta;
1235
- Object.assign(state, action.payload);
1236
- }).addCase(bcFetchRowMeta, (state, action) => {
1237
- state.metaInProgress[action.payload.bcName] = true;
1238
- }).addCase(bcLoadMore, (state, action) => {
1239
- const infiniteWidgets = state.infiniteWidgets || [];
1240
- if (action.payload.widgetName !== void 0) {
1241
- infiniteWidgets.push(action.payload.widgetName);
1242
- }
1243
- state.infiniteWidgets = Array.from(new Set(infiniteWidgets));
1244
- }).addCase(sendOperation, (state, action) => {
1245
- if (action.payload.operationType === OperationTypeCrud4.create) {
1246
- state.metaInProgress[action.payload.bcName] = true;
1247
- }
1248
- }).addCase(bcFetchRowMetaSuccess, (state, action) => {
1249
- var _a;
1250
- state.rowMeta[action.payload.bcName] = (_a = state.rowMeta[action.payload.bcName]) != null ? _a : {};
1251
- state.rowMeta[action.payload.bcName][action.payload.bcUrl] = action.payload.rowMeta;
1252
- state.metaInProgress[action.payload.bcName] = false;
1253
- }).addCase(bcNewDataSuccess, (state, action) => {
1254
- state.selectedCell = initialViewState.selectedCell;
1255
- }).addCase(forceActiveRmUpdate, (state, action) => {
1256
- var _a, _b, _c, _d, _e;
1257
- const { bcName, bcUrl, currentRecordData, rowMeta, cursor } = action.payload;
1258
- const handledForceActive = {};
1259
- const rowMetaForcedValues = {};
1260
- const newPendingChangesDiff = {};
1261
- const forceActiveFieldKeys = [];
1262
- rowMeta.fields.forEach((field) => {
1263
- rowMetaForcedValues[field.key] = field.currentValue;
1264
- if (field.forceActive) {
1265
- forceActiveFieldKeys.push(field.key);
1266
- }
1267
- });
1268
- state.pendingDataChanges[bcName] = (_a = state.pendingDataChanges[bcName]) != null ? _a : {};
1269
- const consolidatedFrontData = __spreadValues(__spreadValues({}, currentRecordData), state.pendingDataChanges[bcName][cursor]);
1270
- Object.keys(consolidatedFrontData).forEach((key) => {
1271
- if (rowMetaForcedValues[key] !== void 0 && consolidatedFrontData[key] !== rowMetaForcedValues[key]) {
1272
- newPendingChangesDiff[key] = rowMetaForcedValues[key];
1273
- }
1274
- });
1275
- const newPendingDataChanges = __spreadValues(__spreadValues({}, state.pendingDataChanges[bcName][cursor]), newPendingChangesDiff);
1276
- forceActiveFieldKeys.forEach((key) => {
1277
- if (newPendingDataChanges[key] !== void 0) {
1278
- handledForceActive[key] = newPendingDataChanges[key];
1279
- }
1280
- });
1281
- state.handledForceActive[bcName] = (_b = state.handledForceActive[bcName]) != null ? _b : {};
1282
- state.handledForceActive[bcName][cursor] = (_c = state.handledForceActive[bcName][cursor]) != null ? _c : {};
1283
- Object.assign(state.handledForceActive[bcName][cursor], handledForceActive);
1284
- state.pendingDataChanges[bcName] = (_d = state.pendingDataChanges[bcName]) != null ? _d : {};
1285
- state.pendingDataChanges[bcName][cursor] = newPendingDataChanges;
1286
- state.rowMeta[bcName] = (_e = state.rowMeta[bcName]) != null ? _e : {};
1287
- state.rowMeta[bcName][bcUrl] = rowMeta;
1288
- }).addCase(changeDataItem, (state, action) => {
1289
- var _a, _b, _c, _d;
1290
- const actionBcName = action.payload.bcName;
1291
- const prevBc = state.pendingDataChanges[action.payload.bcName] || {};
1292
- const prevCursor = prevBc[action.payload.cursor] || {};
1293
- const prevPending = prevCursor || {};
1294
- const nextPending = __spreadValues(__spreadValues({}, prevPending), action.payload.dataItem);
1295
- const bcUrl = action.payload.bcUrl;
1296
- const rowMeta = (_a = state.rowMeta[actionBcName]) == null ? void 0 : _a[bcUrl];
1297
- const nextValidationFails = {};
1298
- const isTargetFormatPVF = state.pendingValidationFailsFormat === "target" /* target */;
1299
- Object.keys(nextPending).forEach((fieldKey) => {
1300
- const required = rowMeta == null ? void 0 : rowMeta.fields.find((item) => item.required && item.key === fieldKey);
1301
- const isEmpty = nextPending[fieldKey] === null || nextPending[fieldKey] === void 0 || nextPending[fieldKey] === "" || Array.isArray(nextPending[fieldKey]) && Object.keys(nextPending[fieldKey]).length === 0;
1302
- if (required && isEmpty) {
1303
- nextValidationFails[fieldKey] = "This field is mandatory";
1304
- }
1305
- });
1306
- state.pendingDataChanges[action.payload.bcName] = (_b = state.pendingDataChanges[action.payload.bcName]) != null ? _b : {};
1307
- state.pendingDataChanges[action.payload.bcName][action.payload.cursor] = nextPending;
1308
- if (isTargetFormatPVF) {
1309
- state.pendingValidationFails = (_c = state.pendingValidationFails) != null ? _c : {};
1310
- state.pendingValidationFails[actionBcName] = (_d = state.pendingValidationFails[actionBcName]) != null ? _d : {};
1311
- state.pendingValidationFails[actionBcName][action.payload.cursor] = nextValidationFails;
1312
- }
1313
- else {
1314
- state.pendingValidationFails = nextValidationFails;
1315
- }
1316
- }).addCase(changeDataItems, (state, action) => {
1317
- const newPendingChanges = __spreadValues({}, state.pendingDataChanges[action.payload.bcName]);
1318
- action.payload.cursors.forEach((cursor, index) => {
1319
- newPendingChanges[cursor] = action.payload.dataItems[index];
1320
- });
1321
- state.pendingDataChanges[action.payload.bcName] = newPendingChanges;
1322
- }).addCase(dropAllAssociations, (state, action) => {
1323
- const pendingDataChanges = __spreadValues({}, state.pendingDataChanges);
1324
- action.payload.bcNames.forEach((bcName) => {
1325
- const pendingBcChanges = {};
1326
- Object.keys(pendingDataChanges[bcName] || {}).forEach((itemId) => {
1327
- pendingBcChanges[itemId] = { id: itemId, _associate: false };
1328
- });
1329
- pendingDataChanges[bcName] = pendingBcChanges;
1330
- });
1331
- const isTargetFormatPVF = state.pendingValidationFailsFormat === "target" /* target */;
1332
- const pendingValidationFails = state.pendingValidationFails ? __spreadValues({}, state.pendingValidationFails) : {};
1333
- if (isTargetFormatPVF) {
1334
- action.payload.bcNames.forEach((i) => {
1335
- pendingValidationFails[i] = {};
1336
- });
1337
- }
1338
- state.pendingDataChanges = pendingDataChanges;
1339
- state.pendingValidationFails = isTargetFormatPVF ? pendingValidationFails : initialViewState.pendingValidationFails;
1340
- }).addCase(dropAllAssociationsSameBc, (state, action) => {
1341
- }).addCase(dropAllAssociationsFull, (state, action) => {
1342
- }).addCase(bcNewDataFail, (state, action) => {
1343
- state.metaInProgress[action.payload.bcName] = false;
1344
- }).addCase(bcFetchRowMetaFail, (state, action) => {
1345
- state.metaInProgress[action.payload.bcName] = false;
1346
- }).addCase(forceActiveChangeFail, (state, action) => {
1347
- var _a;
1348
- const { bcName, bcUrl, entityError } = action.payload;
1349
- const errors = {};
1350
- if (entityError) {
1351
- Object.entries(entityError.fields).forEach(([fieldName, violation]) => {
1352
- errors[fieldName] = violation;
1353
- });
1354
- }
1355
- state.rowMeta[bcName] = (_a = state.rowMeta[bcName]) != null ? _a : {};
1356
- state.rowMeta[bcName][bcUrl].errors = errors;
1357
- }).addCase(bcSaveDataFail, (state, action) => {
1358
- var _a;
1359
- const { bcName, bcUrl, entityError } = action.payload;
1360
- const errors = {};
1361
- if (entityError) {
1362
- Object.entries(entityError.fields).forEach(([fieldName, violation]) => {
1363
- errors[fieldName] = violation;
1364
- });
1365
- }
1366
- state.rowMeta[bcName] = (_a = state.rowMeta[bcName]) != null ? _a : {};
1367
- state.rowMeta[bcName][bcUrl].errors = errors;
1368
- }).addCase(sendOperationFail, (state, action) => {
1369
- var _a;
1370
- const { bcName, bcUrl, entityError } = action.payload;
1371
- const errors = {};
1372
- if (entityError) {
1373
- Object.entries(entityError.fields).forEach(([fieldName, violation]) => {
1374
- errors[fieldName] = violation;
1375
- });
1376
- }
1377
- state.rowMeta[bcName] = (_a = state.rowMeta[bcName]) != null ? _a : {};
1378
- state.rowMeta[bcName][bcUrl].errors = errors;
1379
- }).addCase(sendOperationSuccess, (state, action) => {
1380
- var _a, _b, _c, _d;
1381
- const bcName = action.payload.bcName;
1382
- const cursor = action.payload.cursor;
1383
- const isTargetFormatPVF = state.pendingValidationFailsFormat === "target" /* target */;
1384
- state.pendingDataChanges[bcName] = (_a = state.pendingDataChanges[bcName]) != null ? _a : {};
1385
- state.pendingDataChanges[bcName][cursor] = {};
1386
- if (isTargetFormatPVF) {
1387
- state.pendingValidationFails = (_b = state.pendingValidationFails) != null ? _b : {};
1388
- state.pendingValidationFails[bcName] = (_c = state.pendingValidationFails[bcName]) != null ? _c : {};
1389
- state.pendingValidationFails[bcName][cursor] = {};
1390
- }
1391
- else {
1392
- state.pendingValidationFails = initialViewState.pendingValidationFails;
1393
- }
1394
- state.handledForceActive[bcName] = (_d = state.handledForceActive[bcName]) != null ? _d : {};
1395
- state.handledForceActive[bcName][cursor] = {};
1396
- }).addCase(bcSaveDataSuccess, (state, action) => {
1397
- var _a, _b, _c;
1398
- const { bcName, cursor } = action.payload;
1399
- const isTargetFormatPVF = state.pendingValidationFailsFormat === "target" /* target */;
1400
- state.pendingDataChanges[bcName] = (_a = state.pendingDataChanges[bcName]) != null ? _a : {};
1401
- state.pendingDataChanges[bcName][cursor] = {};
1402
- if (isTargetFormatPVF) {
1403
- state.pendingValidationFails = (_b = state.pendingValidationFails) != null ? _b : {};
1404
- state.pendingValidationFails[bcName][cursor] = {};
1405
- }
1406
- else {
1407
- state.pendingValidationFails = initialViewState.pendingValidationFails;
1408
- }
1409
- state.handledForceActive[bcName] = (_c = state.handledForceActive[bcName]) != null ? _c : {};
1410
- state.handledForceActive[bcName][cursor] = {};
1411
- }).addCase(bcCancelPendingChanges, (state, action) => {
1412
- var _a, _b;
1413
- const pendingDataChanges = __spreadValues({}, state.pendingDataChanges);
1414
- for (const bcName in state.pendingDataChanges) {
1415
- if (action.payload ? action.payload.bcNames.includes(bcName) : true) {
1416
- pendingDataChanges[bcName] = {};
1417
- }
1418
- }
1419
- const isTargetFormatPVF = state.pendingValidationFailsFormat === "target" /* target */;
1420
- let pendingValidationFails = state.pendingValidationFails ? __spreadValues({}, state.pendingValidationFails) : {};
1421
- if (isTargetFormatPVF) {
1422
- if (((_b = (_a = action.payload) == null ? void 0 : _a.bcNames) == null ? void 0 : _b.length) > 0) {
1423
- action.payload.bcNames.forEach((i) => {
1424
- pendingValidationFails[i] = {};
1425
- });
1426
- }
1427
- else {
1428
- pendingValidationFails = initialViewState.pendingValidationFails;
1429
- }
1430
- }
1431
- state.pendingDataChanges = pendingDataChanges;
1432
- state.pendingValidationFails = isTargetFormatPVF ? pendingValidationFails : initialViewState.pendingValidationFails;
1433
- }).addCase(clearValidationFails, (state) => {
1434
- state.pendingValidationFails = initialViewState.pendingValidationFails;
1435
- }).addCase(showViewPopup, (state, action) => {
1436
- const { bcName, calleeBCName, calleeWidgetName, associateFieldKey, assocValueKey, active, isFilter, type, widgetName } = action.payload;
1437
- state.popupData = {
1438
- widgetName,
1439
- type,
1440
- bcName,
1441
- calleeBCName,
1442
- calleeWidgetName,
1443
- associateFieldKey,
1444
- assocValueKey,
1445
- active,
1446
- isFilter
1447
- };
1448
- }).addCase(showFileUploadPopup, (state, action) => {
1449
- var _a, _b;
1450
- const bcName = (_b = (_a = state.widgets) == null ? void 0 : _a.find((item) => item.name === action.payload.widgetName)) == null ? void 0 : _b.bcName;
1451
- state.popupData = {
1452
- type: "file-upload",
1453
- bcName,
1454
- // should be null
1455
- calleeBCName: bcName
1456
- };
1457
- }).addCase(viewPutPickMap, (state, action) => {
1458
- state.pickMap = action.payload.map;
1459
- }).addCase(viewClearPickMap, (state) => {
1460
- state.pickMap = null;
1461
- }).addCase(closeViewPopup, (state) => {
1462
- state.popupData = {};
1463
- state.popupData.bcName = null;
1464
- }).addCase(selectTableCell, (state, action) => {
1465
- state.selectedCell = { widgetName: action.payload.widgetName, rowId: action.payload.rowId, fieldKey: action.payload.fieldKey };
1466
- }).addCase(changeLocation, (state, action) => {
1467
- state.pendingDataChanges = initialViewState.pendingDataChanges;
1468
- state.selectedCell = initialViewState.selectedCell;
1469
- }).addCase(showNotification, (state, action) => {
1470
- var _a, _b;
1471
- state.systemNotifications = (_a = state.systemNotifications) != null ? _a : [];
1472
- state.systemNotifications.push({
1473
- type: action.payload.type,
1474
- message: action.payload.message,
1475
- id: (_b = state.systemNotifications) == null ? void 0 : _b.length
1476
- });
1477
- }).addCase(closeNotification, (state, action) => {
1478
- var _a;
1479
- state.systemNotifications = (_a = state.systemNotifications) != null ? _a : [];
1480
- state.systemNotifications = state.systemNotifications.filter((item) => item.id !== action.payload.id);
1481
- }).addCase(showViewError, (state, action) => {
1482
- state.error = action.payload.error;
1483
- }).addCase(operationConfirmation, (state, action) => {
1484
- state.modalInvoke = action.payload;
1485
- }).addCase(closeConfirmModal, (state, action) => {
1486
- state.modalInvoke = null;
1487
- }).addCase(closeViewError, (state) => {
1488
- state.error = null;
1489
- }).addCase(processPostInvoke, (state) => {
1490
- state.selectedCell = null;
1491
- });
1492
- // src/epics/index.ts
1493
- var epics_exports = {};
1494
- __export(epics_exports, {
1495
- apiErrorEpic: () => apiErrorEpic,
1496
- bcCancelCreateDataEpic: () => bcCancelCreateDataEpic,
1497
- bcDeleteDataEpic: () => bcDeleteDataEpic,
1498
- bcFetchDataEpic: () => bcFetchDataEpic,
1499
- bcFetchRowMetaRequestEpic: () => bcFetchRowMetaRequestEpic,
1500
- bcLoadMoreEpic: () => bcLoadMoreEpic,
1501
- bcNewDataEpic: () => bcNewDataEpic,
1502
- bcSaveDataEpic: () => bcSaveDataEpic,
1503
- bcSelectDepthRecordEpic: () => bcSelectDepthRecordEpic,
1504
- bcSelectRecordEpic: () => bcSelectRecordEpic,
1505
- changeAssociationEpic: () => changeAssociationEpic,
1506
- changeAssociationFullEpic: () => changeAssociationFullEpic,
1507
- changeAssociationSameBcEpic: () => changeAssociationSameBcEpic,
1508
- changeChildrenAssociationsEpic: () => changeChildrenAssociationsEpic,
1509
- changeChildrenAssociationsSameBcEpic: () => changeChildrenAssociationsSameBcEpic,
1510
- changeDescendantsAssociationsFullEpic: () => changeDescendantsAssociationsFullEpic,
1511
- changeLocationEpic: () => changeLocationEpic,
1512
- changeScreen: () => changeScreen,
1513
- changeViewEpic: () => changeViewEpic,
1514
- clearPendingDataChangesAfterCursorChangeEpic: () => clearPendingDataChangesAfterCursorChangeEpic,
1515
- downloadFileByUrlEpic: () => downloadFileByUrlEpic,
1516
- downloadFileEpic: () => downloadFileEpic,
1517
- drillDownEpic: () => drillDownEpic,
1518
- fileUploadConfirmEpic: () => fileUploadConfirmEpic,
1519
- getRowMetaByForceActiveEpic: () => getRowMetaByForceActiveEpic,
1520
- handleRouterEpic: () => handleRouterEpic,
1521
- httpError401Epic: () => httpError401Epic,
1522
- httpError409Epic: () => httpError409Epic,
1523
- httpError418Epic: () => httpError418Epic,
1524
- httpError500Epic: () => httpError500Epic,
1525
- httpErrorDefaultEpic: () => httpErrorDefaultEpic,
1526
- inlinePickListFetchDataEpic: () => inlinePickListFetchDataEpic,
1527
- loginByAnotherRoleEpic: () => loginByAnotherRoleEpic,
1528
- loginDoneEpic: () => loginDoneEpic,
1529
- loginDoneSessionEpic: () => loginDoneSessionEpic,
1530
- processPostInvokeConfirmEpic: () => processPostInvokeConfirmEpic,
1531
- processPostInvokeEpic: () => processPostInvokeEpic,
1532
- refreshMetaAndReloadPageEpic: () => refreshMetaAndReloadPageEpic,
1533
- refreshMetaEpic: () => refreshMetaEpic,
1534
- removeMultivalueTagEpic: () => removeMultivalueTagEpic,
1535
- saveAssociationsActiveEpic: () => saveAssociationsActiveEpic,
1536
- saveAssociationsPassiveEpic: () => saveAssociationsPassiveEpic,
1537
- selectScreenFailEpic: () => selectScreenFailEpic,
1538
- selectTableCellInitEpic: () => selectTableCellInitEpic,
1539
- selectViewEpic: () => selectViewEpic,
1540
- selectViewFailEpic: () => selectViewFailEpic,
1541
- sendOperationAssociateEpic: () => sendOperationAssociateEpic,
1542
- sendOperationEpic: () => sendOperationEpic,
1543
- showAllTableRecordsInitEpic: () => showAllTableRecordsInitEpic,
1544
- showAssocPopupEpic: () => showAssocPopupEpic,
1545
- showFileUploadPopupEpic: () => showFileUploadPopupEpic,
1546
- switchRoleEpic: () => switchRoleEpic,
1547
- userDrillDownChangeCursorsEpic: () => userDrillDownChangeCursorsEpic,
1548
- userDrillDownEpic: () => userDrillDownEpic
1549
- });
1550
- // src/epics/view/sendOperationEpic.ts
1551
- import { catchError, concat, EMPTY as EMPTY2, filter, mergeMap, of as of3 } from "rxjs";
1552
- // src/epics/utils/postOperationRoutine.ts
1553
- import { of as of2 } from "rxjs";
1554
- function postOperationRoutine(widgetName, postInvoke, preInvoke, operationType, bcName) {
1555
- const postInvokeConfirm = Object.values(OperationPostInvokeConfirmType).includes(postInvoke == null ? void 0 : postInvoke.type);
1556
- const result = [];
1557
- if (postInvoke) {
1558
- result.push(processPostInvoke({ bcName, postInvoke, widgetName }));
1559
- }
1560
- if (postInvokeConfirm) {
1561
- result.push(processPostInvokeConfirm({
1562
- bcName,
1563
- operationType,
1564
- widgetName,
1565
- postInvokeConfirm: postInvoke
1566
- }));
1567
- }
1568
- if (preInvoke) {
1569
- result.push(processPreInvoke({
1570
- bcName,
1571
- operationType,
1572
- widgetName,
1573
- preInvoke
1574
- }));
1575
- }
1576
- return result.map((item) => of2(item));
1577
- }
1578
- // src/epics/view/sendOperationEpic.ts
1579
- var sendOperationEpic = (action$, state$, { api }) => action$.pipe(filter(sendOperation.match), filter((action) => matchOperationRole("none", action.payload, state$.value)), mergeMap((action) => {
1580
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1581
- const state = state$.value;
1582
- const screenName = state.screen.screenName;
1583
- const { bcName, operationType, widgetName } = action.payload;
1584
- const confirm = ((_a = action.payload.confirmOperation) == null ? void 0 : _a.type) || action.payload.confirm;
1585
- const bcUrl = buildBcUrl(bcName, true, state);
1586
- const bc = state.screen.bo.bc[bcName];
1587
- const rowMeta = bcUrl && ((_b = state.view.rowMeta[bcName]) == null ? void 0 : _b[bcUrl]);
1588
- const fields = rowMeta == null ? void 0 : rowMeta.fields;
1589
- const cursor = bc.cursor;
1590
- const record = (_c = state.data[bcName]) == null ? void 0 : _c.find((item) => item.id === bc.cursor);
1591
- const filters = state.screen.filters[bcName];
1592
- const sorters = state.screen.sorters[bcName];
1593
- const pendingRecordChange = __spreadValues({}, (_d = state.view.pendingDataChanges[bcName]) == null ? void 0 : _d[bc.cursor]);
1594
- for (const key in pendingRecordChange) {
1595
- if (fields.find((item) => item.key === key && item.disabled)) {
1596
- delete pendingRecordChange[key];
1597
- }
1598
- }
1599
- const data = record && __spreadProps(__spreadValues({}, pendingRecordChange), { vstamp: record.vstamp });
1600
- const defaultSaveOperation = ((_h = (_g = (_f = (_e = state.view.widgets) == null ? void 0 : _e.find((item) => item.name === widgetName)) == null ? void 0 : _f.options) == null ? void 0 : _g.actionGroups) == null ? void 0 : _h.defaultSave) === action.payload.operationType && changeLocation.match((_j = (_i = action.payload) == null ? void 0 : _i.onSuccessAction) == null ? void 0 : _j.type);
1601
- const params = __spreadValues(__spreadValues({
1602
- _action: operationType
1603
- }, getFilters(filters)), getSorters(sorters));
1604
- if (confirm) {
1605
- params._confirm = confirm;
1606
- }
1607
- const context = { widgetName: action.payload.widgetName };
1608
- return api.customAction(screenName, bcUrl, data, context, params).pipe(mergeMap((response) => {
1609
- var _a2, _b2;
1610
- const postInvoke = (_a2 = response.postActions) == null ? void 0 : _a2[0];
1611
- const dataItem = response.record;
1612
- const preInvoke = response.preInvoke;
1613
- return defaultSaveOperation ? ((_b2 = action == null ? void 0 : action.payload) == null ? void 0 : _b2.onSuccessAction) ? concat(of3(bcCancelPendingChanges({ bcNames: [bcName] })), of3(action.payload.onSuccessAction)) : EMPTY2 : concat(of3(sendOperationSuccess({ bcName, cursor, dataItem })), of3(bcForceUpdate({ bcName })), ...postOperationRoutine(widgetName, postInvoke, preInvoke, operationType, bcName));
1614
- }), catchError((e) => {
1615
- var _a2, _b2, _c2, _d2, _e2, _f2;
1616
- console.error(e);
1617
- let viewError = null;
1618
- let entityError = null;
1619
- const operationError = (_a2 = e.response) == null ? void 0 : _a2.data;
1620
- if (((_b2 = e.response) == null ? void 0 : _b2.data) === Object((_c2 = e.response) == null ? void 0 : _c2.data)) {
1621
- entityError = (_d2 = operationError == null ? void 0 : operationError.error) == null ? void 0 : _d2.entity;
1622
- viewError = (_f2 = (_e2 = operationError == null ? void 0 : operationError.error) == null ? void 0 : _e2.popup) == null ? void 0 : _f2[0];
1623
- }
1624
- return concat(of3(sendOperationFail({ bcName, bcUrl, viewError, entityError })), createApiErrorObservable(e, context));
1625
- }));
1626
- }));
1627
- // src/epics/view/showAssocPopupEpic.ts
1628
- import { EMPTY as EMPTY3, filter as filter2, mergeMap as mergeMap2, of as of4 } from "rxjs";
1629
- import { WidgetTypes as WidgetTypes3 } from "@cxbox-ui/schema";
1630
- var showAssocPopupEpic = (action$, state$) => action$.pipe(filter2(showViewPopup.match), filter2((action) => !!(action.payload.calleeBCName && action.payload.associateFieldKey)), mergeMap2((action) => {
1631
- var _a, _b, _c, _d;
1632
- const { bcName, calleeBCName } = action.payload;
1633
- const state = state$.value;
1634
- const assocWidget = state.view.widgets.find((widget) => widget.bcName === bcName && widget.type === WidgetTypes3.AssocListPopup);
1635
- const calleeCursor = (_a = state.screen.bo.bc[calleeBCName]) == null ? void 0 : _a.cursor;
1636
- const calleePendingChanges = (_b = state.view.pendingDataChanges[calleeBCName]) == null ? void 0 : _b[calleeCursor];
1637
- const assocFieldKey = action.payload.associateFieldKey;
1638
- const assocFieldChanges = calleePendingChanges == null ? void 0 : calleePendingChanges[assocFieldKey];
1639
- const somethingMissing = !assocWidget || !calleePendingChanges || !assocFieldChanges || !assocFieldChanges;
1640
- if (somethingMissing || assocWidget.options && !assocWidget.options.hierarchyFull) {
1641
- return EMPTY3;
1642
- }
1643
- const popupInitPendingChanges = {};
1644
- assocFieldChanges.forEach((record) => {
1645
- popupInitPendingChanges[record.id] = {
1646
- id: record.id,
1647
- _associate: true,
1648
- _value: record.value
1649
- };
1650
- });
1651
- const calleeData = (_c = state.data[calleeBCName]) == null ? void 0 : _c.find((dataRecord) => dataRecord.id === calleeCursor);
1652
- const assocIds = (_d = calleeData == null ? void 0 : calleeData[assocFieldKey]) == null ? void 0 : _d.map((recordId) => recordId.id);
1653
- const assocPendingIds = assocFieldChanges.map((recordId) => recordId.id);
1654
- if (assocIds) {
1655
- assocIds.forEach((recordId) => {
1656
- if (!assocPendingIds.includes(recordId)) {
1657
- popupInitPendingChanges[recordId] = {
1658
- id: recordId,
1659
- _associate: false
1660
- };
1661
- }
1662
- });
1663
- }
1664
- return of4(changeDataItems({
1665
- bcName,
1666
- cursors: Object.keys(popupInitPendingChanges),
1667
- dataItems: Object.values(popupInitPendingChanges)
1668
- }));
1669
- }));
1670
- // src/epics/view/fileUploadConfirmEpic.ts
1671
- import { catchError as catchError2, concat as concat2, EMPTY as EMPTY4, filter as filter3, mergeMap as mergeMap3, of as of5 } from "rxjs";
1672
- import { OperationTypeCrud as OperationTypeCrud5 } from "@cxbox-ui/schema";
1673
- var fileUploadConfirmEpic = (action$, state$, { api }) => action$.pipe(filter3(bulkUploadFiles.match), mergeMap3((action) => {
1674
- var _a, _b, _c, _d;
1675
- const state = state$.value;
1676
- const isPopup = (_a = action.payload.isPopup) != null ? _a : true;
1677
- const bcName = (_c = action.payload.bcName) != null ? _c : (_b = state.view.popupData) == null ? void 0 : _b.bcName;
1678
- const bcUrl = buildBcUrl(bcName, true, state);
1679
- const widgetName = (_d = state.view.widgets.find((item) => item.bcName === bcName)) == null ? void 0 : _d.name;
1680
- const data = action.payload.fileIds.map((id) => ({
1681
- id,
1682
- _associate: true,
1683
- vstamp: 0
1684
- }));
1685
- return api.associate(state.screen.screenName, bcUrl, data, null).pipe(mergeMap3((response) => {
1686
- var _a2;
1687
- const postInvoke = (_a2 = response.postActions) == null ? void 0 : _a2[0];
1688
- const preInvoke = response.preInvoke;
1689
- return concat2(of5(sendOperationSuccess({ bcName, cursor: null })), of5(bcForceUpdate({ bcName })), isPopup ? of5(closeViewPopup(null)) : EMPTY4, ...postOperationRoutine(widgetName, postInvoke, preInvoke, OperationTypeCrud5.save, bcName));
1690
- }), catchError2((error) => {
1691
- console.error(error);
1692
- return createApiErrorObservable(error);
1693
- }));
1694
- }));
1695
- // src/epics/view/selectTableCellInitEpic.ts
1696
- import { concat as concat3, filter as filter4, mergeMap as mergeMap4, of as of6 } from "rxjs";
1697
- var selectTableCellInitEpic = (action$, state$) => action$.pipe(filter4(selectTableCellInit.match), mergeMap4((action) => {
1698
- var _a;
1699
- const resultObservables = [];
1700
- const state = state$.value;
1701
- const { rowId: nextRowId, fieldKey } = action.payload;
1702
- const nextWidget = state.view.widgets.find((widget) => widget.name === action.payload.widgetName);
1703
- const nextBcName = nextWidget == null ? void 0 : nextWidget.bcName;
1704
- const nextBcCursor = (_a = state.screen.bo.bc[nextBcName]) == null ? void 0 : _a.cursor;
1705
- const selectedCell = state.view.selectedCell;
1706
- if (nextRowId !== nextBcCursor) {
1707
- resultObservables.push(of6(bcSelectRecord({ bcName: nextBcName, cursor: nextRowId })));
1708
- }
1709
- if (!selectedCell || fieldKey !== selectedCell.fieldKey || nextRowId !== selectedCell.rowId || (nextWidget == null ? void 0 : nextWidget.name) !== selectedCell.widgetName) {
1710
- resultObservables.push(of6(selectTableCell({ widgetName: nextWidget == null ? void 0 : nextWidget.name, rowId: nextRowId, fieldKey })));
1711
- }
1712
- return concat3(...resultObservables);
1713
- }));
1714
- // src/epics/view/showFileUploadPopupEpic.ts
1715
- import { concat as concat4, filter as filter5, mergeMap as mergeMap5, of as of7 } from "rxjs";
1716
- import { OperationTypeCrud as OperationTypeCrud6 } from "@cxbox-ui/schema";
1717
- var showFileUploadPopupEpic = (action$, state$) => action$.pipe(filter5(sendOperation.match), filter5((action) => matchOperationRole(OperationTypeCrud6.fileUpload, action.payload, state$.value)), mergeMap5((action) => {
1718
- return concat4(of7(bcChangeCursors({ cursorsMap: { [action.payload.bcName]: null } })), of7(showFileUploadPopup({ widgetName: action.payload.widgetName })));
1719
- }));
1720
- // src/epics/view/sendOperationAssociateEpic.ts
1721
- import { filter as filter6, map } from "rxjs";
1722
- import { OperationTypeCrud as OperationTypeCrud7 } from "@cxbox-ui/schema";
1723
- var sendOperationAssociateEpic = (action$, state$) => action$.pipe(filter6(sendOperation.match), filter6((action) => matchOperationRole(OperationTypeCrud7.associate, action.payload, state$.value)), map((action) => {
1724
- var _a, _b;
1725
- const state = state$.value;
1726
- const bcUrl = buildBcUrl(action.payload.bcName, true, state);
1727
- const operations = flattenOperations((_b = (_a = state.view.rowMeta[action.payload.bcName]) == null ? void 0 : _a[bcUrl]) == null ? void 0 : _b.actions);
1728
- const operation = operations.find((item) => item.type === action.payload.operationType);
1729
- if (operation.subtype === "multiFileUpload") {
1730
- return showFileUploadPopup({
1731
- widgetName: action.payload.widgetName
1732
- });
1733
- }
1734
- return showViewPopup({
1735
- // TODO: 2.0.0 bcKey and bcName will be removed in favor `widgetName`
1736
- bcName: action.payload.bcKey ? `${action.payload.bcKey}` : `${action.payload.bcName}Assoc`,
1737
- calleeBCName: action.payload.bcName,
1738
- active: true,
1739
- calleeWidgetName: action.payload.widgetName
1740
- });
1741
- }));
1742
- // src/epics/view/getRowMetaByForceActiveEpic.ts
1743
- import { EMPTY as EMPTY5, concat as concat5, filter as filter7, mergeMap as mergeMap6, of as of8, catchError as catchError3 } from "rxjs";
1744
- import { WidgetTypes as WidgetTypes4 } from "@cxbox-ui/schema";
1745
- import { nanoid } from "@reduxjs/toolkit";
1746
- var getRowMetaByForceActiveEpic = (action$, state$, { api }) => action$.pipe(filter7(changeDataItem.match), mergeMap6((action) => {
1747
- var _a, _b, _c, _d, _e;
1748
- const state = state$.value;
1749
- const initUrl = state.view.url;
1750
- const { bcName, cursor, disableRetry } = action.payload;
1751
- const isBcHierarchy = state.view.widgets.some((widget) => {
1752
- var _a2, _b2;
1753
- return widget.bcName === bcName && widget.type === WidgetTypes4.AssocListPopup && (((_a2 = widget.options) == null ? void 0 : _a2.hierarchySameBc) || ((_b2 = widget.options) == null ? void 0 : _b2.hierarchyFull));
1754
- });
1755
- if (isBcHierarchy) {
1756
- return EMPTY5;
1757
- }
1758
- const isPickListPopup = state.view.widgets.find((item) => {
1759
- var _a2;
1760
- return item.name === ((_a2 = state.view.popupData) == null ? void 0 : _a2.widgetName) && [WidgetTypes4.PickListPopup, WidgetTypes4.FlatTreePopup].includes(item.type);
1761
- });
1762
- const bcUrl = buildBcUrl(bcName, true, state);
1763
- const pendingChanges = (_a = state.view.pendingDataChanges[bcName]) == null ? void 0 : _a[cursor];
1764
- const handledForceActive = ((_b = state.view.handledForceActive[bcName]) == null ? void 0 : _b[cursor]) || {};
1765
- const currentRecordData = (_c = state.data[bcName]) == null ? void 0 : _c.find((record) => record.id === cursor);
1766
- const fieldsRowMeta = (_e = (_d = state.view.rowMeta[bcName]) == null ? void 0 : _d[bcUrl]) == null ? void 0 : _e.fields;
1767
- let changedFiledKey = null;
1768
- const closePopup = concat5(of8(closeViewPopup(null)), of8(viewClearPickMap(null)), of8(bcRemoveAllFilters({ bcName })));
1769
- const someForceActiveChanged = fieldsRowMeta == null ? void 0 : fieldsRowMeta.filter((field) => field.forceActive && pendingChanges[field.key] !== void 0).some((field) => {
1770
- const result = pendingChanges[field.key] !== handledForceActive[field.key];
1771
- if (result) {
1772
- changedFiledKey = field.key;
1773
- }
1774
- return result;
1775
- });
1776
- const requestId = nanoid();
1777
- if (someForceActiveChanged && !disableRetry) {
1778
- return concat5(of8(addPendingRequest({ request: { requestId, type: "force-active" } })), api.getRmByForceActive(state.screen.screenName, bcUrl, __spreadProps(__spreadValues({}, pendingChanges), { vstamp: currentRecordData == null ? void 0 : currentRecordData.vstamp })).pipe(mergeMap6((data) => {
1779
- const result = [of8(removePendingRequest({ requestId }))];
1780
- if (state.view.url === initUrl) {
1781
- result.push(of8(forceActiveRmUpdate({
1782
- rowMeta: data,
1783
- currentRecordData,
1784
- bcName,
1785
- bcUrl,
1786
- cursor
1787
- })));
1788
- }
1789
- if (isPickListPopup) {
1790
- result.push(closePopup);
1791
- }
1792
- return concat5(...result);
1793
- }), catchError3((e) => {
1794
- var _a2, _b2, _c2, _d2, _e2, _f;
1795
- console.error(e);
1796
- let viewError = null;
1797
- let entityError = null;
1798
- const operationError = (_a2 = e.response) == null ? void 0 : _a2.data;
1799
- if (((_b2 = e.response) == null ? void 0 : _b2.data) === Object((_c2 = e.response) == null ? void 0 : _c2.data)) {
1800
- entityError = (_d2 = operationError == null ? void 0 : operationError.error) == null ? void 0 : _d2.entity;
1801
- viewError = (_f = (_e2 = operationError == null ? void 0 : operationError.error) == null ? void 0 : _e2.popup) == null ? void 0 : _f[0];
1802
- }
1803
- return concat5(of8(removePendingRequest({ requestId })), state.view.url === initUrl ? concat5(of8(changeDataItem({
1804
- bcName,
1805
- bcUrl: buildBcUrl(bcName, true, state),
1806
- cursor,
1807
- dataItem: { [changedFiledKey]: currentRecordData == null ? void 0 : currentRecordData[changedFiledKey] },
1808
- disableRetry: true
1809
- })), of8(forceActiveChangeFail({ bcName, bcUrl, viewError, entityError }))) : EMPTY5, createApiErrorObservable(e));
1810
- })));
1811
- }
1812
- return isPickListPopup ? closePopup : EMPTY5;
1813
- }));
1814
- // src/epics/view/showAllTableRecordsInitEpic.ts
1815
- import { concat as concat6, filter as filter8, mergeMap as mergeMap7, of as of9 } from "rxjs";
1816
- var showAllTableRecordsInitEpic = (action$, state$) => action$.pipe(filter8(showAllTableRecordsInit.match), mergeMap7((action) => {
1817
- const resultObservables = [];
1818
- const { bcName, cursor } = action.payload;
1819
- const state = state$.value;
1820
- const route = state.router;
1821
- resultObservables.push(of9(bcChangeCursors({ cursorsMap: { [bcName]: null } })));
1822
- const bcPath = route.bcPath.slice(0, route.bcPath.indexOf(`${bcName}/${cursor}`));
1823
- const url = defaultBuildURL(__spreadProps(__spreadValues({}, route), { bcPath }));
1824
- resultObservables.push(of9(bcForceUpdate({ bcName })));
1825
- resultObservables.push(of9(changeLocation({ location: defaultParseURL(new URL(url, window.location.origin)) })));
1826
- return concat6(...resultObservables);
1827
- }));
1828
- // src/epics/view/clearPendingDataChangesAfterCursorChangeEpic.ts
1829
- import { EMPTY as EMPTY6, filter as filter9, mergeMap as mergeMap8, of as of10 } from "rxjs";
1830
- var clearPendingDataChangesAfterCursorChangeEpic = (action$, state$) => action$.pipe(filter9(bcChangeCursors.match), mergeMap8((action) => {
1831
- const state = state$.value;
1832
- const nextCursors = parseBcCursors(state.router.bcPath) || {};
1833
- const cursorsDiffMap = {};
1834
- Object.entries(nextCursors).forEach((entry) => {
1835
- const [bcName, cursor] = entry;
1836
- const bc = state.screen.bo.bc[bcName];
1837
- if (!bc || (bc == null ? void 0 : bc.cursor) !== cursor) {
1838
- cursorsDiffMap[bcName] = cursor;
1839
- }
1840
- });
1841
- if (Object.keys(cursorsDiffMap).length) {
1842
- return of10(bcChangeCursors({ cursorsMap: cursorsDiffMap }));
1843
- }
1844
- return EMPTY6;
1845
- }));
1846
- // src/epics/router/drilldownEpic.ts
1847
- import { concat as concat7, EMPTY as EMPTY7, filter as filter10, switchMap } from "rxjs";
1848
- var drillDownEpic = (action$, state$) => action$.pipe(filter10(drillDown.match), switchMap((action) => {
1849
- var _a, _b;
1850
- const state = state$.value;
1851
- const url = action.payload.url;
1852
- const result = [];
1853
- switch (action.payload.drillDownType) {
1854
- case DrillDownType.external:
1855
- window.location.href = url;
1856
- break;
1857
- case DrillDownType.externalNew:
1858
- if (/^[a-z0-9]+:\/\//i.test(url)) {
1859
- window.open(url);
1860
- }
1861
- break;
1862
- case DrillDownType.relative:
1863
- window.location.href = `${window.location.origin}/${url}`;
1864
- break;
1865
- case DrillDownType.relativeNew:
1866
- window.open(`${window.location.origin}/${url}`, "_blank");
1867
- break;
1868
- case DrillDownType.inner:
1869
- default:
1870
- const [urlBase] = url.split("?");
1871
- const urlObject = new URL(url, window.location.origin);
1872
- const urlFilters = urlObject.searchParams.get("filters");
1873
- const urlSorters = urlObject.searchParams.get("sorters");
1874
- let newFilters = {};
1875
- let newSorters = {};
1876
- try {
1877
- newFilters = (_a = JSON.parse(urlFilters)) != null ? _a : newFilters;
1878
- }
1879
- catch (e) {
1880
- urlFilters && console.warn("Failed to parse filters on drilldown");
1881
- newFilters = {};
1882
- }
1883
- try {
1884
- newSorters = (_b = JSON.parse(urlSorters)) != null ? _b : newSorters;
1885
- }
1886
- catch (e) {
1887
- urlSorters && console.warn("Failed to parse sorters on drilldown");
1888
- newSorters = {};
1889
- }
1890
- const bcToUpdate = {};
1891
- Object.keys(state.screen.filters).forEach((bcName) => {
1892
- if (newFilters[bcName] === "" || newFilters[bcName]) {
1893
- bcToUpdate[bcName] = true;
1894
- result.push(bcRemoveAllFilters({ bcName }));
1895
- }
1896
- });
1897
- const nextState = defaultParseURL(urlObject);
1898
- const viewName = nextState.viewName;
1899
- Object.entries(newFilters).forEach(([bcName, filterExpression]) => {
1900
- var _a2;
1901
- const parsedFilters = (_a2 = parseFilters(filterExpression)) == null ? void 0 : _a2.map((item) => __spreadProps(__spreadValues({}, item), { viewName }));
1902
- parsedFilters == null ? void 0 : parsedFilters.forEach((parsedFilter) => {
1903
- bcToUpdate[bcName] = true;
1904
- result.push(bcAddFilter({ bcName, filter: parsedFilter }));
1905
- });
1906
- });
1907
- Object.entries(newSorters).forEach(([bcName, sortExpression]) => {
1908
- const sorter = parseSorters(sortExpression);
1909
- result.push(bcAddSorter({ bcName, sorter }));
1910
- bcToUpdate[bcName] = true;
1911
- });
1912
- const prevState = state.router;
1913
- const willUpdateAnyway = shallowCompare(prevState, nextState, ["params"]).length > 0;
1914
- if (!willUpdateAnyway) {
1915
- Object.keys(bcToUpdate).forEach((bcName) => {
1916
- result.push(bcForceUpdate({ bcName }));
1917
- });
1918
- }
1919
- result.push(changeLocation({
1920
- location: defaultParseURL(new URL(makeRelativeUrl(urlBase), window.location.origin)),
1921
- forceUpdate: true
1922
- }));
1923
- break;
1924
- }
1925
- return result.length ? concat7(result) : EMPTY7;
1926
- }));
1927
- function shallowCompare(prevProps, nextProps, ignore = []) {
1928
- const diffProps = [];
1929
- if (!prevProps && !nextProps) {
1930
- return null;
1931
- }
1932
- if (!prevProps) {
1933
- return Object.keys(nextProps);
1934
- }
1935
- if (!nextProps) {
1936
- return Object.keys(prevProps);
1937
- }
1938
- const newKeys = Object.keys(nextProps);
1939
- newKeys.forEach((key) => {
1940
- if (prevProps[key] !== nextProps[key] && !ignore.includes(key)) {
1941
- diffProps.push(key);
1942
- }
1943
- });
1944
- Object.keys(prevProps).forEach((key) => {
1945
- if (!newKeys.includes(key)) {
1946
- diffProps.push(key);
1947
- }
1948
- });
1949
- return diffProps;
1950
- }
1951
- // src/epics/router/loginDoneEpic.ts
1952
- import { filter as filter11, of as of11, switchMap as switchMap2 } from "rxjs";
1953
- var loginDoneEpic = (action$, state$) => action$.pipe(filter11(loginDone.match), switchMap2((action) => {
1954
- const state = state$.value;
1955
- if (state.router.type === "router" /* router */) {
1956
- return of11(handleRouter(state.router));
1957
- }
1958
- return of11(changeLocation({
1959
- location: getRouteFromString(window.location.hash.replace("#", "")),
1960
- forceUpdate: true
1961
- }));
1962
- }));
1963
- // src/epics/router/selectViewEpic.ts
1964
- import { EMPTY as EMPTY8, filter as filter12, of as of12, switchMap as switchMap3 } from "rxjs";
1965
- var changeViewEpic = (action$, state$) => action$.pipe(filter12(selectView.match), switchMap3((action) => {
1966
- const state = state$.value;
1967
- const nextCursors = parseBcCursors(state.router.bcPath) || {};
1968
- const cursorsDiffMap = {};
1969
- Object.entries(nextCursors).forEach((entry) => {
1970
- const [bcName, cursor] = entry;
1971
- const bc = state.screen.bo.bc[bcName];
1972
- if (!bc || bc.cursor !== cursor) {
1973
- cursorsDiffMap[bcName] = cursor;
1974
- }
1975
- });
1976
- if (Object.keys(cursorsDiffMap).length) {
1977
- return of12(bcChangeCursors({ cursorsMap: cursorsDiffMap }));
1978
- }
1979
- return EMPTY8;
1980
- }));
1981
- // src/epics/router/handleRouterEpic.ts
1982
- import { catchError as catchError4, EMPTY as EMPTY9, filter as filter13, mergeMap as mergeMap9, switchMap as switchMap4 } from "rxjs";
1983
- var handleRouterEpic = (action$, state$, { api }) => action$.pipe(filter13(handleRouter.match), switchMap4((action) => {
1984
- const path = action.payload.path;
1985
- const params = action.payload.params;
1986
- return api.routerRequest(path, params).pipe(mergeMap9(() => {
1987
- return EMPTY9;
1988
- }), catchError4((error) => {
1989
- console.error(error);
1990
- return createApiErrorObservable(error);
1991
- }));
1992
- }));
1993
- // src/epics/router/selectScreenEpic.ts
1994
- import { filter as filter14, of as of13, switchMap as switchMap5 } from "rxjs";
1995
- var changeScreen = (action$, state$) => action$.pipe(filter14(selectScreen.match), switchMap5((action) => {
1996
- const state = state$.value;
1997
- const nextViewName = state.router.viewName;
1998
- const requestedView = state.screen.views.find((item) => item.name === nextViewName);
1999
- const defaultView = !nextViewName && state.screen.primaryView && state.screen.views.find((item) => item.name === state.screen.primaryView);
2000
- const nextView = requestedView || defaultView || state.screen.views[0];
2001
- return nextView ? of13(selectView(nextView)) : of13(selectViewFail({ viewName: nextViewName }));
2002
- }));
2003
- // src/epics/router/userDrillDownEpic.ts
2004
- import { catchError as catchError5, concat as concat8, EMPTY as EMPTY10, filter as filter15, mergeMap as mergeMap10, of as of14, switchMap as switchMap6 } from "rxjs";
2005
- var userDrillDownEpic = (action$, state$, { api }) => action$.pipe(filter15(userDrillDown.match), switchMap6((action) => {
2006
- const state = state$.value;
2007
- const { bcName, fieldKey, cursor } = action.payload;
2008
- const bcUrl = buildBcUrl(bcName, true, state);
2009
- return api.fetchRowMeta(state.screen.screenName, bcUrl).pipe(mergeMap10((rowMeta) => {
2010
- var _a, _b, _c, _d;
2011
- const drillDownField = rowMeta.fields.find((field) => field.key === fieldKey);
2012
- const route = state.router;
2013
- const drillDownKey = (_b = (_a = state.view.widgets.find((widget) => widget.bcName === bcName)) == null ? void 0 : _a.fields.find((field) => field.key === fieldKey)) == null ? void 0 : _b.drillDownKey;
2014
- const customDrillDownUrl = (_d = (_c = state.data[bcName]) == null ? void 0 : _c.find((record) => record.id === cursor)) == null ? void 0 : _d[drillDownKey];
2015
- return customDrillDownUrl || (drillDownField == null ? void 0 : drillDownField.drillDown) || (drillDownField == null ? void 0 : drillDownField.drillDown) !== route.path ? concat8((drillDownField == null ? void 0 : drillDownField.drillDownType) !== DrillDownType.inner ? of14(bcFetchRowMetaSuccess({ bcName, rowMeta, bcUrl, cursor })) : EMPTY10, of14(userDrillDownSuccess({ bcName, bcUrl, cursor })), of14(drillDown({
2016
- url: customDrillDownUrl || drillDownField.drillDown,
2017
- drillDownType: drillDownField.drillDownType,
2018
- route
2019
- }))) : EMPTY10;
2020
- }), catchError5((error) => {
2021
- console.error(error);
2022
- return createApiErrorObservable(error);
2023
- }));
2024
- }));
2025
- // src/epics/router/changeLocationEpic.ts
2026
- import { concat as concat9, EMPTY as EMPTY11, filter as filter16, mergeMap as mergeMap11, of as of15 } from "rxjs";
2027
- var changeLocationEpic = (action$, state$) => action$.pipe(filter16(changeLocation.match), mergeMap11((action) => {
2028
- var _a, _b;
2029
- const state = state$.value;
2030
- if (!state.session.active) {
2031
- return EMPTY11;
2032
- }
2033
- if (state.router.type === "router" /* router */) {
2034
- return of15(handleRouter(state.router));
2035
- }
2036
- const currentScreenName = state.screen.screenName;
2037
- const defaultScreenName = ((_a = state.session.screens.find((screen) => screen.defaultScreen)) == null ? void 0 : _a.name) || ((_b = state.session.screens[0]) == null ? void 0 : _b.name);
2038
- const nextScreenName = state.router.type === "default" /* default */ ? defaultScreenName : state.router.screenName;
2039
- if (nextScreenName !== currentScreenName || action.payload.forceUpdate) {
2040
- const nextScreen = state.session.screens.find((item) => item.name === nextScreenName);
2041
- return nextScreen ? of15(selectScreen({ screen: nextScreen })) : of15(selectScreenFail({ screenName: nextScreenName }));
2042
- }
2043
- const currentViewName = state.view.name;
2044
- const nextViewName = state.router.viewName;
2045
- const nextCursors = parseBcCursors(state.router.bcPath) || {};
2046
- const cursorsDiffMap = {};
2047
- Object.entries(nextCursors).forEach((entry) => {
2048
- const [bcName, cursor] = entry;
2049
- const bc = state.screen.bo.bc[bcName];
2050
- if (!bc || (bc == null ? void 0 : bc.cursor) !== cursor) {
2051
- cursorsDiffMap[bcName] = cursor;
2052
- }
2053
- });
2054
- const needUpdateCursors = Object.keys(cursorsDiffMap).length;
2055
- const needUpdateViews = nextViewName !== currentViewName;
2056
- const resultObservables = [];
2057
- if (needUpdateCursors) {
2058
- resultObservables.push(of15(bcChangeCursors({ cursorsMap: cursorsDiffMap })));
2059
- }
2060
- if (needUpdateViews) {
2061
- const nextView = nextViewName ? state.screen.views.find((item) => item.name === nextViewName) : state.screen.primaryView ? state.screen.views.find((item) => item.name === state.screen.primaryView) : state.screen.views[0];
2062
- resultObservables.push(nextView ? of15(selectView(nextView)) : of15(selectViewFail({ viewName: nextViewName })));
2063
- }
2064
- if (needUpdateCursors && !needUpdateViews) {
2065
- Object.entries(nextCursors).forEach((entry) => {
2066
- const [bcName, cursor] = entry;
2067
- if (!state.data[bcName].find((item) => item.id === cursor)) {
2068
- resultObservables.push(of15(bcForceUpdate({ bcName })));
2069
- }
2070
- });
2071
- }
2072
- return concat9(...resultObservables);
2073
- }));
2074
- // src/epics/router/selectViewFailEpic.ts
2075
- import { filter as filter17, map as map2 } from "rxjs";
2076
- var selectViewFailEpic = (action$, state$) => action$.pipe(filter17(selectViewFail.match), map2((action) => {
2077
- return addNotification({
2078
- type: "error",
2079
- key: "selectViewFail",
2080
- message: "View is missing or unavailable for your role",
2081
- options: {
2082
- messageOptions: { viewName: action.payload.viewName }
2083
- },
2084
- duration: 15
2085
- });
2086
- }));
2087
- // src/epics/router/selectScreenFailEpic.ts
2088
- import { filter as filter18, map as map3 } from "rxjs";
2089
- var selectScreenFailEpic = (action$) => action$.pipe(filter18(selectScreenFail.match), map3((action) => {
2090
- return addNotification({
2091
- type: "error",
2092
- key: "selectScreenFail",
2093
- message: "Screen is missing or unavailable for your role",
2094
- options: {
2095
- messageOptions: { screenName: action.payload.screenName }
2096
- },
2097
- duration: 15
2098
- });
2099
- }));
2100
- // src/epics/router/userDrilldownChangeCursorsEpic.ts
2101
- import { filter as filter19, map as map4 } from "rxjs";
2102
- var userDrillDownChangeCursorsEpic = (action$, state$) => action$.pipe(filter19(userDrillDown.match), map4((action) => {
2103
- var _a;
2104
- const state = state$.value;
2105
- const widget = state.view.widgets.find((item) => item.name === action.payload.widgetName);
2106
- const cursor = (_a = state.screen.bo.bc[widget == null ? void 0 : widget.bcName]) == null ? void 0 : _a.cursor;
2107
- if (cursor !== action.payload.cursor) {
2108
- return bcChangeCursors({ cursorsMap: { [action.payload.bcName]: action.payload.cursor } });
2109
- }
2110
- return emptyAction;
2111
- }));
2112
- // src/epics/screen/apiErrorEpic.ts
2113
- import axios from "axios";
2114
- import { EMPTY as EMPTY12, filter as filter20, mergeMap as mergeMap12, of as of16 } from "rxjs";
2115
- var apiErrorEpic = (action$) => action$.pipe(filter20(apiError.match), mergeMap12((action) => {
2116
- const { error, callContext } = action.payload;
2117
- if (error.response) {
2118
- return of16(httpError({
2119
- statusCode: error.response.status,
2120
- error,
2121
- callContext
2122
- }));
2123
- }
2124
- else if (!axios.isCancel(error)) {
2125
- return of16(showViewError({
2126
- error: {
2127
- type: 2 /* NetworkError */
2128
- }
2129
- }));
2130
- }
2131
- return EMPTY12;
2132
- }));
2133
- // src/epics/screen/downloadFileEpic.ts
2134
- import { EMPTY as EMPTY13, filter as filter21, mergeMap as mergeMap13, tap } from "rxjs";
2135
- var downloadFileEpic = (action$, state$, { api }) => action$.pipe(filter21(downloadFile.match), tap((action) => {
2136
- const { fileId } = action.payload;
2137
- const anchor = document.createElement("a");
2138
- anchor.href = `${api.fileUploadEndpoint}?id=${encodeURIComponent(fileId)}`;
2139
- anchor.style.display = "none";
2140
- document.body.appendChild(anchor);
2141
- setTimeout(() => {
2142
- anchor.click();
2143
- document.body.removeChild(anchor);
2144
- }, 100);
2145
- }), mergeMap13(() => EMPTY13));
2146
- // src/epics/screen/httpError401Epic.ts
2147
- import { filter as filter22, map as map5 } from "rxjs";
2148
- var httpError401Epic = (action$) => action$.pipe(filter22(httpError.match), filter22((action) => action.payload.statusCode === 401), map5((action) => {
2149
- return logoutDone(null);
2150
- }));
2151
- // src/epics/screen/httpError409Epic.ts
2152
- import { filter as filter23, map as map6 } from "rxjs";
2153
- var httpError409Epic = (action$, state$) => action$.pipe(filter23(httpError.match), filter23((action) => action.payload.statusCode === 409), map6((action) => {
2154
- var _a, _b, _c;
2155
- const notificationMessage = ((_c = (_b = ((_a = action.payload.error.response) == null ? void 0 : _a.data).error) == null ? void 0 : _b.popup) == null ? void 0 : _c[0]) || "";
2156
- return addNotification({
2157
- key: "action_edit_error",
2158
- message: notificationMessage,
2159
- type: "buttonWarningNotification",
2160
- duration: 0,
2161
- options: {
2162
- buttonWarningNotificationOptions: {
2163
- buttonText: "OK"
2164
- }
2165
- }
2166
- });
2167
- }));
2168
- // src/epics/screen/httpError418Epic.ts
2169
- import { concat as concat10, EMPTY as EMPTY14, filter as filter24, mergeMap as mergeMap14, of as of17 } from "rxjs";
2170
- var httpError418Epic = (action$, state$) => action$.pipe(filter24(httpError.match), filter24((action) => action.payload.statusCode === 418), mergeMap14((action) => {
2171
- var _a, _b;
2172
- const { error, callContext } = action.payload;
2173
- const result = [];
2174
- const typedError = (_a = error.response) == null ? void 0 : _a.data;
2175
- if (!typedError.error.popup) {
2176
- return EMPTY14;
2177
- }
2178
- const businessError = {
2179
- type: 0 /* BusinessError */,
2180
- message: typedError.error.popup[0]
2181
- };
2182
- result.push(of17(showViewError({ error: businessError })));
2183
- if ((_b = typedError.error.postActions) == null ? void 0 : _b[0]) {
2184
- const widget = state$.value.view.widgets.find((item) => item.name === callContext.widgetName);
2185
- const bcName = widget == null ? void 0 : widget.bcName;
2186
- result.push(of17(processPostInvoke({
2187
- bcName,
2188
- postInvoke: typedError.error.postActions[0],
2189
- widgetName: widget == null ? void 0 : widget.name
2190
- })));
2191
- }
2192
- return concat10(...result);
2193
- }));
2194
- // src/epics/screen/httpError500Epic.ts
2195
- import { filter as filter25, map as map7 } from "rxjs";
2196
- var httpError500Epic = (action$, state$) => action$.pipe(filter25(httpError.match), filter25((action) => action.payload.statusCode === 500), map7((action) => {
2197
- var _a;
2198
- const systemError = {
2199
- type: 1 /* SystemError */,
2200
- details: ((_a = action.payload.error.response) == null ? void 0 : _a.statusText) || "",
2201
- error: action.payload.error
2202
- };
2203
- return showViewError({ error: systemError });
2204
- }));
2205
- // src/epics/screen/httpErrorDefaultEpic.ts
2206
- import { filter as filter26, map as map8 } from "rxjs";
2207
- var knownHttpErrors = [401, 409, 418, 500];
2208
- var httpErrorDefaultEpic = (action$, state$) => action$.pipe(filter26(httpError.match), filter26((action) => !knownHttpErrors.includes(action.payload.statusCode)), map8((action) => {
2209
- var _a, _b;
2210
- const businessError = {
2211
- type: 0 /* BusinessError */,
2212
- code: (_a = action.payload.error.response) == null ? void 0 : _a.status,
2213
- details: (_b = action.payload.error.response) == null ? void 0 : _b.data
2214
- };
2215
- return showViewError({ error: businessError });
2216
- }));
2217
- // src/epics/screen/downloadFileByUrlEpic.ts
2218
- import { EMPTY as EMPTY15, filter as filter27, mergeMap as mergeMap15, tap as tap2 } from "rxjs";
2219
- var downloadFileByUrlEpic = (action$, state$) => action$.pipe(filter27(downloadFileByUrl.match), tap2((action) => {
2220
- const { url } = action.payload;
2221
- const anchor = document.createElement("a");
2222
- anchor.href = url;
2223
- anchor.style.display = "none";
2224
- document.body.appendChild(anchor);
2225
- setTimeout(() => {
2226
- anchor.click();
2227
- document.body.removeChild(anchor);
2228
- }, 100);
2229
- }), mergeMap15(() => EMPTY15));
2230
- // src/epics/screen/processPostInvokeEpic.ts
2231
- import { EMPTY as EMPTY16, filter as filter28, mergeMap as mergeMap16, of as of18 } from "rxjs";
2232
- var processPostInvokeEpic = (action$, state$) => action$.pipe(filter28(processPostInvoke.match), mergeMap16((action) => {
2233
- var _a;
2234
- const state = state$.value;
2235
- switch (action.payload.postInvoke.type) {
2236
- case "drillDown" /* drillDown */:
2237
- return of18(drillDown(__spreadProps(__spreadValues({}, action.payload.postInvoke), {
2238
- route: state.router,
2239
- widgetName: action.payload.widgetName
2240
- })));
2241
- case "postDelete" /* postDelete */: {
2242
- const cursorsMap = { [action.payload.bcName]: null };
2243
- const result = [bcChangeCursors({ cursorsMap })];
2244
- if ((_a = state.router.bcPath) == null ? void 0 : _a.includes(`${action.payload.bcName}/`)) {
2245
- const newBcUrl = state.router.bcPath.split(action.payload.bcName)[0] || "";
2246
- const newUrl = `/screen/${state.router.screenName}/view/${state.router.viewName}/${newBcUrl}`;
2247
- result.push(changeLocation({ location: defaultParseURL(new URL(newUrl, window.location.origin)) }));
2248
- }
2249
- else {
2250
- result.push(bcFetchDataRequest({
2251
- bcName: action.payload.bcName,
2252
- widgetName: action.payload.widgetName
2253
- }));
2254
- }
2255
- return of18(...result);
2256
- }
2257
- case "refreshBC" /* refreshBC */: {
2258
- const bo = state.screen.bo;
2259
- const postInvoke = action.payload.postInvoke;
2260
- const postInvokeBC = postInvoke.bc;
2261
- const postInvokeBCItem = bo.bc[postInvoke.bc];
2262
- const widgetName = action.payload.widgetName || "";
2263
- const infiniteWidgets = state.view.infiniteWidgets || [];
2264
- const infinitePagination = state.view.widgets.some((item) => item.bcName === postInvokeBC && infiniteWidgets.includes(item.name));
2265
- return infinitePagination ? of18(bcFetchDataPages({
2266
- bcName: postInvokeBCItem == null ? void 0 : postInvokeBCItem.name,
2267
- widgetName,
2268
- from: 1,
2269
- to: postInvokeBCItem == null ? void 0 : postInvokeBCItem.page
2270
- })) : of18(bcFetchDataRequest({
2271
- bcName: postInvokeBCItem == null ? void 0 : postInvokeBCItem.name,
2272
- widgetName
2273
- }));
2274
- }
2275
- case "showMessage" /* showMessage */: {
2276
- const postInvoke = action.payload.postInvoke;
2277
- return of18(showNotification({ type: postInvoke.messageType, message: postInvoke.messageText }));
2278
- }
2279
- case "downloadFile" /* downloadFile */: {
2280
- const postInvoke = action.payload.postInvoke;
2281
- return of18(downloadFile({ fileId: postInvoke.fileId }));
2282
- }
2283
- case "downloadFileByUrl" /* downloadFileByUrl */: {
2284
- const postInvoke = action.payload.postInvoke;
2285
- return of18(downloadFileByUrl({ url: postInvoke.url }));
2286
- }
2287
- default:
2288
- return EMPTY16;
2289
- }
2290
- }));
2291
- // src/epics/screen/processPostInvokeConfirmEpic.ts
2292
- import { EMPTY as EMPTY17, filter as filter29, mergeMap as mergeMap17, of as of19 } from "rxjs";
2293
- import { isAnyOf } from "@reduxjs/toolkit";
2294
- var processPostInvokeConfirmEpic = (action$, state$) => action$.pipe(filter29(isAnyOf(processPostInvokeConfirm, processPreInvoke)), mergeMap17((action) => {
2295
- const { bcName, operationType, widgetName } = action.payload;
2296
- const confirm = processPostInvokeConfirm.match(action) ? action.payload.postInvokeConfirm : action.payload.preInvoke;
2297
- switch (confirm.type) {
2298
- case "confirm" /* confirm */:
2299
- case "info" /* info */:
2300
- case "error" /* error */:
2301
- case "confirmText" /* confirmText */: {
2302
- return of19(operationConfirmation({
2303
- operation: {
2304
- bcName,
2305
- operationType,
2306
- widgetName
2307
- },
2308
- confirmOperation: confirm
2309
- }));
2310
- }
2311
- default:
2312
- return EMPTY17;
2313
- }
2314
- }));
2315
- // src/epics/session/switchRoleEpic.ts
2316
- import { concat as concat11, filter as filter30, switchMap as switchMap7 } from "rxjs";
2317
- var switchRoleEpic = (action$, state$) => action$.pipe(filter30(switchRole.match), switchMap7((action) => {
2318
- return concat11([logoutDone(null), login({ login: "", password: "", role: action.payload.role })]);
2319
- }));
2320
- // src/epics/session/refreshMetaEpic.ts
2321
- import { catchError as catchError6, concat as concat12, filter as filter31, mergeMap as mergeMap18, switchMap as switchMap8 } from "rxjs";
2322
- var refreshMetaEpic = (action$, state$, { api }) => action$.pipe(filter31(refreshMeta.match), mergeMap18(() => {
2323
- const state = state$.value;
2324
- const { activeRole } = state.session;
2325
- return api.refreshMeta().pipe(switchMap8(() => concat12([refreshMetaDone(), logoutDone(null), login({ login: "", password: "", role: activeRole })])), catchError6((error) => concat12([loginFail(error), refreshMetaFail(), createApiError(error)])));
2326
- }));
2327
- // src/epics/session/loginDoneEpic.ts
2328
- import { EMPTY as EMPTY18, filter as filter32, switchMap as switchMap9 } from "rxjs";
2329
- var loginDoneSessionEpic = (action$, store) => action$.pipe(filter32(login.match), switchMap9((action) => EMPTY18));
2330
- // src/epics/session/loginByAnotherRoleEpic.ts
2331
- import { catchError as catchError7, concat as concat13, filter as filter33, mergeMap as mergeMap19, of as of20, switchMap as switchMap10 } from "rxjs";
2332
- var responseStatusMessages = {
2333
- 401: "Invalid credentials",
2334
- 403: "Access denied"
2335
- };
2336
- var loginByAnotherRoleEpic = (action$, state$, { api }) => action$.pipe(filter33(login.match), filter33((action) => {
2337
- var _a;
2338
- return !!((_a = action.payload) == null ? void 0 : _a.role);
2339
- }), switchMap10((action) => {
2340
- var _a;
2341
- const role = (_a = action.payload.role) != null ? _a : "";
2342
- const isSwitchRole = role && role !== state$.value.session.activeRole;
2343
- return api.loginByRoleRequest(role).pipe(mergeMap19((data) => {
2344
- var _a2;
2345
- const result = [];
2346
- if (isSwitchRole) {
2347
- const defaultScreen = data.screens.find((screen) => screen.defaultScreen) || data.screens[0];
2348
- const defaultViewName = (_a2 = defaultScreen == null ? void 0 : defaultScreen.primary) != null ? _a2 : defaultScreen.meta.views[0].name;
2349
- const defaultView = defaultScreen == null ? void 0 : defaultScreen.meta.views.find((view) => defaultViewName === view.name);
2350
- if (defaultView)
2351
- result.push(changeLocation({ location: defaultParseURL(new URL(defaultView.url, window.location.origin)) }));
2352
- }
2353
- return concat13([
2354
- ...result,
2355
- loginDone({
2356
- devPanelEnabled: data.devPanelEnabled,
2357
- activeRole: data.activeRole,
2358
- roles: data.roles,
2359
- screens: data.screens,
2360
- firstName: data.firstName,
2361
- lastName: data.lastName,
2362
- login: data.login
2363
- })
2364
- ]);
2365
- }), catchError7((error) => {
2366
- console.error(error);
2367
- const errorMsg = error.response ? responseStatusMessages[error.response.status] || "Server application unavailable" : "Empty server response";
2368
- return concat13(of20(loginFail({ errorMsg })), createApiErrorObservable(error));
2369
- }));
2370
- }));
2371
- // src/epics/session/refreshMetaAndReloadPageEpic.ts
2372
- import { concat as concat14, EMPTY as EMPTY19, filter as filter34, of as of21, switchMap as switchMap11, take, tap as tap3 } from "rxjs";
2373
- var refreshMetaAndReloadPageEpic = (action$, state$) => action$.pipe(filter34(refreshMetaAndReloadPage.match), switchMap11(() => concat14(of21(refreshMeta()), action$.pipe(filter34(loginDone.match), take(1), tap3(() => location.reload()), switchMap11(() => EMPTY19)))));
2374
- // src/epics/data/bcNewDataEpic.ts
2375
- import { catchError as catchError8, concat as concat15, EMPTY as EMPTY20, filter as filter35, mergeMap as mergeMap20, of as of22 } from "rxjs";
2376
- import { OperationTypeCrud as OperationTypeCrud8 } from "@cxbox-ui/schema";
2377
- var bcNewDataEpic = (action$, state$, { api }) => action$.pipe(filter35(sendOperation.match), filter35((action) => matchOperationRole(OperationTypeCrud8.create, action.payload, state$.value)), mergeMap20((action) => {
2378
- var _a;
2379
- const state = state$.value;
2380
- const bcName = action.payload.bcName;
2381
- const bcUrl = (_a = buildBcUrl(bcName, false, state)) != null ? _a : "";
2382
- const context = { widgetName: action.payload.widgetName };
2383
- const params = { _action: action.payload.operationType };
2384
- return api.newBcData(state.screen.screenName, bcUrl, context, params).pipe(mergeMap20((data) => {
2385
- var _a2, _b;
2386
- const rowMeta = data.row;
2387
- const dataItem = { id: null, vstamp: -1 };
2388
- data.row.fields.forEach((field) => {
2389
- dataItem[field.key] = field.currentValue;
2390
- });
2391
- const postInvoke = (_a2 = data.postActions) == null ? void 0 : _a2[0];
2392
- const cursor = dataItem.id;
2393
- return concat15(of22(bcNewDataSuccess({ bcName, dataItem, bcUrl })), of22(bcFetchRowMetaSuccess({ bcName, bcUrl: `${bcUrl}/${cursor}`, rowMeta, cursor })), of22(changeDataItem({
2394
- bcName,
2395
- bcUrl: (_b = buildBcUrl(bcName, true, state)) != null ? _b : "",
2396
- cursor,
2397
- dataItem: {
2398
- id: cursor
2399
- }
2400
- })), postInvoke ? of22(processPostInvoke({ bcName, postInvoke, cursor, widgetName: action.payload.widgetName })) : EMPTY20);
2401
- }), catchError8((error) => {
2402
- console.error(error);
2403
- return concat15(of22(bcNewDataFail({ bcName })), createApiErrorObservable(error, context));
2404
- }));
2405
- }));
2406
- // src/epics/data/bcLoadMoreEpic.ts
2407
- import { catchError as catchError9, concat as concat16, filter as filter37, mergeMap as mergeMap22, of as of24, race } from "rxjs";
2408
- // src/utils/cancelRequestEpic.ts
2409
- import { filter as filter36, mergeMap as mergeMap21, of as of23, take as take2 } from "rxjs";
2410
- import { isAnyOf as isAnyOf2 } from "@reduxjs/toolkit";
2411
- var cancelRequestActionTypes = [selectView, logout];
2412
- function cancelRequestEpic(action$, actionTypes, cancelFn, cancelActionCreator, filterFn = (item) => {
2413
- return true;
2414
- }) {
2415
- return action$.pipe(filter36(isAnyOf2(...actionTypes)), filter36(filterFn), mergeMap21(() => {
2416
- cancelFn == null ? void 0 : cancelFn();
2417
- return of23(cancelActionCreator);
2418
- }), take2(1));
2419
- }
2420
- // src/epics/data/bcLoadMoreEpic.ts
2421
- var bcLoadMoreEpic = (action$, state$, { api }) => action$.pipe(filter37(bcLoadMore.match), mergeMap22((action) => {
2422
- var _a, _b;
2423
- const state = state$.value;
2424
- const bcName = action.payload.bcName;
2425
- const bc = state.screen.bo.bc[bcName];
2426
- const { cursor, page } = bc;
2427
- const limit = ((_a = state.view.widgets.find((i) => i.bcName === bcName)) == null ? void 0 : _a.limit) || bc.limit;
2428
- const limitBySelfCursor = (_b = state.router.bcPath) == null ? void 0 : _b.includes(`${bcName}/${cursor}`);
2429
- const bcUrl = buildBcUrl(bcName, limitBySelfCursor, state);
2430
- const filters = state.screen.filters[bcName] || [];
2431
- const sorters = state.screen.sorters[bcName];
2432
- const fetchParams = __spreadValues(__spreadValues({
2433
- _page: page,
2434
- _limit: limit
2435
- }, getFilters(filters)), getSorters(sorters));
2436
- const canceler = api.createCanceler();
2437
- const cancelFlow = cancelRequestEpic(action$, cancelRequestActionTypes, canceler.cancel, bcFetchDataFail({ bcName, bcUrl }));
2438
- const normalFlow = api.fetchBcData(state.screen.screenName, bcUrl, fetchParams, canceler.cancelToken).pipe(mergeMap22((data) => {
2439
- var _a2;
2440
- const oldBcDataIds = (_a2 = state.data[bcName]) == null ? void 0 : _a2.map((i) => i.id);
2441
- const newData = [...state.data[bcName], ...data.data.filter((i) => !oldBcDataIds.includes(i.id))];
2442
- return of24(bcFetchDataSuccess({
2443
- bcName,
2444
- data: newData,
2445
- bcUrl,
2446
- hasNext: data.hasNext
2447
- }));
2448
- }), catchError9((error) => {
2449
- console.error(error);
2450
- return concat16(of24(bcFetchDataFail({ bcName, bcUrl })), createApiErrorObservable(error));
2451
- }));
2452
- return race(cancelFlow, normalFlow);
2453
- }));
2454
- // src/epics/data/bcSaveDataEpic.ts
2455
- import { catchError as catchError10, concat as concat17, EMPTY as EMPTY21, filter as filter38, mergeMap as mergeMap23, of as of25 } from "rxjs";
2456
- var bcSaveDataEpic = (action$, state$, { api }) => action$.pipe(filter38(sendOperation.match), filter38((action) => matchOperationRole(OperationTypeCrud.save, action.payload, state$.value)), mergeMap23((action) => {
2457
- var _a, _b, _c, _d;
2458
- const state = state$.value;
2459
- const bcName = action.payload.bcName;
2460
- const bcUrl = (_a = buildBcUrl(bcName, true, state)) != null ? _a : "";
2461
- const widgetName = action.payload.widgetName;
2462
- const cursor = state.screen.bo.bc[bcName].cursor;
2463
- const dataItem = state.data[bcName].find((item) => item.id === cursor);
2464
- const pendingChanges = __spreadValues({}, (_b = state.view.pendingDataChanges[bcName]) == null ? void 0 : _b[cursor]);
2465
- const rowMeta = bcUrl && ((_c = state.view.rowMeta[bcName]) == null ? void 0 : _c[bcUrl]);
2466
- const options = (_d = state.view.widgets.find((widget) => widget.name === widgetName)) == null ? void 0 : _d.options;
2467
- if (rowMeta) {
2468
- const fields = rowMeta.fields;
2469
- for (const key in pendingChanges) {
2470
- if (fields.find((item) => item.key === key && item.disabled)) {
2471
- delete pendingChanges[key];
2472
- }
2473
- }
2474
- }
2475
- const fetchChildrenBcData = Object.entries(getBcChildren(bcName, state.view.widgets, state.screen.bo.bc)).map((entry) => {
2476
- const [childBcName, widgetNames] = entry;
2477
- return bcFetchDataRequest({ bcName: childBcName, widgetName: widgetNames[0] });
2478
- });
2479
- const context = { widgetName: action.payload.widgetName };
2480
- return api.saveBcData(state.screen.screenName, bcUrl, __spreadProps(__spreadValues({}, pendingChanges), { vstamp: dataItem == null ? void 0 : dataItem.vstamp }), context).pipe(mergeMap23((data) => {
2481
- var _a2;
2482
- const postInvoke = (_a2 = data.postActions) == null ? void 0 : _a2[0];
2483
- const responseDataItem = data.record;
2484
- return concat17(of25(bcSaveDataSuccess({ bcName, cursor, dataItem: responseDataItem })), of25(bcFetchRowMeta({ widgetName, bcName })), of25(...fetchChildrenBcData), postInvoke ? of25(processPostInvoke({
2485
- bcName,
2486
- widgetName,
2487
- postInvoke,
2488
- cursor: responseDataItem.id
2489
- })) : EMPTY21, action.payload.onSuccessAction ? of25(action.payload.onSuccessAction) : EMPTY21);
2490
- }), catchError10((e) => {
2491
- var _a2, _b2, _c2, _d2, _e, _f, _g, _h;
2492
- console.error(e);
2493
- let notification$ = EMPTY21;
2494
- if (action.payload.onSuccessAction && !(options == null ? void 0 : options.disableNotification)) {
2495
- notification$ = of25(addNotification({
2496
- key: "data_autosave_undo",
2497
- type: "buttonWarningNotification",
2498
- message: "There are pending changes. Please save them or cancel.",
2499
- duration: 0,
2500
- options: {
2501
- buttonWarningNotificationOptions: {
2502
- buttonText: "Cancel changes",
2503
- actionsForClick: [bcCancelPendingChanges({ bcNames: [bcName] })]
2504
- }
2505
- }
2506
- }));
2507
- }
2508
- let viewError = null;
2509
- let entityError = null;
2510
- const operationError = (_a2 = e.response) == null ? void 0 : _a2.data;
2511
- if (((_b2 = e.response) == null ? void 0 : _b2.data) === Object((_c2 = e.response) == null ? void 0 : _c2.data)) {
2512
- entityError = (_e = (_d2 = operationError == null ? void 0 : operationError.error) == null ? void 0 : _d2.entity) != null ? _e : entityError;
2513
- viewError = (_h = (_g = (_f = operationError == null ? void 0 : operationError.error) == null ? void 0 : _f.popup) == null ? void 0 : _g[0]) != null ? _h : viewError;
2514
- }
2515
- return concat17(of25(bcSaveDataFail({ bcName, bcUrl, viewError, entityError })), notification$, createApiErrorObservable(e, context));
2516
- }));
2517
- }));
2518
- // src/epics/data/selectViewEpic.ts
2519
- import { EMPTY as EMPTY22, filter as filter39, mergeMap as mergeMap24 } from "rxjs";
2520
- var selectViewEpic = (action$, state$) => action$.pipe(filter39(selectView.match), mergeMap24((action) => {
2521
- try {
2522
- const state = state$.value;
2523
- const bcToLoad = {};
2524
- state.view.widgets.filter((widget) => !PopupWidgetTypes.includes(widget.type)).forEach((widget) => {
2525
- if (widget.bcName) {
2526
- let bcName = widget.bcName;
2527
- let parentName = state.screen.bo.bc[widget.bcName].parentName;
2528
- while (parentName) {
2529
- bcName = parentName;
2530
- parentName = state.screen.bo.bc[parentName].parentName;
2531
- }
2532
- if (!bcToLoad[bcName]) {
2533
- bcToLoad[bcName] = widget;
2534
- }
2535
- }
2536
- });
2537
- const result = Object.entries(bcToLoad).map(([bcName, widget]) => {
2538
- return bcFetchDataRequest({ widgetName: widget.name, bcName });
2539
- });
2540
- return result;
2541
- }
2542
- catch (e) {
2543
- console.error(`selectView Epic:: ${e}`);
2544
- return EMPTY22;
2545
- }
2546
- }));
2547
- // src/epics/data/bcFetchDataEpic.ts
2548
- import { catchError as catchError11, concat as concat18, EMPTY as EMPTY23, filter as filter40, mergeMap as mergeMap25, of as of26, race as race2 } from "rxjs";
2549
- import { WidgetTypes as WidgetTypes5 } from "@cxbox-ui/schema";
2550
- import { isAnyOf as isAnyOf3 } from "@reduxjs/toolkit";
2551
- var bcFetchDataEpic = (action$, state$, { api }) => action$.pipe(filter40(isAnyOf3(bcFetchDataRequest, bcFetchDataPages, showViewPopup, bcForceUpdate, bcChangePage)), mergeMap25((action) => {
2552
- const getCursorChange = (data, prevCursor, isHierarchy) => {
2553
- var _a;
2554
- const { bcName } = action.payload;
2555
- const keepDelta = bcFetchDataRequest.match(action) ? action.payload.keepDelta : void 0;
2556
- const newCursor = (_a = data[0]) == null ? void 0 : _a.id;
2557
- return of26(bcChangeCursors({
2558
- cursorsMap: {
2559
- [bcName]: data.some((i) => i.id === prevCursor) ? prevCursor : newCursor
2560
- },
2561
- keepDelta: isHierarchy || keepDelta
2562
- }));
2563
- };
2564
- const getChildrenData = (widgets, bcDictionary, isHierarchy, showConditionCheck) => {
2565
- const { bcName } = action.payload;
2566
- const { ignorePageLimit, keepDelta } = bcFetchDataRequest.match(action) ? action.payload : { ignorePageLimit: void 0, keepDelta: void 0 };
2567
- return concat18(...Object.entries(getBcChildren(bcName, widgets, bcDictionary)).filter(([childBcName, widgetNames]) => {
2568
- const nonLazyWidget = widgets.find((item) => {
2569
- return widgetNames.includes(item.name) && !PopupWidgetTypes.includes(item.type) && showConditionCheck(item);
2570
- });
2571
- const ignoreLazyLoad = showViewPopup.match(action);
2572
- if (ignoreLazyLoad) {
2573
- return true;
2574
- }
2575
- return !!nonLazyWidget;
2576
- }).map(([childBcName, widgetNames]) => {
2577
- const nonLazyWidget = widgets.find((item) => {
2578
- return widgetNames.includes(item.name) && !PopupWidgetTypes.includes(item.type) && showConditionCheck(item);
2579
- });
2580
- return of26(bcFetchDataRequest({
2581
- bcName: childBcName,
2582
- widgetName: nonLazyWidget == null ? void 0 : nonLazyWidget.name,
2583
- ignorePageLimit: ignorePageLimit || showViewPopup.match(action),
2584
- keepDelta: isHierarchy || keepDelta
2585
- }));
2586
- }));
2587
- };
2588
- const bcFetchDataImpl = () => {
2589
- var _a, _b, _c, _d, _e, _f, _g, _h;
2590
- const state = state$.value;
2591
- const { widgetName = "" } = action.payload;
2592
- const { widgets, infiniteWidgets } = state.view;
2593
- const widget = (_a = widgets == null ? void 0 : widgets.find((item) => item.name === widgetName)) != null ? _a : widgets == null ? void 0 : widgets.find((item) => item.bcName === action.payload.bcName);
2594
- if (!widget) {
2595
- return [EMPTY23];
2596
- }
2597
- const bcName = action.payload.bcName;
2598
- const bc = state.screen.bo.bc[bcName];
2599
- const { cursor, page = 1 } = bc;
2600
- const limit = (_c = ((_b = widgets == null ? void 0 : widgets.find((i) => i.bcName === bcName)) == null ? void 0 : _b.limit) || bc.limit) != null ? _c : 5;
2601
- const sorters = state.screen.sorters[bcName];
2602
- if (showViewPopup.match(action) && bcName === action.payload.calleeBCName) {
2603
- return [EMPTY23];
2604
- }
2605
- const anyHierarchyWidget = widgets == null ? void 0 : widgets.find((item) => {
2606
- return item.bcName === widget.bcName && item.type === WidgetTypes5.AssocListPopup && isHierarchyWidget(item);
2607
- });
2608
- const fullHierarchyWidget = (_d = state.view.widgets) == null ? void 0 : _d.find((item) => {
2609
- var _a2;
2610
- return item.bcName === widget.bcName && item.type === WidgetTypes5.AssocListPopup && ((_a2 = item.options) == null ? void 0 : _a2.hierarchyFull);
2611
- });
2612
- const limitBySelfCursor = (_e = state.router.bcPath) == null ? void 0 : _e.includes(`${bcName}/${cursor}`);
2613
- const bcUrl = buildBcUrl(bcName, limitBySelfCursor, state);
2614
- const fetchParams = __spreadValues(__spreadValues({
2615
- _page: page,
2616
- _limit: limit
2617
- }, getFilters(fullHierarchyWidget ? [] : state.screen.filters[bcName] || [])), getSorters(sorters));
2618
- if (bcForceUpdate.match(action)) {
2619
- const infinityPaginationWidget = widgetName && (infiniteWidgets == null ? void 0 : infiniteWidgets.includes(widgetName)) || ((_g = (_f = widgets == null ? void 0 : widgets.filter((item) => item.bcName === bcName)) == null ? void 0 : _f.find((item) => infiniteWidgets == null ? void 0 : infiniteWidgets.includes(item.name))) == null ? void 0 : _g.name);
2620
- if (infinityPaginationWidget) {
2621
- fetchParams._page = 1;
2622
- fetchParams._limit = limit * page;
2623
- }
2624
- }
2625
- if (bcFetchDataPages.match(action)) {
2626
- fetchParams._page = action.payload.from || 1;
2627
- fetchParams._limit = (action.payload.to || page - fetchParams._page) * limit;
2628
- }
2629
- if (bcFetchDataRequest.match(action) && action.payload.ignorePageLimit || ((_h = anyHierarchyWidget == null ? void 0 : anyHierarchyWidget.options) == null ? void 0 : _h.hierarchyFull)) {
2630
- fetchParams._limit = 0;
2631
- }
2632
- const canceler = api.createCanceler();
2633
- const cancelFlow = cancelRequestEpic(action$, cancelRequestActionTypes, canceler.cancel, bcFetchDataFail({ bcName, bcUrl }));
2634
- const cancelByParentBc = cancelRequestEpic(action$, [bcSelectRecord], canceler.cancel, bcFetchDataFail({ bcName, bcUrl }), (filteredAction) => {
2635
- const actionBc = filteredAction.payload.bcName;
2636
- return bc.parentName === actionBc;
2637
- });
2638
- const normalFlow = api.fetchBcData(state.screen.screenName, bcUrl, fetchParams, canceler.cancelToken).pipe(mergeMap25((response) => {
2639
- var _a2, _b2;
2640
- const cursorChange = getCursorChange(response.data, cursor, !!anyHierarchyWidget);
2641
- const parentOfNotLazyWidget = widgets == null ? void 0 : widgets.some((item) => {
2642
- var _a3;
2643
- return ((_a3 = state.screen.bo.bc[item.bcName]) == null ? void 0 : _a3.parentName) === bcName && !PopupWidgetTypes.includes(item.type);
2644
- });
2645
- const isWidgetVisible = (w) => {
2646
- var _a3, _b3, _c2, _d2, _e2, _f2, _g2, _h2, _i;
2647
- if (((_a3 = w.showCondition) == null ? void 0 : _a3.bcName) === ((_b3 = state.screen.bo.bc[w.bcName]) == null ? void 0 : _b3.parentName)) {
2648
- let parentName = (_d2 = state.screen.bo.bc[(_c2 = w.showCondition) == null ? void 0 : _c2.bcName]) == null ? void 0 : _d2.parentName;
2649
- let parent = parentName === bcName;
2650
- while (!parent && parentName) {
2651
- parentName = (_e2 = state.screen.bo.bc[parentName]) == null ? void 0 : _e2.parentName;
2652
- parent = parentName === bcName;
2653
- }
2654
- if (parent) {
2655
- return true;
2656
- }
2657
- }
2658
- const dataToCheck = bcName === ((_f2 = w.showCondition) == null ? void 0 : _f2.bcName) ? response.data : state.data[(_g2 = w.showCondition) == null ? void 0 : _g2.bcName];
2659
- return checkShowCondition(w.showCondition, (_i = state.screen.bo.bc[(_h2 = w.showCondition) == null ? void 0 : _h2.bcName]) == null ? void 0 : _i.cursor, dataToCheck, state.view.pendingDataChanges);
2660
- };
2661
- const lazyWidget = (!isWidgetVisible(widget) || PopupWidgetTypes.includes(widget.type)) && !parentOfNotLazyWidget;
2662
- const skipLazy = ((_a2 = state.view.popupData) == null ? void 0 : _a2.bcName) !== widget.bcName;
2663
- if (lazyWidget && skipLazy) {
2664
- return EMPTY23;
2665
- }
2666
- const fetchChildren = ((_b2 = response.data) == null ? void 0 : _b2.length) ? getChildrenData(widgets, state.screen.bo.bc, !!anyHierarchyWidget, isWidgetVisible) : EMPTY23;
2667
- const fetchRowMeta = of26(bcFetchRowMeta({ widgetName, bcName }));
2668
- return concat18(cursorChange, of26(bcFetchDataSuccess({
2669
- bcName,
2670
- data: response.data,
2671
- bcUrl,
2672
- hasNext: response.hasNext
2673
- })), fetchRowMeta, fetchChildren);
2674
- }), catchError11((error) => {
2675
- console.error(error);
2676
- return concat18(of26(bcFetchDataFail({ bcName: action.payload.bcName, bcUrl })), createApiErrorObservable(error));
2677
- }));
2678
- return [cancelFlow, cancelByParentBc, normalFlow];
2679
- };
2680
- return race2(...bcFetchDataImpl());
2681
- }));
2682
- function isHierarchyWidget(widget) {
2683
- var _a, _b;
2684
- return ((_a = widget.options) == null ? void 0 : _a.hierarchy) || ((_b = widget.options) == null ? void 0 : _b.hierarchyFull);
2685
- }
2686
- // src/epics/data/bcDeleteDataEpic.ts
2687
- import { catchError as catchError12, concat as concat19, EMPTY as EMPTY24, filter as filter41, mergeMap as mergeMap26, of as of27 } from "rxjs";
2688
- import { OperationTypeCrud as OperationTypeCrud9 } from "@cxbox-ui/schema";
2689
- var bcDeleteDataEpic = (action$, store$, { api }) => action$.pipe(filter41(sendOperation.match), filter41((action) => matchOperationRole(OperationTypeCrud9.delete, action.payload, store$.value)), mergeMap26((action) => {
2690
- const widgetName = action.payload.widgetName;
2691
- const state = store$.value;
2692
- const bcName = action.payload.bcName;
2693
- const cursor = state.screen.bo.bc[bcName].cursor;
2694
- const bcUrl = buildBcUrl(bcName, true, state);
2695
- const context = { widgetName: action.payload.widgetName };
2696
- const isTargetFormatPVF = state.view.pendingValidationFailsFormat === "target" /* target */;
2697
- return api.deleteBcData(state.screen.screenName, bcUrl, context).pipe(mergeMap26((data) => {
2698
- var _a;
2699
- const postInvoke = (_a = data.postActions) == null ? void 0 : _a[0];
2700
- return concat19(isTargetFormatPVF ? of27(bcCancelPendingChanges({ bcNames: [bcName] })) : EMPTY24, of27(bcFetchDataRequest({ bcName, widgetName })), postInvoke ? of27(processPostInvoke({ bcName, postInvoke, cursor, widgetName })) : EMPTY24);
2701
- }), catchError12((error) => {
2702
- console.error(error);
2703
- return concat19(of27(bcDeleteDataFail({ bcName })), createApiErrorObservable(error, context));
2704
- }));
2705
- }));
2706
- // src/epics/data/bcSelectRecordEpic.ts
2707
- import { concat as concat20, filter as filter42, mergeMap as mergeMap27, of as of28 } from "rxjs";
2708
- var bcSelectRecordEpic = (action$, store$) => action$.pipe(filter42(bcSelectRecord.match), mergeMap27((action) => {
2709
- const { bcName, cursor } = action.payload;
2710
- const widgets = store$.value.view.widgets;
2711
- const bcMap = store$.value.screen.bo.bc;
2712
- const fetchChildrenBcData = Object.entries(getBcChildren(bcName, widgets, bcMap)).map((entry) => {
2713
- const [childBcName, widgetNames] = entry;
2714
- return bcFetchDataRequest({
2715
- bcName: childBcName,
2716
- widgetName: widgetNames[0],
2717
- ignorePageLimit: action.payload.ignoreChildrenPageLimit,
2718
- keepDelta: action.payload.keepDelta
2719
- });
2720
- });
2721
- return concat20(of28(bcChangeCursors({ cursorsMap: { [bcName]: cursor }, keepDelta: action.payload.keepDelta })), of28(bcFetchRowMeta({ widgetName: "", bcName })), fetchChildrenBcData);
2722
- }));
2723
- // src/epics/data/changeAssociationEpic.ts
2724
- import { concat as concat21, filter as filter43, mergeMap as mergeMap28, of as of29 } from "rxjs";
2725
- var changeAssociationEpic = (action$, state$) => action$.pipe(filter43(changeAssociation.match), mergeMap28((action) => {
2726
- var _a, _b, _c, _d, _e;
2727
- const state = state$.value;
2728
- const selected = action.payload.dataItem._associate;
2729
- const bcName = action.payload.bcName;
2730
- const result = [
2731
- of29(changeDataItem({
2732
- bcName,
2733
- bcUrl: buildBcUrl(bcName, true, state),
2734
- cursor: action.payload.dataItem.id,
2735
- dataItem: action.payload.dataItem
2736
- }))
2737
- ];
2738
- const widget = state.view.widgets.find((item) => item.name === action.payload.widgetName);
2739
- const isRoot = action.payload.bcName === widget.bcName;
2740
- const rootHierarchyDescriptor = {
2741
- bcName: widget.bcName,
2742
- radio: (_a = widget.options) == null ? void 0 : _a.hierarchyRadio,
2743
- fields: widget.fields
2744
- };
2745
- const hierarchy = (_b = widget.options) == null ? void 0 : _b.hierarchy;
2746
- const hierarchyDescriptor = isRoot ? rootHierarchyDescriptor : hierarchy == null ? void 0 : hierarchy.find((item) => item.bcName === action.payload.bcName);
2747
- const hierarchyGroupSelection = (_c = widget.options) == null ? void 0 : _c.hierarchyGroupSelection;
2748
- const hierarchyTraverse = (_d = widget.options) == null ? void 0 : _d.hierarchyTraverse;
2749
- const childrenBc = hierarchy == null ? void 0 : hierarchy.slice(hierarchy.findIndex((item) => item.bcName === action.payload.bcName) + 1).map((item) => item.bcName);
2750
- if (hierarchyGroupSelection && hierarchyDescriptor.radio && !selected) {
2751
- result.push(of29(dropAllAssociations({
2752
- bcNames: childrenBc
2753
- })));
2754
- }
2755
- const parent = isRoot ? null : (hierarchy == null ? void 0 : hierarchy.find((item, index) => {
2756
- var _a2;
2757
- return ((_a2 = hierarchy[index + 1]) == null ? void 0 : _a2.bcName) === action.payload.bcName;
2758
- })) || rootHierarchyDescriptor;
2759
- const parentItem = (_e = state.data[parent == null ? void 0 : parent.bcName]) == null ? void 0 : _e.find((item) => item.id === state.screen.bo.bc[parent == null ? void 0 : parent.bcName].cursor);
2760
- if (parent && hierarchyTraverse && selected) {
2761
- if (hierarchyDescriptor.radio) {
2762
- result.push(of29(dropAllAssociations({
2763
- bcNames: [parent.bcName]
2764
- })));
2765
- }
2766
- result.push(of29(changeAssociation({
2767
- bcName: parent.bcName,
2768
- widgetName: action.payload.widgetName,
2769
- dataItem: __spreadProps(__spreadValues({}, parentItem), {
2770
- _associate: true,
2771
- _value: parentItem == null ? void 0 : parentItem[parent.assocValueKey || action.payload.assocValueKey]
2772
- }),
2773
- assocValueKey: action.payload.assocValueKey
2774
- })));
2775
- }
2776
- if (parent && hierarchyTraverse && !selected) {
2777
- const data = state.data[action.payload.bcName];
2778
- const wasLastInData = data.filter((item) => item.id !== action.payload.dataItem.id).every((item) => !item._associate);
2779
- const delta = state.view.pendingDataChanges[action.payload.bcName];
2780
- const wasLastInDelta = !delta || !Object.values(delta).find((deltaValue) => {
2781
- return deltaValue._associate === true && deltaValue.id !== action.payload.dataItem.id && // Filter by dataEpics.ts records, because delta can contain records from another hierarchy branch, but dataEpics.ts always contains
2782
- // only target branch records, that we see in widget
2783
- data.find((dataValue) => dataValue.id === deltaValue.id);
2784
- });
2785
- if (wasLastInData && wasLastInDelta) {
2786
- result.push(of29(changeAssociation({
2787
- bcName: parent.bcName,
2788
- widgetName: action.payload.widgetName,
2789
- dataItem: __spreadProps(__spreadValues({}, parentItem), { _associate: false }),
2790
- assocValueKey: action.payload.assocValueKey
2791
- })));
2792
- }
2793
- }
2794
- return concat21(...result);
2795
- }));
2796
- // src/epics/data/bcCancelCreateDataEpic.ts
2797
- import { catchError as catchError13, concat as concat22, EMPTY as EMPTY25, filter as filter44, mergeMap as mergeMap29, of as of30 } from "rxjs";
2798
- import { OperationTypeCrud as OperationTypeCrud10 } from "@cxbox-ui/schema";
2799
- import { isAnyOf as isAnyOf4 } from "@reduxjs/toolkit";
2800
- var actionTypesMatcher = isAnyOf4(sendOperation);
2801
- var bcCancelCreateDataEpic = (action$, state$, { api }) => action$.pipe(filter44(actionTypesMatcher), filter44((action) => matchOperationRole(OperationTypeCrud10.cancelCreate, action.payload, state$.value)), mergeMap29((action) => {
2802
- var _a, _b;
2803
- const state = state$.value;
2804
- const screenName = state.screen.screenName;
2805
- const bcName = action.payload.bcName;
2806
- const bcUrl = buildBcUrl(bcName, true, state);
2807
- const bc = state.screen.bo.bc[bcName];
2808
- const cursor = bc == null ? void 0 : bc.cursor;
2809
- const context = { widgetName: action.payload.widgetName };
2810
- const record = (_a = state.data[bcName]) == null ? void 0 : _a.find((item) => item.id === bc.cursor);
2811
- const pendingRecordChange = (_b = state.view.pendingDataChanges[bcName]) == null ? void 0 : _b[bc.cursor];
2812
- const data = record && __spreadProps(__spreadValues({}, pendingRecordChange), { vstamp: record.vstamp });
2813
- const params = { _action: action.payload.operationType };
2814
- const cursorsMap = { [action.payload.bcName]: null };
2815
- return api.customAction(screenName, bcUrl, data, context, params).pipe(mergeMap29((response) => {
2816
- var _a2;
2817
- const postInvoke = (_a2 = response.postActions) == null ? void 0 : _a2[0];
2818
- return concat22(of30(sendOperationSuccess({ bcName, cursor })), of30(bcChangeCursors({ cursorsMap })), postInvoke ? of30(processPostInvoke({ bcName, postInvoke, cursor, widgetName: context.widgetName })) : EMPTY25);
2819
- }), catchError13((error) => {
2820
- console.error(error);
2821
- return concat22(of30(bcDeleteDataFail({ bcName })), createApiErrorObservable(error, context));
2822
- }));
2823
- }));
2824
- // src/epics/data/bcSelectDepthRecordEpic.ts
2825
- import { concat as concat23, filter as filter45, mergeMap as mergeMap30, of as of31 } from "rxjs";
2826
- var bcSelectDepthRecordEpic = (action$) => action$.pipe(filter45(bcSelectDepthRecord.match), mergeMap30((action) => {
2827
- const { bcName, cursor, depth } = action.payload;
2828
- return concat23(of31(bcChangeDepthCursor({ bcName, depth, cursor })), of31(bcFetchDataRequest({
2829
- bcName,
2830
- depth: depth + 1,
2831
- widgetName: "",
2832
- ignorePageLimit: true
2833
- })));
2834
- }));
2835
- // src/epics/data/removeMultivalueTagEpic.ts
2836
- import { concat as concat24, filter as filter46, mergeMap as mergeMap31, of as of32 } from "rxjs";
2837
- var removeMultivalueTagEpic = (action$, state$) => action$.pipe(filter46(removeMultivalueTag.match), mergeMap31((action) => {
2838
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2839
- const state = state$.value;
2840
- const { bcName, cursor, popupBcName, associateFieldKey } = action.payload;
2841
- const widget = state.view.widgets.find((item) => item.bcName === popupBcName && PopupWidgetTypes.includes(item.type));
2842
- const storeData = (state == null ? void 0 : state.data[popupBcName]) || [];
2843
- let data = storeData.map((item) => {
2844
- var _a2;
2845
- const pendingChanges = (_a2 = state.view.pendingDataChanges[popupBcName]) == null ? void 0 : _a2[item.id];
2846
- return __spreadValues(__spreadValues({}, item), pendingChanges);
2847
- });
2848
- const removedItem = data.find((item) => item.id === action.payload.removedItem.id);
2849
- const associated = action.payload.dataItem.map((item) => item.id);
2850
- let removedNodes = [];
2851
- if ((_a = widget == null ? void 0 : widget.options) == null ? void 0 : _a.hierarchyGroupDeselection) {
2852
- if ((_b = widget == null ? void 0 : widget.options) == null ? void 0 : _b.hierarchyTraverse) {
2853
- data = assignTreeLinks(data);
2854
- }
2855
- const removedItemChildren = data.filter((item) => item.parentId === (removedItem == null ? void 0 : removedItem.id));
2856
- removedNodes = [removedItem == null ? void 0 : removedItem.id, ...removedItemChildren.filter((item) => associated.includes(item.id)).map((item) => item.id)];
2857
- if ((_c = widget == null ? void 0 : widget.options) == null ? void 0 : _c.hierarchyTraverse) {
2858
- getDescendants(removedItemChildren, removedNodes);
2859
- removedNodes = data.filter((item) => removedNodes.includes(item.id) && associated.includes(item.id)).map((item) => item.id);
2860
- }
2861
- const parent = data.find((item) => item.id === (removedItem == null ? void 0 : removedItem.parentId));
2862
- const siblings = data.filter((item) => item.parentId === (parent == null ? void 0 : parent.id));
2863
- const parentEmpty = siblings.every((child) => removedNodes.includes(child.id) || !associated.includes(child.id));
2864
- if (parent && parentEmpty) {
2865
- if ((_d = widget == null ? void 0 : widget.options) == null ? void 0 : _d.hierarchyTraverse) {
2866
- const parentDescendants = [];
2867
- getDescendants(siblings, parentDescendants);
2868
- const parentDeepEmpty = parentDescendants.every((descendant) => {
2869
- return removedNodes.includes(descendant) || !associated.includes(descendant);
2870
- });
2871
- if (parentDeepEmpty) {
2872
- return concat24(of32(removeMultivalueTag(__spreadProps(__spreadValues({}, action.payload), {
2873
- removedItem: { id: parent.id, value: null }
2874
- }))));
2875
- }
2876
- }
2877
- else {
2878
- removedNodes.push(parent.id);
2879
- }
2880
- }
2881
- }
2882
- if ((_e = widget == null ? void 0 : widget.options) == null ? void 0 : _e.hierarchyFull) {
2883
- return of32(changeDataItem({
2884
- bcName,
2885
- bcUrl: buildBcUrl(bcName, true, state),
2886
- cursor,
2887
- dataItem: { [associateFieldKey]: action.payload.dataItem.filter((item) => !removedNodes.includes(item.id)) }
2888
- }));
2889
- }
2890
- if ((_f = widget == null ? void 0 : widget.options) == null ? void 0 : _f.hierarchy) {
2891
- const hierarchyBcName = (_j = (_i = (_h = (_g = widget == null ? void 0 : widget.options) == null ? void 0 : _g.hierarchy) == null ? void 0 : _h.find((hierarchyData) => {
2892
- var _a2;
2893
- return (_a2 = state.view.pendingDataChanges[hierarchyData.bcName]) == null ? void 0 : _a2[action.payload.removedItem.id];
2894
- })) == null ? void 0 : _i.bcName) != null ? _j : bcName;
2895
- return concat24(of32(changeDataItem({
2896
- /**
2897
- * This is incorrect and will break if different BC has records with
2898
- * identical ids.
2899
- *
2900
- * TODO: Record `level` should be mapped to hierarchyData index instead
2901
- */
2902
- bcName: hierarchyBcName,
2903
- bcUrl: buildBcUrl(hierarchyBcName, true, state),
2904
- cursor: action.payload.removedItem.id,
2905
- dataItem: __spreadProps(__spreadValues({}, action.payload.removedItem), { _associate: false })
2906
- })), of32(changeDataItem({
2907
- bcName,
2908
- bcUrl: buildBcUrl(bcName, true, state),
2909
- cursor,
2910
- dataItem: { [associateFieldKey]: action.payload.dataItem }
2911
- })));
2912
- }
2913
- return concat24(of32(changeDataItem({
2914
- bcName: popupBcName,
2915
- bcUrl: buildBcUrl(popupBcName, true, state),
2916
- cursor: action.payload.removedItem.id,
2917
- dataItem: __spreadProps(__spreadValues({}, action.payload.removedItem), { _associate: false })
2918
- })), of32(changeDataItem({
2919
- bcName,
2920
- bcUrl: buildBcUrl(bcName, true, state),
2921
- cursor,
2922
- dataItem: { [associateFieldKey]: action.payload.dataItem }
2923
- })));
2924
- }));
2925
- // src/epics/data/bcFetchRowMetaRequestEpic.ts
2926
- import { catchError as catchError14, concat as concat25, filter as filter47, map as map9, mergeMap as mergeMap32, of as of33, race as race3 } from "rxjs";
2927
- var bcFetchRowMetaRequestEpic = (action$, state$, { api }) => action$.pipe(filter47(bcFetchRowMeta.match), mergeMap32((action) => {
2928
- var _a, _b;
2929
- const state = state$.value;
2930
- const screenName = state.screen.screenName;
2931
- const bcName = action.payload.bcName;
2932
- const cursor = (_a = state.screen.bo.bc[bcName].cursor) != null ? _a : "";
2933
- const bcUrl = (_b = buildBcUrl(bcName, true, state)) != null ? _b : "";
2934
- const canceler = api.createCanceler();
2935
- const cancelFlow = cancelRequestEpic(action$, cancelRequestActionTypes, canceler.cancel, bcFetchRowMetaFail({ bcName }));
2936
- const cancelByParentBc = cancelRequestEpic(action$, [bcSelectRecord], canceler.cancel, bcFetchRowMetaFail({ bcName }), (filteredAction) => {
2937
- const actionBc = filteredAction.payload.bcName;
2938
- return state.screen.bo.bc[bcName].parentName === actionBc;
2939
- });
2940
- const normalFlow = api.fetchRowMeta(screenName, bcUrl, void 0, canceler.cancelToken).pipe(map9((rowMeta) => {
2941
- return bcFetchRowMetaSuccess({ bcName, rowMeta, bcUrl, cursor });
2942
- }), catchError14((error) => {
2943
- console.error(error);
2944
- return concat25(of33(bcFetchRowMetaFail({ bcName })), createApiErrorObservable(error));
2945
- }));
2946
- return race3(cancelFlow, cancelByParentBc, normalFlow);
2947
- }));
2948
- // src/epics/data/changeAssociationFullEpic.ts
2949
- import { concat as concat26, filter as filter48, mergeMap as mergeMap33, of as of34 } from "rxjs";
2950
- var changeAssociationFullEpic = (action$, state$) => action$.pipe(filter48(changeAssociationFull.match), mergeMap33((action) => {
2951
- var _a, _b, _c, _d, _e;
2952
- const state = state$.value;
2953
- const result = [];
2954
- const assocValueKey = action.payload.assocValueKey || ((_a = state.view.popupData) == null ? void 0 : _a.assocValueKey);
2955
- const bcName = action.payload.bcName;
2956
- const allData = state.data[bcName];
2957
- const selected = action.payload.dataItem._associate;
2958
- const depth = action.payload.depth || 1;
2959
- const parentDepth = depth - 1;
2960
- const parentItem = depth > 1 && allData.find((item) => item.id === action.payload.dataItem.parentId);
2961
- const widget = state.view.widgets.find((item) => item.name === action.payload.widgetName);
2962
- const hierarchyTraverse = (_b = widget.options) == null ? void 0 : _b.hierarchyTraverse;
2963
- const rootRadio = (_c = widget.options) == null ? void 0 : _c.hierarchyRadio;
2964
- const hierarchyGroupDeselection = (_d = widget.options) == null ? void 0 : _d.hierarchyGroupDeselection;
2965
- const currentLevelData = allData.filter((item) => item.level === depth && (item.level === 1 || item.parentId === (parentItem == null ? void 0 : parentItem.id)));
2966
- if (rootRadio && hierarchyGroupDeselection && depth === 1) {
2967
- if (selected) {
2968
- const delta = state.view.pendingDataChanges[bcName];
2969
- const prevSelected = allData.find((dataItem) => {
2970
- if (dataItem.level === 1 && dataItem.id !== action.payload.dataItem.id) {
2971
- const deltaItem = delta == null ? void 0 : delta[dataItem.id];
2972
- if ((deltaItem == null ? void 0 : deltaItem._associate) || !deltaItem && dataItem._associate) {
2973
- return true;
2974
- }
2975
- }
2976
- return false;
2977
- });
2978
- if (prevSelected) {
2979
- result.push(of34(changeAssociationFull({
2980
- bcName,
2981
- depth,
2982
- widgetName: action.payload.widgetName,
2983
- dataItem: __spreadProps(__spreadValues({}, prevSelected), { _associate: false }),
2984
- assocValueKey
2985
- })));
2986
- }
2987
- }
2988
- else {
2989
- result.push(of34(changeDescendantsAssociationsFull({
2990
- bcName,
2991
- parentId: action.payload.dataItem.id,
2992
- depth: depth + 1,
2993
- assocValueKey,
2994
- selected: false
2995
- })));
2996
- }
2997
- }
2998
- result.push(of34(changeDataItem({
2999
- bcName: action.payload.bcName,
3000
- bcUrl: buildBcUrl(action.payload.bcName, true, state),
3001
- cursor: action.payload.dataItem.id,
3002
- dataItem: action.payload.dataItem
3003
- })));
3004
- if (parentDepth && hierarchyTraverse && selected) {
3005
- result.push(of34(changeAssociationFull({
3006
- bcName,
3007
- depth: parentDepth,
3008
- widgetName: action.payload.widgetName,
3009
- dataItem: __spreadProps(__spreadValues({}, parentItem), {
3010
- _associate: true,
3011
- _value: parentItem == null ? void 0 : parentItem[assocValueKey]
3012
- }),
3013
- assocValueKey
3014
- })));
3015
- }
3016
- if (parentDepth && hierarchyTraverse && !selected) {
3017
- const delta = state.view.pendingDataChanges[bcName];
3018
- const wasLastInDelta = !delta || !Object.values(delta).find((deltaValue) => {
3019
- return deltaValue._associate === true && deltaValue.id !== action.payload.dataItem.id && currentLevelData.find((dataValue) => dataValue.id === deltaValue.id);
3020
- });
3021
- const deltaFalseId = delta && ((_e = Object.values(delta)) == null ? void 0 : _e.filter((item) => item._associate === false).map((item) => item.id));
3022
- const wasLastInData = currentLevelData.filter((item) => item.id !== action.payload.dataItem.id && !(deltaFalseId == null ? void 0 : deltaFalseId.includes(item.id))).every((item) => !item._associate);
3023
- if (wasLastInData && wasLastInDelta) {
3024
- result.push(of34(changeAssociationFull({
3025
- bcName,
3026
- depth: parentDepth,
3027
- widgetName: action.payload.widgetName,
3028
- dataItem: __spreadProps(__spreadValues({}, parentItem), { _associate: false }),
3029
- assocValueKey
3030
- })));
3031
- }
3032
- }
3033
- return concat26(...result);
3034
- }));
3035
- // src/epics/data/saveAssociationsActiveEpic.ts
3036
- import { catchError as catchError15, concat as concat27, EMPTY as EMPTY26, filter as filter49, mergeMap as mergeMap34, of as of35, switchMap as switchMap12 } from "rxjs";
3037
- var saveAssociationsActiveEpic = (action$, state$, { api }) => action$.pipe(filter49(saveAssociations.match), filter49((action) => {
3038
- var _a;
3039
- return (_a = state$.value.view.popupData) == null ? void 0 : _a.active;
3040
- }), switchMap12((action) => {
3041
- var _a, _b;
3042
- const state = state$.value;
3043
- const calleeBCName = (_a = state.view.popupData) == null ? void 0 : _a.calleeBCName;
3044
- const calleeWidgetName = (_b = state.view.popupData) == null ? void 0 : _b.calleeWidgetName;
3045
- const bcNames = action.payload.bcNames;
3046
- const bcUrl = buildBcUrl(calleeBCName, true, state);
3047
- const pendingChanges = state.view.pendingDataChanges[bcNames[0]] || {};
3048
- const params = bcNames.length ? { _bcName: bcNames[bcNames.length - 1] } : {};
3049
- return api.associate(state.screen.screenName, bcUrl, Object.values(pendingChanges).filter((i) => i._associate), params).pipe(mergeMap34((response) => {
3050
- const postInvoke = response.postActions[0];
3051
- const calleeWidget = state.view.widgets.find((widgetItem) => widgetItem.bcName === calleeBCName);
3052
- return concat27(postInvoke ? of35(processPostInvoke({ bcName: calleeBCName, postInvoke, widgetName: calleeWidget == null ? void 0 : calleeWidget.name })) : EMPTY26, of35(bcCancelPendingChanges({ bcNames })), of35(bcForceUpdate({ bcName: calleeBCName, widgetName: calleeWidgetName })));
3053
- }), catchError15((err) => {
3054
- console.error(err);
3055
- return EMPTY26;
3056
- }));
3057
- }));
3058
- // src/epics/data/changeAssociationSameBcEpic.ts
3059
- import { concat as concat28, filter as filter50, mergeMap as mergeMap35, of as of36 } from "rxjs";
3060
- var changeAssociationSameBcEpic = (action$, state$) => action$.pipe(filter50(changeAssociationSameBc.match), mergeMap35((action) => {
3061
- var _a, _b, _c, _d, _e, _f;
3062
- const state = state$.value;
3063
- const bcName = action.payload.bcName;
3064
- const result = [
3065
- of36(changeDataItem({
3066
- bcName,
3067
- bcUrl: buildBcUrl(bcName, true, state),
3068
- cursor: action.payload.dataItem.id,
3069
- dataItem: action.payload.dataItem
3070
- }))
3071
- ];
3072
- const selected = action.payload.dataItem._associate;
3073
- const depth = action.payload.depth || 1;
3074
- const parentDepth = depth - 1;
3075
- const widget = state.view.widgets.find((item) => item.name === action.payload.widgetName);
3076
- const hierarchyTraverse = (_a = widget.options) == null ? void 0 : _a.hierarchyTraverse;
3077
- const currentData = depth > 1 ? (_b = state.depthData[depth]) == null ? void 0 : _b[bcName] : state.data[bcName];
3078
- const parentCursor = parentDepth ? parentDepth > 1 ? (_d = (_c = state.screen.bo.bc[bcName].depthBc) == null ? void 0 : _c[parentDepth]) == null ? void 0 : _d.cursor : state.screen.bo.bc[bcName].cursor : null;
3079
- const parentItem = parentCursor ? parentDepth > 1 ? (_f = (_e = state.depthData[parentDepth]) == null ? void 0 : _e[bcName]) == null ? void 0 : _f.find((item) => item.id === parentCursor) : state.data[bcName].find((item) => item.id === parentCursor) : null;
3080
- if (parentDepth && hierarchyTraverse && selected) {
3081
- result.push(of36(changeAssociationSameBc({
3082
- bcName,
3083
- depth: parentDepth,
3084
- widgetName: action.payload.widgetName,
3085
- dataItem: __spreadProps(__spreadValues({}, parentItem), {
3086
- _associate: true,
3087
- _value: parentItem == null ? void 0 : parentItem[action.payload.assocValueKey]
3088
- }),
3089
- assocValueKey: action.payload.assocValueKey
3090
- })));
3091
- }
3092
- if (parentDepth && hierarchyTraverse && !selected) {
3093
- const wasLastInData = currentData.filter((item) => item.id !== action.payload.dataItem.id).every((item) => !item._associate);
3094
- if (wasLastInData) {
3095
- result.push(of36(changeAssociationSameBc({
3096
- bcName,
3097
- depth: parentDepth,
3098
- widgetName: action.payload.widgetName,
3099
- dataItem: __spreadProps(__spreadValues({}, parentItem), { _associate: false }),
3100
- assocValueKey: action.payload.assocValueKey
3101
- })));
3102
- }
3103
- }
3104
- return concat28(...result);
3105
- }));
3106
- // src/epics/data/inlinePickListFetchDataEpic.ts
3107
- import { catchError as catchError16, filter as filter51, mergeMap as mergeMap36, of as of37, race as race4 } from "rxjs";
3108
- var inlinePickListFetchDataEpic = (action$, state$, { api }) => action$.pipe(filter51(inlinePickListFetchDataRequest.match), mergeMap36((action) => {
3109
- const { bcName, searchSpec, searchString } = action.payload;
3110
- const state = state$.value;
3111
- const bcUrl = buildBcUrl(bcName, false, state);
3112
- const canceler = api.createCanceler();
3113
- const cancelFlow = cancelRequestEpic(action$, cancelRequestActionTypes, canceler.cancel, bcFetchDataFail({ bcName, bcUrl }));
3114
- const normalFlow = api.fetchBcData(state$.value.screen.screenName, bcUrl, { [searchSpec + ".contains"]: searchString }, canceler.cancelToken).pipe(mergeMap36((data) => {
3115
- return of37(bcFetchDataSuccess({ bcName, data: data.data, bcUrl }));
3116
- }), catchError16((error) => {
3117
- console.error(error);
3118
- return of37(bcFetchDataFail({ bcName: action.payload.bcName, bcUrl }));
3119
- }));
3120
- return race4(cancelFlow, normalFlow);
3121
- }));
3122
- // src/epics/data/saveAssociationsPassiveEpic.ts
3123
- import { filter as filter52, of as of38, switchMap as switchMap13 } from "rxjs";
3124
- var saveAssociationsPassiveEpic = (action$, state$) => action$.pipe(filter52(saveAssociations.match), filter52(() => {
3125
- var _a;
3126
- return !((_a = state$.value.view.popupData) == null ? void 0 : _a.active);
3127
- }), switchMap13((action) => {
3128
- var _a, _b;
3129
- const state = state$.value;
3130
- const { calleeBCName = action.payload.calleeBcName, associateFieldKey = action.payload.associateFieldKey } = (_a = state.view.popupData) != null ? _a : {};
3131
- const cursor = state.screen.bo.bc[calleeBCName].cursor;
3132
- const recordPrevData = (_b = state.data[calleeBCName].find((dataStateRecord) => dataStateRecord.id === cursor)[associateFieldKey]) != null ? _b : [];
3133
- const newValues = [];
3134
- action.payload.bcNames.forEach((pendingBc) => {
3135
- const pendingChanges = state.view.pendingDataChanges[pendingBc] || {};
3136
- Object.entries(pendingChanges).forEach(([id, item]) => {
3137
- newValues.push(item);
3138
- });
3139
- });
3140
- const addedItems = newValues.filter((newItem) => {
3141
- const isNew = !recordPrevData.find((prevItem) => prevItem.id === newItem.id) && newItem._associate;
3142
- return isNew;
3143
- }).map((newItem) => ({
3144
- id: newItem.id,
3145
- options: {},
3146
- value: newItem._value
3147
- }));
3148
- const result = recordPrevData.filter((prevItem) => {
3149
- const removedItem = newValues.find((item) => item.id === prevItem.id);
3150
- if (removedItem && (removedItem == null ? void 0 : removedItem._associate) === false) {
3151
- return false;
3152
- }
3153
- return true;
3154
- }).concat(...addedItems);
3155
- return of38(changeDataItem({
3156
- bcName: calleeBCName,
3157
- bcUrl: buildBcUrl(calleeBCName, true, state),
3158
- cursor,
3159
- dataItem: {
3160
- [associateFieldKey]: result
3161
- }
3162
- }));
3163
- }));
3164
- // src/epics/data/changeChildrenAssociationsEpic.ts
3165
- import { filter as filter53, mergeMap as mergeMap37, of as of39 } from "rxjs";
3166
- var changeChildrenAssociationsEpic = (action$, state$, { api }) => action$.pipe(filter53(changeChildrenAssociations.match), mergeMap37((action) => {
3167
- const state = state$.value;
3168
- const data = state.data[action.payload.bcName];
3169
- return of39(changeDataItems({
3170
- bcName: action.payload.bcName,
3171
- cursors: data.map((item) => item.id),
3172
- dataItems: data.map((item) => __spreadProps(__spreadValues({}, item), {
3173
- _value: item[action.payload.assocValueKey],
3174
- _associate: action.payload.selected
3175
- }))
3176
- }));
3177
- }));
3178
- // src/epics/data/changeChildrenAssociationsSameBcEpic.ts
3179
- import { filter as filter54, mergeMap as mergeMap38, of as of40 } from "rxjs";
3180
- var changeChildrenAssociationsSameBcEpic = (action$, state$) => action$.pipe(filter54(changeChildrenAssociationsSameBc.match), mergeMap38((action) => {
3181
- var _a;
3182
- const state = state$.value;
3183
- const data = ((_a = state.depthData[action.payload.depth]) == null ? void 0 : _a[action.payload.bcName]) || [];
3184
- return of40(changeDataItems({
3185
- bcName: action.payload.bcName,
3186
- cursors: data.map((item) => item.id),
3187
- dataItems: data.map((item) => __spreadProps(__spreadValues({}, item), {
3188
- _value: item[action.payload.assocValueKey],
3189
- _associate: action.payload.selected
3190
- }))
3191
- }));
3192
- }));
3193
- // src/epics/data/changeDescendantsAssociationsFullEpic.ts
3194
- import { concat as concat29, filter as filter55, mergeMap as mergeMap39, of as of41 } from "rxjs";
3195
- var changeDescendantsAssociationsFullEpic = (action$, state$) => action$.pipe(filter55(changeDescendantsAssociationsFull.match), mergeMap39((action) => {
3196
- const state = state$.value;
3197
- const depth = action.payload.depth;
3198
- const data = state.data[action.payload.bcName];
3199
- const targetData = (data || []).filter((item) => item.level === depth && item.parentId === action.payload.parentId);
3200
- const result = [
3201
- of41(changeDataItems({
3202
- bcName: action.payload.bcName,
3203
- cursors: targetData.map((item) => item.id),
3204
- dataItems: targetData.map((item) => __spreadProps(__spreadValues({}, item), {
3205
- _value: item[action.payload.assocValueKey],
3206
- _associate: action.payload.selected
3207
- }))
3208
- }))
3209
- ];
3210
- targetData.forEach((targetDataItem) => {
3211
- if (data.find((dataItem) => dataItem.parentId === targetDataItem.id)) {
3212
- result.push(of41(changeDescendantsAssociationsFull(__spreadProps(__spreadValues({}, action.payload), {
3213
- parentId: targetDataItem.id,
3214
- depth: depth + 1
3215
- }))));
3216
- }
3217
- });
3218
- return concat29(...result);
3219
- }));
3220
- // src/api/ObservableApiWrapper.ts
3221
- import axios2 from "axios";
3222
- import { from, map as map10, takeWhile } from "rxjs";
3223
- function redirectOccurred(value) {
3224
- var _a;
3225
- if ((_a = value.data) == null ? void 0 : _a.redirectUrl) {
3226
- let redirectUrl = value.data.redirectUrl;
3227
- if (!redirectUrl.startsWith("/") && !redirectUrl.match("^http(.?)://")) {
3228
- redirectUrl = `${window.location.pathname}#/${redirectUrl}`;
3229
- }
3230
- if (redirectUrl.startsWith("/") && !redirectUrl.startsWith("//")) {
3231
- redirectUrl = `${window.location.origin}${redirectUrl}`;
3232
- }
3233
- window.location.replace(redirectUrl);
3234
- return false;
3235
- }
3236
- return true;
3237
- }
3238
- var ObservableApiWrapper = class {
3239
- constructor(instance) {
3240
- __publicField(this, "instance", axios2.create({
3241
- responseType: "json",
3242
- headers: { Pragma: "no-cache", "Cache-Control": "no-cache, no-store, must-revalidate" }
3243
- }));
3244
- this.instance = instance;
3245
- }
3246
- get(path, config, callContext) {
3247
- return from(this.instance.get(path, config)).pipe(takeWhile(redirectOccurred), map10((response) => response.data));
3248
- }
3249
- put(path, data, callContext) {
3250
- return from(this.instance.put(path, data)).pipe(takeWhile(redirectOccurred), map10((response) => response.data));
3251
- }
3252
- post(path, data, config, callContext) {
3253
- return from(this.instance.post(path, data)).pipe(takeWhile(redirectOccurred), map10((response) => response.data));
3254
- }
3255
- delete(path, data, config, callContext) {
3256
- return from(this.instance.delete(path, data)).pipe(takeWhile(redirectOccurred), map10((response) => response.data));
3257
- }
3258
- };
3259
- // src/api/ObservableApi.ts
3260
- import axios3 from "axios";
3261
- import { EMPTY as EMPTY27, expand, map as map11, reduce } from "rxjs";
3262
- var Api = class {
3263
- constructor(instance) {
3264
- __publicField(this, "api$");
3265
- this.api$ = new ObservableApiWrapper(instance);
3266
- }
3267
- routerRequest(path, params) {
3268
- return this.api$.get(applyRawParams(path, params));
3269
- }
3270
- fetchBcData(screenName, bcUrl, params = {}, cancelToken) {
3271
- const noLimit = params._limit === 0;
3272
- const queryStringObject = __spreadProps(__spreadValues({}, params), {
3273
- _page: !noLimit ? "_page" in params ? params._page : 1 : void 0,
3274
- _limit: !noLimit ? "_limit" in params ? params._limit : 30 : void 0
3275
- });
3276
- const url = applyParams(buildUrl `data/${screenName}/` + bcUrl, queryStringObject);
3277
- return this.api$.get(url, { cancelToken });
3278
- }
3279
- fetchBcDataAll(screenName, bcUrl, params = {}) {
3280
- let currentPage = 1;
3281
- return this.fetchBcData(screenName, bcUrl, __spreadProps(__spreadValues({}, params), { _page: currentPage })).pipe(expand((response) => {
3282
- return response.hasNext ? this.fetchBcData(screenName, bcUrl, __spreadProps(__spreadValues({}, params), { _page: ++currentPage })) : EMPTY27;
3283
- }), reduce((items, nextResponse) => {
3284
- return [...items, ...nextResponse.data];
3285
- }, []));
3286
- }
3287
- fetchRowMeta(screenName, bcUrl, params, cancelToken) {
3288
- const url = applyParams(buildUrl `row-meta/${screenName}/` + bcUrl, params);
3289
- return this.api$.get(url, { cancelToken }).pipe(map11((response) => response.data.row));
3290
- }
3291
- newBcData(screenName, bcUrl, context, params) {
3292
- const url = applyParams(buildUrl `row-meta-new/${screenName}/` + bcUrl, params);
3293
- return this.api$.get(url, void 0, context).pipe(map11((response) => response.data));
3294
- }
3295
- saveBcData(screenName, bcUrl, data, context, params) {
3296
- const url = applyParams(buildUrl `data/${screenName}/` + bcUrl, params);
3297
- return this.api$.put(url, { data }, context).pipe(map11((response) => response.data));
3298
- }
3299
- deleteBcData(screenName, bcUrl = "", context, params) {
3300
- const url = applyParams(buildUrl `data/${screenName}/` + bcUrl, params);
3301
- return this.api$.delete(url, context).pipe(map11((response) => response.data));
3302
- }
3303
- customAction(screenName, bcUrl, data, context, params) {
3304
- const url = applyParams(buildUrl `custom-action/${screenName}/` + bcUrl, params);
3305
- return this.api$.post(url, { data: data || {} }, void 0, context).pipe(map11((response) => response.data));
3306
- }
3307
- associate(screenName, bcUrl, data, params) {
3308
- const processedData = Array.isArray(data) ? data.map((item) => ({
3309
- id: item.id,
3310
- vstamp: item.vstamp,
3311
- associated: item._associate
3312
- })) : data;
3313
- const url = applyParams(buildUrl `associate/${screenName}/` + bcUrl, params);
3314
- return this.api$.post(url, processedData).pipe(map11((response) => response.data));
3315
- }
3316
- getRmByForceActive(screenName, bcUrl, data, params) {
3317
- const url = applyParams(buildUrl `row-meta/${screenName}/` + (bcUrl != null ? bcUrl : ""), params);
3318
- return this.api$.post(url, { data }).pipe(map11((response) => response.data.row));
3319
- }
3320
- /**
3321
- * Get Cxbox API file upload endpoint based on baseURL of axios instance
3322
- *
3323
- * Handles empty baseURL and trailing slash
3324
- *
3325
- * @returns File upload endpoint
3326
- */
3327
- get fileUploadEndpoint() {
3328
- const instance = this.api$.instance;
3329
- if (!instance.defaults.baseURL) {
3330
- return "/file";
3331
- }
3332
- return instance.defaults.baseURL.endsWith("/") ? `${instance.defaults.baseURL}file` : `${instance.defaults.baseURL}/file`;
3333
- }
3334
- refreshMeta() {
3335
- return this.api$.get(buildUrl `bc-registry/refresh-meta`);
3336
- }
3337
- loginByRoleRequest(role) {
3338
- return this.api$.get(buildUrl `login?role=${role}`);
3339
- }
3340
- createCanceler() {
3341
- let cancel;
3342
- const cancelToken = new axios3.CancelToken((c) => {
3343
- cancel = c;
3344
- });
3345
- return {
3346
- cancel,
3347
- cancelToken
3348
- };
3349
- }
3350
- };
3351
- // src/utils/autosave.ts
3352
- function autosaveRoutine(action, store, next) {
3353
- var _a, _b, _c;
3354
- const state = store.getState();
3355
- const dispatch = store.dispatch;
3356
- const pendingDataChanges = state.view.pendingDataChanges;
3357
- const bcList = Object.keys(pendingDataChanges);
3358
- const baseBcNameIndex = ((_a = action.payload) == null ? void 0 : _a.bcName) && bcHasPendingAutosaveChanges(state, action.payload.bcName, (_b = state.screen.bo.bc[action.payload.bcName]) == null ? void 0 : _b.cursor) ? bcList.findIndex((bcName) => {
3359
- var _a2;
3360
- return bcName === ((_a2 = action.payload) == null ? void 0 : _a2.bcName);
3361
- }) : bcList.findIndex((bcName) => {
3362
- var _a2;
3363
- return bcHasPendingAutosaveChanges(state, bcName, (_a2 = state.screen.bo.bc[bcName]) == null ? void 0 : _a2.cursor);
3364
- });
3365
- const baseBcName = bcList[baseBcNameIndex];
3366
- if (baseBcNameIndex > -1) {
3367
- bcList.splice(baseBcNameIndex, 1);
3368
- }
3369
- if (baseBcName) {
3370
- bcList.forEach((bcName) => {
3371
- var _a2, _b2;
3372
- const widget = (_a2 = state.view.widgets) == null ? void 0 : _a2.find((v) => v.bcName === bcName);
3373
- const cursor = (_b2 = state.screen.bo.bc[bcName]) == null ? void 0 : _b2.cursor;
3374
- if (bcHasPendingAutosaveChanges(state, bcName, cursor)) {
3375
- dispatch(sendOperation({
3376
- bcName,
3377
- operationType: OperationTypeCrud.save,
3378
- widgetName: widget == null ? void 0 : widget.name
3379
- }));
3380
- }
3381
- });
3382
- const baseWidget = (_c = state.view.widgets) == null ? void 0 : _c.find((v) => v.bcName === baseBcName);
3383
- return next(sendOperation({
3384
- bcName: baseBcName,
3385
- operationType: OperationTypeCrud.save,
3386
- widgetName: baseWidget == null ? void 0 : baseWidget.name,
3387
- onSuccessAction: action
3388
- }));
3389
- }
3390
- return next(action);
3391
- }
3392
- function bcHasPendingAutosaveChanges(store, bcName, cursor) {
3393
- var _a;
3394
- const pendingChanges = store.view.pendingDataChanges;
3395
- const cursorChanges = (_a = pendingChanges[bcName]) == null ? void 0 : _a[cursor];
3396
- const result = cursorChanges && !Object.keys(cursorChanges).includes("_associate") && Object.values(cursorChanges).length > 0;
3397
- return result;
3398
- }
3399
- function checkUnsavedChangesOfBc(store, bcName) {
3400
- var _a, _b;
3401
- const pendingCursors = Object.keys((_b = (_a = store.view.pendingDataChanges) == null ? void 0 : _a[bcName]) != null ? _b : {});
3402
- return pendingCursors.some((cursor) => bcHasPendingAutosaveChanges(store, bcName, cursor));
3403
- }
3404
- // src/middlewares/autosaveMiddleware.ts
3405
- var saveFormMiddleware = ({ getState, dispatch }) => (next) => (action) => {
3406
- var _a, _b, _c, _d, _e, _f, _g;
3407
- const state = getState();
3408
- const isSendOperation = sendOperation.match(action);
3409
- const isCoreSendOperation = isSendOperation && coreOperations.includes(action.payload.operationType);
3410
- const isSelectTableCellInit = selectTableCellInit.match(action);
3411
- const isSaveAction = isSendOperation && action.payload.operationType === OperationTypeCrud.save;
3412
- const isNotSaveAction = !isSaveAction;
3413
- const actionBcName = isSendOperation && action.payload.bcName;
3414
- const hasAnotherUnsavedBc = Object.keys(state.view.pendingDataChanges).filter((key) => key !== actionBcName).filter((key) => checkUnsavedChangesOfBc(state, key)).length > 0;
3415
- const isSendOperationForAnotherBc = isCoreSendOperation && hasAnotherUnsavedBc;
3416
- const selectedCell = state.view.selectedCell;
3417
- const isSelectTableCellInitOnAnotherRowOrWidget = selectedCell && isSelectTableCellInit && (selectedCell.widgetName !== action.payload.widgetName || selectedCell.rowId !== action.payload.rowId);
3418
- const defaultSaveWidget = (_a = state.view.widgets) == null ? void 0 : _a.find((item) => {
3419
- var _a2, _b2;
3420
- return (_b2 = (_a2 = item == null ? void 0 : item.options) == null ? void 0 : _a2.actionGroups) == null ? void 0 : _b2.defaultSave;
3421
- });
3422
- const defaultCursor = (_c = (_b = state.screen.bo.bc) == null ? void 0 : _b[defaultSaveWidget == null ? void 0 : defaultSaveWidget.bcName]) == null ? void 0 : _c.cursor;
3423
- const pendingData = (_f = (_e = (_d = state.view) == null ? void 0 : _d.pendingDataChanges) == null ? void 0 : _e[defaultSaveWidget == null ? void 0 : defaultSaveWidget.bcName]) == null ? void 0 : _f[defaultCursor];
3424
- const isChangeLocation = defaultSaveWidget && changeLocation.match(action) && Object.keys(pendingData || {}).length > 0;
3425
- if (isChangeLocation) {
3426
- return next(sendOperation({
3427
- bcName: defaultSaveWidget.bcName,
3428
- operationType: ((_g = defaultSaveWidget.options) == null ? void 0 : _g.actionGroups).defaultSave,
3429
- widgetName: defaultSaveWidget.name,
3430
- onSuccessAction: action
3431
- }));
3432
- }
3433
- const isNeedSaveCondition = isNotSaveAction && (isSendOperationForAnotherBc || isSelectTableCellInitOnAnotherRowOrWidget);
3434
- if (isNeedSaveCondition) {
3435
- return autosaveRoutine(action, { getState, dispatch }, next);
3436
- }
3437
- return next(action);
3438
- };
3439
- // src/middlewares/requiredFieldsMiddleware.ts
3440
- var requiredFields = ({ getState, dispatch }) => (next) => (action) => {
3441
- var _a, _b, _c, _d;
3442
- const state = getState();
3443
- if (sendOperation.match(action)) {
3444
- const { bcName, operationType, widgetName } = action.payload;
3445
- const cursor = (_a = state.screen.bo.bc[bcName]) == null ? void 0 : _a.cursor;
3446
- if (cursor) {
3447
- const bcUrl = buildBcUrl(bcName, true, state);
3448
- const record = (_b = state.data[bcName]) == null ? void 0 : _b.find((item) => item.id === cursor);
3449
- const rowMeta = bcUrl && ((_c = state.view.rowMeta[bcName]) == null ? void 0 : _c[bcUrl]);
3450
- const pendingValues = (_d = state.view.pendingDataChanges[bcName]) == null ? void 0 : _d[cursor];
3451
- const widget = state.view.widgets.find((item) => item.name === widgetName);
3452
- if (operationRequiresAutosave(operationType, rowMeta == null ? void 0 : rowMeta.actions)) {
3453
- const fieldsToCheck = {};
3454
- state.view.widgets.filter((item) => item.bcName === (widget == null ? void 0 : widget.bcName)).forEach((item) => {
3455
- const itemFieldsCalc = [...item.fields];
3456
- if (item.fields) {
3457
- item.fields.forEach((block) => {
3458
- if (isWidgetFieldBlock(block)) {
3459
- block.fields.forEach((field) => itemFieldsCalc.push(field));
3460
- }
3461
- });
3462
- }
3463
- itemFieldsCalc.forEach((widgetField) => {
3464
- var _a2;
3465
- const matchingRowMeta = (_a2 = rowMeta == null ? void 0 : rowMeta.fields) == null ? void 0 : _a2.find((rowMetaField) => rowMetaField.key === widgetField.key);
3466
- if (!fieldsToCheck[widgetField.key] && matchingRowMeta && !matchingRowMeta.hidden) {
3467
- fieldsToCheck[widgetField.key] = matchingRowMeta;
3468
- }
3469
- });
3470
- });
3471
- const dataItem = getRequiredFieldsMissing(record, pendingValues, Object.values(fieldsToCheck));
3472
- if (dataItem && TableLikeWidgetTypes.includes(widget == null ? void 0 : widget.type)) {
3473
- dispatch(selectTableCellInit({ widgetName, rowId: cursor, fieldKey: Object.keys(dataItem)[0] }));
3474
- }
3475
- return dataItem ? next(changeDataItem({ bcName, bcUrl: buildBcUrl(bcName, true, state), cursor, dataItem })) : next(action);
3476
- }
3477
- if (hasPendingValidationFails(state, bcName)) {
3478
- return addNotification({
3479
- key: "requiredFieldsMissing",
3480
- type: "buttonWarningNotification",
3481
- message: "Required fields are missing",
3482
- duration: 0,
3483
- options: {
3484
- buttonWarningNotificationOptions: {
3485
- buttonText: "Cancel changes",
3486
- actionsForClick: [bcCancelPendingChanges(null), clearValidationFails(null)]
3487
- }
3488
- }
3489
- });
3490
- }
3491
- }
3492
- }
3493
- return next(action);
3494
- };
3495
- function operationRequiresAutosave(operationType, actions2) {
3496
- let result = false;
3497
- if (!actions2) {
3498
- console.error('rowMeta is missing in the middle of "sendOperation" action');
3499
- return result;
3500
- }
3501
- result = flattenOperations(actions2).some((action) => action.type === operationType && action.autoSaveBefore);
3502
- return result;
3503
- }
3504
- function getRequiredFieldsMissing(record, pendingChanges, fieldsMeta) {
3505
- const result = {};
3506
- fieldsMeta.forEach((field) => {
3507
- const value = record == null ? void 0 : record[field.key];
3508
- const pendingValue = pendingChanges == null ? void 0 : pendingChanges[field.key];
3509
- const effectiveValue = pendingValue !== void 0 ? pendingValue : value;
3510
- let falsyValue = false;
3511
- if (effectiveValue === null || effectiveValue === void 0 || effectiveValue === "") {
3512
- falsyValue = true;
3513
- }
3514
- else if (Array.isArray(effectiveValue) && !effectiveValue.length) {
3515
- falsyValue = true;
3516
- }
3517
- else if (effectiveValue && typeof effectiveValue === "object" && !Object.keys(effectiveValue).length) {
3518
- falsyValue = true;
3519
- }
3520
- if (field.required && falsyValue) {
3521
- result[field.key] = Array.isArray(effectiveValue) ? [] : null;
3522
- }
3523
- });
3524
- return Object.keys(result).length > 0 ? result : null;
3525
- }
3526
- function hasPendingValidationFails(store, bcName) {
3527
- var _a;
3528
- if (store.view.pendingValidationFailsFormat !== "target" /* target */ && store.view.pendingValidationFails && Object.keys(store.view.pendingValidationFails).length) {
3529
- return true;
3530
- }
3531
- let checkResult = false;
3532
- const bcPendingValidations = (_a = store.view.pendingValidationFails) == null ? void 0 : _a[bcName];
3533
- const cursorsList = bcPendingValidations && Object.keys(bcPendingValidations);
3534
- if (!cursorsList) {
3535
- return false;
3536
- }
3537
- let i = 0;
3538
- for (; i < cursorsList.length; i++) {
3539
- if (Object.keys(bcPendingValidations[cursorsList[i]]).length) {
3540
- checkResult = true;
3541
- break;
3542
- }
3543
- }
3544
- return checkResult;
3545
- }
3546
- // src/middlewares/preInvokeMiddleware.ts
3547
- var preInvokeAction = ({ getState }) => (next) => (action) => {
3548
- var _a, _b, _c;
3549
- if (sendOperation.match(action)) {
3550
- const state = getState();
3551
- const { operationType, widgetName, confirm } = action.payload;
3552
- const bcName = (_a = state.view.widgets.find((widgetItem) => widgetItem.name === widgetName)) == null ? void 0 : _a.bcName;
3553
- const bcUrl = buildBcUrl(bcName, true, state);
3554
- const rowMeta = bcUrl && ((_b = state.view.rowMeta[bcName]) == null ? void 0 : _b[bcUrl]);
3555
- const actions2 = rowMeta && flattenOperations(rowMeta.actions);
3556
- const preInvoke = (_c = actions2 == null ? void 0 : actions2.find((item) => item.type === operationType)) == null ? void 0 : _c.preInvoke;
3557
- return preInvoke && !confirm ? next(processPreInvoke({
3558
- bcName,
3559
- operationType,
3560
- widgetName,
3561
- preInvoke
3562
- })) : next(action);
3563
- }
3564
- return next(action);
3565
- };
3566
- // src/middlewares/popupMiddleware.ts
3567
- var popupMiddleware = ({ getState }) => (next) => (action) => {
3568
- var _a, _b, _c;
3569
- if (showViewPopup.match(action)) {
3570
- const state = getState();
3571
- const bcName = action.payload.bcName;
3572
- const widgetValueKey = (_b = (_a = state.view.widgets.find((item) => item.bcName === bcName)) == null ? void 0 : _a.options) == null ? void 0 : _b.displayedValueKey;
3573
- const assocValueKey = (_c = action.payload.assocValueKey) != null ? _c : widgetValueKey;
3574
- return widgetValueKey ? next(showViewPopup(__spreadProps(__spreadValues({}, action.payload), { assocValueKey }))) : next(action);
3575
- }
3576
- return next(action);
3577
- };
3578
- // src/middlewares/index.ts
3579
- var middlewares = {
3580
- autosave: saveFormMiddleware,
3581
- requiredFields,
3582
- preInvoke: preInvokeAction,
3583
- popup: popupMiddleware
3584
- };
3585
- export { Api, actions_exports as actions, epics_exports as epics, interfaces_exports as interfaces, middlewares, reducers_exports as reducers, utils_exports as utils };
3586
- //# sourceMappingURL=cxbox-ui-core.modern.js.map