@dashadmin/dash-auto-admin 1.3.24 → 1.3.26
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/DashAutoAdminComponentRegistry.js +64 -1
- package/dist/DashAutoAdminForm.js +137 -1
- package/dist/DashAutoAdminResizableDrawer.js +63 -1
- package/dist/DashAutoAdminSaveButton.js +57 -1
- package/dist/DashAutoCreate.js +102 -1
- package/dist/DashAutoDrawer.js +256 -1
- package/dist/DashAutoEdit.js +99 -1
- package/dist/DashAutoFiltersGenerator.js +193 -1
- package/dist/DashAutoFormGroups.js +118 -1
- package/dist/DashAutoFormLayout.js +68 -1
- package/dist/DashAutoFormMuiTabs.js +291 -1
- package/dist/DashAutoFormTabs.js +132 -1
- package/dist/DashAutoGroup.js +27 -1
- package/dist/DashAutoLayout.js +31 -1
- package/dist/DashAutoList.js +218 -1
- package/dist/DashAutoPostFilterForm.js +47 -1
- package/dist/DashAutoReferenceTab.js +10 -1
- package/dist/DashAutoResource.js +77 -1
- package/dist/DashAutoResourceLayout.js +16 -1
- package/dist/DashAutoShow.js +195 -1
- package/dist/DashAutoTabbedForm.js +244 -1
- package/dist/DashAutoTabbedForm.review.js +221 -1
- package/dist/DashAutoTabs.js +11 -1
- package/dist/DashFilterWrapper.js +62 -1
- package/dist/DashRedirect.js +56 -1
- package/dist/TabbedLayout.js +38 -1
- package/dist/common/DashAutoTitle.js +33 -1
- package/dist/common/components/FabButton.js +59 -1
- package/dist/common/components/TranslatedLabel.js +60 -1
- package/dist/common/settings/Settings.js +196 -1
- package/dist/common/settings/SettingsBarIcons.js +61 -1
- package/dist/context/DashAutoAdminFormContext.js +15 -1
- package/dist/hooks/useAutoAdminLoadingStateMediator.js +36 -1
- package/dist/hooks/useAutoAdminTranslate.js +61 -1
- package/dist/hooks/useHash.js +24 -1
- package/dist/hooks/useLogger.js +20 -1
- package/dist/hooks/useRoutePathPattern.js +20 -1
- package/dist/hooks/useVirtualHash.js +28 -1
- package/dist/index.js +77 -3406
- package/dist/list/DashAutoListActions.js +57 -1
- package/dist/list/DashAutoListDatagridWrapper.js +68 -1
- package/dist/list/DashAutoListDefaultActionsWrapper.js +14 -1
- package/dist/list/DashAutoListFilterFormWithButton.js +80 -1
- package/dist/list/DashAutoListTopToolbar.js +180 -1
- package/dist/mui/AttributeToField.js +576 -1
- package/dist/mui/AttributeToInput.js +630 -1
- package/dist/mui/AutoAdminResizableDrawer.js +63 -1
- package/dist/mui/AutoDataGrid.js +120 -1
- package/dist/mui/AutoReferenceFormTab.js +53 -1
- package/dist/mui/AutoReferenceTab.js +46 -1
- package/dist/mui/AutoTabs.js +19 -1
- package/dist/mui/components/ExtendedPagination.js +34 -1
- package/dist/mui/components/ListStringField.js +25 -1
- package/dist/providers/DashAuthProvider.js +215 -1
- package/dist/providers/DashDataProvider.js +310 -1
- package/dist/providers/index.js +10 -1
- package/dist/react-admin.d.js +0 -0
- package/dist/toolbar/buttons/BottomToolbarButtons.js +65 -1
- package/dist/toolbar/buttons/DashResourceButton.js +181 -1
- package/dist/toolbar/buttons/ListButtons.js +80 -1
- package/dist/toolbar/buttons/ToolbarButtons.js +135 -1
- package/dist/types/ActionCallback.d.js +0 -0
- package/dist/utils/SimpleLogger.js +52 -1
- package/dist/utils/enumToChoices.js +5 -1
- package/dist/utils/evalActionPermission.js +11 -1
- package/dist/utils/groupByTabs.js +21 -1
- package/dist/utils/hashedGroupByTabs.js +12 -1
- package/dist/utils/invertMap.js +12 -1
- package/dist/utils/isClassComponent.js +7 -1
- package/dist/utils/isComponent.js +29 -1
- package/dist/utils/isEnum.js +5 -1
- package/dist/utils/isFC.js +8 -1
- package/dist/utils/replaceParams.js +9 -1
- package/dist/utils/validate.js +19 -1
- package/dist/wrappers/UserAction.js +60 -1
- package/dist/wrappers/index.js +4 -1
- package/package.json +135 -120
- package/src/DashAutoAdminComponentRegistry.tsx +75 -0
- package/src/DashAutoAdminForm.tsx +155 -0
- package/src/DashAutoAdminResizableDrawer.tsx +69 -0
- package/src/DashAutoAdminSaveButton.tsx +116 -0
- package/src/DashAutoCreate.tsx +118 -0
- package/src/DashAutoDrawer.tsx +288 -0
- package/src/DashAutoEdit.tsx +109 -0
- package/src/DashAutoFiltersGenerator.tsx +208 -0
- package/src/DashAutoFormGroups.tsx +146 -0
- package/src/DashAutoFormLayout.tsx.review +113 -0
- package/src/DashAutoFormMuiTabs.tsx +368 -0
- package/src/DashAutoFormTabs.tsx +177 -0
- package/src/DashAutoGroup.tsx +42 -0
- package/src/DashAutoLayout.tsx +57 -0
- package/src/DashAutoList.tsx +237 -0
- package/src/DashAutoPostFilterForm.tsx +35 -0
- package/src/DashAutoReferenceTab.tsx +9 -0
- package/src/DashAutoResource.tsx +85 -0
- package/src/DashAutoResourceLayout.tsx +50 -0
- package/src/DashAutoShow.tsx +200 -0
- package/src/DashAutoTabbedForm.review.tsx +262 -0
- package/src/DashAutoTabbedForm.tsx +324 -0
- package/src/DashAutoTabs.tsx +19 -0
- package/src/DashFilterWrapper.tsx +43 -0
- package/src/DashRedirect.tsx +46 -0
- package/src/TabbedLayout.tsx +29 -0
- package/src/common/DashAutoTitle.tsx +24 -0
- package/src/common/components/FabButton.tsx +40 -0
- package/src/common/components/TranslatedLabel.tsx +81 -0
- package/src/common/settings/Settings.tsx +236 -0
- package/src/common/settings/SettingsBarIcons.tsx +72 -0
- package/src/context/DashAutoAdminFormContext.tsx +31 -0
- package/src/hooks/useAutoAdminLoadingStateMediator.tsx +42 -0
- package/src/hooks/useAutoAdminTranslate.tsx +106 -0
- package/src/hooks/useHash.tsx +27 -0
- package/src/hooks/useLogger.tsx +23 -0
- package/src/hooks/useRoutePathPattern.tsx +24 -0
- package/src/hooks/useVirtualHash.tsx +34 -0
- package/src/index.ts +85 -0
- package/src/interfaces/ICustomResourceSubComponent.ts +11 -0
- package/src/interfaces/IDashApplicationLayoutMainAction.ts +37 -0
- package/src/interfaces/IDashApplicationLayoutMenuItem.ts +24 -0
- package/src/interfaces/IDashAutoAdminAttribute.ts +104 -0
- package/src/interfaces/IDashAutoAdminCustomFieldComponent.ts +18 -0
- package/src/interfaces/IDashAutoAdminFormOptions.ts +22 -0
- package/src/interfaces/IDashAutoAdminListActions.ts +13 -0
- package/src/interfaces/IDashAutoAdminReference.ts +16 -0
- package/src/interfaces/IDashAutoAdminResourceConfig.ts +360 -0
- package/src/interfaces/IDashAutoForm.ts +24 -0
- package/src/interfaces/IDashAutoGridButton.ts +35 -0
- package/src/interfaces/IDashAutoShow.ts +12 -0
- package/src/interfaces/IGroupExtraData.ts +8 -0
- package/src/interfaces/IRecord.ts +7 -0
- package/src/interfaces/IReferenceFilter.ts +55 -0
- package/src/interfaces/IResourceComponent.ts +8 -0
- package/src/interfaces/IToolbarButton.ts +11 -0
- package/src/list/DashAutoListActions.tsx +88 -0
- package/src/list/DashAutoListDatagridWrapper.tsx +74 -0
- package/src/list/DashAutoListDefaultActionsWrapper.tsx +31 -0
- package/src/list/DashAutoListFilterFormWithButton.tsx +93 -0
- package/src/list/DashAutoListTopToolbar.tsx +240 -0
- package/src/mui/AttributeToField.tsx +657 -0
- package/src/mui/AttributeToInput.tsx +728 -0
- package/src/mui/AutoAdminResizableDrawer.tsx +69 -0
- package/src/mui/AutoDataGrid.tsx +127 -0
- package/src/mui/AutoReferenceFormTab.tsx +51 -0
- package/src/mui/AutoReferenceTab.tsx +45 -0
- package/src/mui/AutoTabs.tsx +32 -0
- package/src/mui/components/ExtendedPagination.tsx +23 -0
- package/src/mui/components/ListStringField.tsx +32 -0
- package/src/providers/DashAuthProvider.ts +341 -0
- package/src/providers/DashDataProvider.ts +466 -0
- package/src/providers/index.ts +17 -0
- package/src/toolbar/buttons/BottomToolbarButtons.tsx +59 -0
- package/src/toolbar/buttons/DashResourceButton.tsx +223 -0
- package/src/toolbar/buttons/ListButtons.tsx +137 -0
- package/src/toolbar/buttons/ToolbarButtons.tsx +186 -0
- package/src/utils/SimpleLogger.tsx +46 -0
- package/src/utils/enumToChoices.tsx +3 -0
- package/src/utils/evalActionPermission.tsx +14 -0
- package/src/utils/groupByTabs.tsx +23 -0
- package/src/utils/hashedGroupByTabs.tsx +16 -0
- package/src/utils/invertMap.tsx +10 -0
- package/src/utils/isClassComponent.tsx +9 -0
- package/src/utils/isComponent.tsx +45 -0
- package/src/utils/isEnum.tsx +3 -0
- package/src/utils/isFC.tsx +6 -0
- package/src/utils/replaceParams.tsx +6 -0
- package/src/utils/validate.tsx +24 -0
- package/src/wrappers/UserAction.tsx +67 -0
- package/src/wrappers/index.tsx +1 -0
- /package/{dist → src}/DashAutoAdminSaveButton.tsx.bkup +0 -0
- /package/{dist/DashAutoFormLayout.tsx.review → src/DashAutoFormLayout.tsx} +0 -0
- /package/{dist → src}/DashAutoFormTabs.review +0 -0
- /package/{dist → src}/DashAutoFormTabs.tsx.formcontext.wip +0 -0
- /package/{dist → src}/mui/AttributeToField.tsx.review +0 -0
- /package/{dist → src}/mui/AttributeToInput.tsx.review +0 -0
- /package/{dist → src}/react-admin.d.ts +0 -0
- /package/{dist → src}/types/ActionCallback.d.ts +0 -0
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import { FormTab } from 'react-admin';
|
|
2
|
+
import { Tab, Tabs, Box } from '@mui/material';
|
|
3
|
+
import IDashAutoAdminAttribute from './interfaces/IDashAutoAdminAttribute';
|
|
4
|
+
import IDashAutoAdminFormOptions from './interfaces/IDashAutoAdminFormOptions';
|
|
5
|
+
import groupByTabs from './utils/groupByTabs';
|
|
6
|
+
import AttributeToInput from './mui/AttributeToInput';
|
|
7
|
+
import IDashAutoAdminResourceConfig from './interfaces/IDashAutoAdminResourceConfig';
|
|
8
|
+
import { useDispatch, useSelector } from 'react-redux';
|
|
9
|
+
//import { IDASHAppState } from 'dash-admin-state';
|
|
10
|
+
//import { CLEAR_FORM_DATA, SET_FORM_DATA } from 'dash-admin-state/src/redux/actions/ActionTypes';
|
|
11
|
+
import { useEffect, useState } from 'react';
|
|
12
|
+
import { useFormContext } from 'react-hook-form';
|
|
13
|
+
|
|
14
|
+
interface IAutoForm {
|
|
15
|
+
schema: IDashAutoAdminAttribute[],
|
|
16
|
+
resourceConfig: IDashAutoAdminResourceConfig,
|
|
17
|
+
options?: IDashAutoAdminFormOptions,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const CreateFormTabs = ({ schema, resourceConfig, options, isDrawer }) => {
|
|
21
|
+
const dispatch = useDispatch();
|
|
22
|
+
const [value, setValue] = useState(0);
|
|
23
|
+
|
|
24
|
+
const handleChange = (event) => {
|
|
25
|
+
const { name, value, type } = event.target;
|
|
26
|
+
let payloadValue;
|
|
27
|
+
|
|
28
|
+
switch (type) {
|
|
29
|
+
case 'checkbox':
|
|
30
|
+
payloadValue = event.target.checked;
|
|
31
|
+
break;
|
|
32
|
+
case 'select':
|
|
33
|
+
payloadValue = value;
|
|
34
|
+
break;
|
|
35
|
+
case 'text':
|
|
36
|
+
case 'number':
|
|
37
|
+
case 'email':
|
|
38
|
+
payloadValue = value;
|
|
39
|
+
break;
|
|
40
|
+
default:
|
|
41
|
+
payloadValue = value;
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
console.log("DashAutoFormMuiTabs: dispatch method deprecated")
|
|
45
|
+
//dispatch({ type: SET_FORM_DATA, payload: { [name]: payloadValue } });
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const handleTabChange = (event, newValue) => {
|
|
49
|
+
setValue(newValue);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
return () => {
|
|
54
|
+
console.log("DashAutoFormMuiTabs: dispatch method deprecated")
|
|
55
|
+
//dispatch({ type: CLEAR_FORM_DATA });
|
|
56
|
+
};
|
|
57
|
+
}, [dispatch]);
|
|
58
|
+
|
|
59
|
+
const tabGroups = groupByTabs(schema);
|
|
60
|
+
|
|
61
|
+
if (options?.meta?.tabs === "mui") {
|
|
62
|
+
return (
|
|
63
|
+
<Box sx={{ width: '100%' }}>
|
|
64
|
+
<Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
|
|
65
|
+
<Tabs value={value} onChange={handleTabChange}>
|
|
66
|
+
{tabGroups.map((group, idx) => (
|
|
67
|
+
<Tab key={`tab-${group[0].tab || idx}`} label={group[0].tab || options?.label || ''} />
|
|
68
|
+
))}
|
|
69
|
+
</Tabs>
|
|
70
|
+
</Box>
|
|
71
|
+
{tabGroups.map((groupOfAttributes, idx) => {
|
|
72
|
+
let grouppedAttributes = groupOfAttributes.filter(
|
|
73
|
+
(attribute) => attribute?.inCreate !== false,
|
|
74
|
+
);
|
|
75
|
+
if (isDrawer) {
|
|
76
|
+
grouppedAttributes = grouppedAttributes.filter(
|
|
77
|
+
(attribute) => attribute?.inDrawer !== false,
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
return (
|
|
81
|
+
<div
|
|
82
|
+
role="tabpanel"
|
|
83
|
+
hidden={value !== idx}
|
|
84
|
+
key={`panel-${idx}`}
|
|
85
|
+
style={{ padding: '20px 0' }}
|
|
86
|
+
>
|
|
87
|
+
{grouppedAttributes.map((attribute, i) => (
|
|
88
|
+
<div key={`input-${i}`}>
|
|
89
|
+
{AttributeToInput('create', resourceConfig, attribute, i, { ...options, handleChange })}
|
|
90
|
+
</div>
|
|
91
|
+
))}
|
|
92
|
+
</div>
|
|
93
|
+
);
|
|
94
|
+
})}
|
|
95
|
+
</Box>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return groupByTabs(schema).map((groupOfAttributes, idx) => {
|
|
100
|
+
let grouppedAttributes = groupOfAttributes.filter(
|
|
101
|
+
(attribute) => attribute?.inCreate !== false,
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
if (isDrawer) {
|
|
105
|
+
grouppedAttributes = grouppedAttributes.filter(
|
|
106
|
+
(attribute) => attribute?.inDrawer !== false,
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
return (
|
|
110
|
+
grouppedAttributes.length && (
|
|
111
|
+
<FormTab
|
|
112
|
+
key={`tab-${groupOfAttributes[0].tab || idx}`}
|
|
113
|
+
value={idx}
|
|
114
|
+
label={groupOfAttributes[0].tab || options?.label || ''}
|
|
115
|
+
>
|
|
116
|
+
{grouppedAttributes.map((attribute, i) => (
|
|
117
|
+
<div key={`input-${i}`}>
|
|
118
|
+
{AttributeToInput('create', resourceConfig, attribute, i, { ...options, handleChange })}
|
|
119
|
+
</div>
|
|
120
|
+
))}
|
|
121
|
+
</FormTab>
|
|
122
|
+
)
|
|
123
|
+
);
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const EditFormTabs = ({ schema, resourceConfig, options, isDrawer }) => {
|
|
128
|
+
const dispatch = useDispatch();
|
|
129
|
+
const [value, setValue] = useState(0);
|
|
130
|
+
|
|
131
|
+
const handleChange = (event) => {
|
|
132
|
+
const { name, value, type } = event.target;
|
|
133
|
+
let payloadValue;
|
|
134
|
+
|
|
135
|
+
switch (type) {
|
|
136
|
+
case 'checkbox':
|
|
137
|
+
payloadValue = event.target.checked;
|
|
138
|
+
break;
|
|
139
|
+
case 'select':
|
|
140
|
+
payloadValue = value;
|
|
141
|
+
break;
|
|
142
|
+
case 'text':
|
|
143
|
+
case 'number':
|
|
144
|
+
case 'email':
|
|
145
|
+
payloadValue = value;
|
|
146
|
+
break;
|
|
147
|
+
default:
|
|
148
|
+
payloadValue = value;
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
console.log("DashAutoFormMuiTabs: dispatch method deprecated")
|
|
153
|
+
//dispatch({ type: SET_FORM_DATA, payload: { [name]: payloadValue } });
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const handleTabChange = (event, newValue) => {
|
|
157
|
+
setValue(newValue);
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
useEffect(() => {
|
|
161
|
+
return () => {
|
|
162
|
+
console.log("DashAutoFormMuiTabs: dispatch method deprecated")
|
|
163
|
+
//dispatch({ type: CLEAR_FORM_DATA });
|
|
164
|
+
};
|
|
165
|
+
}, [dispatch]);
|
|
166
|
+
|
|
167
|
+
const tabGroups = groupByTabs(schema);
|
|
168
|
+
if (options?.meta?.tabs === "mui") {
|
|
169
|
+
return (
|
|
170
|
+
<Box sx={{ width: '100%' }}>
|
|
171
|
+
<Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
|
|
172
|
+
<Tabs value={value} onChange={handleTabChange}>
|
|
173
|
+
{tabGroups.map((group, idx) => (
|
|
174
|
+
<Tab key={`tab-${group[0].tab || idx}`} label={group[0].tab || options?.label || ''} />
|
|
175
|
+
))}
|
|
176
|
+
</Tabs>
|
|
177
|
+
</Box>
|
|
178
|
+
{tabGroups.map((groupOfAttributes, idx) => {
|
|
179
|
+
let grouppedAttributes = groupOfAttributes.filter(
|
|
180
|
+
(attribute) => attribute?.inEdit !== false,
|
|
181
|
+
);
|
|
182
|
+
if (isDrawer) {
|
|
183
|
+
grouppedAttributes = grouppedAttributes.filter(
|
|
184
|
+
(attribute) => attribute?.inDrawer !== false,
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
return (
|
|
188
|
+
<div
|
|
189
|
+
role="tabpanel"
|
|
190
|
+
hidden={value !== idx}
|
|
191
|
+
key={`panel-${idx}`}
|
|
192
|
+
style={{ padding: '20px 0' }}
|
|
193
|
+
>
|
|
194
|
+
{grouppedAttributes.map((attribute, i) => (
|
|
195
|
+
<div key={`input-${i}`}>
|
|
196
|
+
{AttributeToInput('edit', resourceConfig, attribute, i, { ...options, handleChange })}
|
|
197
|
+
</div>
|
|
198
|
+
))}
|
|
199
|
+
</div>
|
|
200
|
+
);
|
|
201
|
+
})}
|
|
202
|
+
</Box>
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return groupByTabs(schema).map((groupOfAttributes, idx) => {
|
|
207
|
+
let grouppedAttributes = groupOfAttributes.filter(
|
|
208
|
+
(attribute) => attribute?.inEdit !== false,
|
|
209
|
+
);
|
|
210
|
+
if (isDrawer) {
|
|
211
|
+
grouppedAttributes = grouppedAttributes.filter(
|
|
212
|
+
(attribute) => attribute?.inDrawer !== false,
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return (
|
|
217
|
+
grouppedAttributes.length && (
|
|
218
|
+
<FormTab
|
|
219
|
+
key={`tab-${groupOfAttributes[0].tab || idx}`}
|
|
220
|
+
value={idx}
|
|
221
|
+
label={groupOfAttributes[0].tab || options?.label || ''}
|
|
222
|
+
>
|
|
223
|
+
{grouppedAttributes.map((attribute, i) => (
|
|
224
|
+
<div key={`input-${i}`}>
|
|
225
|
+
{AttributeToInput('edit', resourceConfig, attribute, i, { ...options, handleChange })}
|
|
226
|
+
</div>
|
|
227
|
+
))}
|
|
228
|
+
</FormTab>
|
|
229
|
+
)
|
|
230
|
+
);
|
|
231
|
+
});
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
const ViewFormTabs = ({ schema, resourceConfig, options, isDrawer }) => {
|
|
235
|
+
const dispatch = useDispatch();
|
|
236
|
+
const [value, setValue] = useState(0);
|
|
237
|
+
|
|
238
|
+
const handleChange = (event) => {
|
|
239
|
+
const { name, value, type } = event.target;
|
|
240
|
+
let payloadValue;
|
|
241
|
+
|
|
242
|
+
switch (type) {
|
|
243
|
+
case 'checkbox':
|
|
244
|
+
payloadValue = event.target.checked;
|
|
245
|
+
break;
|
|
246
|
+
case 'select':
|
|
247
|
+
payloadValue = value;
|
|
248
|
+
break;
|
|
249
|
+
case 'text':
|
|
250
|
+
case 'number':
|
|
251
|
+
case 'email':
|
|
252
|
+
payloadValue = value;
|
|
253
|
+
break;
|
|
254
|
+
default:
|
|
255
|
+
payloadValue = value;
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
console.log("DashAutoFormMuiTabs: dispatch method deprecated")
|
|
260
|
+
//dispatch({ type: SET_FORM_DATA, payload: { [name]: payloadValue } });
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
const handleTabChange = (event, newValue) => {
|
|
264
|
+
setValue(newValue);
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
useEffect(() => {
|
|
268
|
+
return () => {
|
|
269
|
+
console.log("DashAutoFormMuiTabs: dispatch method deprecated")
|
|
270
|
+
//dispatch({ type: CLEAR_FORM_DATA });
|
|
271
|
+
};
|
|
272
|
+
}, [dispatch]);
|
|
273
|
+
|
|
274
|
+
const tabGroups = groupByTabs(schema);
|
|
275
|
+
|
|
276
|
+
if (options?.meta?.tabs === "mui") {
|
|
277
|
+
return (
|
|
278
|
+
<Box sx={{ width: '100%' }}>
|
|
279
|
+
<Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
|
|
280
|
+
<Tabs value={value} onChange={handleTabChange}>
|
|
281
|
+
{tabGroups.map((group, idx) => (
|
|
282
|
+
<Tab key={`tab-${group[0].tab || idx}`} label={group[0].tab || options?.label || ''} />
|
|
283
|
+
))}
|
|
284
|
+
</Tabs>
|
|
285
|
+
</Box>
|
|
286
|
+
{tabGroups.map((groupOfAttributes, idx) => {
|
|
287
|
+
let grouppedAttributes = groupOfAttributes.filter(
|
|
288
|
+
(attribute) => attribute?.inShow !== false,
|
|
289
|
+
);
|
|
290
|
+
if (isDrawer) {
|
|
291
|
+
grouppedAttributes = grouppedAttributes.filter(
|
|
292
|
+
(attribute) => attribute?.inDrawer !== false,
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
return (
|
|
296
|
+
<div
|
|
297
|
+
role="tabpanel"
|
|
298
|
+
hidden={value !== idx}
|
|
299
|
+
key={`panel-${idx}`}
|
|
300
|
+
style={{ padding: '20px 0' }}
|
|
301
|
+
>
|
|
302
|
+
{grouppedAttributes.map((attribute, i) => (
|
|
303
|
+
<div key={`input-${i}`}>
|
|
304
|
+
{AttributeToInput('view', resourceConfig, attribute, i, { ...options, handleChange })}
|
|
305
|
+
</div>
|
|
306
|
+
))}
|
|
307
|
+
</div>
|
|
308
|
+
);
|
|
309
|
+
})}
|
|
310
|
+
</Box>
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
return groupByTabs(schema).map((groupOfAttributes, idx) => {
|
|
315
|
+
let grouppedAttributes = groupOfAttributes.filter(
|
|
316
|
+
(attribute) => attribute?.inShow !== false,
|
|
317
|
+
);
|
|
318
|
+
if (isDrawer) {
|
|
319
|
+
grouppedAttributes = grouppedAttributes.filter(
|
|
320
|
+
(attribute) => attribute?.inDrawer !== false,
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
return (
|
|
324
|
+
grouppedAttributes.length && (
|
|
325
|
+
<FormTab
|
|
326
|
+
key={`tab-${groupOfAttributes[0].tab || idx}`}
|
|
327
|
+
value={idx}
|
|
328
|
+
label={groupOfAttributes[0].tab || options?.label || ''}
|
|
329
|
+
>
|
|
330
|
+
{grouppedAttributes.map((attribute, i) => (
|
|
331
|
+
<div key={`input-${i}`}>
|
|
332
|
+
{AttributeToInput('view', resourceConfig, attribute, i, { ...options, handleChange })}
|
|
333
|
+
</div>
|
|
334
|
+
))}
|
|
335
|
+
</FormTab>
|
|
336
|
+
)
|
|
337
|
+
);
|
|
338
|
+
});
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
const DashAutoFormMuiTabs = ({
|
|
342
|
+
schema,
|
|
343
|
+
resourceConfig,
|
|
344
|
+
options
|
|
345
|
+
}: IAutoForm) => {
|
|
346
|
+
const isDrawer = options.isDrawer === true ? true : false;
|
|
347
|
+
const meta = options?.meta || {};
|
|
348
|
+
|
|
349
|
+
const commonProps = {
|
|
350
|
+
schema,
|
|
351
|
+
resourceConfig,
|
|
352
|
+
options,
|
|
353
|
+
isDrawer
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
switch (options.mode) {
|
|
357
|
+
case 'create':
|
|
358
|
+
return <CreateFormTabs {...commonProps} />;
|
|
359
|
+
case 'edit':
|
|
360
|
+
return <EditFormTabs {...commonProps} />;
|
|
361
|
+
case 'view':
|
|
362
|
+
return <ViewFormTabs {...commonProps} />;
|
|
363
|
+
default:
|
|
364
|
+
return null;
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
export default DashAutoFormMuiTabs;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { FormTab } from 'react-admin';
|
|
2
|
+
import IDashAutoAdminAttribute from './interfaces/IDashAutoAdminAttribute';
|
|
3
|
+
import IDashAutoAdminFormOptions from './interfaces/IDashAutoAdminFormOptions';
|
|
4
|
+
import groupByTabs from './utils/groupByTabs';
|
|
5
|
+
import AttributeToInput from './mui/AttributeToInput';
|
|
6
|
+
import IDashAutoAdminResourceConfig from './interfaces/IDashAutoAdminResourceConfig';
|
|
7
|
+
interface IAutoForm {
|
|
8
|
+
schema: IDashAutoAdminAttribute[],
|
|
9
|
+
resourceConfig: IDashAutoAdminResourceConfig,
|
|
10
|
+
options?: IDashAutoAdminFormOptions,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The `DashAutoFormTabs` component is responsible for rendering the form tabs in the Dash Auto Admin interface.
|
|
15
|
+
* It takes in a `schema` of `IDashAutoAdminAttribute` objects, a `resource` of `IDashAutoAdminResourceConfig`, and optional `options` of `IDashAutoAdminFormOptions`.
|
|
16
|
+
* The component handles different form modes ('create', 'edit', 'view') and renders the appropriate form tabs based on the provided schema and options.
|
|
17
|
+
* It also features a form data state management using Redux and handles changes to form inputs for Tabbed Forms.
|
|
18
|
+
*
|
|
19
|
+
* If there is only one tab group, it renders the inputs directly without the FormTab wrapper.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const DashAutoFormTabs = ({
|
|
23
|
+
schema,
|
|
24
|
+
resourceConfig,
|
|
25
|
+
options
|
|
26
|
+
}: IAutoForm) => {
|
|
27
|
+
|
|
28
|
+
const isDrawer = options.isDrawer === true ? true : false;
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
const handleChange = (event) => {
|
|
32
|
+
|
|
33
|
+
const { name, value, type } = event.target;
|
|
34
|
+
|
|
35
|
+
// Handle different input types
|
|
36
|
+
let payloadValue;
|
|
37
|
+
switch (type) {
|
|
38
|
+
case 'checkbox':
|
|
39
|
+
// For checkboxes, the value is a boolean
|
|
40
|
+
payloadValue = event.target.checked; // Use checked for checkbox inputs
|
|
41
|
+
break;
|
|
42
|
+
case 'select':
|
|
43
|
+
// For select inputs, you might need to handle differently if you have multiple selections
|
|
44
|
+
payloadValue = value; // For single select
|
|
45
|
+
break;
|
|
46
|
+
case 'text':
|
|
47
|
+
case 'number':
|
|
48
|
+
case 'email':
|
|
49
|
+
// For text, number, and email inputs
|
|
50
|
+
payloadValue = value;
|
|
51
|
+
break;
|
|
52
|
+
// Add cases for other input types as needed
|
|
53
|
+
default:
|
|
54
|
+
payloadValue = value; // Fallback for other input types
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
options = {...options, handleChange};
|
|
63
|
+
|
|
64
|
+
// Helper to render inputs for a group
|
|
65
|
+
const renderInputs = (mode: 'create' | 'edit' | 'view', grouppedAttributes: IDashAutoAdminAttribute[]) => {
|
|
66
|
+
return grouppedAttributes.map((attribute, i) => (
|
|
67
|
+
<div key={`input-${i}`}>
|
|
68
|
+
{AttributeToInput(mode, resourceConfig, attribute, i, options)}
|
|
69
|
+
</div>
|
|
70
|
+
));
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// Helper to filter attributes based on mode and drawer
|
|
74
|
+
const filterAttributes = (
|
|
75
|
+
groupOfAttributes: IDashAutoAdminAttribute[],
|
|
76
|
+
mode: 'create' | 'edit' | 'view'
|
|
77
|
+
) => {
|
|
78
|
+
let filtered = groupOfAttributes.filter((attribute) => {
|
|
79
|
+
switch (mode) {
|
|
80
|
+
case 'create':
|
|
81
|
+
return attribute?.inCreate !== false;
|
|
82
|
+
case 'edit':
|
|
83
|
+
return attribute?.inEdit !== false;
|
|
84
|
+
case 'view':
|
|
85
|
+
return attribute?.inShow !== false;
|
|
86
|
+
default:
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
if (isDrawer) {
|
|
92
|
+
filtered = filtered.filter((attribute) => attribute?.inDrawer !== false);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return filtered;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// Get all tab groups
|
|
99
|
+
const tabGroups = groupByTabs(schema);
|
|
100
|
+
|
|
101
|
+
// Filter tab groups to only include those with visible attributes for current mode
|
|
102
|
+
const getFilteredTabGroups = (mode: 'create' | 'edit' | 'view') => {
|
|
103
|
+
return tabGroups
|
|
104
|
+
.map((group) => ({
|
|
105
|
+
original: group,
|
|
106
|
+
filtered: filterAttributes(group, mode),
|
|
107
|
+
}))
|
|
108
|
+
.filter((g) => g.filtered.length > 0);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
switch (options.mode) {
|
|
112
|
+
case 'create': {
|
|
113
|
+
const filteredGroups = getFilteredTabGroups('create');
|
|
114
|
+
|
|
115
|
+
// If only one tab group, render inputs directly without FormTab wrapper
|
|
116
|
+
if (filteredGroups.length === 1) {
|
|
117
|
+
return <>{renderInputs('create', filteredGroups[0].filtered)}</>;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Multiple tabs - wrap each in FormTab
|
|
121
|
+
return filteredGroups.map((group, idx) => (
|
|
122
|
+
<FormTab
|
|
123
|
+
key={`tab-${group.original[0].tab || idx}`}
|
|
124
|
+
value={idx}
|
|
125
|
+
label={group.original[0].tab || options?.label || resourceConfig?.label}
|
|
126
|
+
>
|
|
127
|
+
{renderInputs('create', group.filtered)}
|
|
128
|
+
</FormTab>
|
|
129
|
+
));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
case 'edit': {
|
|
133
|
+
const filteredGroups = getFilteredTabGroups('edit');
|
|
134
|
+
|
|
135
|
+
// If only one tab group, render inputs directly without FormTab wrapper
|
|
136
|
+
if (filteredGroups.length === 1) {
|
|
137
|
+
return <>{renderInputs('edit', filteredGroups[0].filtered)}</>;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Multiple tabs - wrap each in FormTab
|
|
141
|
+
return filteredGroups.map((group, idx) => (
|
|
142
|
+
<FormTab
|
|
143
|
+
key={`tab-${group.original[0].tab || idx}`}
|
|
144
|
+
value={idx}
|
|
145
|
+
label={group.original[0].tab || options?.label || resourceConfig?.label}
|
|
146
|
+
>
|
|
147
|
+
{renderInputs('edit', group.filtered)}
|
|
148
|
+
</FormTab>
|
|
149
|
+
));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
case 'view': {
|
|
153
|
+
const filteredGroups = getFilteredTabGroups('view');
|
|
154
|
+
|
|
155
|
+
// If only one tab group, render inputs directly without FormTab wrapper
|
|
156
|
+
if (filteredGroups.length === 1) {
|
|
157
|
+
return <>{renderInputs('view', filteredGroups[0].filtered)}</>;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Multiple tabs - wrap each in FormTab
|
|
161
|
+
return filteredGroups.map((group, idx) => (
|
|
162
|
+
<FormTab
|
|
163
|
+
key={`tab-${group.original[0].tab || idx}`}
|
|
164
|
+
value={idx}
|
|
165
|
+
label={group.original[0].tab || options?.label || resourceConfig?.label}
|
|
166
|
+
>
|
|
167
|
+
{renderInputs('view', group.filtered)}
|
|
168
|
+
</FormTab>
|
|
169
|
+
));
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
DashAutoFormTabs.whyDidYouRender = true;
|
|
176
|
+
|
|
177
|
+
export default DashAutoFormTabs;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { SimpleShowLayout } from 'react-admin';
|
|
2
|
+
import IDashAutoAdminResourceConfig from './interfaces/IDashAutoAdminResourceConfig';
|
|
3
|
+
import { AttributeToField } from './mui/AttributeToField';
|
|
4
|
+
import groupByTabs from './utils/groupByTabs';
|
|
5
|
+
import { AutoAdminSettings } from '.';
|
|
6
|
+
import IDashAutoAdminFormOptions from './interfaces/IDashAutoAdminFormOptions';
|
|
7
|
+
|
|
8
|
+
const DashAutoGroup = (
|
|
9
|
+
resourceConfig: IDashAutoAdminResourceConfig,
|
|
10
|
+
options?: IDashAutoAdminFormOptions,
|
|
11
|
+
) => {
|
|
12
|
+
return (
|
|
13
|
+
<SimpleShowLayout>
|
|
14
|
+
{groupByTabs(resourceConfig.schema).map((groupOfAttributes, idx) => {
|
|
15
|
+
|
|
16
|
+
const label = groupOfAttributes[0].tab || AutoAdminSettings.defaultTabName;
|
|
17
|
+
|
|
18
|
+
const count = groupOfAttributes
|
|
19
|
+
.filter((attribute) => attribute?.inShow !== false).length;
|
|
20
|
+
|
|
21
|
+
return count ?
|
|
22
|
+
<fieldset key={'fieldset-group-' + idx}>
|
|
23
|
+
<legend>{label}</legend>
|
|
24
|
+
{groupOfAttributes
|
|
25
|
+
.filter((attribute) => attribute?.inShow !== false)
|
|
26
|
+
.map((attribute, i) =>
|
|
27
|
+
AttributeToField(
|
|
28
|
+
'view',
|
|
29
|
+
resourceConfig,
|
|
30
|
+
attribute,
|
|
31
|
+
i,
|
|
32
|
+
options,
|
|
33
|
+
),
|
|
34
|
+
)}
|
|
35
|
+
</fieldset> : <></>
|
|
36
|
+
|
|
37
|
+
})}
|
|
38
|
+
</SimpleShowLayout>
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export default DashAutoGroup;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { SimpleShowLayout } from 'react-admin';
|
|
2
|
+
import AutoTabs from './DashAutoTabs';
|
|
3
|
+
import IDashAutoAdminResourceConfig from './interfaces/IDashAutoAdminResourceConfig';
|
|
4
|
+
import { AttributeToField } from './mui/AttributeToField';
|
|
5
|
+
import hashedGroupByTabs from './utils/hashedGroupByTabs';
|
|
6
|
+
import IDashAutoAdminFormOptions from './interfaces/IDashAutoAdminFormOptions';
|
|
7
|
+
import { JSX } from 'react';
|
|
8
|
+
|
|
9
|
+
export interface IDashAutoLayoutRenderFunction {
|
|
10
|
+
(
|
|
11
|
+
tab: string,
|
|
12
|
+
options?: IDashAutoAdminFormOptions,
|
|
13
|
+
forceAttributeToFieldMethod?: 'view' | 'list' | 'create' | 'edit',
|
|
14
|
+
): JSX.Element[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const DashAutoLayout = (
|
|
18
|
+
resourceConfig: IDashAutoAdminResourceConfig,
|
|
19
|
+
options?: IDashAutoAdminFormOptions,
|
|
20
|
+
) => {
|
|
21
|
+
const renderShow: IDashAutoLayoutRenderFunction = (
|
|
22
|
+
tab,
|
|
23
|
+
options,
|
|
24
|
+
forceAttributeToFieldMethod,
|
|
25
|
+
): JSX.Element[] => {
|
|
26
|
+
const groupedTabs = hashedGroupByTabs(resourceConfig.schema);
|
|
27
|
+
|
|
28
|
+
const groupedAttributesByTab = groupedTabs[tab] ? groupedTabs[tab] : [];
|
|
29
|
+
return groupedAttributesByTab
|
|
30
|
+
.filter((attribute) => attribute?.inShow !== false)
|
|
31
|
+
.map((attribute, idx) =>
|
|
32
|
+
AttributeToField(
|
|
33
|
+
forceAttributeToFieldMethod || 'view',
|
|
34
|
+
resourceConfig,
|
|
35
|
+
attribute,
|
|
36
|
+
idx,
|
|
37
|
+
options,
|
|
38
|
+
),
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
if (
|
|
43
|
+
!resourceConfig.showLayout ||
|
|
44
|
+
typeof resourceConfig.showLayout !== 'function'
|
|
45
|
+
) {
|
|
46
|
+
console.error(
|
|
47
|
+
'showLayout must be present and be a function in the resource definition when using formGroupMode layout, fallback to tabs',
|
|
48
|
+
);
|
|
49
|
+
return AutoTabs(resourceConfig);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<SimpleShowLayout>{resourceConfig.showLayout(renderShow)}</SimpleShowLayout>
|
|
54
|
+
);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export default DashAutoLayout;
|