@aventoapp/framework 0.2.0 → 0.2.2

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 (159) hide show
  1. package/README.md +281 -0
  2. package/dist/index.js.map +1 -1
  3. package/dist/native/index.js.map +1 -1
  4. package/dist/offline/index.js.map +1 -1
  5. package/dist/server/index.js +69 -6
  6. package/dist/server/index.js.map +2 -2
  7. package/dist/server/workflow/index.js.map +1 -1
  8. package/dist/shared/index.js.map +1 -1
  9. package/dist/web/index.js.map +1 -1
  10. package/package.json +84 -79
  11. package/schemas/Workflow.json +14 -14
  12. package/schemas/WorkflowHistory.json +22 -22
  13. package/schemas/WorkflowInstance.json +16 -16
  14. package/schemas/WorkflowState.json +18 -18
  15. package/schemas/WorkflowTransition.json +27 -27
  16. package/src/index.js +8 -8
  17. package/src/native/components/NativeAuthProvider.jsx +249 -249
  18. package/src/native/components/NativeDetail.jsx +270 -270
  19. package/src/native/components/NativeForm.jsx +543 -543
  20. package/src/native/components/NativeGrid.jsx +90 -90
  21. package/src/native/components/NativeJsonGrid.jsx +213 -213
  22. package/src/native/components/NativeJsonView.jsx +454 -454
  23. package/src/native/components/NativeJsonViewContext.js +17 -17
  24. package/src/native/components/NativeShell.jsx +68 -68
  25. package/src/native/components/NativeViewComponent.jsx +351 -351
  26. package/src/native/extensions/NativeExtensionRegistry.js +81 -81
  27. package/src/native/hooks/useNativeStore.js +72 -72
  28. package/src/native/index.js +15 -15
  29. package/src/native/layouts/NativeStackLayout.jsx +30 -30
  30. package/src/native/layouts/NativeTabLayout.jsx +96 -96
  31. package/src/native/storage.js +13 -13
  32. package/src/native/stores/NativeBaseStore.js +348 -348
  33. package/src/native/stores/NativeStoreContext.jsx +53 -53
  34. package/src/offline/index.js +1 -1
  35. package/src/server/ai/capabilities-routes.js +106 -106
  36. package/src/server/ai/index.js +1 -1
  37. package/src/server/cache/MemoryCache.js +153 -153
  38. package/src/server/cache/index.js +2 -2
  39. package/src/server/cache/middleware.js +12 -12
  40. package/src/server/db/index.js +14 -14
  41. package/src/server/db/mongo.js +137 -137
  42. package/src/server/db/postgres.js +144 -144
  43. package/src/server/index.js +42 -42
  44. package/src/server/middleware/auth.js +682 -682
  45. package/src/server/middleware/can-flags.js +132 -132
  46. package/src/server/middleware/entityRoles.js +105 -105
  47. package/src/server/middleware/index.js +58 -58
  48. package/src/server/middleware/permissions.js +240 -240
  49. package/src/server/middleware/tenant.js +203 -203
  50. package/src/server/offline/field-lww.js +98 -6
  51. package/src/server/realtime/EventBus.js +45 -45
  52. package/src/server/realtime/WebSocketServer.js +105 -105
  53. package/src/server/realtime/index.js +3 -3
  54. package/src/server/realtime/middleware.js +18 -18
  55. package/src/server/services/email-templates.js +157 -157
  56. package/src/server/services/email.js +78 -78
  57. package/src/server/services/index.js +15 -15
  58. package/src/server/services/storage.js +119 -119
  59. package/src/server/utils/index.js +16 -16
  60. package/src/server/utils/paginate.js +65 -65
  61. package/src/server/utils/query-builder.js +293 -293
  62. package/src/server/utils/route-loader.js +61 -61
  63. package/src/server/workflow/WorkflowEngine.js +494 -494
  64. package/src/server/workflow/index.js +2 -2
  65. package/src/server/workflow/workflow-routes.js +174 -174
  66. package/src/shared/index.js +10 -10
  67. package/src/shared/utils/field-accessor.js +108 -108
  68. package/src/shared/utils/index.js +7 -7
  69. package/src/shared/utils/validation-utils.js +83 -83
  70. package/src/web/components/AppRouter/AppRouter.jsx +130 -130
  71. package/src/web/components/AppRouter/index.js +1 -1
  72. package/src/web/components/AppShell/AppShell.jsx +101 -101
  73. package/src/web/components/AppShell/DefaultUserMenu.jsx +54 -54
  74. package/src/web/components/AppShell/ShellConfig.js +53 -53
  75. package/src/web/components/AppShell/index.js +3 -3
  76. package/src/web/components/AuthProvider.jsx +426 -426
  77. package/src/web/components/CardList/CardList.jsx +272 -272
  78. package/src/web/components/CardList/index.js +2 -2
  79. package/src/web/components/DetailView/DetailView.jsx +281 -281
  80. package/src/web/components/DetailView/index.js +2 -2
  81. package/src/web/components/Form/Form.jsx +300 -300
  82. package/src/web/components/Form/FormField.jsx +226 -226
  83. package/src/web/components/Form/index.js +3 -3
  84. package/src/web/components/Grid/Grid.jsx +304 -304
  85. package/src/web/components/Grid/index.js +2 -2
  86. package/src/web/components/IconRegistry/IconRegistry.jsx +127 -127
  87. package/src/web/components/IconRegistry/index.js +1 -1
  88. package/src/web/components/JsonView/JsonView.jsx +647 -647
  89. package/src/web/components/JsonView/ViewComponent.jsx +1045 -1045
  90. package/src/web/components/JsonView/ViewToolbar.jsx +141 -141
  91. package/src/web/components/JsonView/index.js +14 -14
  92. package/src/web/components/JsonView/layouts/SingleLayout.jsx +41 -41
  93. package/src/web/components/JsonView/layouts/SplitLayout.jsx +122 -122
  94. package/src/web/components/JsonView/layouts/TabLayout.jsx +112 -112
  95. package/src/web/components/JsonView/layouts/index.js +8 -8
  96. package/src/web/components/Layout.jsx +265 -265
  97. package/src/web/components/MobileLayout/MobileLayout.jsx +385 -385
  98. package/src/web/components/MobileLayout/index.js +1 -1
  99. package/src/web/components/Navigation/Navigation.jsx +248 -248
  100. package/src/web/components/Navigation/index.js +1 -1
  101. package/src/web/components/NotificationProvider.jsx +55 -55
  102. package/src/web/components/Pagination/InfiniteScroll.jsx +82 -82
  103. package/src/web/components/Pagination/Pagination.jsx +73 -73
  104. package/src/web/components/Pagination/index.js +8 -8
  105. package/src/web/components/SimpleList/SimpleList.jsx +177 -177
  106. package/src/web/components/SimpleList/index.js +2 -2
  107. package/src/web/components/TenantProvider.jsx +121 -121
  108. package/src/web/components/WorkflowActions/WorkflowActions.jsx +71 -71
  109. package/src/web/components/WorkflowActions/index.js +1 -1
  110. package/src/web/components/WorkflowField/WorkflowField.jsx +176 -176
  111. package/src/web/components/WorkflowField/index.js +2 -2
  112. package/src/web/components/WorkflowField/workflowColors.js +32 -32
  113. package/src/web/components/auth/DevTenantSelector.jsx +90 -90
  114. package/src/web/components/auth/ForgotPasswordForm.jsx +94 -94
  115. package/src/web/components/auth/RegisterForm.jsx +168 -168
  116. package/src/web/components/auth/ResetPasswordForm.jsx +121 -121
  117. package/src/web/components/auth/VerifyEmailView.jsx +85 -85
  118. package/src/web/components/auth/index.js +5 -5
  119. package/src/web/components/index.js +39 -39
  120. package/src/web/components/layouts/CardListLayout.jsx +68 -68
  121. package/src/web/components/layouts/FullscreenLayout.jsx +30 -30
  122. package/src/web/components/layouts/MobileStackLayout.jsx +28 -28
  123. package/src/web/components/layouts/WizardLayout.jsx +86 -86
  124. package/src/web/components/layouts/index.js +4 -4
  125. package/src/web/components/mobile/Badge.jsx +105 -105
  126. package/src/web/components/mobile/BadgeThemeEditor.jsx +104 -104
  127. package/src/web/components/mobile/EmptyState.jsx +30 -30
  128. package/src/web/components/mobile/QuickActionButton.jsx +77 -77
  129. package/src/web/components/mobile/ServerAutocomplete.jsx +123 -123
  130. package/src/web/components/mobile/StarRating.jsx +42 -42
  131. package/src/web/components/mobile/StatCard.jsx +65 -65
  132. package/src/web/components/mobile/index.js +7 -7
  133. package/src/web/extensions/ExtensionRegistry.js +79 -79
  134. package/src/web/extensions/index.js +7 -7
  135. package/src/web/hooks/index.js +15 -15
  136. package/src/web/hooks/useApi.js +76 -76
  137. package/src/web/hooks/useAuth.js +37 -37
  138. package/src/web/hooks/useDebouncedSave.js +158 -158
  139. package/src/web/hooks/useIsMobile.js +14 -14
  140. package/src/web/hooks/useOfflineQueue.js +99 -99
  141. package/src/web/hooks/useSelectionModel.js +143 -143
  142. package/src/web/hooks/useServerAutocomplete.js +146 -146
  143. package/src/web/hooks/useStore.js +107 -107
  144. package/src/web/hooks/useSubscription.js +130 -130
  145. package/src/web/hooks/useTenant.js +39 -39
  146. package/src/web/hooks/useTenantResolver.js +65 -65
  147. package/src/web/hooks/useUndoRedo.js +77 -77
  148. package/src/web/hooks/useViews.js +113 -113
  149. package/src/web/hooks/useWorkflow.js +190 -190
  150. package/src/web/index.js +117 -117
  151. package/src/web/stores/BaseStore.js +439 -439
  152. package/src/web/stores/StoreContext.jsx +93 -93
  153. package/src/web/stores/index.js +3 -3
  154. package/src/web/theme/index.js +3 -3
  155. package/src/web/theme/mui-theme.js +228 -228
  156. package/src/web/utils/formatTimeAgo.js +22 -22
  157. package/src/web/utils/index.js +1 -1
  158. package/src/web/views/ViewRegistry.js +235 -235
  159. package/src/web/views/index.js +2 -2
