@aventoapp/framework 0.1.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.
- package/dist/index.js +6 -0
- package/dist/index.js.map +7 -0
- package/dist/native/index.js +2522 -0
- package/dist/native/index.js.map +7 -0
- package/dist/server/index.js +2776 -0
- package/dist/server/index.js.map +7 -0
- package/dist/server/workflow/index.js +537 -0
- package/dist/server/workflow/index.js.map +7 -0
- package/dist/shared/index.js +62 -0
- package/dist/shared/index.js.map +7 -0
- package/dist/web/index.js +7323 -0
- package/dist/web/index.js.map +7 -0
- package/package.json +81 -0
- package/schemas/Workflow.json +14 -0
- package/schemas/WorkflowHistory.json +22 -0
- package/schemas/WorkflowInstance.json +16 -0
- package/schemas/WorkflowState.json +18 -0
- package/schemas/WorkflowTransition.json +27 -0
- package/src/index.js +8 -0
- package/src/native/components/NativeAuthProvider.jsx +249 -0
- package/src/native/components/NativeDetail.jsx +270 -0
- package/src/native/components/NativeForm.jsx +543 -0
- package/src/native/components/NativeGrid.jsx +90 -0
- package/src/native/components/NativeJsonGrid.jsx +213 -0
- package/src/native/components/NativeJsonView.jsx +454 -0
- package/src/native/components/NativeJsonViewContext.js +17 -0
- package/src/native/components/NativeShell.jsx +68 -0
- package/src/native/components/NativeViewComponent.jsx +351 -0
- package/src/native/extensions/NativeExtensionRegistry.js +81 -0
- package/src/native/hooks/useNativeStore.js +72 -0
- package/src/native/index.js +15 -0
- package/src/native/layouts/NativeStackLayout.jsx +30 -0
- package/src/native/layouts/NativeTabLayout.jsx +96 -0
- package/src/native/storage.js +13 -0
- package/src/native/stores/NativeBaseStore.js +348 -0
- package/src/native/stores/NativeStoreContext.jsx +53 -0
- package/src/server/ai/capabilities-routes.js +106 -0
- package/src/server/ai/index.js +1 -0
- package/src/server/cache/MemoryCache.js +153 -0
- package/src/server/cache/index.js +2 -0
- package/src/server/cache/middleware.js +12 -0
- package/src/server/db/index.js +14 -0
- package/src/server/db/mongo.js +137 -0
- package/src/server/db/postgres.js +144 -0
- package/src/server/index.js +38 -0
- package/src/server/middleware/auth.js +682 -0
- package/src/server/middleware/can-flags.js +132 -0
- package/src/server/middleware/entityRoles.js +105 -0
- package/src/server/middleware/index.js +58 -0
- package/src/server/middleware/permissions.js +240 -0
- package/src/server/middleware/tenant.js +203 -0
- package/src/server/realtime/EventBus.js +45 -0
- package/src/server/realtime/WebSocketServer.js +105 -0
- package/src/server/realtime/index.js +3 -0
- package/src/server/realtime/middleware.js +18 -0
- package/src/server/services/email-templates.js +157 -0
- package/src/server/services/email.js +78 -0
- package/src/server/services/index.js +15 -0
- package/src/server/services/storage.js +119 -0
- package/src/server/utils/index.js +16 -0
- package/src/server/utils/paginate.js +65 -0
- package/src/server/utils/query-builder.js +293 -0
- package/src/server/utils/route-loader.js +61 -0
- package/src/server/workflow/WorkflowEngine.js +494 -0
- package/src/server/workflow/index.js +2 -0
- package/src/server/workflow/workflow-routes.js +174 -0
- package/src/shared/index.js +10 -0
- package/src/shared/utils/field-accessor.js +108 -0
- package/src/shared/utils/index.js +7 -0
- package/src/shared/utils/validation-utils.js +83 -0
- package/src/web/components/AppRouter/AppRouter.jsx +130 -0
- package/src/web/components/AppRouter/index.js +1 -0
- package/src/web/components/AppShell/AppShell.jsx +101 -0
- package/src/web/components/AppShell/DefaultUserMenu.jsx +54 -0
- package/src/web/components/AppShell/ShellConfig.js +53 -0
- package/src/web/components/AppShell/index.js +3 -0
- package/src/web/components/AuthProvider.jsx +426 -0
- package/src/web/components/CardList/CardList.jsx +272 -0
- package/src/web/components/CardList/index.js +2 -0
- package/src/web/components/DetailView/DetailView.jsx +281 -0
- package/src/web/components/DetailView/index.js +2 -0
- package/src/web/components/Form/Form.jsx +300 -0
- package/src/web/components/Form/FormField.jsx +226 -0
- package/src/web/components/Form/index.js +3 -0
- package/src/web/components/Grid/Grid.jsx +304 -0
- package/src/web/components/Grid/index.js +2 -0
- package/src/web/components/IconRegistry/IconRegistry.jsx +127 -0
- package/src/web/components/IconRegistry/index.js +1 -0
- package/src/web/components/JsonView/JsonView.jsx +647 -0
- package/src/web/components/JsonView/ViewComponent.jsx +1045 -0
- package/src/web/components/JsonView/ViewToolbar.jsx +141 -0
- package/src/web/components/JsonView/index.js +14 -0
- package/src/web/components/JsonView/layouts/SingleLayout.jsx +41 -0
- package/src/web/components/JsonView/layouts/SplitLayout.jsx +122 -0
- package/src/web/components/JsonView/layouts/TabLayout.jsx +112 -0
- package/src/web/components/JsonView/layouts/index.js +8 -0
- package/src/web/components/Layout.jsx +265 -0
- package/src/web/components/MobileLayout/MobileLayout.jsx +385 -0
- package/src/web/components/MobileLayout/index.js +1 -0
- package/src/web/components/Navigation/Navigation.jsx +248 -0
- package/src/web/components/Navigation/index.js +1 -0
- package/src/web/components/NotificationProvider.jsx +55 -0
- package/src/web/components/Pagination/InfiniteScroll.jsx +82 -0
- package/src/web/components/Pagination/Pagination.jsx +73 -0
- package/src/web/components/Pagination/index.js +8 -0
- package/src/web/components/SimpleList/SimpleList.jsx +177 -0
- package/src/web/components/SimpleList/index.js +2 -0
- package/src/web/components/TenantProvider.jsx +121 -0
- package/src/web/components/WorkflowActions/WorkflowActions.jsx +71 -0
- package/src/web/components/WorkflowActions/index.js +1 -0
- package/src/web/components/WorkflowField/WorkflowField.jsx +176 -0
- package/src/web/components/WorkflowField/index.js +2 -0
- package/src/web/components/WorkflowField/workflowColors.js +32 -0
- package/src/web/components/auth/DevTenantSelector.jsx +90 -0
- package/src/web/components/auth/ForgotPasswordForm.jsx +94 -0
- package/src/web/components/auth/RegisterForm.jsx +168 -0
- package/src/web/components/auth/ResetPasswordForm.jsx +121 -0
- package/src/web/components/auth/VerifyEmailView.jsx +85 -0
- package/src/web/components/auth/index.js +5 -0
- package/src/web/components/index.js +39 -0
- package/src/web/components/layouts/CardListLayout.jsx +68 -0
- package/src/web/components/layouts/FullscreenLayout.jsx +30 -0
- package/src/web/components/layouts/MobileStackLayout.jsx +28 -0
- package/src/web/components/layouts/WizardLayout.jsx +86 -0
- package/src/web/components/layouts/index.js +4 -0
- package/src/web/components/mobile/Badge.jsx +105 -0
- package/src/web/components/mobile/BadgeThemeEditor.jsx +104 -0
- package/src/web/components/mobile/EmptyState.jsx +30 -0
- package/src/web/components/mobile/QuickActionButton.jsx +77 -0
- package/src/web/components/mobile/ServerAutocomplete.jsx +123 -0
- package/src/web/components/mobile/StarRating.jsx +42 -0
- package/src/web/components/mobile/StatCard.jsx +65 -0
- package/src/web/components/mobile/index.js +7 -0
- package/src/web/extensions/ExtensionRegistry.js +79 -0
- package/src/web/extensions/index.js +7 -0
- package/src/web/hooks/index.js +15 -0
- package/src/web/hooks/useApi.js +76 -0
- package/src/web/hooks/useAuth.js +37 -0
- package/src/web/hooks/useDebouncedSave.js +158 -0
- package/src/web/hooks/useIsMobile.js +14 -0
- package/src/web/hooks/useOfflineQueue.js +99 -0
- package/src/web/hooks/useSelectionModel.js +143 -0
- package/src/web/hooks/useServerAutocomplete.js +146 -0
- package/src/web/hooks/useStore.js +107 -0
- package/src/web/hooks/useSubscription.js +130 -0
- package/src/web/hooks/useTenant.js +39 -0
- package/src/web/hooks/useTenantResolver.js +65 -0
- package/src/web/hooks/useUndoRedo.js +77 -0
- package/src/web/hooks/useViews.js +113 -0
- package/src/web/hooks/useWorkflow.js +190 -0
- package/src/web/index.js +117 -0
- package/src/web/stores/BaseStore.js +439 -0
- package/src/web/stores/StoreContext.jsx +93 -0
- package/src/web/stores/index.js +3 -0
- package/src/web/theme/index.js +3 -0
- package/src/web/theme/mui-theme.js +228 -0
- package/src/web/utils/formatTimeAgo.js +22 -0
- package/src/web/utils/index.js +1 -0
- package/src/web/views/ViewRegistry.js +235 -0
- package/src/web/views/index.js +2 -0
|
@@ -0,0 +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;
|