@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,116 @@
|
|
|
1
|
+
import { SaveButton } from 'react-admin';
|
|
2
|
+
import { SaveButtonProps } from 'react-admin/src';
|
|
3
|
+
import { useFormContext } from 'react-hook-form';
|
|
4
|
+
|
|
5
|
+
import IDashAutoAdminResourceConfig from './interfaces/IDashAutoAdminResourceConfig';
|
|
6
|
+
import { FC, useCallback, useState } from 'react'; // Add useState
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export interface IDashAutoAdminSaveButton extends SaveButtonProps {
|
|
10
|
+
resourceConfig: IDashAutoAdminResourceConfig;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const DashAutoAdminSaveButton: FC<IDashAutoAdminSaveButton> = (props) => {
|
|
14
|
+
const { resourceConfig, ...customProps } = props;
|
|
15
|
+
const { formState } = useFormContext();
|
|
16
|
+
|
|
17
|
+
const alwaysEnabled = resourceConfig?.saveButtonAlwaysEnabled === true ? true : false;
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
const handleClick = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
21
|
+
|
|
22
|
+
if (customProps?.onClick) {
|
|
23
|
+
customProps.onClick(e);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return (<>
|
|
29
|
+
|
|
30
|
+
<SaveButton
|
|
31
|
+
alwaysEnable={alwaysEnabled}
|
|
32
|
+
{...customProps}
|
|
33
|
+
onClick={handleClick}
|
|
34
|
+
disabled={formState.isSubmitting}
|
|
35
|
+
/></>
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export default DashAutoAdminSaveButton;
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
/*
|
|
43
|
+
|
|
44
|
+
import { SaveButton } from 'react-admin';
|
|
45
|
+
import { SaveButtonProps } from 'react-admin/src';
|
|
46
|
+
import { useFormContext } from 'react-hook-form';
|
|
47
|
+
|
|
48
|
+
import IDashAutoAdminResourceConfig from './interfaces/IDashAutoAdminResourceConfig';
|
|
49
|
+
import { FC, useState, useCallback } from 'react';
|
|
50
|
+
import { useDashAutoAdminForm } from './context/DashAutoAdminFormContext';
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
export interface IDashAutoAdminSaveButton extends SaveButtonProps {
|
|
54
|
+
resourceConfig: IDashAutoAdminResourceConfig;
|
|
55
|
+
//
|
|
56
|
+
//Custom onSave handler that will be called with validated form values.
|
|
57
|
+
//If not provided, will use the onSave from DashAutoAdminFormContext.
|
|
58
|
+
//This allows hooking into DashAutoAdminForm's onSave logic when using type="button"
|
|
59
|
+
//
|
|
60
|
+
onSave?: (values: any) => Promise<void> | void;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const DashAutoAdminSaveButton: FC<IDashAutoAdminSaveButton> = (props) => {
|
|
64
|
+
const { resourceConfig, onSave: propOnSave, ...customProps } = props;
|
|
65
|
+
const { handleSubmit, formState } = useFormContext();
|
|
66
|
+
const { onSave: contextOnSave } = useDashAutoAdminForm();
|
|
67
|
+
|
|
68
|
+
// Use prop onSave if provided, otherwise fall back to context onSave
|
|
69
|
+
const onSave = propOnSave || contextOnSave;
|
|
70
|
+
|
|
71
|
+
const alwaysEnabled = resourceConfig?.saveButtonAlwaysEnabled === true ? true : false;
|
|
72
|
+
const [buttonDisabled, setButtonDisabled] = useState(false);
|
|
73
|
+
|
|
74
|
+
//
|
|
75
|
+
//When using type="button", we need to manually trigger form validation
|
|
76
|
+
//and submission using react-hook-form's handleSubmit.
|
|
77
|
+
//This wraps the submission to control the button's disabled state.
|
|
78
|
+
//
|
|
79
|
+
const handleClick = useCallback(async (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
80
|
+
e.preventDefault();
|
|
81
|
+
|
|
82
|
+
if (customProps?.onClick) {
|
|
83
|
+
customProps.onClick(e);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
setButtonDisabled(true);
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
// Use handleSubmit to validate and get form values
|
|
90
|
+
// Then call the onSave from context (DashAutoAdminForm's save handler)
|
|
91
|
+
await handleSubmit(async (values) => {
|
|
92
|
+
if (onSave) {
|
|
93
|
+
await onSave(values);
|
|
94
|
+
}
|
|
95
|
+
})(e);
|
|
96
|
+
} catch (error) {
|
|
97
|
+
console.error('DashAutoAdminSaveButton submission error:', error);
|
|
98
|
+
} finally {
|
|
99
|
+
setButtonDisabled(false);
|
|
100
|
+
}
|
|
101
|
+
}, [handleSubmit, onSave, customProps]);
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<SaveButton
|
|
105
|
+
type="button"
|
|
106
|
+
alwaysEnable={alwaysEnabled}
|
|
107
|
+
{...customProps}
|
|
108
|
+
onClick={handleClick}
|
|
109
|
+
disabled={buttonDisabled || formState.isSubmitting}
|
|
110
|
+
/>
|
|
111
|
+
);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export default DashAutoAdminSaveButton;
|
|
115
|
+
|
|
116
|
+
*/
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import AutoTabbedForm from './DashAutoTabbedForm';
|
|
2
|
+
import IAutoForm from './interfaces/IDashAutoForm';
|
|
3
|
+
import React, { Fragment, ReactNode } from 'react';
|
|
4
|
+
import { Create, TopToolbar, ListButton, Toolbar } from 'react-admin';
|
|
5
|
+
import evalActionPermission from './utils/evalActionPermission';
|
|
6
|
+
import AutoTitle from './common/DashAutoTitle';
|
|
7
|
+
|
|
8
|
+
import DashAutoAdminSaveButton from './DashAutoAdminSaveButton';
|
|
9
|
+
import { Portal } from '@mui/material';
|
|
10
|
+
import IDashAutoAdminResourceConfig from './interfaces/IDashAutoAdminResourceConfig';
|
|
11
|
+
|
|
12
|
+
const DashAutoCreate: React.FC<IAutoForm> = ({
|
|
13
|
+
resourceConfig,
|
|
14
|
+
toolbar,
|
|
15
|
+
actions,
|
|
16
|
+
onSubmit,
|
|
17
|
+
onError,
|
|
18
|
+
beforeSubmit,
|
|
19
|
+
isDrawer /*, showActions, */,
|
|
20
|
+
locale,
|
|
21
|
+
}) => {
|
|
22
|
+
const CreateActions: React.FC = ({ ...props }) => {
|
|
23
|
+
const _showListwbutton: boolean =
|
|
24
|
+
resourceConfig.drawer === true
|
|
25
|
+
? false
|
|
26
|
+
: resourceConfig.toolbarListButton
|
|
27
|
+
? true
|
|
28
|
+
: false;
|
|
29
|
+
|
|
30
|
+
const hasToolbar:boolean = !!resourceConfig?.AutoEditTopToolbarElements || _showListwbutton;
|
|
31
|
+
|
|
32
|
+
if (!hasToolbar) return null;
|
|
33
|
+
return (
|
|
34
|
+
<TopToolbar sx={{ mb:2 }} {...props}>
|
|
35
|
+
{_showListwbutton && <ListButton />}
|
|
36
|
+
{resourceConfig?.AutoEditTopToolbarElements ? (
|
|
37
|
+
resourceConfig.AutoCreateTopToolbarElements(resourceConfig)
|
|
38
|
+
) : (
|
|
39
|
+
<></>
|
|
40
|
+
)}
|
|
41
|
+
</TopToolbar>
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const CreateToolbar: React.FC = ({ ...props }) => {
|
|
46
|
+
const SaveComponent =
|
|
47
|
+
resourceConfig.toolbarSaveButton &&
|
|
48
|
+
resourceConfig.toolbarSaveButton.component
|
|
49
|
+
? resourceConfig.toolbarSaveButton.component
|
|
50
|
+
: DashAutoAdminSaveButton;
|
|
51
|
+
|
|
52
|
+
return <Toolbar {...props}>
|
|
53
|
+
{evalActionPermission(
|
|
54
|
+
resourceConfig,
|
|
55
|
+
resourceConfig.toolbarSaveButton,
|
|
56
|
+
) && (
|
|
57
|
+
<SaveComponent
|
|
58
|
+
resourceConfig={resourceConfig}
|
|
59
|
+
onSubmit={onSubmit}
|
|
60
|
+
{...(resourceConfig.toolbarSaveButton &&
|
|
61
|
+
resourceConfig.toolbarSaveButton?.props)}
|
|
62
|
+
/>
|
|
63
|
+
)}
|
|
64
|
+
{resourceConfig?.AutoEditBottomToolbarElements ? (
|
|
65
|
+
resourceConfig.AutoCreateBottomToolbarElements(resourceConfig)
|
|
66
|
+
) : (
|
|
67
|
+
<></>
|
|
68
|
+
)}
|
|
69
|
+
</Toolbar>
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
/*return <Portal container={document.querySelector("div.dash-app-layout")}>
|
|
73
|
+
<Toolbar {...props}>
|
|
74
|
+
{evalActionPermission(
|
|
75
|
+
resourceConfig,
|
|
76
|
+
resourceConfig.toolbarSaveButton,
|
|
77
|
+
) && (
|
|
78
|
+
<SaveComponent
|
|
79
|
+
resourceConfig={resourceConfig}
|
|
80
|
+
onSubmit={onSubmit}
|
|
81
|
+
{...(resourceConfig.toolbarSaveButton &&
|
|
82
|
+
resourceConfig.toolbarSaveButton?.props)}
|
|
83
|
+
/>
|
|
84
|
+
)}
|
|
85
|
+
{resourceConfig?.AutoEditBottomToolbarElements ? (
|
|
86
|
+
resourceConfig.AutoCreateBottomToolbarElements(resourceConfig)
|
|
87
|
+
) : (
|
|
88
|
+
<></>
|
|
89
|
+
)}
|
|
90
|
+
</Toolbar>
|
|
91
|
+
</Portal>;*/
|
|
92
|
+
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<Create
|
|
98
|
+
component="div"
|
|
99
|
+
actions={actions || <CreateActions />}
|
|
100
|
+
mutationMode={resourceConfig.mutationMode}
|
|
101
|
+
title={<AutoTitle resourceConfig={resourceConfig} />}
|
|
102
|
+
>
|
|
103
|
+
|
|
104
|
+
<AutoTabbedForm
|
|
105
|
+
mode='create'
|
|
106
|
+
resourceConfig={resourceConfig}
|
|
107
|
+
toolbar={toolbar || <CreateToolbar />}
|
|
108
|
+
onSubmit={onSubmit}
|
|
109
|
+
onError={onError}
|
|
110
|
+
beforeSubmit={beforeSubmit}
|
|
111
|
+
isDrawer={isDrawer}
|
|
112
|
+
locale={locale}
|
|
113
|
+
/>
|
|
114
|
+
|
|
115
|
+
</Create>
|
|
116
|
+
);
|
|
117
|
+
};
|
|
118
|
+
export default DashAutoCreate;
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { PropsWithChildren, useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import AutoCreate from './DashAutoCreate';
|
|
3
|
+
import AutoEdit from './DashAutoEdit';
|
|
4
|
+
|
|
5
|
+
import { Toolbar, SaveButton, Button } from 'react-admin';
|
|
6
|
+
|
|
7
|
+
import IDashAutoAdminResourceConfig from './interfaces/IDashAutoAdminResourceConfig';
|
|
8
|
+
|
|
9
|
+
import { match } from 'node-match-path';
|
|
10
|
+
import { useLocation } from 'react-router';
|
|
11
|
+
import AutoShow from './DashAutoShow';
|
|
12
|
+
import React from 'react';
|
|
13
|
+
import { Drawer, SwipeableDrawer, DrawerProps } from '@mui/material';
|
|
14
|
+
import DashAutoAdminSaveButton from './DashAutoAdminSaveButton';
|
|
15
|
+
|
|
16
|
+
export interface IDashAutoDrawerPublicProps extends DrawerProps {
|
|
17
|
+
beforeSubmit?: (data: any) => any;
|
|
18
|
+
onSubmit?: (data: any) => any;
|
|
19
|
+
onError?: (error: any) => any;
|
|
20
|
+
type?: 'normal' | 'swipeable';
|
|
21
|
+
placement?: 'top' | 'bottom' | 'left' | 'right';
|
|
22
|
+
width?: number | string;
|
|
23
|
+
height?: number;
|
|
24
|
+
}
|
|
25
|
+
export interface IDashAutoDrawer extends IDashAutoDrawerPublicProps, PropsWithChildren {
|
|
26
|
+
recordId?: React.Key;
|
|
27
|
+
resourceConfig: IDashAutoAdminResourceConfig;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const DashAutoDrawer: React.FC<IDashAutoDrawer> = ({
|
|
31
|
+
resourceConfig,
|
|
32
|
+
recordId,
|
|
33
|
+
type = 'normal',
|
|
34
|
+
placement = 'right',
|
|
35
|
+
width = '100%', // TODO: This is the default value for the drawer width, to be deprecated; must be set at a HoC.
|
|
36
|
+
height,
|
|
37
|
+
beforeSubmit,
|
|
38
|
+
onSubmit,
|
|
39
|
+
onError,
|
|
40
|
+
children,
|
|
41
|
+
...props
|
|
42
|
+
}) => {
|
|
43
|
+
const location = useLocation();
|
|
44
|
+
|
|
45
|
+
const DrawerComponent = type === 'swipeable' ? SwipeableDrawer : Drawer;
|
|
46
|
+
|
|
47
|
+
const [open, setOpen] = useState<boolean>(
|
|
48
|
+
location.state?.hash ? true : false,
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const handleCloseDrawer = () => {
|
|
52
|
+
setOpen(false);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const handleOpenDrawer = () => {
|
|
56
|
+
setOpen(true);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const _onSubmit = (values: any) => {
|
|
60
|
+
if (resourceConfig.closeDrawerAfterSave) handleCloseDrawer();
|
|
61
|
+
if (onSubmit) onSubmit(values);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const [localHash, setLocalHash] = useState<string>(
|
|
65
|
+
location.state?.hash ? location.state.hash : window.location.hash,
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
//if(!localHash.includes("inline/")) return <></> // TODO unecessary ???
|
|
69
|
+
|
|
70
|
+
const hashChangeHandler = useCallback((e) => {
|
|
71
|
+
|
|
72
|
+
setLocalHash(e.data);
|
|
73
|
+
setOpen(true);
|
|
74
|
+
}, []);
|
|
75
|
+
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
//let _match = localHash.includes("inline/");
|
|
78
|
+
//if(_match.matches)
|
|
79
|
+
window.addEventListener('virtualhash', hashChangeHandler);
|
|
80
|
+
return () => {
|
|
81
|
+
|
|
82
|
+
//if(_match.matches)
|
|
83
|
+
window.removeEventListener('virtualhash', hashChangeHandler);
|
|
84
|
+
};
|
|
85
|
+
}, []);
|
|
86
|
+
|
|
87
|
+
let mode = 'edit';
|
|
88
|
+
const _createMatch = match(
|
|
89
|
+
`/${resourceConfig.model}/inline/create`,
|
|
90
|
+
String(localHash).substring(1),
|
|
91
|
+
);
|
|
92
|
+
if (_createMatch.matches) {
|
|
93
|
+
mode = 'create';
|
|
94
|
+
}
|
|
95
|
+
const _editMatch = match(
|
|
96
|
+
`/${resourceConfig.model}/inline/:id/:mode`,
|
|
97
|
+
String(localHash).substring(1),
|
|
98
|
+
);
|
|
99
|
+
mode =
|
|
100
|
+
_editMatch.matches && _editMatch.params?.mode
|
|
101
|
+
? _editMatch.params.mode
|
|
102
|
+
: mode;
|
|
103
|
+
const resource_id = ['edit', 'show'].includes(mode)
|
|
104
|
+
? _editMatch.params?.id
|
|
105
|
+
: null;
|
|
106
|
+
|
|
107
|
+
//const [placement, setPlacement] = useState<DrawerProps['anchor']>('right');
|
|
108
|
+
//const [open, setOpen] = useState<boolean>(location.state?.hash ? true : false);
|
|
109
|
+
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
if (location.state?.hash) {
|
|
112
|
+
history.replaceState(null, '', location.state.hash);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return () => {
|
|
116
|
+
history.replaceState(null, '', null);
|
|
117
|
+
};
|
|
118
|
+
}, []);
|
|
119
|
+
|
|
120
|
+
/*
|
|
121
|
+
useEffect(() => {
|
|
122
|
+
setOpen(mode === "edit" || mode === "create" ? true : false)
|
|
123
|
+
console.log("has updated in autolist, hash,mode,open",hash,mode,open)
|
|
124
|
+
}, [hash]);*/
|
|
125
|
+
|
|
126
|
+
const DrawerToolbar = () => {
|
|
127
|
+
if (resourceConfig?.bottomToolbar === false) return <></>;
|
|
128
|
+
return (
|
|
129
|
+
<Toolbar>
|
|
130
|
+
{mode === 'edit' && resourceConfig?.saveButton !== false && (
|
|
131
|
+
<DashAutoAdminSaveButton
|
|
132
|
+
alwaysEnable={
|
|
133
|
+
resourceConfig?.saveButtonAlwaysEnabled === true ? true : false
|
|
134
|
+
}
|
|
135
|
+
label='Guardar'
|
|
136
|
+
resourceConfig={resourceConfig}
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
/>
|
|
140
|
+
)}
|
|
141
|
+
{mode === 'create' && resourceConfig?.saveButton !== false && (
|
|
142
|
+
<DashAutoAdminSaveButton
|
|
143
|
+
resourceConfig={resourceConfig}
|
|
144
|
+
alwaysEnable={
|
|
145
|
+
resourceConfig?.saveButtonAlwaysEnabled === true ? true : false
|
|
146
|
+
}
|
|
147
|
+
label='Crear'
|
|
148
|
+
|
|
149
|
+
/>
|
|
150
|
+
)}
|
|
151
|
+
{/*resourceConfig?.listDeleteButton?.enabled && (
|
|
152
|
+
<DeleteButton label="Eliminar" />
|
|
153
|
+
)*/}
|
|
154
|
+
<Button onClick={() => handleCloseDrawer()}>
|
|
155
|
+
<>Cerrar</>
|
|
156
|
+
</Button>
|
|
157
|
+
</Toolbar>
|
|
158
|
+
);
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
if (mode !== 'list' && mode === 'create')
|
|
162
|
+
return (
|
|
163
|
+
<DrawerComponent
|
|
164
|
+
anchor={placement}
|
|
165
|
+
//onClose={(_event: React.ChangeEvent<HTMLInputElement>) => { handleCloseDrawer(); }}
|
|
166
|
+
/* @ts-ignore : Mismatch with the DrawerProps Event */
|
|
167
|
+
onClose={() => handleCloseDrawer()}
|
|
168
|
+
{...(type === 'swipeable' && { onOpen: handleOpenDrawer })}
|
|
169
|
+
open={open}
|
|
170
|
+
key={placement}
|
|
171
|
+
sx={{
|
|
172
|
+
width: { xs: "90%", sm: "90%", md: "50%", lg: "40%" },
|
|
173
|
+
'& .MuiDrawer-paper': {
|
|
174
|
+
width: { xs: "90%", sm: "90%", md: "50%", lg: "40%" }
|
|
175
|
+
}
|
|
176
|
+
}}
|
|
177
|
+
slotProps={{
|
|
178
|
+
|
|
179
|
+
}}
|
|
180
|
+
size={"large"}
|
|
181
|
+
{...props}
|
|
182
|
+
>
|
|
183
|
+
<div
|
|
184
|
+
style={{
|
|
185
|
+
...(height && { height: height }),
|
|
186
|
+
...(width && { width: width }),
|
|
187
|
+
}}
|
|
188
|
+
>
|
|
189
|
+
<AutoCreate
|
|
190
|
+
toolbar={<DrawerToolbar />}
|
|
191
|
+
isDrawer={true}
|
|
192
|
+
//id={Number(edit_mode.params.id)}
|
|
193
|
+
resourceConfig={{ ...resourceConfig, formGroupMode: (resourceConfig.formGroupMode === 'tabs' || !resourceConfig.formGroupMode ? 'groups' : resourceConfig.formGroupMode) }}
|
|
194
|
+
//schema={resourceConfig.schema}
|
|
195
|
+
beforeSubmit={beforeSubmit}
|
|
196
|
+
onSubmit={_onSubmit}
|
|
197
|
+
onError={onError}
|
|
198
|
+
onCancel={() => handleCloseDrawer()}
|
|
199
|
+
/>
|
|
200
|
+
</div>
|
|
201
|
+
</DrawerComponent>
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
if (mode !== 'list' && mode === 'edit' && resource_id)
|
|
205
|
+
return (
|
|
206
|
+
<DrawerComponent
|
|
207
|
+
anchor={placement}
|
|
208
|
+
/* @ts-ignore : Mismatch with the DrawerProps Event */
|
|
209
|
+
onClose={() => handleCloseDrawer()}
|
|
210
|
+
{...(type === 'swipeable' && { onOpen: handleOpenDrawer })}
|
|
211
|
+
open={open}
|
|
212
|
+
key={placement}
|
|
213
|
+
sx={{
|
|
214
|
+
width: { xs: "90%", sm: "90%", md: "50%", lg: "40%" },
|
|
215
|
+
'& .MuiDrawer-paper': {
|
|
216
|
+
width: { xs: "90%", sm: "90%", md: "50%", lg: "40%" }
|
|
217
|
+
}
|
|
218
|
+
}}
|
|
219
|
+
slotProps={{
|
|
220
|
+
|
|
221
|
+
}}
|
|
222
|
+
size={"large"}
|
|
223
|
+
{...props}
|
|
224
|
+
|
|
225
|
+
>
|
|
226
|
+
<div
|
|
227
|
+
style={{
|
|
228
|
+
...(height && { height: height }),
|
|
229
|
+
...(width && { width: width }),
|
|
230
|
+
}}
|
|
231
|
+
>
|
|
232
|
+
<AutoEdit
|
|
233
|
+
isDrawer={true}
|
|
234
|
+
toolbar={<DrawerToolbar />}
|
|
235
|
+
id={resource_id}
|
|
236
|
+
resourceConfig={{ ...resourceConfig, formGroupMode: (resourceConfig.formGroupMode === 'tabs' || !resourceConfig.formGroupMode ? 'groups' : resourceConfig.formGroupMode) }}
|
|
237
|
+
//schema={resourceConfig.schema}
|
|
238
|
+
beforeSubmit={beforeSubmit}
|
|
239
|
+
onSubmit={_onSubmit}
|
|
240
|
+
onError={onError}
|
|
241
|
+
onCancel={() => handleCloseDrawer()}
|
|
242
|
+
/>
|
|
243
|
+
</div>
|
|
244
|
+
</DrawerComponent>
|
|
245
|
+
);
|
|
246
|
+
|
|
247
|
+
if (mode === 'show' && resource_id) {
|
|
248
|
+
return (
|
|
249
|
+
<DrawerComponent
|
|
250
|
+
anchor={placement}
|
|
251
|
+
/* @ts-ignore : Mismatch with the DrawerProps Event */
|
|
252
|
+
onClose={() => handleCloseDrawer()}
|
|
253
|
+
{...(type === 'swipeable' && { onOpen: handleOpenDrawer })}
|
|
254
|
+
open={open}
|
|
255
|
+
key={placement}
|
|
256
|
+
sx={{
|
|
257
|
+
width: { xs: "90%", sm: "90%", md: "50%", lg: "40%" },
|
|
258
|
+
'& .MuiDrawer-paper': {
|
|
259
|
+
width: { xs: "90%", sm: "90%", md: "50%", lg: "40%" }
|
|
260
|
+
}
|
|
261
|
+
}}
|
|
262
|
+
slotProps={{
|
|
263
|
+
|
|
264
|
+
}}
|
|
265
|
+
size={"large"}
|
|
266
|
+
{...props}
|
|
267
|
+
|
|
268
|
+
>
|
|
269
|
+
<div
|
|
270
|
+
style={{
|
|
271
|
+
...(height && { height: height }),
|
|
272
|
+
...(width && { width: width }),
|
|
273
|
+
}}
|
|
274
|
+
>
|
|
275
|
+
<AutoShow
|
|
276
|
+
isDrawer={true}
|
|
277
|
+
id={resource_id}
|
|
278
|
+
resourceConfig={{ ...resourceConfig, formGroupMode: (resourceConfig.formGroupMode === 'tabs' || !resourceConfig.formGroupMode ? 'groups' : resourceConfig.formGroupMode) }}
|
|
279
|
+
/>
|
|
280
|
+
</div>
|
|
281
|
+
</DrawerComponent>
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return <></>;
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
export default DashAutoDrawer;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import AutoTitle from './common/DashAutoTitle';
|
|
2
|
+
import IAutoForm from './interfaces/IDashAutoForm';
|
|
3
|
+
import AutoTabbedForm from './DashAutoTabbedForm';
|
|
4
|
+
import { TopToolbar, Edit, Toolbar } from 'react-admin';
|
|
5
|
+
import React, { ReactNode } from 'react';
|
|
6
|
+
import { ToolbarCreateButton, ToolbarDeleteButton, ToolbarEditButton, ToolbarExportButton, ToolbarListButton, ToolbarSaveButton } from './toolbar/buttons/ToolbarButtons';
|
|
7
|
+
import { BottomToolbarDeleteButton, BottomToolbarSaveButton } from './toolbar/buttons/BottomToolbarButtons';
|
|
8
|
+
import { Portal } from '@mui/material';
|
|
9
|
+
import IDashAutoAdminResourceConfig from './interfaces/IDashAutoAdminResourceConfig';
|
|
10
|
+
|
|
11
|
+
const DashAutoEdit: React.FC<IAutoForm> = ({
|
|
12
|
+
id,
|
|
13
|
+
resourceConfig,
|
|
14
|
+
onSubmit,
|
|
15
|
+
onError,
|
|
16
|
+
onCancel,
|
|
17
|
+
beforeSubmit,
|
|
18
|
+
toolbar,
|
|
19
|
+
actions,
|
|
20
|
+
isDrawer = false,
|
|
21
|
+
locale,
|
|
22
|
+
}) => {
|
|
23
|
+
const EditActions: React.FC = ({ ...props }) => {
|
|
24
|
+
|
|
25
|
+
const _isDrawer = !!resourceConfig.drawer;
|
|
26
|
+
// Top Toolbar
|
|
27
|
+
return <TopToolbar sx={{ mb:2 }} {...props}>
|
|
28
|
+
{resourceConfig?.AutoEditTopToolbarElements ? (
|
|
29
|
+
resourceConfig.AutoEditTopToolbarElements(resourceConfig)
|
|
30
|
+
) : null}
|
|
31
|
+
|
|
32
|
+
{/* Save button can't be here */}
|
|
33
|
+
{!_isDrawer && <ToolbarListButton mode='edit' resourceConfig={resourceConfig}/>}
|
|
34
|
+
{!_isDrawer && <ToolbarEditButton mode='edit' resourceConfig={resourceConfig}/>}
|
|
35
|
+
{!_isDrawer && <ToolbarCreateButton mode='edit' resourceConfig={resourceConfig}/>}
|
|
36
|
+
{!_isDrawer && <ToolbarDeleteButton mode='edit' resourceConfig={resourceConfig}/>}
|
|
37
|
+
{!_isDrawer && <ToolbarExportButton mode='edit' resourceConfig={resourceConfig}/>}
|
|
38
|
+
</TopToolbar>;
|
|
39
|
+
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// Bottom Toolbar
|
|
43
|
+
const EditToolbar: React.FC = ({ ...props }) => {
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<Toolbar {...props}>
|
|
47
|
+
{/*evalActionPermission(
|
|
48
|
+
resourceConfig,
|
|
49
|
+
resourceConfig.toolbarSaveButton,
|
|
50
|
+
) && (
|
|
51
|
+
<SaveComponent
|
|
52
|
+
resourceConfig={resourceConfig}
|
|
53
|
+
{...(onSubmit && { onSubmit: onSubmit })}
|
|
54
|
+
{...(resourceConfig.toolbarSaveButton &&
|
|
55
|
+
resourceConfig.toolbarSaveButton?.props)}
|
|
56
|
+
/>
|
|
57
|
+
)*/}
|
|
58
|
+
|
|
59
|
+
<BottomToolbarSaveButton mode='edit' resourceConfig={resourceConfig} onError={onError} onSubmit={onSubmit} />
|
|
60
|
+
<BottomToolbarDeleteButton mode='edit' resourceConfig={resourceConfig} onError={onError} onSubmit={onSubmit} />
|
|
61
|
+
{/*evalActionPermission(
|
|
62
|
+
resourceConfig,
|
|
63
|
+
resourceConfig.toolbarDeleteButton,
|
|
64
|
+
) && (
|
|
65
|
+
<DeleteComponent
|
|
66
|
+
resourceConfig={resourceConfig}
|
|
67
|
+
{...(resourceConfig.toolbarDeleteButton &&
|
|
68
|
+
resourceConfig.toolbarDeleteButton?.props)}
|
|
69
|
+
/>
|
|
70
|
+
)*/}
|
|
71
|
+
{resourceConfig?.AutoEditBottomToolbarElements ? (
|
|
72
|
+
resourceConfig.AutoEditBottomToolbarElements(resourceConfig)
|
|
73
|
+
) : (
|
|
74
|
+
<></>
|
|
75
|
+
)}
|
|
76
|
+
|
|
77
|
+
</Toolbar>
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
return <Edit
|
|
84
|
+
component="div"
|
|
85
|
+
{...(id && { id })}
|
|
86
|
+
actions={actions || <EditActions />}
|
|
87
|
+
mutationMode={resourceConfig.mutationMode}
|
|
88
|
+
title={<AutoTitle resourceConfig={resourceConfig} />}
|
|
89
|
+
{...resourceConfig?.editProps || {}}
|
|
90
|
+
>
|
|
91
|
+
|
|
92
|
+
<AutoTabbedForm
|
|
93
|
+
isDrawer={isDrawer}
|
|
94
|
+
mode='edit'
|
|
95
|
+
resourceConfig={resourceConfig}
|
|
96
|
+
//{...(_showToolbar && { toolbar: <EditToolbar /> })}
|
|
97
|
+
toolbar={toolbar || <EditToolbar />}
|
|
98
|
+
onSubmit={onSubmit}
|
|
99
|
+
onError={onError}
|
|
100
|
+
{...(beforeSubmit && { beforeSubmit: beforeSubmit })}
|
|
101
|
+
onCancel={onCancel}
|
|
102
|
+
locale={locale}
|
|
103
|
+
/>
|
|
104
|
+
|
|
105
|
+
</Edit>
|
|
106
|
+
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export default DashAutoEdit;
|