@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
package/README.md CHANGED
@@ -58,54 +58,287 @@ widgets, fields, layouts (views), navigation (screens).
58
58
 
59
59
  ## Main concepts
60
60
 
61
- UI side of Cxbox framework is based on a concept of configurable dashboards ("views") with widgets. Visually widgets could be represented as a card with a table, graph, form or something more exotic inside.
62
- Internally, every widget has a direct link to an entity that we call "business component" (BC). BC controls what data is displayed on widget and whhich interactions are available to the user. Interactions could be a simple filtration or some complex business process, initiated through Cxbox API.
63
- Information about loaded views and widgets grouped into "screens" and stored in application Redux store.
64
- Client applications could reuse, extend and customize that functionality by providing its own reducers and epics, widgets and ui controls.
61
+ **[@cxbox-ui/core](https://www.npmjs.com/package/@cxbox-ui/core)** is a typescript library that includes set of prebuilt pieces of Redux ecosystem, to correctly interact with CXBox framework. It contains all parts to combine Redux store inside of your React application.
65
62
 
66
- ## Installation
63
+ - Actions
64
+ - Reducers
65
+ - Middlewares
66
+ - Epics
67
+ - *RxJS methods for asynchronous interaction with CXBOX framework*
68
+ - Api
69
+ - *Wrapped in RxJS observables*
70
+ - Utilities
71
+ - Interfaces
72
+ - *CXBOX interaction typescript contract*
67
73
 
68
- Cxbox UI distributed in form of ES5 compatible npm package:
69
- ```sh
74
+ ![schema](./docs/schemas/arch.jpg)
75
+
76
+ ---
77
+
78
+ ## Changelog
79
+
80
+ ![changelog](./docs/schemas/changelog.jpg)
81
+
82
+ ---
83
+
84
+ ## Getting started
85
+
86
+ The best way to start CXBox project is to clone [CXBox-Demo](https://github.com/CX-Box/cxbox-demo) and follow the [README](https://github.com/CX-Box/cxbox-demo/blob/main/README.md) instructions
87
+
88
+ ---
89
+
90
+ ## Manual installation
91
+
92
+ **[@cxbox-ui/core](https://www.npmjs.com/package/@cxbox-ui/core)** distributed in form of ESM* npm package:
93
+ ```bash
70
94
  yarn add @cxbox-ui/core
71
95
  ```
96
+ or
97
+ ```bash
98
+ npm install @cxbox-ui/core
99
+ ```
100
+
101
+ Several libraries are specified as peer dependencies and should be installed
102
+ - react
103
+ - react-dom
104
+ - @reduxjs/toolkit
105
+ - rxjs
106
+ - redux-observable
107
+ - axios
72
108
 
73
- Several libraries are specified as peer dependencies and should be installed for client application: react, react-dom, redux, react-redux, rxjs, redux-observable, antd, axios.
109
+ > [!WARNING]
110
+ > CJS module system are no longer supported
111
+ ---
74
112
 
75
113
  ## Usage
76
114
 
77
- <Provider> component provides configurable Redux context and should be used on top level of your application:
115
+ Library proposes to use common way of configuring your Redux store with some nuances
78
116
 
79
- ```tsx
80
- import {Provider} from '@cxbox-ui/core'
81
- import {reducers} from 'reducers'
117
+ [How to configure default Redux store](https://redux-toolkit.js.org/tutorials/quick-start)
118
+
119
+ ### Reducers
120
+ [Proper way of creating reducers](https://redux-toolkit.js.org/api/createReducer#usage-with-the-builder-callback-notation)
121
+
122
+ **@cxbox-ui/core** exports all arguments for **@reduxjs/toolkit** `createReducer` method, such as `initialState` and `createReducerBuilderManager` instances of default **_CXBox reducers_**
123
+
124
+ ```ts
125
+ import {reducers} from '@cxbox-ui/core'
126
+ import {createReducer} from '@reduxjs/toolkit'
127
+
128
+ const viewReducerBuilder = reducers
129
+ .createViewReducerBuilderManager(reducers.initialViewState)
130
+ .builder
131
+
132
+ const viewReducer = createReducer(reducers.initialViewState, viewReducerBuilder)
133
+ ```
134
+
135
+ `ReducerBuildManager` implements default methods of `createReducer` builder callback argument, with `removeCase` and `replaceCase`
136
+
137
+ ```ts
138
+ const viewReducerBuilder = reducers
139
+ .createViewReducerBuilderManager(reducers.initialViewState)
140
+ .removeCase('sampleCXBoxAction')
141
+ .addCase('anotherSampleAction', () => {/** do something with state */})
142
+ .replaceCase('someCXBoxActionToo', () => {/** in case of CXBox realization is not satisfying */})
143
+ .builder
144
+
145
+ const viewReducer = createReducer(reducers.initialViewState, viewReducerBuilder)
146
+ ```
147
+
148
+ More appropriate case samples in [CXBox-Demo](https://github.com/CX-Box/cxbox-demo/tree/main/ui/src/reducers)
149
+
150
+ ### Combine reducers
151
+
152
+ ```ts
153
+ import {combineReducers, configureStore} from '@reduxjs/toolkit'
154
+
155
+ const rootReducer = combineReducers({
156
+ screen: screenReducer,
157
+ data: dataReducer,
158
+ view: viewReducer,
159
+ session: sessionReducer,
160
+ router: routerReducer,
161
+ notification: notificationReducer
162
+ })
163
+
164
+ const store = configureStore({
165
+ reducers: rootReducer
166
+ })
167
+ ```
168
+
169
+ ### Redux-observable middleware
170
+
171
+ To make this store work with CXBox backend, you should configure asynchronous interaction by applying preconfigured [Redux-Observable](https://redux-observable.js.org/) **Epics**
172
+
173
+ It will take two steps
174
+ - Configure Api Axios instance
175
+
176
+ ```ts
177
+ import {Api} from '@cxbox-ui/core'
178
+ import Axios from 'axios'
179
+
180
+ const __AJAX_TIMEOUT__ = 900000
181
+ const __CLIENT_ID__: number = Date.now()
182
+
183
+ const HEADERS = { Pragma: 'no-cache', 'Cache-Control': 'no-cache, no-store, must-revalidate' }
82
184
 
83
- const App = <Provider>
84
- <div>Client side application</div>
85
- </Provider>
185
+ const instance = axios.create({
186
+ baseURL: __API__,
187
+ timeout: __AJAX_TIMEOUT__,
188
+ responseType: 'json',
189
+ headers: {
190
+ ...HEADERS,
191
+ ...{ ClientId: __CLIENT_ID__ }
192
+ }
193
+ })
86
194
 
87
- render(App, document.getElementById('root'))
195
+ const CXBoxApiInstance = new Api(instance)
88
196
  ```
89
197
 
90
- After that, components of your own application could access combined Redux store and import library components:
198
+ _You can also extend any of Api methods to use in your epics_
199
+
200
+ ```ts
201
+ import {Api} from '@cxbox-ui/core'
202
+
203
+ class ExtendedApi extends Api {
204
+ getSomethingUnusual(thing: string) {
205
+ return this.$api.get(thing)
206
+ }
207
+ }
208
+
209
+ const CXBoxApiInstance = new ExtendedApi(axiosInstance)
210
+ ```
211
+
212
+ - [Setting up middleware](https://redux-observable.js.org/docs/basics/SettingUpTheMiddleware.html)
213
+
214
+ ```ts
215
+ import {epics} from '@cxbox-ui/core'
216
+ import {combineEpics, createEpicMiddleware} from 'redux-observable'
217
+ import {configureStore, getDefaultMiddleware} from '@reduxjs/toolkit'
218
+
219
+ // Typescript cast if you changed default CXBoxEpic type
220
+ const coreEpics = {...epics} as unknown as Record<string, RootEpic>
221
+
222
+ const rootEpic = combineEpics(Object.values(coreEpics))
223
+
224
+ const epicMiddleware = createEpicMiddleware({
225
+ dependencies: {
226
+ api: CXBoxApiInstance
227
+ }
228
+ })
229
+
230
+ const store = configureStore({
231
+ reducer: rootReducer,
232
+ middleware: getDefaultMiddleware().concat(epicMiddleware)
233
+ })
234
+
235
+ epicMiddleware.run(rootEpic)
236
+ ```
237
+
238
+ ### Epics
239
+
240
+ Feel free to add, but be careful to replace or remove some epics. They can call actions that causes chain effect, but if you sure in consequences, manipulate imported epics object as you want.
241
+
242
+ ```ts
243
+ import {createAction} from '@reduxjs/toolkit'
244
+
245
+ const sampleAction = createAction<string>('sampleAction')
246
+
247
+ const sampleEpic: RootEpic = (action$, state$, {api}) =>
248
+ action$.pipe(
249
+ filter(sampleAction.match),
250
+ switchMap(action => {
251
+ const name = action.payload
252
+
253
+ if (name) {
254
+ api.doSomething(name)
255
+ }
256
+
257
+ return EMPTY
258
+ }),
259
+ catchError(error => {
260
+ return utils.createApiErrorObservable(error)
261
+ })
262
+ )
263
+
264
+ const rootEpic = combineEpics(...Object.values(epics), sampleEpic)
265
+ ```
266
+
267
+ ### Middlewares
268
+
269
+ @cxbox-ui/core also exports some middlewares, that not uses Redux-Observable way, but they still need to be applied
270
+
271
+ ```ts
272
+ import {configureStore, getDefaultMiddleware} from '@reduxjs/toolkit'
273
+ import {middlewares} from '@cxbox-ui/core'
274
+
275
+ const store = configureStore({
276
+ reducer: rootReducer,
277
+ middleware: getDefaultMiddleware()
278
+ .concat(...Object.values(middlewares))
279
+ .concat(epicMiddleware)
280
+ })
281
+ ```
282
+
283
+ ---
284
+
285
+ ## Widget example
286
+
91
287
 
92
288
  ```tsx
93
289
  import React from 'react'
94
- import {connect, View} from '@cxbox-ui/core'
95
-
96
- export const ClientComponent: FunctionComponent = (props: { screenName }) => {
97
- const Card = (props) => <div>
98
- <h1>Client side component</h1>
99
- {props.children}
100
- </div>
101
- return <View card={Card} />
290
+ import { interfaces } from '@cxbox-ui/core'
291
+ import { useDispatch } from 'react-redux'
292
+ import { useAppSelector } from '@store'
293
+ import { actions } from '@cxbox-ui/core'
294
+ import InfoRow from './components/InfoRow'
295
+ import { Row } from 'antd'
296
+ import { useFlatFormFields } from '@hooks/useFlatFormFields'
297
+
298
+ interface FunnelProps {
299
+ meta: FunnelWidgetMeta
300
+ }
301
+
302
+ function Funnel({ meta }: FunnelProps) {
303
+ const { bcName } = meta
304
+ const data = useAppSelector(state => state.data[bcName])
305
+ const sortedData = data?.slice().sort(sorter)
306
+ const funnelData = sortedData?.map(i => ({ id: i.funnelKey, value: i.amount }))
307
+ const color = sortedData?.map(i => i.color) as Array<string>
308
+
309
+ const legend: Types.LegendCfg = {
310
+ position: 'right',
311
+ layout: 'vertical',
312
+ itemMarginBottom: 16,
313
+ itemName: { style: { fontSize: 14, fontFamily: 'Roboto', fontWeight: 400 } },
314
+ marker: (name, index) => ({
315
+ symbol: 'circle',
316
+ style: {
317
+ fill: color[index]
318
+ }
319
+ })
320
+ }
321
+ const label: Label = {
322
+ content: labelData => labelData.value,
323
+ style: {
324
+ fontSize: 20,
325
+ fontFamily: 'Roboto',
326
+ fontWeight: '700',
327
+ fill: '#141F35'
328
+ }
329
+ }
330
+ return (
331
+ <div>
332
+ <AntFunnel data={funnelData} xField="id" yField="value" color={color} conversionTag={false} legend={legend} label={label} />
333
+ </div>
334
+ )
102
335
  }
103
336
 
104
- function mapStateToProps(store) {
105
- return { screenName: store.router.screenName }
337
+ function sorter(a: interfaces.DataItem, b: interfaces.DataItem) {
338
+ return parseInt(b.amount as string) - parseInt(a.amount as string)
106
339
  }
107
340
 
108
- export default connect(mapStateToProps)(ClientComponent)
341
+ export default React.memo(Funnel)
109
342
  ```
110
343
 
111
344
  # Contributing