@@ -1,647 +1,647 @@
1
- /**
2
- * JsonView Component
3
- *
4
- * Main orchestrator for JSON-declared views. Parses view config,
5
- * connects to stores, and renders layouts with reactive components.
6
- * Supports extensions for custom actions and components.
7
- */
8
- import React, { createContext, useContext, useReducer, useEffect, useMemo, useCallback } from 'react';
9
- import { Box, Alert, CircularProgress } from '@mui/material';
10
- import { useStore } from '../../hooks/useStore.js';
11
- import { ViewToolbar } from './ViewToolbar.jsx';
12
- import { SplitLayout, TabLayout, SingleLayout } from './layouts/index.js';
13
- import { extensionRegistry } from '../../extensions/index.js';
14
-
15
- /**
16
- * Action types for view state management
17
- */
18
- const ActionTypes = {
19
- SET_SELECTION: 'SET_SELECTION',
20
- CLEAR_SELECTION: 'CLEAR_SELECTION',
21
- SET_EDIT_ITEM: 'SET_EDIT_ITEM',
22
- CLEAR_EDIT_ITEM: 'CLEAR_EDIT_ITEM',
23
- OPEN_DIALOG: 'OPEN_DIALOG',
24
- CLOSE_DIALOG: 'CLOSE_DIALOG',
25
- SET_COMPONENT_STATE: 'SET_COMPONENT_STATE',
26
- SET_PAGINATION: 'SET_PAGINATION',
27
- SET_RELATED_ITEMS: 'SET_RELATED_ITEMS',
28
- SET_RELATED_LOADING: 'SET_RELATED_LOADING'
29
- };
30
-
31
- /**
32
- * Get initial pagination state from config
33
- */
34
- function getInitialPaginationState(paginationConfig) {
35
- if (!paginationConfig || paginationConfig.mode === 'none') {
36
- return null;
37
- }
38
- return {
39
- mode: paginationConfig.mode || 'pages',
40
- page: 1,
41
- pageSize: paginationConfig.pageSize || 25,
42
- pageSizeOptions: paginationConfig.pageSizeOptions || [10, 25, 50, 100],
43
- threshold: paginationConfig.threshold || 200,
44
- total: 0,
45
- totalPages: 0,
46
- hasNext: false,
47
- hasPrev: false
48
- };
49
- }
50
-
51
- /**
52
- * Initial view state
53
- */
54
- const initialState = {
55
- selections: {}, // { componentId: selectedRow }
56
- editItems: {}, // { componentId: editingRow }
57
- dialogs: {}, // { dialogId: { open: boolean, data: any } }
58
- componentStates: {}, // { componentId: { ...state } }
59
- pagination: null, // Pagination state when enabled
60
- relatedItems: {}, // { componentId: { items: [], loading: boolean, parentId: string } }
61
- relatedLoading: {} // { componentId: boolean }
62
- };
63
-
64
- /**
65
- * View state reducer
66
- */
67
- function viewReducer(state, action) {
68
- switch (action.type) {
69
- case ActionTypes.SET_SELECTION:
70
- return {
71
- ...state,
72
- selections: {
73
- ...state.selections,
74
- [action.componentId]: action.data
75
- }
76
- };
77
-
78
- case ActionTypes.CLEAR_SELECTION:
79
- return {
80
- ...state,
81
- selections: {
82
- ...state.selections,
83
- [action.componentId]: null
84
- }
85
- };
86
-
87
- case ActionTypes.SET_EDIT_ITEM:
88
- return {
89
- ...state,
90
- editItems: {
91
- ...state.editItems,
92
- [action.componentId]: action.data
93
- }
94
- };
95
-
96
- case ActionTypes.CLEAR_EDIT_ITEM:
97
- return {
98
- ...state,
99
- editItems: {
100
- ...state.editItems,
101
- [action.componentId]: null
102
- }
103
- };
104
-
105
- case ActionTypes.OPEN_DIALOG:
106
- return {
107
- ...state,
108
- dialogs: {
109
- ...state.dialogs,
110
- [action.dialogId]: { open: true, data: action.data }
111
- }
112
- };
113
-
114
- case ActionTypes.CLOSE_DIALOG:
115
- return {
116
- ...state,
117
- dialogs: {
118
- ...state.dialogs,
119
- [action.dialogId]: { open: false, data: null }
120
- }
121
- };
122
-
123
- case ActionTypes.SET_COMPONENT_STATE:
124
- return {
125
- ...state,
126
- componentStates: {
127
- ...state.componentStates,
128
- [action.componentId]: {
129
- ...state.componentStates[action.componentId],
130
- ...action.state
131
- }
132
- }
133
- };
134
-
135
- case ActionTypes.SET_PAGINATION:
136
- return {
137
- ...state,
138
- pagination: {
139
- ...state.pagination,
140
- ...action.pagination
141
- }
142
- };
143
-
144
- case ActionTypes.SET_RELATED_ITEMS:
145
- return {
146
- ...state,
147
- relatedItems: {
148
- ...state.relatedItems,
149
- [action.componentId]: {
150
- items: action.items,
151
- parentId: action.parentId,
152
- pagination: action.pagination
153
- }
154
- },
155
- relatedLoading: {
156
- ...state.relatedLoading,
157
- [action.componentId]: false
158
- }
159
- };
160
-
161
- case ActionTypes.SET_RELATED_LOADING:
162
- return {
163
- ...state,
164
- relatedLoading: {
165
- ...state.relatedLoading,
166
- [action.componentId]: action.loading
167
- }
168
- };
169
-
170
- default:
171
- return state;
172
- }
173
- }
174
-
175
- /**
176
- * JsonView Context for component communication
177
- */
178
- export const JsonViewContext = createContext(null);
179
-
180
- /**
181
- * Hook to access JsonView context
182
- */
183
- export function useJsonView() {
184
- const context = useContext(JsonViewContext);
185
- if (!context) {
186
- throw new Error('useJsonView must be used within a JsonView');
187
- }
188
- return context;
189
- }
190
-
191
- /**
192
- * Layout component mapping
193
- */
194
- const LAYOUTS = {
195
- split: SplitLayout,
196
- tabs: TabLayout,
197
- single: SingleLayout,
198
- accordion: SingleLayout // Fallback to single for now
199
- };
200
-
201
- /**
202
- * Inner component that uses the store hook
203
- * This ensures the hook is always called (not conditionally)
204
- */
205
- function JsonViewWithStore({ config, storeName }) {
206
- const store = useStore(storeName);
207
-
208
- // Extract config with defaults
209
- const {
210
- id: viewId,
211
- layout = 'single',
212
- layoutConfig = {},
213
- dataSource = {},
214
- components = [],
215
- toolbar,
216
- extension: extensionName
217
- } = config || {};
218
-
219
- // Initialize state with pagination config
220
- const initialStateWithPagination = useMemo(() => ({
221
- ...initialState,
222
- pagination: getInitialPaginationState(dataSource?.pagination)
223
- }), []);
224
-
225
- const [viewState, dispatch] = useReducer(viewReducer, initialStateWithPagination);
226
-
227
- const storeLoading = store.loading;
228
- const storeError = store.error;
229
- const storePagination = store.pagination;
230
-
231
- const storeActions = useMemo(() => ({
232
- list: store.list,
233
- get: store.get,
234
- create: store.create,
235
- update: store.update,
236
- delete: store.delete,
237
- select: store.select,
238
- clearSelection: store.clearSelection,
239
- loadMore: store.loadMore,
240
- setPageSize: store.setPageSize
241
- }), [store]);
242
-
243
- // Get extension hook if specified
244
- const useExtension = extensionName ? extensionRegistry.get(extensionName) : null;
245
-
246
- // Sync store pagination to view state
247
- useEffect(() => {
248
- if (viewState.pagination && storePagination) {
249
- dispatch({
250
- type: ActionTypes.SET_PAGINATION,
251
- pagination: {
252
- page: storePagination.page,
253
- pageSize: storePagination.pageSize,
254
- total: storePagination.total,
255
- totalPages: storePagination.totalPages,
256
- hasNext: storePagination.hasNext,
257
- hasPrev: storePagination.hasPrev
258
- }
259
- });
260
- }
261
- }, [storePagination, viewState.pagination !== null]);
262
-
263
- // Sync selections with store items when items change
264
- // This ensures detail views show updated data after edits
265
- const storeItems = store.items;
266
- useEffect(() => {
267
- if (!storeItems?.length) return;
268
-
269
- // Check each selection and update if the item exists in the new items
270
- Object.entries(viewState.selections).forEach(([componentId, selectedItem]) => {
271
- if (!selectedItem?.id) return;
272
-
273
- // Find the updated item in the store
274
- const updatedItem = storeItems.find(item => item.id === selectedItem.id);
275
- if (updatedItem && updatedItem !== selectedItem) {
276
- dispatch({
277
- type: ActionTypes.SET_SELECTION,
278
- componentId,
279
- data: updatedItem
280
- });
281
- }
282
- });
283
- }, [storeItems]);
284
-
285
- // Auto-load data on mount
286
- useEffect(() => {
287
- if (dataSource?.autoLoad) {
288
- const loadOptions = {};
289
- if (viewState.pagination) {
290
- loadOptions.page = viewState.pagination.page;
291
- loadOptions.pageSize = viewState.pagination.pageSize;
292
- }
293
- if (dataSource.sliceId) {
294
- loadOptions.sliceId = dataSource.sliceId;
295
- }
296
- store.list(loadOptions);
297
- }
298
- }, []);
299
-
300
- return (
301
- <JsonViewInner
302
- config={config}
303
- viewId={viewId}
304
- layout={layout}
305
- layoutConfig={layoutConfig}
306
- dataSource={dataSource}
307
- components={components}
308
- toolbar={toolbar}
309
- viewState={viewState}
310
- dispatch={dispatch}
311
- storeData={store}
312
- storeLoading={storeLoading}
313
- storeError={storeError}
314
- storeActions={storeActions}
315
- useExtension={useExtension}
316
- />
317
- );
318
- }
319
-
320
- /**
321
- * JsonView without store (for views that don't need data)
322
- */
323
- function JsonViewWithoutStore({ config }) {
324
- const [viewState, dispatch] = useReducer(viewReducer, initialState);
325
-
326
- const {
327
- id: viewId,
328
- layout = 'single',
329
- layoutConfig = {},
330
- dataSource = {},
331
- components = [],
332
- toolbar,
333
- extension: extensionName
334
- } = config || {};
335
-
336
- // Get extension hook if specified
337
- const useExtension = extensionName ? extensionRegistry.get(extensionName) : null;
338
-
339
- return (
340
- <JsonViewInner
341
- config={config}
342
- viewId={viewId}
343
- layout={layout}
344
- layoutConfig={layoutConfig}
345
- dataSource={dataSource}
346
- components={components}
347
- toolbar={toolbar}
348
- viewState={viewState}
349
- dispatch={dispatch}
350
- storeData={null}
351
- storeLoading={false}
352
- storeError={null}
353
- storeActions={{}}
354
- useExtension={useExtension}
355
- />
356
- );
357
- }
358
-
359
- /**
360
- * JsonView Component
361
- *
362
- * @param {Object} config - View configuration object
363
- * @param {string} config.id - Unique view identifier
364
- * @param {string} config.layout - Layout type: split | tabs | single | accordion
365
- * @param {Object} config.layoutConfig - Layout-specific configuration
366
- * @param {Object} config.dataSource - Data source configuration
367
- * @param {Array} config.components - Array of component configurations
368
- * @param {Object} config.toolbar - Toolbar configuration
369
- */
370
- export function JsonView({ config }) {
371
- const storeName = config?.dataSource?.store;
372
-
373
- // Route to appropriate implementation based on whether store is needed
374
- if (storeName) {
375
- return <JsonViewWithStore config={config} storeName={storeName} />;
376
- }
377
- return <JsonViewWithoutStore config={config} />;
378
- }
379
-
380
- /**
381
- * Inner JsonView implementation
382
- */
383
- function JsonViewInner({
384
- config,
385
- viewId,
386
- layout,
387
- layoutConfig,
388
- dataSource,
389
- components,
390
- toolbar,
391
- viewState,
392
- dispatch,
393
- storeData,
394
- storeLoading,
395
- storeError,
396
- storeActions,
397
- useExtension
398
- }) {
399
-
400
- // Action dispatch helpers
401
- const setSelection = useCallback((componentId, data) => {
402
- dispatch({ type: ActionTypes.SET_SELECTION, componentId, data });
403
- }, []);
404
-
405
- const clearSelection = useCallback((componentId) => {
406
- dispatch({ type: ActionTypes.CLEAR_SELECTION, componentId });
407
- }, []);
408
-
409
- const setEditItem = useCallback((componentId, data) => {
410
- dispatch({ type: ActionTypes.SET_EDIT_ITEM, componentId, data });
411
- }, []);
412
-
413
- const clearEditItem = useCallback((componentId) => {
414
- dispatch({ type: ActionTypes.CLEAR_EDIT_ITEM, componentId });
415
- }, []);
416
-
417
- const openDialog = useCallback((dialogId, data = null) => {
418
- dispatch({ type: ActionTypes.OPEN_DIALOG, dialogId, data });
419
- }, []);
420
-
421
- const closeDialog = useCallback((dialogId) => {
422
- dispatch({ type: ActionTypes.CLOSE_DIALOG, dialogId });
423
- }, []);
424
-
425
- const setComponentState = useCallback((componentId, state) => {
426
- dispatch({ type: ActionTypes.SET_COMPONENT_STATE, componentId, state });
427
- }, []);
428
-
429
- // Related items handlers (for hasMany)
430
- const setRelatedItems = useCallback((componentId, items, parentId, pagination) => {
431
- dispatch({ type: ActionTypes.SET_RELATED_ITEMS, componentId, items, parentId, pagination });
432
- }, []);
433
-
434
- const setRelatedLoading = useCallback((componentId, loading) => {
435
- dispatch({ type: ActionTypes.SET_RELATED_LOADING, componentId, loading });
436
- }, []);
437
-
438
- // Pagination handlers
439
- const handlePageChange = useCallback((page) => {
440
- if (!viewState.pagination) return;
441
- dispatch({ type: ActionTypes.SET_PAGINATION, pagination: { page } });
442
- storeActions.list?.({
443
- page,
444
- pageSize: viewState.pagination.pageSize,
445
- sliceId: dataSource?.sliceId
446
- });
447
- }, [viewState.pagination, storeActions, dataSource?.sliceId]);
448
-
449
- const handlePageSizeChange = useCallback((pageSize) => {
450
- if (!viewState.pagination) return;
451
- dispatch({ type: ActionTypes.SET_PAGINATION, pagination: { page: 1, pageSize } });
452
- storeActions.list?.({
453
- page: 1,
454
- pageSize,
455
- sliceId: dataSource?.sliceId
456
- });
457
- }, [viewState.pagination, storeActions, dataSource?.sliceId]);
458
-
459
- const handleLoadMore = useCallback(() => {
460
- storeActions.loadMore?.();
461
- }, [storeActions]);
462
-
463
- // Call extension hook if provided
464
- // Extension receives context and returns { actions, components, ...customState }
465
- const extensionContext = useMemo(() => ({
466
- store: storeData,
467
- storeActions,
468
- viewState,
469
- openDialog,
470
- closeDialog,
471
- setSelection,
472
- setEditItem
473
- }), [storeData, storeActions, viewState, openDialog, closeDialog, setSelection, setEditItem]);
474
-
475
- const extension = useExtension ? useExtension(extensionContext) : null;
476
- const extensionActions = extension?.actions || {};
477
- const extensionComponents = extension?.components || {};
478
-
479
- // Execute a custom action (from extension or server-side)
480
- const executeCustomAction = useCallback(async (actionConfig, data) => {
481
- // Check for extension handler
482
- if (actionConfig.handler && extensionActions[actionConfig.handler]) {
483
- return extensionActions[actionConfig.handler](data);
484
- }
485
-
486
- // Check for declarative server action
487
- if (actionConfig.serverAction) {
488
- const endpoint = actionConfig.endpoint.replace(':id', data?.id);
489
- const method = actionConfig.method || 'POST';
490
-
491
- const response = await fetch(endpoint, {
492
- method,
493
- headers: { 'Content-Type': 'application/json' },
494
- body: method !== 'GET' ? JSON.stringify(data) : undefined
495
- });
496
-
497
- if (!response.ok) {
498
- throw new Error(`Server action failed: ${response.statusText}`);
499
- }
500
-
501
- // Refresh data if configured (include sliceId for joined data)
502
- if (actionConfig.refreshAfter !== false) {
503
- storeActions.list?.(dataSource?.sliceId ? { sliceId: dataSource.sliceId } : undefined);
504
- }
505
-
506
- return response.json().catch(() => ({}));
507
- }
508
- }, [extensionActions, storeActions, dataSource?.sliceId]);
509
-
510
- // Context value
511
- const contextValue = useMemo(() => ({
512
- // View config
513
- viewId,
514
- config,
515
- components,
516
-
517
- // View state
518
- viewState,
519
- selections: viewState.selections,
520
- editItems: viewState.editItems,
521
- dialogs: viewState.dialogs,
522
-
523
- // Pagination state and handlers
524
- pagination: viewState.pagination,
525
- paginationConfig: dataSource?.pagination,
526
- onPageChange: handlePageChange,
527
- onPageSizeChange: handlePageSizeChange,
528
- onLoadMore: handleLoadMore,
529
-
530
- // Related items state and handlers (for hasMany)
531
- relatedItems: viewState.relatedItems,
532
- relatedLoading: viewState.relatedLoading,
533
- setRelatedItems,
534
- setRelatedLoading,
535
-
536
- // State actions
537
- setSelection,
538
- clearSelection,
539
- setEditItem,
540
- clearEditItem,
541
- openDialog,
542
- closeDialog,
543
- setComponentState,
544
-
545
- // Store data and actions
546
- store: storeData,
547
- storeActions,
548
- items: storeData?.items || [],
549
- loading: storeLoading,
550
- error: storeError,
551
-
552
- // Extension data
553
- extension,
554
- extensionActions,
555
- extensionComponents,
556
- executeCustomAction
557
- }), [
558
- viewId,
559
- config,
560
- components,
561
- viewState,
562
- dataSource?.pagination,
563
- storeData,
564
- storeLoading,
565
- storeError,
566
- setSelection,
567
- clearSelection,
568
- setEditItem,
569
- clearEditItem,
570
- openDialog,
571
- closeDialog,
572
- setComponentState,
573
- setRelatedItems,
574
- setRelatedLoading,
575
- storeActions,
576
- handlePageChange,
577
- handlePageSizeChange,
578
- handleLoadMore,
579
- extension,
580
- extensionActions,
581
- extensionComponents,
582
- executeCustomAction
583
- ]);
584
-
585
- // Handle toolbar actions
586
- const handleToolbarAction = useCallback((actionId, actionConfig) => {
587
- switch (actionId) {
588
- case 'refresh':
589
- storeActions.list?.({ sliceId: dataSource?.sliceId });
590
- break;
591
- case 'create':
592
- if (actionConfig?.opens) {
593
- openDialog(actionConfig.opens, null);
594
- }
595
- break;
596
- default:
597
- // Check for custom handler in extension or server action
598
- if (actionConfig?.handler || actionConfig?.serverAction) {
599
- executeCustomAction(actionConfig, null);
600
- }
601
- break;
602
- }
603
- }, [storeActions, openDialog, executeCustomAction, dataSource?.sliceId]);
604
-
605
- // Select layout component
606
- const LayoutComponent = LAYOUTS[layout] || SingleLayout;
607
-
608
- // Error state
609
- if (storeError && !storeData?.items?.length) {
610
- return (
611
- <Box sx={{ p: 2 }}>
612
- <Alert severity="error">
613
- {storeError}
614
- </Alert>
615
- </Box>
616
- );
617
- }
618
-
619
- return (
620
- <JsonViewContext.Provider value={contextValue}>
621
- <Box sx={{ display: 'flex', flexDirection: 'column', height: '100%' }}>
622
- {/* Toolbar */}
623
- {(toolbar || dataSource?.pagination?.mode === 'pages') && (
624
- <ViewToolbar
625
- config={toolbar}
626
- onAction={handleToolbarAction}
627
- loading={storeLoading}
628
- pagination={viewState.pagination}
629
- paginationConfig={dataSource?.pagination}
630
- onPageChange={handlePageChange}
631
- onPageSizeChange={handlePageSizeChange}
632
- />
633
- )}
634
-
635
- {/* Layout with components */}
636
- <Box sx={{ flex: 1, overflow: 'auto' }}>
637
- <LayoutComponent
638
- config={layoutConfig}
639
- components={components}
640
- />
641
- </Box>
642
- </Box>
643
- </JsonViewContext.Provider>
644
- );
645
- }
646
-
647
- export default JsonView;
1
+ /**
2
+ * JsonView Component
3
+ *
4
+ * Main orchestrator for JSON-declared views. Parses view config,
5
+ * connects to stores, and renders layouts with reactive components.
6
+ * Supports extensions for custom actions and components.
7
+ */
8
+ import React, { createContext, useContext, useReducer, useEffect, useMemo, useCallback } from 'react';
9
+ import { Box, Alert, CircularProgress } from '@mui/material';
10
+ import { useStore } from '../../hooks/useStore.js';
11
+ import { ViewToolbar } from './ViewToolbar.jsx';
12
+ import { SplitLayout, TabLayout, SingleLayout } from './layouts/index.js';
13
+ import { extensionRegistry } from '../../extensions/index.js';
14
+
15
+ /**
16
+ * Action types for view state management
17
+ */
18
+ const ActionTypes = {
19
+ SET_SELECTION: 'SET_SELECTION',
20
+ CLEAR_SELECTION: 'CLEAR_SELECTION',
21
+ SET_EDIT_ITEM: 'SET_EDIT_ITEM',
22
+ CLEAR_EDIT_ITEM: 'CLEAR_EDIT_ITEM',
23
+ OPEN_DIALOG: 'OPEN_DIALOG',
24
+ CLOSE_DIALOG: 'CLOSE_DIALOG',
25
+ SET_COMPONENT_STATE: 'SET_COMPONENT_STATE',
26
+ SET_PAGINATION: 'SET_PAGINATION',
27
+ SET_RELATED_ITEMS: 'SET_RELATED_ITEMS',
28
+ SET_RELATED_LOADING: 'SET_RELATED_LOADING'
29
+ };
30
+
31
+ /**
32
+ * Get initial pagination state from config
33
+ */
34
+ function getInitialPaginationState(paginationConfig) {
35
+ if (!paginationConfig || paginationConfig.mode === 'none') {
36
+ return null;
37
+ }
38
+ return {
39
+ mode: paginationConfig.mode || 'pages',
40
+ page: 1,
41
+ pageSize: paginationConfig.pageSize || 25,
42
+ pageSizeOptions: paginationConfig.pageSizeOptions || [10, 25, 50, 100],
43
+ threshold: paginationConfig.threshold || 200,
44
+ total: 0,
45
+ totalPages: 0,
46
+ hasNext: false,
47
+ hasPrev: false
48
+ };
49
+ }
50
+
51
+ /**
52
+ * Initial view state
53
+ */
54
+ const initialState = {
55
+ selections: {}, // { componentId: selectedRow }
56
+ editItems: {}, // { componentId: editingRow }
57
+ dialogs: {}, // { dialogId: { open: boolean, data: any } }
58
+ componentStates: {}, // { componentId: { ...state } }
59
+ pagination: null, // Pagination state when enabled
60
+ relatedItems: {}, // { componentId: { items: [], loading: boolean, parentId: string } }
61
+ relatedLoading: {} // { componentId: boolean }
62
+ };
63
+
64
+ /**
65
+ * View state reducer
66
+ */
67
+ function viewReducer(state, action) {
68
+ switch (action.type) {
69
+ case ActionTypes.SET_SELECTION:
70
+ return {
71
+ ...state,
72
+ selections: {
73
+ ...state.selections,
74
+ [action.componentId]: action.data
75
+ }
76
+ };
77
+
78
+ case ActionTypes.CLEAR_SELECTION:
79
+ return {
80
+ ...state,
81
+ selections: {
82
+ ...state.selections,
83
+ [action.componentId]: null
84
+ }
85
+ };
86
+
87
+ case ActionTypes.SET_EDIT_ITEM:
88
+ return {
89
+ ...state,
90
+ editItems: {
91
+ ...state.editItems,
92
+ [action.componentId]: action.data
93
+ }
94
+ };
95
+
96
+ case ActionTypes.CLEAR_EDIT_ITEM:
97
+ return {
98
+ ...state,
99
+ editItems: {
100
+ ...state.editItems,
101
+ [action.componentId]: null
102
+ }
103
+ };
104
+
105
+ case ActionTypes.OPEN_DIALOG:
106
+ return {
107
+ ...state,
108
+ dialogs: {
109
+ ...state.dialogs,
110
+ [action.dialogId]: { open: true, data: action.data }
111
+ }
112
+ };
113
+
114
+ case ActionTypes.CLOSE_DIALOG:
115
+ return {
116
+ ...state,
117
+ dialogs: {
118
+ ...state.dialogs,
119
+ [action.dialogId]: { open: false, data: null }
120
+ }
121
+ };
122
+
123
+ case ActionTypes.SET_COMPONENT_STATE:
124
+ return {
125
+ ...state,
126
+ componentStates: {
127
+ ...state.componentStates,
128
+ [action.componentId]: {
129
+ ...state.componentStates[action.componentId],
130
+ ...action.state
131
+ }
132
+ }
133
+ };
134
+
135
+ case ActionTypes.SET_PAGINATION:
136
+ return {
137
+ ...state,
138
+ pagination: {
139
+ ...state.pagination,
140
+ ...action.pagination
141
+ }
142
+ };
143
+
144
+ case ActionTypes.SET_RELATED_ITEMS:
145
+ return {
146
+ ...state,
147
+ relatedItems: {
148
+ ...state.relatedItems,
149
+ [action.componentId]: {
150
+ items: action.items,
151
+ parentId: action.parentId,
152
+ pagination: action.pagination
153
+ }
154
+ },
155
+ relatedLoading: {
156
+ ...state.relatedLoading,
157
+ [action.componentId]: false
158
+ }
159
+ };
160
+
161
+ case ActionTypes.SET_RELATED_LOADING:
162
+ return {
163
+ ...state,
164
+ relatedLoading: {
165
+ ...state.relatedLoading,
166
+ [action.componentId]: action.loading
167
+ }
168
+ };
169
+
170
+ default:
171
+ return state;
172
+ }
173
+ }
174
+
175
+ /**
176
+ * JsonView Context for component communication
177
+ */
178
+ export const JsonViewContext = createContext(null);
179
+
180
+ /**
181
+ * Hook to access JsonView context
182
+ */
183
+ export function useJsonView() {
184
+ const context = useContext(JsonViewContext);
185
+ if (!context) {
186
+ throw new Error('useJsonView must be used within a JsonView');
187
+ }
188
+ return context;
189
+ }
190
+
191
+ /**
192
+ * Layout component mapping
193
+ */
194
+ const LAYOUTS = {
195
+ split: SplitLayout,
196
+ tabs: TabLayout,
197
+ single: SingleLayout,
198
+ accordion: SingleLayout // Fallback to single for now
199
+ };
200
+
201
+ /**
202
+ * Inner component that uses the store hook
203
+ * This ensures the hook is always called (not conditionally)
204
+ */
205
+ function JsonViewWithStore({ config, storeName }) {
206
+ const store = useStore(storeName);
207
+
208
+ // Extract config with defaults
209
+ const {
210
+ id: viewId,
211
+ layout = 'single',
212
+ layoutConfig = {},
213
+ dataSource = {},
214
+ components = [],
215
+ toolbar,
216
+ extension: extensionName
217
+ } = config || {};
218
+
219
+ // Initialize state with pagination config
220
+ const initialStateWithPagination = useMemo(() => ({
221
+ ...initialState,
222
+ pagination: getInitialPaginationState(dataSource?.pagination)
223
+ }), []);
224
+
225
+ const [viewState, dispatch] = useReducer(viewReducer, initialStateWithPagination);
226
+
227
+ const storeLoading = store.loading;
228
+ const storeError = store.error;
229
+ const storePagination = store.pagination;
230
+
231
+ const storeActions = useMemo(() => ({
232
+ list: store.list,
233
+ get: store.get,
234
+ create: store.create,
235
+ update: store.update,
236
+ delete: store.delete,
237
+ select: store.select,
238
+ clearSelection: store.clearSelection,
239
+ loadMore: store.loadMore,
240
+ setPageSize: store.setPageSize
241
+ }), [store]);
242
+
243
+ // Get extension hook if specified
244
+ const useExtension = extensionName ? extensionRegistry.get(extensionName) : null;
245
+
246
+ // Sync store pagination to view state
247
+ useEffect(() => {
248
+ if (viewState.pagination && storePagination) {
249
+ dispatch({
250
+ type: ActionTypes.SET_PAGINATION,
251
+ pagination: {
252
+ page: storePagination.page,
253
+ pageSize: storePagination.pageSize,
254
+ total: storePagination.total,
255
+ totalPages: storePagination.totalPages,
256
+ hasNext: storePagination.hasNext,
257
+ hasPrev: storePagination.hasPrev
258
+ }
259
+ });
260
+ }
261
+ }, [storePagination, viewState.pagination !== null]);
262
+
263
+ // Sync selections with store items when items change
264
+ // This ensures detail views show updated data after edits
265
+ const storeItems = store.items;
266
+ useEffect(() => {
267
+ if (!storeItems?.length) return;
268
+
269
+ // Check each selection and update if the item exists in the new items
270
+ Object.entries(viewState.selections).forEach(([componentId, selectedItem]) => {
271
+ if (!selectedItem?.id) return;
272
+
273
+ // Find the updated item in the store
274
+ const updatedItem = storeItems.find(item => item.id === selectedItem.id);
275
+ if (updatedItem && updatedItem !== selectedItem) {
276
+ dispatch({
277
+ type: ActionTypes.SET_SELECTION,
278
+ componentId,
279
+ data: updatedItem
280
+ });
281
+ }
282
+ });
283
+ }, [storeItems]);
284
+
285
+ // Auto-load data on mount
286
+ useEffect(() => {
287
+ if (dataSource?.autoLoad) {
288
+ const loadOptions = {};
289
+ if (viewState.pagination) {
290
+ loadOptions.page = viewState.pagination.page;
291
+ loadOptions.pageSize = viewState.pagination.pageSize;
292
+ }
293
+ if (dataSource.sliceId) {
294
+ loadOptions.sliceId = dataSource.sliceId;
295
+ }
296
+ store.list(loadOptions);
297
+ }
298
+ }, []);
299
+
300
+ return (
301
+ <JsonViewInner
302
+ config={config}
303
+ viewId={viewId}
304
+ layout={layout}
305
+ layoutConfig={layoutConfig}
306
+ dataSource={dataSource}
307
+ components={components}
308
+ toolbar={toolbar}
309
+ viewState={viewState}
310
+ dispatch={dispatch}
311
+ storeData={store}
312
+ storeLoading={storeLoading}
313
+ storeError={storeError}
314
+ storeActions={storeActions}
315
+ useExtension={useExtension}
316
+ />
317
+ );
318
+ }
319
+
320
+ /**
321
+ * JsonView without store (for views that don't need data)
322
+ */
323
+ function JsonViewWithoutStore({ config }) {
324
+ const [viewState, dispatch] = useReducer(viewReducer, initialState);
325
+
326
+ const {
327
+ id: viewId,
328
+ layout = 'single',
329
+ layoutConfig = {},
330
+ dataSource = {},
331
+ components = [],
332
+ toolbar,
333
+ extension: extensionName
334
+ } = config || {};
335
+
336
+ // Get extension hook if specified
337
+ const useExtension = extensionName ? extensionRegistry.get(extensionName) : null;
338
+
339
+ return (
340
+ <JsonViewInner
341
+ config={config}
342
+ viewId={viewId}
343
+ layout={layout}
344
+ layoutConfig={layoutConfig}
345
+ dataSource={dataSource}
346
+ components={components}
347
+ toolbar={toolbar}
348
+ viewState={viewState}
349
+ dispatch={dispatch}
350
+ storeData={null}
351
+ storeLoading={false}
352
+ storeError={null}
353
+ storeActions={{}}
354
+ useExtension={useExtension}
355
+ />
356
+ );
357
+ }
358
+
359
+ /**
360
+ * JsonView Component
361
+ *
362
+ * @param {Object} config - View configuration object
363
+ * @param {string} config.id - Unique view identifier
364
+ * @param {string} config.layout - Layout type: split | tabs | single | accordion
365
+ * @param {Object} config.layoutConfig - Layout-specific configuration
366
+ * @param {Object} config.dataSource - Data source configuration
367
+ * @param {Array} config.components - Array of component configurations
368
+ * @param {Object} config.toolbar - Toolbar configuration
369
+ */
370
+ export function JsonView({ config }) {
371
+ const storeName = config?.dataSource?.store;
372
+
373
+ // Route to appropriate implementation based on whether store is needed
374
+ if (storeName) {
375
+ return <JsonViewWithStore config={config} storeName={storeName} />;
376
+ }
377
+ return <JsonViewWithoutStore config={config} />;
378
+ }
379
+
380
+ /**
381
+ * Inner JsonView implementation
382
+ */
383
+ function JsonViewInner({
384
+ config,
385
+ viewId,
386
+ layout,
387
+ layoutConfig,
388
+ dataSource,
389
+ components,
390
+ toolbar,
391
+ viewState,
392
+ dispatch,
393
+ storeData,
394
+ storeLoading,
395
+ storeError,
396
+ storeActions,
397
+ useExtension
398
+ }) {
399
+
400
+ // Action dispatch helpers
401
+ const setSelection = useCallback((componentId, data) => {
402
+ dispatch({ type: ActionTypes.SET_SELECTION, componentId, data });
403
+ }, []);
404
+
405
+ const clearSelection = useCallback((componentId) => {
406
+ dispatch({ type: ActionTypes.CLEAR_SELECTION, componentId });
407
+ }, []);
408
+
409
+ const setEditItem = useCallback((componentId, data) => {
410
+ dispatch({ type: ActionTypes.SET_EDIT_ITEM, componentId, data });
411
+ }, []);
412
+
413
+ const clearEditItem = useCallback((componentId) => {
414
+ dispatch({ type: ActionTypes.CLEAR_EDIT_ITEM, componentId });
415
+ }, []);
416
+
417
+ const openDialog = useCallback((dialogId, data = null) => {
418
+ dispatch({ type: ActionTypes.OPEN_DIALOG, dialogId, data });
419
+ }, []);
420
+
421
+ const closeDialog = useCallback((dialogId) => {
422
+ dispatch({ type: ActionTypes.CLOSE_DIALOG, dialogId });
423
+ }, []);
424
+
425
+ const setComponentState = useCallback((componentId, state) => {
426
+ dispatch({ type: ActionTypes.SET_COMPONENT_STATE, componentId, state });
427
+ }, []);
428
+
429
+ // Related items handlers (for hasMany)
430
+ const setRelatedItems = useCallback((componentId, items, parentId, pagination) => {
431
+ dispatch({ type: ActionTypes.SET_RELATED_ITEMS, componentId, items, parentId, pagination });
432
+ }, []);
433
+
434
+ const setRelatedLoading = useCallback((componentId, loading) => {
435
+ dispatch({ type: ActionTypes.SET_RELATED_LOADING, componentId, loading });
436
+ }, []);
437
+
438
+ // Pagination handlers
439
+ const handlePageChange = useCallback((page) => {
440
+ if (!viewState.pagination) return;
441
+ dispatch({ type: ActionTypes.SET_PAGINATION, pagination: { page } });
442
+ storeActions.list?.({
443
+ page,
444
+ pageSize: viewState.pagination.pageSize,
445
+ sliceId: dataSource?.sliceId
446
+ });
447
+ }, [viewState.pagination, storeActions, dataSource?.sliceId]);
448
+
449
+ const handlePageSizeChange = useCallback((pageSize) => {
450
+ if (!viewState.pagination) return;
451
+ dispatch({ type: ActionTypes.SET_PAGINATION, pagination: { page: 1, pageSize } });
452
+ storeActions.list?.({
453
+ page: 1,
454
+ pageSize,
455
+ sliceId: dataSource?.sliceId
456
+ });
457
+ }, [viewState.pagination, storeActions, dataSource?.sliceId]);
458
+
459
+ const handleLoadMore = useCallback(() => {
460
+ storeActions.loadMore?.();
461
+ }, [storeActions]);
462
+
463
+ // Call extension hook if provided
464
+ // Extension receives context and returns { actions, components, ...customState }
465
+ const extensionContext = useMemo(() => ({
466
+ store: storeData,
467
+ storeActions,
468
+ viewState,
469
+ openDialog,
470
+ closeDialog,
471
+ setSelection,
472
+ setEditItem
473
+ }), [storeData, storeActions, viewState, openDialog, closeDialog, setSelection, setEditItem]);
474
+
475
+ const extension = useExtension ? useExtension(extensionContext) : null;
476
+ const extensionActions = extension?.actions || {};
477
+ const extensionComponents = extension?.components || {};
478
+
479
+ // Execute a custom action (from extension or server-side)
480
+ const executeCustomAction = useCallback(async (actionConfig, data) => {
481
+ // Check for extension handler
482
+ if (actionConfig.handler && extensionActions[actionConfig.handler]) {
483
+ return extensionActions[actionConfig.handler](data);
484
+ }
485
+
486
+ // Check for declarative server action
487
+ if (actionConfig.serverAction) {
488
+ const endpoint = actionConfig.endpoint.replace(':id', data?.id);
489
+ const method = actionConfig.method || 'POST';
490
+
491
+ const response = await fetch(endpoint, {
492
+ method,
493
+ headers: { 'Content-Type': 'application/json' },
494
+ body: method !== 'GET' ? JSON.stringify(data) : undefined
495
+ });
496
+
497
+ if (!response.ok) {
498
+ throw new Error(`Server action failed: ${response.statusText}`);
499
+ }
500
+
501
+ // Refresh data if configured (include sliceId for joined data)
502
+ if (actionConfig.refreshAfter !== false) {
503
+ storeActions.list?.(dataSource?.sliceId ? { sliceId: dataSource.sliceId } : undefined);
504
+ }
505
+
506
+ return response.json().catch(() => ({}));
507
+ }
508
+ }, [extensionActions, storeActions, dataSource?.sliceId]);
509
+
510
+ // Context value
511
+ const contextValue = useMemo(() => ({
512
+ // View config
513
+ viewId,
514
+ config,
515
+ components,
516
+
517
+ // View state
518
+ viewState,
519
+ selections: viewState.selections,
520
+ editItems: viewState.editItems,
521
+ dialogs: viewState.dialogs,
522
+
523
+ // Pagination state and handlers
524
+ pagination: viewState.pagination,
525
+ paginationConfig: dataSource?.pagination,
526
+ onPageChange: handlePageChange,
527
+ onPageSizeChange: handlePageSizeChange,
528
+ onLoadMore: handleLoadMore,
529
+
530
+ // Related items state and handlers (for hasMany)
531
+ relatedItems: viewState.relatedItems,
532
+ relatedLoading: viewState.relatedLoading,
533
+ setRelatedItems,
534
+ setRelatedLoading,
535
+
536
+ // State actions
537
+ setSelection,
538
+ clearSelection,
539
+ setEditItem,
540
+ clearEditItem,
541
+ openDialog,
542
+ closeDialog,
543
+ setComponentState,
544
+
545
+ // Store data and actions
546
+ store: storeData,
547
+ storeActions,
548
+ items: storeData?.items || [],
549
+ loading: storeLoading,
550
+ error: storeError,
551
+
552
+ // Extension data
553
+ extension,
554
+ extensionActions,
555
+ extensionComponents,
556
+ executeCustomAction
557
+ }), [
558
+ viewId,
559
+ config,
560
+ components,
561
+ viewState,
562
+ dataSource?.pagination,
563
+ storeData,
564
+ storeLoading,
565
+ storeError,
566
+ setSelection,
567
+ clearSelection,
568
+ setEditItem,
569
+ clearEditItem,
570
+ openDialog,
571
+ closeDialog,
572
+ setComponentState,
573
+ setRelatedItems,
574
+ setRelatedLoading,
575
+ storeActions,
576
+ handlePageChange,
577
+ handlePageSizeChange,
578
+ handleLoadMore,
579
+ extension,
580
+ extensionActions,
581
+ extensionComponents,
582
+ executeCustomAction
583
+ ]);
584
+
585
+ // Handle toolbar actions
586
+ const handleToolbarAction = useCallback((actionId, actionConfig) => {
587
+ switch (actionId) {
588
+ case 'refresh':
589
+ storeActions.list?.({ sliceId: dataSource?.sliceId });
590
+ break;
591
+ case 'create':
592
+ if (actionConfig?.opens) {
593
+ openDialog(actionConfig.opens, null);
594
+ }
595
+ break;
596
+ default:
597
+ // Check for custom handler in extension or server action
598
+ if (actionConfig?.handler || actionConfig?.serverAction) {
599
+ executeCustomAction(actionConfig, null);
600
+ }
601
+ break;
602
+ }
603
+ }, [storeActions, openDialog, executeCustomAction, dataSource?.sliceId]);
604
+
605
+ // Select layout component
606
+ const LayoutComponent = LAYOUTS[layout] || SingleLayout;
607
+
608
+ // Error state
609
+ if (storeError && !storeData?.items?.length) {
610
+ return (
611
+ <Box sx={{ p: 2 }}>
612
+ <Alert severity="error">
613
+ {storeError}
614
+ </Alert>
615
+ </Box>
616
+ );
617
+ }
618
+
619
+ return (
620
+ <JsonViewContext.Provider value={contextValue}>
621
+ <Box sx={{ display: 'flex', flexDirection: 'column', height: '100%' }}>
622
+ {/* Toolbar */}
623
+ {(toolbar || dataSource?.pagination?.mode === 'pages') && (
624
+ <ViewToolbar
625
+ config={toolbar}
626
+ onAction={handleToolbarAction}
627
+ loading={storeLoading}
628
+ pagination={viewState.pagination}
629
+ paginationConfig={dataSource?.pagination}
630
+ onPageChange={handlePageChange}
631
+ onPageSizeChange={handlePageSizeChange}
632
+ />
633
+ )}
634
+
635
+ {/* Layout with components */}
636
+ <Box sx={{ flex: 1, overflow: 'auto' }}>
637
+ <LayoutComponent
638
+ config={layoutConfig}
639
+ components={components}
640
+ />
641
+ </Box>
642
+ </Box>
643
+ </JsonViewContext.Provider>
644
+ );
645
+ }
646
+
647
+ export default JsonView;