@dashadmin/dash-auto-admin 1.3.25 → 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,237 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
import autoFiltersGenerator from './DashAutoFiltersGenerator';
|
|
3
|
+
import { useUnselectAll } from 'react-admin';
|
|
4
|
+
import { PaginationProps } from 'react-admin/src';
|
|
5
|
+
|
|
6
|
+
import { List } from 'react-admin';
|
|
7
|
+
|
|
8
|
+
import IDashAutoAdminResourceConfig from './interfaces/IDashAutoAdminResourceConfig';
|
|
9
|
+
import { FC, Fragment, JSX, useEffect, useState } from 'react';
|
|
10
|
+
import ExtendedPagination from './mui/components/ExtendedPagination';
|
|
11
|
+
|
|
12
|
+
import DashAutoListDefaultListActionsWrapper from './list/DashAutoListDefaultActionsWrapper';
|
|
13
|
+
import DashAutoListDataGridWrapper from './list/DashAutoListDatagridWrapper';
|
|
14
|
+
import DashAutoListActions from './list/DashAutoListActions';
|
|
15
|
+
|
|
16
|
+
export interface IDashAutoList {
|
|
17
|
+
resourceConfig: IDashAutoAdminResourceConfig;
|
|
18
|
+
customToolbarElements?: (props: any) => JSX.Element;
|
|
19
|
+
beforeSubmit?: (data: any) => any;
|
|
20
|
+
onSubmit?: (data: any) => any;
|
|
21
|
+
onError?: (error: any) => any;
|
|
22
|
+
dataGridProps?: any;
|
|
23
|
+
children?: any;
|
|
24
|
+
Pagination?: FC<PaginationProps>;
|
|
25
|
+
locale?: string;
|
|
26
|
+
//stickyHeader?: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Wrapper component for actions that will be rendered inside List context
|
|
30
|
+
interface ListActionsComponentProps {
|
|
31
|
+
resourceConfig: IDashAutoAdminResourceConfig;
|
|
32
|
+
autoFilters: JSX.Element[];
|
|
33
|
+
listProps: any;
|
|
34
|
+
ListActionsWrapper: any;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const ListActionsComponent: FC<ListActionsComponentProps> = ({
|
|
38
|
+
resourceConfig,
|
|
39
|
+
autoFilters,
|
|
40
|
+
listProps,
|
|
41
|
+
ListActionsWrapper,
|
|
42
|
+
}) => {
|
|
43
|
+
// DEBUG: Log actions rendering
|
|
44
|
+
console.log('🎬 DashAutoList DEBUG - Rendering actions (fieldProps standardized):', {
|
|
45
|
+
resourceModel: resourceConfig.model,
|
|
46
|
+
autoFiltersCount: autoFilters.length,
|
|
47
|
+
hasCustomToolbarElements: !!resourceConfig.customToolbarElements,
|
|
48
|
+
timestamp: new Date().toISOString()
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<ListActionsWrapper
|
|
53
|
+
autoFilters={autoFilters}
|
|
54
|
+
resourceConfig={resourceConfig}
|
|
55
|
+
>
|
|
56
|
+
<DashAutoListActions
|
|
57
|
+
filters={autoFilters}
|
|
58
|
+
resourceConfig={resourceConfig}
|
|
59
|
+
autoFilters={autoFilters}
|
|
60
|
+
listProps={listProps}
|
|
61
|
+
/>
|
|
62
|
+
</ListActionsWrapper>
|
|
63
|
+
);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const DashAutoList: React.FC<IDashAutoList> = ({
|
|
67
|
+
resourceConfig,
|
|
68
|
+
customToolbarElements,
|
|
69
|
+
beforeSubmit,
|
|
70
|
+
onSubmit,
|
|
71
|
+
onError,
|
|
72
|
+
Pagination,
|
|
73
|
+
children,
|
|
74
|
+
dataGridProps,
|
|
75
|
+
locale,
|
|
76
|
+
...listProps
|
|
77
|
+
}) => {
|
|
78
|
+
const { exporter } = resourceConfig;
|
|
79
|
+
|
|
80
|
+
// DEBUG: Log the resource configuration
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
console.log('📋 DashAutoList DEBUG - Component initialized (fieldProps standardized):', {
|
|
83
|
+
resourceModel: resourceConfig.model,
|
|
84
|
+
hasReferenceFilters: !!(resourceConfig.referenceFilters && resourceConfig.referenceFilters.length > 0),
|
|
85
|
+
referenceFiltersCount: resourceConfig.referenceFilters?.length || 0,
|
|
86
|
+
referenceFilters: resourceConfig.referenceFilters?.map(f => ({
|
|
87
|
+
id: f.id,
|
|
88
|
+
source: f.source,
|
|
89
|
+
label: f.label,
|
|
90
|
+
hasReferenceComponent: !!f.referenceComponent,
|
|
91
|
+
fieldProps: f.fieldProps, // Only fieldProps now
|
|
92
|
+
})) || [],
|
|
93
|
+
timestamp: new Date().toISOString()
|
|
94
|
+
});
|
|
95
|
+
}, [resourceConfig]);
|
|
96
|
+
|
|
97
|
+
if (customToolbarElements) {
|
|
98
|
+
resourceConfig.customToolbarElements = customToolbarElements;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// DEBUG: Log before generating filters
|
|
102
|
+
console.log('🔧 DashAutoList DEBUG - About to generate filters (fieldProps only):', {
|
|
103
|
+
resourceModel: resourceConfig.model,
|
|
104
|
+
referenceFilters: resourceConfig.referenceFilters,
|
|
105
|
+
timestamp: new Date().toISOString()
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const autoFilters = autoFiltersGenerator(resourceConfig, locale);
|
|
109
|
+
|
|
110
|
+
// DEBUG: Log generated filters
|
|
111
|
+
console.log('✅ DashAutoList DEBUG - Filters generated (fieldProps standardized):', {
|
|
112
|
+
resourceModel: resourceConfig.model,
|
|
113
|
+
filtersCount: autoFilters.length,
|
|
114
|
+
filters: autoFilters.map((filter, idx) => ({
|
|
115
|
+
index: idx,
|
|
116
|
+
key: filter.key,
|
|
117
|
+
type: filter.type?.name || 'unknown',
|
|
118
|
+
props: filter.props,
|
|
119
|
+
})),
|
|
120
|
+
timestamp: new Date().toISOString()
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const unselectAll = useUnselectAll(
|
|
124
|
+
resourceConfig.listProps?.storeKey || resourceConfig.model,
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
const _dataGridProps = { ...resourceConfig.dataGridProps, ...dataGridProps };
|
|
128
|
+
|
|
129
|
+
const [, setHandleLoading] = useState<boolean>(false);
|
|
130
|
+
|
|
131
|
+
useEffect(() => {
|
|
132
|
+
const handleGlobalLoader = (e: any) => {
|
|
133
|
+
if (resourceConfig.model === e.data.resource)
|
|
134
|
+
setHandleLoading(e.data.value);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
window.addEventListener('dash-global-loader', handleGlobalLoader);
|
|
138
|
+
return () => {
|
|
139
|
+
window.removeEventListener('dash-global-loader', handleGlobalLoader);
|
|
140
|
+
};
|
|
141
|
+
}, [resourceConfig.model]);
|
|
142
|
+
|
|
143
|
+
const ListActionsWrapper = resourceConfig.listActionsWrapper || DashAutoListDefaultListActionsWrapper;
|
|
144
|
+
|
|
145
|
+
useEffect(() => {
|
|
146
|
+
if (resourceConfig.resetSelectedIdsOnLoad) {
|
|
147
|
+
unselectAll();
|
|
148
|
+
}
|
|
149
|
+
}, [resourceConfig.resetSelectedIdsOnLoad, unselectAll]);
|
|
150
|
+
|
|
151
|
+
// Check if we should show actions
|
|
152
|
+
const shouldShowActions = () => {
|
|
153
|
+
if (resourceConfig.toolbar === false) {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Check if there are any actual toolbar items
|
|
158
|
+
const hasToolbarItems =
|
|
159
|
+
(autoFilters && autoFilters.length > 0) ||
|
|
160
|
+
resourceConfig.create ||
|
|
161
|
+
resourceConfig.exporter ||
|
|
162
|
+
resourceConfig.customToolbarElements;
|
|
163
|
+
|
|
164
|
+
return hasToolbarItems;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// Create actions element - this will be rendered inside List context
|
|
168
|
+
const actionsElement = shouldShowActions() ? (
|
|
169
|
+
<ListActionsComponent
|
|
170
|
+
resourceConfig={resourceConfig}
|
|
171
|
+
autoFilters={autoFilters}
|
|
172
|
+
listProps={listProps}
|
|
173
|
+
ListActionsWrapper={ListActionsWrapper}
|
|
174
|
+
/>
|
|
175
|
+
) : null;
|
|
176
|
+
|
|
177
|
+
const finalListProps = {
|
|
178
|
+
/* default storeKey */
|
|
179
|
+
sort: { field: 'id', order: 'ASC' as const },
|
|
180
|
+
storeKey: resourceConfig?.model,
|
|
181
|
+
// Explicitly set resource to ensure List component works correctly
|
|
182
|
+
resource: resourceConfig?.model,
|
|
183
|
+
|
|
184
|
+
...listProps,
|
|
185
|
+
...(resourceConfig.listProps || {}),
|
|
186
|
+
|
|
187
|
+
// Set actions to the element (will be rendered inside List context)
|
|
188
|
+
actions: actionsElement,
|
|
189
|
+
|
|
190
|
+
pagination: Pagination ? <Pagination {...resourceConfig.paginationProps} /> : <ExtendedPagination {...resourceConfig.paginationProps} />,
|
|
191
|
+
...(exporter && { exporter: exporter }),
|
|
192
|
+
...(resourceConfig.bulkActionButtons && { bulkActionButtons: resourceConfig.bulkActionButtons }),
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
// DEBUG: Log final list props
|
|
196
|
+
console.log('🚀 DashAutoList DEBUG - Final list props (fieldProps standardized):', {
|
|
197
|
+
resourceModel: resourceConfig.model,
|
|
198
|
+
finalListProps: {
|
|
199
|
+
...finalListProps,
|
|
200
|
+
actions: actionsElement ? 'rendered' : 'null',
|
|
201
|
+
},
|
|
202
|
+
timestamp: new Date().toISOString()
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
const ContextComponent = resourceConfig.contextComponent ? resourceConfig.contextComponent: ({children}) => {
|
|
206
|
+
return children;
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
if (!finalListProps) return <></>;
|
|
211
|
+
|
|
212
|
+
return resourceConfig.listComponent ? (
|
|
213
|
+
resourceConfig.listComponent(resourceConfig, onSubmit, onError)
|
|
214
|
+
) : (
|
|
215
|
+
<List
|
|
216
|
+
component="div"
|
|
217
|
+
{...finalListProps}
|
|
218
|
+
>
|
|
219
|
+
<ContextComponent mode={"list"} resourceConfig={resourceConfig}>
|
|
220
|
+
{resourceConfig.dataGridComponent ? (
|
|
221
|
+
<resourceConfig.dataGridComponent
|
|
222
|
+
resourceConfig={resourceConfig}
|
|
223
|
+
dataGridProps={_dataGridProps}
|
|
224
|
+
/>
|
|
225
|
+
) : (
|
|
226
|
+
<DashAutoListDataGridWrapper
|
|
227
|
+
resourceConfig={resourceConfig}
|
|
228
|
+
dataGridProps={_dataGridProps}
|
|
229
|
+
locale={locale}
|
|
230
|
+
/>
|
|
231
|
+
)}
|
|
232
|
+
</ContextComponent>
|
|
233
|
+
</List>
|
|
234
|
+
);
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
export default DashAutoList;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useForm, FormProvider } from 'react-hook-form';
|
|
2
|
+
import { ListContext } from 'react-admin';
|
|
3
|
+
import { useContext } from 'react';
|
|
4
|
+
|
|
5
|
+
// Safe hook that doesn't throw when context is missing
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
+
const useSafeListContext = (): any => {
|
|
8
|
+
const context = useContext(ListContext);
|
|
9
|
+
return context ?? null;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const DashAutoPostFilterForm = (filters: any) => {
|
|
13
|
+
const listContext = useSafeListContext();
|
|
14
|
+
const filterValues = listContext?.filterValues ?? {};
|
|
15
|
+
const displayedFilters = listContext?.displayedFilters ?? [];
|
|
16
|
+
const setFilters = listContext?.setFilters;
|
|
17
|
+
|
|
18
|
+
const form = useForm({
|
|
19
|
+
defaultValues: filterValues,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const onSubmit = (values) => {
|
|
23
|
+
if (Object.keys(values).length > 0 && setFilters) {
|
|
24
|
+
setFilters(values, displayedFilters);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<FormProvider {...form}>
|
|
30
|
+
<form onSubmit={form.handleSubmit(onSubmit)}>{filters}</form>
|
|
31
|
+
</FormProvider>
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export default DashAutoPostFilterForm;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AutoReferenceTab as MuiAutoReferenceTab } from './mui/AutoReferenceTab';
|
|
2
|
+
import { IDashAutoAdminReference } from './interfaces/IDashAutoAdminReference';
|
|
3
|
+
|
|
4
|
+
export const DashAutoReferenceTab = (reference: IDashAutoAdminReference) => {
|
|
5
|
+
const _AutoReferenceTab = MuiAutoReferenceTab;
|
|
6
|
+
return _AutoReferenceTab(reference);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default DashAutoReferenceTab;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Resource } from 'react-admin';
|
|
2
|
+
|
|
3
|
+
import AutoCreate from './DashAutoCreate';
|
|
4
|
+
import AutoEdit from './DashAutoEdit';
|
|
5
|
+
import AutoShow from './DashAutoShow';
|
|
6
|
+
import IRecord from './interfaces/IRecord';
|
|
7
|
+
import DashAutoList from './DashAutoList';
|
|
8
|
+
|
|
9
|
+
import IDashAutoAdminResourceConfig from './interfaces/IDashAutoAdminResourceConfig';
|
|
10
|
+
import React from 'react';
|
|
11
|
+
import isFC from './utils/isFC';
|
|
12
|
+
|
|
13
|
+
export interface IAutoResource {
|
|
14
|
+
//model: string
|
|
15
|
+
//label: string
|
|
16
|
+
//schema: IDashAutoAdminAttribute[]
|
|
17
|
+
resourceConfig: IDashAutoAdminResourceConfig;
|
|
18
|
+
//references?: IDashAutoAdminReference[]
|
|
19
|
+
//exporter?: any;
|
|
20
|
+
//referenceFilters?: IReferenceFilter[]
|
|
21
|
+
show?: boolean | React.FC;
|
|
22
|
+
list?: boolean | React.FC;
|
|
23
|
+
edit?: boolean | React.FC;
|
|
24
|
+
create?: boolean | React.FC;
|
|
25
|
+
//icon?: any | JSX.Element | React.ReactNode
|
|
26
|
+
//group?: string
|
|
27
|
+
//search?: boolean
|
|
28
|
+
//beforeSubmit?: (values: any) => any
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const DashAutoResource = ({
|
|
32
|
+
resourceConfig,
|
|
33
|
+
show,
|
|
34
|
+
list,
|
|
35
|
+
edit,
|
|
36
|
+
create,
|
|
37
|
+
}: IAutoResource) => {
|
|
38
|
+
const props: any = {};
|
|
39
|
+
|
|
40
|
+
if (typeof list !== 'boolean' && isFC(list)) {
|
|
41
|
+
const CustomList: React.FC<IRecord> = list;
|
|
42
|
+
props.list = () => <CustomList resourceConfig={resourceConfig} />;
|
|
43
|
+
} else if (list !== false) {
|
|
44
|
+
props.list = () => <DashAutoList resourceConfig={resourceConfig} />;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (!resourceConfig.drawer) {
|
|
48
|
+
if (typeof show !== 'boolean' && isFC(show)) {
|
|
49
|
+
const CustomShow: React.FC<IRecord> = show;
|
|
50
|
+
props.show = () => <CustomShow resourceConfig={resourceConfig} />;
|
|
51
|
+
} else if (show !== false) {
|
|
52
|
+
props.show = () => <AutoShow resourceConfig={resourceConfig} />;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (typeof edit !== 'boolean' && isFC(edit)) {
|
|
56
|
+
const CustomEdit: React.FC<IRecord> = edit;
|
|
57
|
+
props.edit = () => <CustomEdit resourceConfig={resourceConfig} />;
|
|
58
|
+
} else if (edit !== false) {
|
|
59
|
+
props.edit = () => <AutoEdit resourceConfig={resourceConfig} />;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (typeof create !== 'boolean' && isFC(create)) {
|
|
63
|
+
const CustomCreate: React.FC<IRecord> = create;
|
|
64
|
+
//props.list = () => <Create />
|
|
65
|
+
props.create = () => <CustomCreate resourceConfig={resourceConfig} />;
|
|
66
|
+
} else if (create !== false) {
|
|
67
|
+
props.create = () => <AutoCreate resourceConfig={resourceConfig} />;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<Resource
|
|
73
|
+
options={{
|
|
74
|
+
label: resourceConfig.label,
|
|
75
|
+
...(resourceConfig.group && { group: resourceConfig.group }),
|
|
76
|
+
}}
|
|
77
|
+
name={resourceConfig.model}
|
|
78
|
+
{...props}
|
|
79
|
+
icon={resourceConfig.icon}
|
|
80
|
+
group={resourceConfig.group}
|
|
81
|
+
/>
|
|
82
|
+
);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export default DashAutoResource;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import React, { PropsWithChildren, memo } from 'react';
|
|
2
|
+
import IDashAutoAdminResourceConfig from './interfaces/IDashAutoAdminResourceConfig';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Defines the interface for the default resource layout component in the Dash Auto Admin application.
|
|
6
|
+
*
|
|
7
|
+
* This interface extends the `PropsWithChildren` type, which means the component can accept child elements.
|
|
8
|
+
*
|
|
9
|
+
* The interface defines two properties:
|
|
10
|
+
*
|
|
11
|
+
* 1. `resourceConfig`: An object of type `IDashAutoAdminResourceConfig` that contains the configuration for the current resource.
|
|
12
|
+
* 2. `ResourceMenu`: A React functional component that renders the side navigation menu for the resource.
|
|
13
|
+
*/
|
|
14
|
+
export interface IDashDefaultResourceLayout extends PropsWithChildren {
|
|
15
|
+
/** React Auto Admin Resource Config */
|
|
16
|
+
resourceConfig: IDashAutoAdminResourceConfig;
|
|
17
|
+
ResourceMenu: React.FC<PropsWithChildren<{ resourceConfig: IDashAutoAdminResourceConfig }>>,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Renders the default resource layout for the Dash Auto Admin application. To serve as an example, this will not fit for all client UI needs.
|
|
22
|
+
*
|
|
23
|
+
* The resource layout provides a side navigation around the main content, which can include views such as 'show', 'edit', 'list', and 'view'.
|
|
24
|
+
*
|
|
25
|
+
* @param props - The component props, including the resource configuration and the ResourceMenu component.
|
|
26
|
+
* @param props.resourceConfig - The configuration for the current resource.
|
|
27
|
+
* @param props.ResourceMenu - A React component that renders the side navigation menu.
|
|
28
|
+
* @param props.children - The main content to be displayed, such as the 'show', 'edit', 'list', or 'view' components.
|
|
29
|
+
* @returns The rendered resource layout.
|
|
30
|
+
*/
|
|
31
|
+
const DashDefaultResourceLayout: React.FC<IDashDefaultResourceLayout> = (props) => {
|
|
32
|
+
const { resourceConfig, ResourceMenu, children } = props;
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<div className='dash-app-module'>
|
|
36
|
+
<div className='dash-module-horizontal-box' style={{ maxWidth: '100%' }}>
|
|
37
|
+
<ResourceMenu resourceConfig={resourceConfig} />
|
|
38
|
+
<div className='dash-module-box-content'>{children}</div>
|
|
39
|
+
</div>
|
|
40
|
+
</div>
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
export default memo(
|
|
46
|
+
DashDefaultResourceLayout,
|
|
47
|
+
(props, nextProps) =>
|
|
48
|
+
props === nextProps,
|
|
49
|
+
);
|
|
50
|
+
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { DashAutoReferenceTab, DashAutoTabs } from '.';
|
|
2
|
+
import AutoTitle from './common/DashAutoTitle';
|
|
3
|
+
import IAutoShow from './interfaces/IDashAutoShow';
|
|
4
|
+
import AutoLayout from './DashAutoLayout';
|
|
5
|
+
import AutoGroup from './DashAutoGroup';
|
|
6
|
+
|
|
7
|
+
import { TopToolbar, Show } from 'react-admin';
|
|
8
|
+
//import { ShowBase } from 'react-admin';
|
|
9
|
+
import {
|
|
10
|
+
ToolbarCreateButton,
|
|
11
|
+
ToolbarDeleteButton,
|
|
12
|
+
ToolbarEditButton,
|
|
13
|
+
ToolbarExportButton,
|
|
14
|
+
ToolbarListButton,
|
|
15
|
+
} from './toolbar/buttons/ToolbarButtons';
|
|
16
|
+
import { ReactNode, useMemo } from 'react';
|
|
17
|
+
import React from 'react';
|
|
18
|
+
|
|
19
|
+
const DashAutoShow: React.FC<IAutoShow> = ({
|
|
20
|
+
resourceConfig,
|
|
21
|
+
id,
|
|
22
|
+
isDrawer = false,
|
|
23
|
+
locale,
|
|
24
|
+
...props
|
|
25
|
+
}) => {
|
|
26
|
+
|
|
27
|
+
// 🔧 Add contextComponent support for view/show mode (matching DashAutoTabbedForm pattern)
|
|
28
|
+
const ContextComponent = useMemo(() => {
|
|
29
|
+
return resourceConfig.contextComponent || (({children}: {children: ReactNode}) => <>{children}</>);
|
|
30
|
+
}, [resourceConfig.contextComponent]);
|
|
31
|
+
|
|
32
|
+
const topToolbarActions = () => {
|
|
33
|
+
|
|
34
|
+
const componentsList = (): any[] => {
|
|
35
|
+
const result: ReactNode[] = [];
|
|
36
|
+
if (!isDrawer) {
|
|
37
|
+
result.push(<ToolbarListButton resourceConfig={resourceConfig} />);
|
|
38
|
+
result.push(<ToolbarEditButton resourceConfig={resourceConfig} />);
|
|
39
|
+
result.push(<ToolbarCreateButton resourceConfig={resourceConfig} />);
|
|
40
|
+
result.push(<ToolbarDeleteButton resourceConfig={resourceConfig} />);
|
|
41
|
+
result.push(<ToolbarExportButton resourceConfig={resourceConfig} />);
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const components = componentsList();
|
|
47
|
+
|
|
48
|
+
return components;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const topToolbarActionsArray = topToolbarActions();
|
|
52
|
+
|
|
53
|
+
if (
|
|
54
|
+
resourceConfig.showComponent &&
|
|
55
|
+
typeof resourceConfig.showComponent === 'function'
|
|
56
|
+
) {
|
|
57
|
+
return (
|
|
58
|
+
<Show
|
|
59
|
+
component="div"
|
|
60
|
+
{...(id && { id })}
|
|
61
|
+
title={<AutoTitle resourceConfig={resourceConfig} />}
|
|
62
|
+
{...props}
|
|
63
|
+
{...topToolbarActionsArray.length && {
|
|
64
|
+
actions: (
|
|
65
|
+
<TopToolbar sx={{ mb: 2 }}>
|
|
66
|
+
{topToolbarActionsArray.map((component, idx) => {
|
|
67
|
+
return React.cloneElement(component, { key: idx });
|
|
68
|
+
},
|
|
69
|
+
)}
|
|
70
|
+
</TopToolbar>
|
|
71
|
+
),
|
|
72
|
+
}}
|
|
73
|
+
>
|
|
74
|
+
<ContextComponent mode="view" resourceConfig={resourceConfig}>
|
|
75
|
+
{resourceConfig.showComponent(resourceConfig)}
|
|
76
|
+
{resourceConfig.references &&
|
|
77
|
+
resourceConfig.references.map((reference) =>
|
|
78
|
+
DashAutoReferenceTab(reference),
|
|
79
|
+
)}
|
|
80
|
+
</ContextComponent>
|
|
81
|
+
</Show>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (resourceConfig.formGroupMode === 'tabs') {
|
|
86
|
+
return (
|
|
87
|
+
<Show
|
|
88
|
+
component="div"
|
|
89
|
+
{...(id && { id })}
|
|
90
|
+
title={<AutoTitle resourceConfig={resourceConfig} />}
|
|
91
|
+
{...props}
|
|
92
|
+
{...topToolbarActionsArray.length && {
|
|
93
|
+
actions: (
|
|
94
|
+
<TopToolbar sx={{ mb: 2 }}>
|
|
95
|
+
{topToolbarActionsArray.map((component, idx) => {
|
|
96
|
+
return React.cloneElement(component, { key: idx });
|
|
97
|
+
},
|
|
98
|
+
)}
|
|
99
|
+
</TopToolbar>
|
|
100
|
+
),
|
|
101
|
+
}}
|
|
102
|
+
>
|
|
103
|
+
<ContextComponent mode="view" resourceConfig={resourceConfig}>
|
|
104
|
+
{DashAutoTabs(resourceConfig, { mode: 'view', locale })}
|
|
105
|
+
{resourceConfig.references &&
|
|
106
|
+
resourceConfig.references.map((reference) =>
|
|
107
|
+
DashAutoReferenceTab(reference),
|
|
108
|
+
)}
|
|
109
|
+
</ContextComponent>
|
|
110
|
+
</Show>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (resourceConfig.formGroupMode === 'groups') {
|
|
115
|
+
return (
|
|
116
|
+
<Show
|
|
117
|
+
component="div"
|
|
118
|
+
{...(id && { id })}
|
|
119
|
+
title={<AutoTitle resourceConfig={resourceConfig} />}
|
|
120
|
+
{...props}
|
|
121
|
+
{...topToolbarActionsArray.length && {
|
|
122
|
+
actions: (
|
|
123
|
+
<TopToolbar sx={{ mb: 2 }}>
|
|
124
|
+
{topToolbarActionsArray.map((component, idx) => {
|
|
125
|
+
return React.cloneElement(component, { key: idx });
|
|
126
|
+
},
|
|
127
|
+
)}
|
|
128
|
+
</TopToolbar>
|
|
129
|
+
),
|
|
130
|
+
}}
|
|
131
|
+
>
|
|
132
|
+
<ContextComponent mode="view" resourceConfig={resourceConfig}>
|
|
133
|
+
{AutoGroup(resourceConfig, { mode: 'view', locale })}
|
|
134
|
+
{resourceConfig.references &&
|
|
135
|
+
resourceConfig.references.map((reference) =>
|
|
136
|
+
DashAutoReferenceTab(reference),
|
|
137
|
+
)}
|
|
138
|
+
</ContextComponent>
|
|
139
|
+
</Show>
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (resourceConfig.formGroupMode === 'layout') {
|
|
144
|
+
return (
|
|
145
|
+
<Show
|
|
146
|
+
component="div"
|
|
147
|
+
{...(id && { id })}
|
|
148
|
+
title={<AutoTitle resourceConfig={resourceConfig} />}
|
|
149
|
+
{...props}
|
|
150
|
+
{...topToolbarActionsArray.length && {
|
|
151
|
+
actions: (
|
|
152
|
+
<TopToolbar sx={{ mb: 2 }}>
|
|
153
|
+
{topToolbarActionsArray.map((component, idx) => {
|
|
154
|
+
return React.cloneElement(component, { key: idx });
|
|
155
|
+
},
|
|
156
|
+
)}
|
|
157
|
+
</TopToolbar>
|
|
158
|
+
),
|
|
159
|
+
}}
|
|
160
|
+
>
|
|
161
|
+
<ContextComponent mode="view" resourceConfig={resourceConfig}>
|
|
162
|
+
{AutoLayout(resourceConfig, { mode: 'view', locale })}
|
|
163
|
+
{resourceConfig.references &&
|
|
164
|
+
resourceConfig.references.map((reference) =>
|
|
165
|
+
DashAutoReferenceTab(reference),
|
|
166
|
+
)}
|
|
167
|
+
</ContextComponent>
|
|
168
|
+
</Show>
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return (
|
|
173
|
+
<Show
|
|
174
|
+
component="div"
|
|
175
|
+
{...(id && { id })}
|
|
176
|
+
title={<AutoTitle resourceConfig={resourceConfig} />}
|
|
177
|
+
{...props}
|
|
178
|
+
{...topToolbarActionsArray.length && {
|
|
179
|
+
actions: (
|
|
180
|
+
<TopToolbar sx={{ mb: 2 }}>
|
|
181
|
+
{topToolbarActionsArray.map((component, idx) => {
|
|
182
|
+
return React.cloneElement(component, { key: idx });
|
|
183
|
+
},
|
|
184
|
+
)}
|
|
185
|
+
</TopToolbar>
|
|
186
|
+
),
|
|
187
|
+
}}
|
|
188
|
+
>
|
|
189
|
+
<ContextComponent mode="view" resourceConfig={resourceConfig}>
|
|
190
|
+
{DashAutoTabs(resourceConfig, { mode: 'view', locale })}
|
|
191
|
+
{resourceConfig.references &&
|
|
192
|
+
resourceConfig.references.map((reference) =>
|
|
193
|
+
DashAutoReferenceTab(reference),
|
|
194
|
+
)}
|
|
195
|
+
</ContextComponent>
|
|
196
|
+
</Show>
|
|
197
|
+
);
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
export default DashAutoShow;
|