@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.
- package/README.md +281 -0
- package/dist/index.js.map +1 -1
- package/dist/native/index.js.map +1 -1
- package/dist/offline/index.js.map +1 -1
- package/dist/server/index.js +69 -6
- package/dist/server/index.js.map +2 -2
- package/dist/server/workflow/index.js.map +1 -1
- package/dist/shared/index.js.map +1 -1
- package/dist/web/index.js.map +1 -1
- package/package.json +84 -79
- package/schemas/Workflow.json +14 -14
- package/schemas/WorkflowHistory.json +22 -22
- package/schemas/WorkflowInstance.json +16 -16
- package/schemas/WorkflowState.json +18 -18
- package/schemas/WorkflowTransition.json +27 -27
- package/src/index.js +8 -8
- package/src/native/components/NativeAuthProvider.jsx +249 -249
- package/src/native/components/NativeDetail.jsx +270 -270
- package/src/native/components/NativeForm.jsx +543 -543
- package/src/native/components/NativeGrid.jsx +90 -90
- package/src/native/components/NativeJsonGrid.jsx +213 -213
- package/src/native/components/NativeJsonView.jsx +454 -454
- package/src/native/components/NativeJsonViewContext.js +17 -17
- package/src/native/components/NativeShell.jsx +68 -68
- package/src/native/components/NativeViewComponent.jsx +351 -351
- package/src/native/extensions/NativeExtensionRegistry.js +81 -81
- package/src/native/hooks/useNativeStore.js +72 -72
- package/src/native/index.js +15 -15
- package/src/native/layouts/NativeStackLayout.jsx +30 -30
- package/src/native/layouts/NativeTabLayout.jsx +96 -96
- package/src/native/storage.js +13 -13
- package/src/native/stores/NativeBaseStore.js +348 -348
- package/src/native/stores/NativeStoreContext.jsx +53 -53
- package/src/offline/index.js +1 -1
- package/src/server/ai/capabilities-routes.js +106 -106
- package/src/server/ai/index.js +1 -1
- package/src/server/cache/MemoryCache.js +153 -153
- package/src/server/cache/index.js +2 -2
- package/src/server/cache/middleware.js +12 -12
- package/src/server/db/index.js +14 -14
- package/src/server/db/mongo.js +137 -137
- package/src/server/db/postgres.js +144 -144
- package/src/server/index.js +42 -42
- package/src/server/middleware/auth.js +682 -682
- package/src/server/middleware/can-flags.js +132 -132
- package/src/server/middleware/entityRoles.js +105 -105
- package/src/server/middleware/index.js +58 -58
- package/src/server/middleware/permissions.js +240 -240
- package/src/server/middleware/tenant.js +203 -203
- package/src/server/offline/field-lww.js +98 -6
- package/src/server/realtime/EventBus.js +45 -45
- package/src/server/realtime/WebSocketServer.js +105 -105
- package/src/server/realtime/index.js +3 -3
- package/src/server/realtime/middleware.js +18 -18
- package/src/server/services/email-templates.js +157 -157
- package/src/server/services/email.js +78 -78
- package/src/server/services/index.js +15 -15
- package/src/server/services/storage.js +119 -119
- package/src/server/utils/index.js +16 -16
- package/src/server/utils/paginate.js +65 -65
- package/src/server/utils/query-builder.js +293 -293
- package/src/server/utils/route-loader.js +61 -61
- package/src/server/workflow/WorkflowEngine.js +494 -494
- package/src/server/workflow/index.js +2 -2
- package/src/server/workflow/workflow-routes.js +174 -174
- package/src/shared/index.js +10 -10
- package/src/shared/utils/field-accessor.js +108 -108
- package/src/shared/utils/index.js +7 -7
- package/src/shared/utils/validation-utils.js +83 -83
- package/src/web/components/AppRouter/AppRouter.jsx +130 -130
- package/src/web/components/AppRouter/index.js +1 -1
- package/src/web/components/AppShell/AppShell.jsx +101 -101
- package/src/web/components/AppShell/DefaultUserMenu.jsx +54 -54
- package/src/web/components/AppShell/ShellConfig.js +53 -53
- package/src/web/components/AppShell/index.js +3 -3
- package/src/web/components/AuthProvider.jsx +426 -426
- package/src/web/components/CardList/CardList.jsx +272 -272
- package/src/web/components/CardList/index.js +2 -2
- package/src/web/components/DetailView/DetailView.jsx +281 -281
- package/src/web/components/DetailView/index.js +2 -2
- package/src/web/components/Form/Form.jsx +300 -300
- package/src/web/components/Form/FormField.jsx +226 -226
- package/src/web/components/Form/index.js +3 -3
- package/src/web/components/Grid/Grid.jsx +304 -304
- package/src/web/components/Grid/index.js +2 -2
- package/src/web/components/IconRegistry/IconRegistry.jsx +127 -127
- package/src/web/components/IconRegistry/index.js +1 -1
- package/src/web/components/JsonView/JsonView.jsx +647 -647
- package/src/web/components/JsonView/ViewComponent.jsx +1045 -1045
- package/src/web/components/JsonView/ViewToolbar.jsx +141 -141
- package/src/web/components/JsonView/index.js +14 -14
- package/src/web/components/JsonView/layouts/SingleLayout.jsx +41 -41
- package/src/web/components/JsonView/layouts/SplitLayout.jsx +122 -122
- package/src/web/components/JsonView/layouts/TabLayout.jsx +112 -112
- package/src/web/components/JsonView/layouts/index.js +8 -8
- package/src/web/components/Layout.jsx +265 -265
- package/src/web/components/MobileLayout/MobileLayout.jsx +385 -385
- package/src/web/components/MobileLayout/index.js +1 -1
- package/src/web/components/Navigation/Navigation.jsx +248 -248
- package/src/web/components/Navigation/index.js +1 -1
- package/src/web/components/NotificationProvider.jsx +55 -55
- package/src/web/components/Pagination/InfiniteScroll.jsx +82 -82
- package/src/web/components/Pagination/Pagination.jsx +73 -73
- package/src/web/components/Pagination/index.js +8 -8
- package/src/web/components/SimpleList/SimpleList.jsx +177 -177
- package/src/web/components/SimpleList/index.js +2 -2
- package/src/web/components/TenantProvider.jsx +121 -121
- package/src/web/components/WorkflowActions/WorkflowActions.jsx +71 -71
- package/src/web/components/WorkflowActions/index.js +1 -1
- package/src/web/components/WorkflowField/WorkflowField.jsx +176 -176
- package/src/web/components/WorkflowField/index.js +2 -2
- package/src/web/components/WorkflowField/workflowColors.js +32 -32
- package/src/web/components/auth/DevTenantSelector.jsx +90 -90
- package/src/web/components/auth/ForgotPasswordForm.jsx +94 -94
- package/src/web/components/auth/RegisterForm.jsx +168 -168
- package/src/web/components/auth/ResetPasswordForm.jsx +121 -121
- package/src/web/components/auth/VerifyEmailView.jsx +85 -85
- package/src/web/components/auth/index.js +5 -5
- package/src/web/components/index.js +39 -39
- package/src/web/components/layouts/CardListLayout.jsx +68 -68
- package/src/web/components/layouts/FullscreenLayout.jsx +30 -30
- package/src/web/components/layouts/MobileStackLayout.jsx +28 -28
- package/src/web/components/layouts/WizardLayout.jsx +86 -86
- package/src/web/components/layouts/index.js +4 -4
- package/src/web/components/mobile/Badge.jsx +105 -105
- package/src/web/components/mobile/BadgeThemeEditor.jsx +104 -104
- package/src/web/components/mobile/EmptyState.jsx +30 -30
- package/src/web/components/mobile/QuickActionButton.jsx +77 -77
- package/src/web/components/mobile/ServerAutocomplete.jsx +123 -123
- package/src/web/components/mobile/StarRating.jsx +42 -42
- package/src/web/components/mobile/StatCard.jsx +65 -65
- package/src/web/components/mobile/index.js +7 -7
- package/src/web/extensions/ExtensionRegistry.js +79 -79
- package/src/web/extensions/index.js +7 -7
- package/src/web/hooks/index.js +15 -15
- package/src/web/hooks/useApi.js +76 -76
- package/src/web/hooks/useAuth.js +37 -37
- package/src/web/hooks/useDebouncedSave.js +158 -158
- package/src/web/hooks/useIsMobile.js +14 -14
- package/src/web/hooks/useOfflineQueue.js +99 -99
- package/src/web/hooks/useSelectionModel.js +143 -143
- package/src/web/hooks/useServerAutocomplete.js +146 -146
- package/src/web/hooks/useStore.js +107 -107
- package/src/web/hooks/useSubscription.js +130 -130
- package/src/web/hooks/useTenant.js +39 -39
- package/src/web/hooks/useTenantResolver.js +65 -65
- package/src/web/hooks/useUndoRedo.js +77 -77
- package/src/web/hooks/useViews.js +113 -113
- package/src/web/hooks/useWorkflow.js +190 -190
- package/src/web/index.js +117 -117
- package/src/web/stores/BaseStore.js +439 -439
- package/src/web/stores/StoreContext.jsx +93 -93
- package/src/web/stores/index.js +3 -3
- package/src/web/theme/index.js +3 -3
- package/src/web/theme/mui-theme.js +228 -228
- package/src/web/utils/formatTimeAgo.js +22 -22
- package/src/web/utils/index.js +1 -1
- package/src/web/views/ViewRegistry.js +235 -235
- package/src/web/views/index.js +2 -2
|
@@ -1,304 +1,304 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Universal Grid Component
|
|
3
|
-
*
|
|
4
|
-
* Config-driven data grid with sorting, pagination, and row actions.
|
|
5
|
-
*/
|
|
6
|
-
import React from 'react';
|
|
7
|
-
import {
|
|
8
|
-
Table,
|
|
9
|
-
TableBody,
|
|
10
|
-
TableCell,
|
|
11
|
-
TableContainer,
|
|
12
|
-
TableHead,
|
|
13
|
-
TableRow,
|
|
14
|
-
TableSortLabel,
|
|
15
|
-
TablePagination,
|
|
16
|
-
Paper,
|
|
17
|
-
IconButton,
|
|
18
|
-
Chip,
|
|
19
|
-
Typography,
|
|
20
|
-
CircularProgress,
|
|
21
|
-
Box,
|
|
22
|
-
Checkbox
|
|
23
|
-
} from '@mui/material';
|
|
24
|
-
import EditIcon from '@mui/icons-material/Edit';
|
|
25
|
-
import DeleteIcon from '@mui/icons-material/Delete';
|
|
26
|
-
import VisibilityIcon from '@mui/icons-material/Visibility';
|
|
27
|
-
import { getFieldValue } from '../../../shared/utils/field-accessor.js';
|
|
28
|
-
import { WorkflowField } from '../WorkflowField/index.js';
|
|
29
|
-
|
|
30
|
-
const ACTION_ICONS = {
|
|
31
|
-
edit: EditIcon,
|
|
32
|
-
delete: DeleteIcon,
|
|
33
|
-
view: VisibilityIcon
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const styles = {
|
|
37
|
-
loading: { display: 'flex', justifyContent: 'center', py: 4 },
|
|
38
|
-
empty: { textAlign: 'center', py: 4 },
|
|
39
|
-
row: { cursor: 'pointer' },
|
|
40
|
-
textCell: { maxWidth: 300 }
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Render cell content based on column type
|
|
45
|
-
*/
|
|
46
|
-
function renderCell(value, column) {
|
|
47
|
-
if (value === null || value === undefined) {
|
|
48
|
-
return <Typography variant="body2" color="text.secondary">-</Typography>;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
switch (column.type) {
|
|
52
|
-
case 'boolean':
|
|
53
|
-
return value ? 'Yes' : 'No';
|
|
54
|
-
|
|
55
|
-
case 'datetime':
|
|
56
|
-
case 'date':
|
|
57
|
-
try {
|
|
58
|
-
const date = new Date(value);
|
|
59
|
-
return column.type === 'date'
|
|
60
|
-
? date.toLocaleDateString()
|
|
61
|
-
: date.toLocaleString();
|
|
62
|
-
} catch {
|
|
63
|
-
return String(value);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
case 'enum':
|
|
67
|
-
const colorMap = column.enumConfig?.colors || {};
|
|
68
|
-
const color = colorMap[value] || 'default';
|
|
69
|
-
return <Chip label={value} color={color} size="small" />;
|
|
70
|
-
|
|
71
|
-
case 'text':
|
|
72
|
-
return (
|
|
73
|
-
<Typography variant="body2" color="text.secondary" noWrap sx={styles.textCell}>
|
|
74
|
-
{value}
|
|
75
|
-
</Typography>
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
case 'number':
|
|
79
|
-
case 'decimal':
|
|
80
|
-
return String(value);
|
|
81
|
-
|
|
82
|
-
case 'string':
|
|
83
|
-
default:
|
|
84
|
-
if (column.primary) {
|
|
85
|
-
return <Typography fontWeight={500}>{value}</Typography>;
|
|
86
|
-
}
|
|
87
|
-
return String(value);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Universal Grid Component
|
|
93
|
-
*
|
|
94
|
-
* @param {Object} config - Grid configuration object
|
|
95
|
-
* @param {Array} data - Array of row data
|
|
96
|
-
* @param {boolean} loading - Whether data is loading
|
|
97
|
-
* @param {string} selectedId - Currently selected row ID
|
|
98
|
-
* @param {Array} selectedIds - Array of selected row IDs (for multi-select)
|
|
99
|
-
* @param {Function} onRowClick - Called when row is clicked (id, row)
|
|
100
|
-
* @param {Function} onAction - Called when action button clicked (actionId, row)
|
|
101
|
-
* @param {Function} onSelectionChange - Called when selection changes (selectedIds)
|
|
102
|
-
* @param {Object} sorting - Current sorting state { field, direction }
|
|
103
|
-
* @param {Function} onSortChange - Called when sort changes (field, direction)
|
|
104
|
-
* @param {Object} pagination - Current pagination state { page, pageSize, total }
|
|
105
|
-
* @param {Function} onPageChange - Called when page changes (page)
|
|
106
|
-
* @param {Function} onPageSizeChange - Called when page size changes (pageSize)
|
|
107
|
-
* @param {string} paginationPosition - Where to show pagination: 'bottom' (default) | 'none'
|
|
108
|
-
*/
|
|
109
|
-
export function Grid({
|
|
110
|
-
config,
|
|
111
|
-
data = [],
|
|
112
|
-
loading = false,
|
|
113
|
-
selectedId,
|
|
114
|
-
selectedIds = [],
|
|
115
|
-
onRowClick,
|
|
116
|
-
onAction,
|
|
117
|
-
onSelectionChange,
|
|
118
|
-
onWorkflowTransition,
|
|
119
|
-
sorting,
|
|
120
|
-
onSortChange,
|
|
121
|
-
pagination,
|
|
122
|
-
onPageChange,
|
|
123
|
-
onPageSizeChange,
|
|
124
|
-
paginationPosition = 'bottom'
|
|
125
|
-
}) {
|
|
126
|
-
const {
|
|
127
|
-
entityName = 'Item',
|
|
128
|
-
entityNamePlural = 'Items',
|
|
129
|
-
rowKey = 'id',
|
|
130
|
-
selectable = false,
|
|
131
|
-
columns = [],
|
|
132
|
-
actions = [],
|
|
133
|
-
pagination: paginationConfig = { enabled: false },
|
|
134
|
-
sorting: sortingConfig = {}
|
|
135
|
-
} = config || {};
|
|
136
|
-
|
|
137
|
-
// Handle sort click
|
|
138
|
-
const handleSort = (field) => {
|
|
139
|
-
if (!onSortChange) return;
|
|
140
|
-
const isAsc = sorting?.field === field && sorting?.direction === 'asc';
|
|
141
|
-
onSortChange(field, isAsc ? 'desc' : 'asc');
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
// Handle select all
|
|
145
|
-
const handleSelectAll = (event) => {
|
|
146
|
-
if (!onSelectionChange) return;
|
|
147
|
-
if (event.target.checked) {
|
|
148
|
-
onSelectionChange(data.map(row => row[rowKey]));
|
|
149
|
-
} else {
|
|
150
|
-
onSelectionChange([]);
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
// Handle row select
|
|
155
|
-
const handleSelectRow = (id, event) => {
|
|
156
|
-
if (!onSelectionChange) return;
|
|
157
|
-
event.stopPropagation();
|
|
158
|
-
const selectedSet = new Set(selectedIds);
|
|
159
|
-
if (selectedSet.has(id)) {
|
|
160
|
-
selectedSet.delete(id);
|
|
161
|
-
} else {
|
|
162
|
-
selectedSet.add(id);
|
|
163
|
-
}
|
|
164
|
-
onSelectionChange(Array.from(selectedSet));
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
// Loading state
|
|
168
|
-
if (loading && data.length === 0) {
|
|
169
|
-
return (
|
|
170
|
-
<Box sx={styles.loading}>
|
|
171
|
-
<CircularProgress />
|
|
172
|
-
</Box>
|
|
173
|
-
);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// Empty state
|
|
177
|
-
if (!loading && data.length === 0) {
|
|
178
|
-
return (
|
|
179
|
-
<Box sx={styles.empty}>
|
|
180
|
-
<Typography color="text.secondary">
|
|
181
|
-
No {entityNamePlural.toLowerCase()} yet. Create one!
|
|
182
|
-
</Typography>
|
|
183
|
-
</Box>
|
|
184
|
-
);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
const numSelected = selectedIds.length;
|
|
188
|
-
const rowCount = data.length;
|
|
189
|
-
|
|
190
|
-
return (
|
|
191
|
-
<Box>
|
|
192
|
-
<TableContainer component={Paper} elevation={0}>
|
|
193
|
-
<Table>
|
|
194
|
-
<TableHead>
|
|
195
|
-
<TableRow>
|
|
196
|
-
{selectable && (
|
|
197
|
-
<TableCell padding="checkbox">
|
|
198
|
-
<Checkbox
|
|
199
|
-
indeterminate={numSelected > 0 && numSelected < rowCount}
|
|
200
|
-
checked={rowCount > 0 && numSelected === rowCount}
|
|
201
|
-
onChange={handleSelectAll}
|
|
202
|
-
/>
|
|
203
|
-
</TableCell>
|
|
204
|
-
)}
|
|
205
|
-
{columns.map((column) => (
|
|
206
|
-
<TableCell key={column.field}>
|
|
207
|
-
{column.sortable && onSortChange ? (
|
|
208
|
-
<TableSortLabel
|
|
209
|
-
active={sorting?.field === column.field}
|
|
210
|
-
direction={sorting?.field === column.field ? sorting.direction : 'asc'}
|
|
211
|
-
onClick={() => handleSort(column.field)}
|
|
212
|
-
>
|
|
213
|
-
{column.header}
|
|
214
|
-
</TableSortLabel>
|
|
215
|
-
) : (
|
|
216
|
-
column.header
|
|
217
|
-
)}
|
|
218
|
-
</TableCell>
|
|
219
|
-
))}
|
|
220
|
-
{actions.length > 0 && (
|
|
221
|
-
<TableCell align="right">Actions</TableCell>
|
|
222
|
-
)}
|
|
223
|
-
</TableRow>
|
|
224
|
-
</TableHead>
|
|
225
|
-
<TableBody>
|
|
226
|
-
{data.map((row) => {
|
|
227
|
-
const rowId = row[rowKey];
|
|
228
|
-
const isSelected = selectedIds.includes(rowId) || selectedId === rowId;
|
|
229
|
-
|
|
230
|
-
return (
|
|
231
|
-
<TableRow
|
|
232
|
-
key={rowId}
|
|
233
|
-
hover
|
|
234
|
-
selected={isSelected}
|
|
235
|
-
onClick={() => onRowClick?.(rowId, row)}
|
|
236
|
-
sx={onRowClick ? styles.row : undefined}
|
|
237
|
-
>
|
|
238
|
-
{selectable && (
|
|
239
|
-
<TableCell padding="checkbox">
|
|
240
|
-
<Checkbox
|
|
241
|
-
checked={selectedIds.includes(rowId)}
|
|
242
|
-
onClick={(e) => handleSelectRow(rowId, e)}
|
|
243
|
-
/>
|
|
244
|
-
</TableCell>
|
|
245
|
-
)}
|
|
246
|
-
{columns.map((column) => (
|
|
247
|
-
<TableCell key={column.field}>
|
|
248
|
-
{column.type === 'workflow' ? (
|
|
249
|
-
<WorkflowField
|
|
250
|
-
mode="compact"
|
|
251
|
-
workflowState={getFieldValue(row, column.field)}
|
|
252
|
-
workflowInstanceId={getFieldValue(row, column.workflowInstanceField || 'workflow_instance_id')}
|
|
253
|
-
stateColors={column.workflowConfig?.colors}
|
|
254
|
-
onTransitionComplete={onWorkflowTransition}
|
|
255
|
-
/>
|
|
256
|
-
) : (
|
|
257
|
-
renderCell(getFieldValue(row, column.field), column)
|
|
258
|
-
)}
|
|
259
|
-
</TableCell>
|
|
260
|
-
))}
|
|
261
|
-
{actions.length > 0 && (
|
|
262
|
-
<TableCell align="right">
|
|
263
|
-
{actions.map((action) => {
|
|
264
|
-
const Icon = ACTION_ICONS[action.id] || ACTION_ICONS.view;
|
|
265
|
-
return (
|
|
266
|
-
<IconButton
|
|
267
|
-
key={action.id}
|
|
268
|
-
size="small"
|
|
269
|
-
color={action.color || 'default'}
|
|
270
|
-
title={action.label}
|
|
271
|
-
onClick={(e) => {
|
|
272
|
-
e.stopPropagation();
|
|
273
|
-
onAction?.(action.id, row);
|
|
274
|
-
}}
|
|
275
|
-
>
|
|
276
|
-
<Icon fontSize="small" />
|
|
277
|
-
</IconButton>
|
|
278
|
-
);
|
|
279
|
-
})}
|
|
280
|
-
</TableCell>
|
|
281
|
-
)}
|
|
282
|
-
</TableRow>
|
|
283
|
-
);
|
|
284
|
-
})}
|
|
285
|
-
</TableBody>
|
|
286
|
-
</Table>
|
|
287
|
-
</TableContainer>
|
|
288
|
-
|
|
289
|
-
{paginationConfig.enabled && pagination && paginationPosition !== 'none' && (
|
|
290
|
-
<TablePagination
|
|
291
|
-
component="div"
|
|
292
|
-
count={pagination.total || 0}
|
|
293
|
-
page={(pagination.page || 1) - 1}
|
|
294
|
-
rowsPerPage={pagination.pageSize || 25}
|
|
295
|
-
onPageChange={(e, newPage) => onPageChange?.(newPage + 1)}
|
|
296
|
-
onRowsPerPageChange={(e) => onPageSizeChange?.(parseInt(e.target.value, 10))}
|
|
297
|
-
rowsPerPageOptions={paginationConfig.pageSizeOptions || [10, 25, 50, 100]}
|
|
298
|
-
/>
|
|
299
|
-
)}
|
|
300
|
-
</Box>
|
|
301
|
-
);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
export default Grid;
|
|
1
|
+
/**
|
|
2
|
+
* Universal Grid Component
|
|
3
|
+
*
|
|
4
|
+
* Config-driven data grid with sorting, pagination, and row actions.
|
|
5
|
+
*/
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import {
|
|
8
|
+
Table,
|
|
9
|
+
TableBody,
|
|
10
|
+
TableCell,
|
|
11
|
+
TableContainer,
|
|
12
|
+
TableHead,
|
|
13
|
+
TableRow,
|
|
14
|
+
TableSortLabel,
|
|
15
|
+
TablePagination,
|
|
16
|
+
Paper,
|
|
17
|
+
IconButton,
|
|
18
|
+
Chip,
|
|
19
|
+
Typography,
|
|
20
|
+
CircularProgress,
|
|
21
|
+
Box,
|
|
22
|
+
Checkbox
|
|
23
|
+
} from '@mui/material';
|
|
24
|
+
import EditIcon from '@mui/icons-material/Edit';
|
|
25
|
+
import DeleteIcon from '@mui/icons-material/Delete';
|
|
26
|
+
import VisibilityIcon from '@mui/icons-material/Visibility';
|
|
27
|
+
import { getFieldValue } from '../../../shared/utils/field-accessor.js';
|
|
28
|
+
import { WorkflowField } from '../WorkflowField/index.js';
|
|
29
|
+
|
|
30
|
+
const ACTION_ICONS = {
|
|
31
|
+
edit: EditIcon,
|
|
32
|
+
delete: DeleteIcon,
|
|
33
|
+
view: VisibilityIcon
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const styles = {
|
|
37
|
+
loading: { display: 'flex', justifyContent: 'center', py: 4 },
|
|
38
|
+
empty: { textAlign: 'center', py: 4 },
|
|
39
|
+
row: { cursor: 'pointer' },
|
|
40
|
+
textCell: { maxWidth: 300 }
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Render cell content based on column type
|
|
45
|
+
*/
|
|
46
|
+
function renderCell(value, column) {
|
|
47
|
+
if (value === null || value === undefined) {
|
|
48
|
+
return <Typography variant="body2" color="text.secondary">-</Typography>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
switch (column.type) {
|
|
52
|
+
case 'boolean':
|
|
53
|
+
return value ? 'Yes' : 'No';
|
|
54
|
+
|
|
55
|
+
case 'datetime':
|
|
56
|
+
case 'date':
|
|
57
|
+
try {
|
|
58
|
+
const date = new Date(value);
|
|
59
|
+
return column.type === 'date'
|
|
60
|
+
? date.toLocaleDateString()
|
|
61
|
+
: date.toLocaleString();
|
|
62
|
+
} catch {
|
|
63
|
+
return String(value);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
case 'enum':
|
|
67
|
+
const colorMap = column.enumConfig?.colors || {};
|
|
68
|
+
const color = colorMap[value] || 'default';
|
|
69
|
+
return <Chip label={value} color={color} size="small" />;
|
|
70
|
+
|
|
71
|
+
case 'text':
|
|
72
|
+
return (
|
|
73
|
+
<Typography variant="body2" color="text.secondary" noWrap sx={styles.textCell}>
|
|
74
|
+
{value}
|
|
75
|
+
</Typography>
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
case 'number':
|
|
79
|
+
case 'decimal':
|
|
80
|
+
return String(value);
|
|
81
|
+
|
|
82
|
+
case 'string':
|
|
83
|
+
default:
|
|
84
|
+
if (column.primary) {
|
|
85
|
+
return <Typography fontWeight={500}>{value}</Typography>;
|
|
86
|
+
}
|
|
87
|
+
return String(value);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Universal Grid Component
|
|
93
|
+
*
|
|
94
|
+
* @param {Object} config - Grid configuration object
|
|
95
|
+
* @param {Array} data - Array of row data
|
|
96
|
+
* @param {boolean} loading - Whether data is loading
|
|
97
|
+
* @param {string} selectedId - Currently selected row ID
|
|
98
|
+
* @param {Array} selectedIds - Array of selected row IDs (for multi-select)
|
|
99
|
+
* @param {Function} onRowClick - Called when row is clicked (id, row)
|
|
100
|
+
* @param {Function} onAction - Called when action button clicked (actionId, row)
|
|
101
|
+
* @param {Function} onSelectionChange - Called when selection changes (selectedIds)
|
|
102
|
+
* @param {Object} sorting - Current sorting state { field, direction }
|
|
103
|
+
* @param {Function} onSortChange - Called when sort changes (field, direction)
|
|
104
|
+
* @param {Object} pagination - Current pagination state { page, pageSize, total }
|
|
105
|
+
* @param {Function} onPageChange - Called when page changes (page)
|
|
106
|
+
* @param {Function} onPageSizeChange - Called when page size changes (pageSize)
|
|
107
|
+
* @param {string} paginationPosition - Where to show pagination: 'bottom' (default) | 'none'
|
|
108
|
+
*/
|
|
109
|
+
export function Grid({
|
|
110
|
+
config,
|
|
111
|
+
data = [],
|
|
112
|
+
loading = false,
|
|
113
|
+
selectedId,
|
|
114
|
+
selectedIds = [],
|
|
115
|
+
onRowClick,
|
|
116
|
+
onAction,
|
|
117
|
+
onSelectionChange,
|
|
118
|
+
onWorkflowTransition,
|
|
119
|
+
sorting,
|
|
120
|
+
onSortChange,
|
|
121
|
+
pagination,
|
|
122
|
+
onPageChange,
|
|
123
|
+
onPageSizeChange,
|
|
124
|
+
paginationPosition = 'bottom'
|
|
125
|
+
}) {
|
|
126
|
+
const {
|
|
127
|
+
entityName = 'Item',
|
|
128
|
+
entityNamePlural = 'Items',
|
|
129
|
+
rowKey = 'id',
|
|
130
|
+
selectable = false,
|
|
131
|
+
columns = [],
|
|
132
|
+
actions = [],
|
|
133
|
+
pagination: paginationConfig = { enabled: false },
|
|
134
|
+
sorting: sortingConfig = {}
|
|
135
|
+
} = config || {};
|
|
136
|
+
|
|
137
|
+
// Handle sort click
|
|
138
|
+
const handleSort = (field) => {
|
|
139
|
+
if (!onSortChange) return;
|
|
140
|
+
const isAsc = sorting?.field === field && sorting?.direction === 'asc';
|
|
141
|
+
onSortChange(field, isAsc ? 'desc' : 'asc');
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
// Handle select all
|
|
145
|
+
const handleSelectAll = (event) => {
|
|
146
|
+
if (!onSelectionChange) return;
|
|
147
|
+
if (event.target.checked) {
|
|
148
|
+
onSelectionChange(data.map(row => row[rowKey]));
|
|
149
|
+
} else {
|
|
150
|
+
onSelectionChange([]);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
// Handle row select
|
|
155
|
+
const handleSelectRow = (id, event) => {
|
|
156
|
+
if (!onSelectionChange) return;
|
|
157
|
+
event.stopPropagation();
|
|
158
|
+
const selectedSet = new Set(selectedIds);
|
|
159
|
+
if (selectedSet.has(id)) {
|
|
160
|
+
selectedSet.delete(id);
|
|
161
|
+
} else {
|
|
162
|
+
selectedSet.add(id);
|
|
163
|
+
}
|
|
164
|
+
onSelectionChange(Array.from(selectedSet));
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// Loading state
|
|
168
|
+
if (loading && data.length === 0) {
|
|
169
|
+
return (
|
|
170
|
+
<Box sx={styles.loading}>
|
|
171
|
+
<CircularProgress />
|
|
172
|
+
</Box>
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Empty state
|
|
177
|
+
if (!loading && data.length === 0) {
|
|
178
|
+
return (
|
|
179
|
+
<Box sx={styles.empty}>
|
|
180
|
+
<Typography color="text.secondary">
|
|
181
|
+
No {entityNamePlural.toLowerCase()} yet. Create one!
|
|
182
|
+
</Typography>
|
|
183
|
+
</Box>
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const numSelected = selectedIds.length;
|
|
188
|
+
const rowCount = data.length;
|
|
189
|
+
|
|
190
|
+
return (
|
|
191
|
+
<Box>
|
|
192
|
+
<TableContainer component={Paper} elevation={0}>
|
|
193
|
+
<Table>
|
|
194
|
+
<TableHead>
|
|
195
|
+
<TableRow>
|
|
196
|
+
{selectable && (
|
|
197
|
+
<TableCell padding="checkbox">
|
|
198
|
+
<Checkbox
|
|
199
|
+
indeterminate={numSelected > 0 && numSelected < rowCount}
|
|
200
|
+
checked={rowCount > 0 && numSelected === rowCount}
|
|
201
|
+
onChange={handleSelectAll}
|
|
202
|
+
/>
|
|
203
|
+
</TableCell>
|
|
204
|
+
)}
|
|
205
|
+
{columns.map((column) => (
|
|
206
|
+
<TableCell key={column.field}>
|
|
207
|
+
{column.sortable && onSortChange ? (
|
|
208
|
+
<TableSortLabel
|
|
209
|
+
active={sorting?.field === column.field}
|
|
210
|
+
direction={sorting?.field === column.field ? sorting.direction : 'asc'}
|
|
211
|
+
onClick={() => handleSort(column.field)}
|
|
212
|
+
>
|
|
213
|
+
{column.header}
|
|
214
|
+
</TableSortLabel>
|
|
215
|
+
) : (
|
|
216
|
+
column.header
|
|
217
|
+
)}
|
|
218
|
+
</TableCell>
|
|
219
|
+
))}
|
|
220
|
+
{actions.length > 0 && (
|
|
221
|
+
<TableCell align="right">Actions</TableCell>
|
|
222
|
+
)}
|
|
223
|
+
</TableRow>
|
|
224
|
+
</TableHead>
|
|
225
|
+
<TableBody>
|
|
226
|
+
{data.map((row) => {
|
|
227
|
+
const rowId = row[rowKey];
|
|
228
|
+
const isSelected = selectedIds.includes(rowId) || selectedId === rowId;
|
|
229
|
+
|
|
230
|
+
return (
|
|
231
|
+
<TableRow
|
|
232
|
+
key={rowId}
|
|
233
|
+
hover
|
|
234
|
+
selected={isSelected}
|
|
235
|
+
onClick={() => onRowClick?.(rowId, row)}
|
|
236
|
+
sx={onRowClick ? styles.row : undefined}
|
|
237
|
+
>
|
|
238
|
+
{selectable && (
|
|
239
|
+
<TableCell padding="checkbox">
|
|
240
|
+
<Checkbox
|
|
241
|
+
checked={selectedIds.includes(rowId)}
|
|
242
|
+
onClick={(e) => handleSelectRow(rowId, e)}
|
|
243
|
+
/>
|
|
244
|
+
</TableCell>
|
|
245
|
+
)}
|
|
246
|
+
{columns.map((column) => (
|
|
247
|
+
<TableCell key={column.field}>
|
|
248
|
+
{column.type === 'workflow' ? (
|
|
249
|
+
<WorkflowField
|
|
250
|
+
mode="compact"
|
|
251
|
+
workflowState={getFieldValue(row, column.field)}
|
|
252
|
+
workflowInstanceId={getFieldValue(row, column.workflowInstanceField || 'workflow_instance_id')}
|
|
253
|
+
stateColors={column.workflowConfig?.colors}
|
|
254
|
+
onTransitionComplete={onWorkflowTransition}
|
|
255
|
+
/>
|
|
256
|
+
) : (
|
|
257
|
+
renderCell(getFieldValue(row, column.field), column)
|
|
258
|
+
)}
|
|
259
|
+
</TableCell>
|
|
260
|
+
))}
|
|
261
|
+
{actions.length > 0 && (
|
|
262
|
+
<TableCell align="right">
|
|
263
|
+
{actions.map((action) => {
|
|
264
|
+
const Icon = ACTION_ICONS[action.id] || ACTION_ICONS.view;
|
|
265
|
+
return (
|
|
266
|
+
<IconButton
|
|
267
|
+
key={action.id}
|
|
268
|
+
size="small"
|
|
269
|
+
color={action.color || 'default'}
|
|
270
|
+
title={action.label}
|
|
271
|
+
onClick={(e) => {
|
|
272
|
+
e.stopPropagation();
|
|
273
|
+
onAction?.(action.id, row);
|
|
274
|
+
}}
|
|
275
|
+
>
|
|
276
|
+
<Icon fontSize="small" />
|
|
277
|
+
</IconButton>
|
|
278
|
+
);
|
|
279
|
+
})}
|
|
280
|
+
</TableCell>
|
|
281
|
+
)}
|
|
282
|
+
</TableRow>
|
|
283
|
+
);
|
|
284
|
+
})}
|
|
285
|
+
</TableBody>
|
|
286
|
+
</Table>
|
|
287
|
+
</TableContainer>
|
|
288
|
+
|
|
289
|
+
{paginationConfig.enabled && pagination && paginationPosition !== 'none' && (
|
|
290
|
+
<TablePagination
|
|
291
|
+
component="div"
|
|
292
|
+
count={pagination.total || 0}
|
|
293
|
+
page={(pagination.page || 1) - 1}
|
|
294
|
+
rowsPerPage={pagination.pageSize || 25}
|
|
295
|
+
onPageChange={(e, newPage) => onPageChange?.(newPage + 1)}
|
|
296
|
+
onRowsPerPageChange={(e) => onPageSizeChange?.(parseInt(e.target.value, 10))}
|
|
297
|
+
rowsPerPageOptions={paginationConfig.pageSizeOptions || [10, 25, 50, 100]}
|
|
298
|
+
/>
|
|
299
|
+
)}
|
|
300
|
+
</Box>
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export default Grid;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Grid } from './Grid.jsx';
|
|
2
|
-
export { default } from './Grid.jsx';
|
|
1
|
+
export { Grid } from './Grid.jsx';
|
|
2
|
+
export { default } from './Grid.jsx';
|