@cxbox-ui/core 2.0.0-alpha.8 → 2.0.0-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +261 -28
- package/dist/core.d.ts +4274 -0
- package/dist/index.js +2 -6
- package/dist/index.js.map +1 -0
- package/package.json +19 -30
- package/dist/actions/index.d.ts +0 -1081
- package/dist/api/ObservableApi.d.ts +0 -53
- package/dist/api/ObservableApiWrapper.d.ts +0 -11
- package/dist/api/index.d.ts +0 -1
- package/dist/cxbox-ui-core.cjs.development.js +0 -3692
- package/dist/cxbox-ui-core.cjs.production.min.js +0 -2
- package/dist/cxbox-ui-core.esm.js +0 -3656
- package/dist/cxbox-ui-core.modern.development.js +0 -3586
- package/dist/cxbox-ui-core.modern.js +0 -3586
- package/dist/cxbox-ui-core.modern.production.min.js +0 -2
- package/dist/epics/data/bcCancelCreateDataEpic.d.ts +0 -9
- package/dist/epics/data/bcDeleteDataEpic.d.ts +0 -2
- package/dist/epics/data/bcFetchDataEpic.d.ts +0 -15
- package/dist/epics/data/bcFetchRowMetaRequestEpic.d.ts +0 -17
- package/dist/epics/data/bcLoadMoreEpic.d.ts +0 -2
- package/dist/epics/data/bcNewDataEpic.d.ts +0 -14
- package/dist/epics/data/bcSaveDataEpic.d.ts +0 -24
- package/dist/epics/data/bcSelectDepthRecordEpic.d.ts +0 -2
- package/dist/epics/data/bcSelectRecordEpic.d.ts +0 -2
- package/dist/epics/data/changeAssociationEpic.d.ts +0 -2
- package/dist/epics/data/changeAssociationFullEpic.d.ts +0 -5
- package/dist/epics/data/changeAssociationSameBcEpic.d.ts +0 -5
- package/dist/epics/data/changeChildrenAssociationsEpic.d.ts +0 -2
- package/dist/epics/data/changeChildrenAssociationsSameBcEpic.d.ts +0 -2
- package/dist/epics/data/changeDescendantsAssociationsFullEpic.d.ts +0 -5
- package/dist/epics/data/index.d.ts +0 -20
- package/dist/epics/data/inlinePickListFetchDataEpic.d.ts +0 -2
- package/dist/epics/data/removeMultivalueTagEpic.d.ts +0 -17
- package/dist/epics/data/saveAssociationsActiveEpic.d.ts +0 -7
- package/dist/epics/data/saveAssociationsPassiveEpic.d.ts +0 -7
- package/dist/epics/data/selectViewEpic.d.ts +0 -11
- package/dist/epics/index.d.ts +0 -6
- package/dist/epics/router/changeLocationEpic.d.ts +0 -10
- package/dist/epics/router/drilldownEpic.d.ts +0 -2
- package/dist/epics/router/handleRouterEpic.d.ts +0 -2
- package/dist/epics/router/index.d.ts +0 -10
- package/dist/epics/router/loginDoneEpic.d.ts +0 -9
- package/dist/epics/router/selectScreenEpic.d.ts +0 -7
- package/dist/epics/router/selectScreenFailEpic.d.ts +0 -7
- package/dist/epics/router/selectViewEpic.d.ts +0 -7
- package/dist/epics/router/selectViewFailEpic.d.ts +0 -6
- package/dist/epics/router/userDrillDownEpic.d.ts +0 -6
- package/dist/epics/router/userDrilldownChangeCursorsEpic.d.ts +0 -2
- package/dist/epics/screen/apiErrorEpic.d.ts +0 -2
- package/dist/epics/screen/downloadFileByUrlEpic.d.ts +0 -2
- package/dist/epics/screen/downloadFileEpic.d.ts +0 -2
- package/dist/epics/screen/httpError401Epic.d.ts +0 -2
- package/dist/epics/screen/httpError409Epic.d.ts +0 -2
- package/dist/epics/screen/httpError418Epic.d.ts +0 -2
- package/dist/epics/screen/httpError500Epic.d.ts +0 -2
- package/dist/epics/screen/httpErrorDefaultEpic.d.ts +0 -2
- package/dist/epics/screen/index.d.ts +0 -10
- package/dist/epics/screen/processPostInvokeConfirmEpic.d.ts +0 -2
- package/dist/epics/screen/processPostInvokeEpic.d.ts +0 -2
- package/dist/epics/session/index.d.ts +0 -5
- package/dist/epics/session/loginByAnotherRoleEpic.d.ts +0 -5
- package/dist/epics/session/loginDoneEpic.d.ts +0 -6
- package/dist/epics/session/refreshMetaAndReloadPageEpic.d.ts +0 -2
- package/dist/epics/session/refreshMetaEpic.d.ts +0 -5
- package/dist/epics/session/switchRoleEpic.d.ts +0 -5
- package/dist/epics/utils/postOperationRoutine.d.ts +0 -13
- package/dist/epics/view/clearPendingDataChangesAfterCursorChangeEpic.d.ts +0 -7
- package/dist/epics/view/fileUploadConfirmEpic.d.ts +0 -11
- package/dist/epics/view/getRowMetaByForceActiveEpic.d.ts +0 -5
- package/dist/epics/view/index.d.ts +0 -9
- package/dist/epics/view/selectTableCellInitEpic.d.ts +0 -2
- package/dist/epics/view/sendOperationAssociateEpic.d.ts +0 -5
- package/dist/epics/view/sendOperationEpic.d.ts +0 -10
- package/dist/epics/view/showAllTableRecordsInitEpic.d.ts +0 -2
- package/dist/epics/view/showAssocPopupEpic.d.ts +0 -2
- package/dist/epics/view/showFileUploadPopupEpic.d.ts +0 -5
- package/dist/index.d.ts +0 -7
- package/dist/interfaces/bc.d.ts +0 -79
- package/dist/interfaces/customEpics.d.ts +0 -15
- package/dist/interfaces/customMiddlewares.d.ts +0 -35
- package/dist/interfaces/data.d.ts +0 -48
- package/dist/interfaces/filters.d.ts +0 -32
- package/dist/interfaces/index.d.ts +0 -27
- package/dist/interfaces/navigation.d.ts +0 -48
- package/dist/interfaces/objectMap.d.ts +0 -36
- package/dist/interfaces/operation.d.ts +0 -336
- package/dist/interfaces/router.d.ts +0 -17
- package/dist/interfaces/rowMeta.d.ts +0 -74
- package/dist/interfaces/screen.d.ts +0 -28
- package/dist/interfaces/session.d.ts +0 -83
- package/dist/interfaces/store.d.ts +0 -14
- package/dist/interfaces/tree.d.ts +0 -66
- package/dist/interfaces/view.d.ts +0 -202
- package/dist/interfaces/widget.d.ts +0 -209
- package/dist/middlewares/autosaveMiddleware.d.ts +0 -2
- package/dist/middlewares/index.d.ts +0 -6
- package/dist/middlewares/popupMiddleware.d.ts +0 -2
- package/dist/middlewares/preInvokeMiddleware.d.ts +0 -5
- package/dist/middlewares/requiredFieldsMiddleware.d.ts +0 -30
- package/dist/reducers/ReducerBuilderManager.d.ts +0 -19
- package/dist/reducers/data.d.ts +0 -4
- package/dist/reducers/depthData.d.ts +0 -4
- package/dist/reducers/index.d.ts +0 -6
- package/dist/reducers/router.d.ts +0 -9
- package/dist/reducers/screen.d.ts +0 -10
- package/dist/reducers/session.d.ts +0 -10
- package/dist/reducers/view.d.ts +0 -10
- package/dist/utils/api.d.ts +0 -25
- package/dist/utils/apiError.d.ts +0 -19
- package/dist/utils/autosave.d.ts +0 -37
- package/dist/utils/bc.d.ts +0 -27
- package/dist/utils/breadthFirst.d.ts +0 -21
- package/dist/utils/cancelRequestEpic.d.ts +0 -27
- package/dist/utils/combineMiddlewares.d.ts +0 -3
- package/dist/utils/deleteUndefinedFromObject.d.ts +0 -1
- package/dist/utils/exportState.d.ts +0 -0
- package/dist/utils/extendPopupWidgetTypes.d.ts +0 -8
- package/dist/utils/filters.d.ts +0 -63
- package/dist/utils/hierarchy.d.ts +0 -17
- package/dist/utils/highlightJson.d.ts +0 -12
- package/dist/utils/history.d.ts +0 -50
- package/dist/utils/index.d.ts +0 -10
- package/dist/utils/operations.d.ts +0 -21
- package/dist/utils/others.d.ts +0 -6
- package/dist/utils/strings.d.ts +0 -44
- package/dist/utils/tree.d.ts +0 -43
- 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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
69
|
-
|
|
74
|
+

|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## Changelog
|
|
79
|
+
|
|
80
|
+

|
|
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
|
-
|
|
109
|
+
> [!WARNING]
|
|
110
|
+
> CJS module system are no longer supported
|
|
111
|
+
---
|
|
74
112
|
|
|
75
113
|
## Usage
|
|
76
114
|
|
|
77
|
-
|
|
115
|
+
Library proposes to use common way of configuring your Redux store with some nuances
|
|
78
116
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
195
|
+
const CXBoxApiInstance = new Api(instance)
|
|
88
196
|
```
|
|
89
197
|
|
|
90
|
-
|
|
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 {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
|
105
|
-
return
|
|
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
|
|
341
|
+
export default React.memo(Funnel)
|
|
109
342
|
```
|
|
110
343
|
|
|
111
344
|
# Contributing
|