@dashadmin/dash-auto-admin 1.3.25 → 1.3.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -6
- 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 +134 -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
package/package.json
CHANGED
|
@@ -1,121 +1,135 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
2
|
+
"name": "@dashadmin/dash-auto-admin",
|
|
3
|
+
"version": "1.3.28",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"lint": "eslint --ext .ts,.tsx .",
|
|
8
|
+
"format": "pnpm prettier --write . && pnpm format-check && pnpm lint",
|
|
9
|
+
"lint:check": "pnpm prettier --check .",
|
|
10
|
+
"lint:fix": "pnpm prettier --write .",
|
|
11
|
+
"check-updates": "pnpm npm-check-updates",
|
|
12
|
+
"updates-packages": "pnpm npm-check-updates -u",
|
|
13
|
+
"build": "tsup"
|
|
14
|
+
},
|
|
15
|
+
"browserslist": {
|
|
16
|
+
"production": [
|
|
17
|
+
">0.2%",
|
|
18
|
+
"not dead",
|
|
19
|
+
"not op_mini all"
|
|
20
|
+
],
|
|
21
|
+
"development": [
|
|
22
|
+
"last 1 chrome version",
|
|
23
|
+
"last 1 firefox version",
|
|
24
|
+
"last 1 safari version"
|
|
25
|
+
]
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@emotion/styled": "latest",
|
|
29
|
+
"@mui/icons-material": "^7.3.10",
|
|
30
|
+
"@mui/material": "^7.3.10",
|
|
31
|
+
"@rollup/plugin-alias": "latest",
|
|
32
|
+
"@rollup/plugin-commonjs": "latest",
|
|
33
|
+
"@rollup/plugin-node-resolve": "latest",
|
|
34
|
+
"@rollup/plugin-replace": "latest",
|
|
35
|
+
"@rollup/plugin-typescript": "latest",
|
|
36
|
+
"axios": "latest",
|
|
37
|
+
"node-match-path": "latest",
|
|
38
|
+
"prop-types": "latest",
|
|
39
|
+
"react": "latest",
|
|
40
|
+
"react-admin": "5.14.6",
|
|
41
|
+
"react-hook-form": "^7.54.0",
|
|
42
|
+
"react-redux": "latest",
|
|
43
|
+
"react-router": "^7.10.0",
|
|
44
|
+
"react-toastify": "latest",
|
|
45
|
+
"rollup-plugin-cleaner": "latest",
|
|
46
|
+
"rollup-plugin-dts": "latest",
|
|
47
|
+
"rollup-plugin-peer-deps-external": "latest",
|
|
48
|
+
"rollup-plugin-svg": "latest",
|
|
49
|
+
"@dashadmin/dash-constants": "workspace:*",
|
|
50
|
+
"@dashadmin/dash-dialog": "workspace:*"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@babel/core": "latest",
|
|
54
|
+
"@babel/preset-env": "latest",
|
|
55
|
+
"@babel/preset-react": "latest",
|
|
56
|
+
"@babel/preset-typescript": "latest",
|
|
57
|
+
"@commitlint/config-conventional": "latest",
|
|
58
|
+
"@types/node": "latest",
|
|
59
|
+
"@types/react": "latest",
|
|
60
|
+
"@types/react-dom": "latest",
|
|
61
|
+
"@zerollup/ts-transform-paths": "latest",
|
|
62
|
+
"babel-loader": "latest",
|
|
63
|
+
"@dashadmin/dash-tsconfig": "workspace:*",
|
|
64
|
+
"eslint": "latest",
|
|
65
|
+
"eslint-config-airbnb": "latest",
|
|
66
|
+
"eslint-config-airbnb-typescript": "latest",
|
|
67
|
+
"@dashadmin/dash-eslint": "workspace:*",
|
|
68
|
+
"eslint-config-prettier": "latest",
|
|
69
|
+
"eslint-import-resolver-typescript": "latest",
|
|
70
|
+
"eslint-plugin-html": "latest",
|
|
71
|
+
"eslint-plugin-import": "latest",
|
|
72
|
+
"eslint-plugin-jsdoc": "latest",
|
|
73
|
+
"eslint-plugin-json": "latest",
|
|
74
|
+
"eslint-plugin-jsx-a11y": "latest",
|
|
75
|
+
"eslint-plugin-prettier": "latest",
|
|
76
|
+
"eslint-plugin-react": "latest",
|
|
77
|
+
"eslint-plugin-react-hooks": "latest",
|
|
78
|
+
"@dashadmin/dash-prettier": "workspace:*",
|
|
79
|
+
"react-dom": "latest",
|
|
80
|
+
"rollup": "latest",
|
|
81
|
+
"rollup-plugin-copy-assets": "latest",
|
|
82
|
+
"rollup-plugin-external-globals": "latest",
|
|
83
|
+
"rollup-plugin-includepaths": "latest",
|
|
84
|
+
"rollup-plugin-less": "latest",
|
|
85
|
+
"rollup-plugin-node-resolve": "latest",
|
|
86
|
+
"rollup-plugin-postcss": "latest",
|
|
87
|
+
"rollup-plugin-sourcemaps": "latest",
|
|
88
|
+
"rollup-plugin-typescript2": "latest",
|
|
89
|
+
"tsc": "latest",
|
|
90
|
+
"tsc-alias": "latest",
|
|
91
|
+
"ttypescript": "latest",
|
|
92
|
+
"typescript": "latest"
|
|
93
|
+
},
|
|
94
|
+
"peerDependencies": {
|
|
95
|
+
"react-custom-scrollbars-2": "^4.5.0",
|
|
96
|
+
"react-dom": "latest"
|
|
97
|
+
},
|
|
98
|
+
"eslintConfig": {
|
|
99
|
+
"extends": "react-app"
|
|
100
|
+
},
|
|
101
|
+
"todo_storybook": {
|
|
102
|
+
"eslint-plugin-storybook": "latest"
|
|
103
|
+
},
|
|
104
|
+
"module": "dist/index.js",
|
|
105
|
+
"types": "./src/index.ts",
|
|
106
|
+
"exports": {
|
|
107
|
+
".": "./dist/index.js",
|
|
108
|
+
"./providers": "./dist/providers/index.js",
|
|
109
|
+
"./src/providers": "./dist/providers/index.js",
|
|
110
|
+
"./wrappers": "./dist/wrappers/index.js",
|
|
111
|
+
"./src/wrappers": "./dist/wrappers/index.js",
|
|
112
|
+
"./*": "./dist/*.js",
|
|
113
|
+
"./src/*": "./dist/*.js"
|
|
114
|
+
},
|
|
115
|
+
"publishConfig": {
|
|
116
|
+
"access": "public",
|
|
117
|
+
"registry": "https://registry.npmjs.org"
|
|
118
|
+
},
|
|
119
|
+
"files": [
|
|
120
|
+
"dist",
|
|
121
|
+
"src"
|
|
122
|
+
],
|
|
123
|
+
"typesVersions": {
|
|
124
|
+
"*": {
|
|
125
|
+
"src/*": [
|
|
126
|
+
"src/*",
|
|
127
|
+
"src/*/index"
|
|
128
|
+
],
|
|
129
|
+
"*": [
|
|
130
|
+
"src/*",
|
|
131
|
+
"src/*/index"
|
|
132
|
+
]
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import React, { createContext, useContext, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import IDashAutoAdminCustomFieldComponent from './interfaces/IDashAutoAdminCustomFieldComponent';
|
|
5
|
+
|
|
6
|
+
// Default components that are always available
|
|
7
|
+
const defaultComponentMap: Record<string, React.FC<IDashAutoAdminCustomFieldComponent>> = {
|
|
8
|
+
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export interface ComponentRegistryContextType {
|
|
12
|
+
components: Record<string, React.FC<IDashAutoAdminCustomFieldComponent>>;
|
|
13
|
+
registerComponent: (type: string, component: React.FC<IDashAutoAdminCustomFieldComponent>) => void;
|
|
14
|
+
registerComponents: (componentMap: Record<string, React.FC<IDashAutoAdminCustomFieldComponent>>) => void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const ComponentRegistryContext = createContext<ComponentRegistryContextType>({
|
|
18
|
+
components: defaultComponentMap,
|
|
19
|
+
registerComponent: () => {},
|
|
20
|
+
registerComponents: () => {},
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export const useComponentRegistry = () => useContext(ComponentRegistryContext);
|
|
24
|
+
|
|
25
|
+
export interface ComponentRegistryProviderProps {
|
|
26
|
+
children: ReactNode;
|
|
27
|
+
customComponents?: Record<string, React.FC<IDashAutoAdminCustomFieldComponent>>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const ComponentRegistryProvider: React.FC<ComponentRegistryProviderProps> = ({
|
|
31
|
+
children,
|
|
32
|
+
customComponents = {}
|
|
33
|
+
}) => {
|
|
34
|
+
const [components, setComponents] = React.useState<Record<string, React.FC<IDashAutoAdminCustomFieldComponent>>>({
|
|
35
|
+
...defaultComponentMap,
|
|
36
|
+
...customComponents,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Sync internal state when customComponents prop changes
|
|
40
|
+
// (e.g. after async component loading completes on remount)
|
|
41
|
+
React.useEffect(() => {
|
|
42
|
+
if (customComponents && Object.keys(customComponents).length > 0) {
|
|
43
|
+
setComponents(prev => ({
|
|
44
|
+
...prev,
|
|
45
|
+
...customComponents,
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
}, [customComponents]);
|
|
49
|
+
|
|
50
|
+
const registerComponent = React.useCallback((type: string, component: React.FC<IDashAutoAdminCustomFieldComponent>) => {
|
|
51
|
+
setComponents(prev => ({
|
|
52
|
+
...prev,
|
|
53
|
+
[type]: component
|
|
54
|
+
}));
|
|
55
|
+
}, []);
|
|
56
|
+
|
|
57
|
+
const registerComponents = React.useCallback((componentMap: Record<string, React.FC<IDashAutoAdminCustomFieldComponent>>) => {
|
|
58
|
+
setComponents(prev => ({
|
|
59
|
+
...prev,
|
|
60
|
+
...componentMap
|
|
61
|
+
}));
|
|
62
|
+
}, []);
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<ComponentRegistryContext.Provider
|
|
66
|
+
value={{
|
|
67
|
+
components,
|
|
68
|
+
registerComponent,
|
|
69
|
+
registerComponents
|
|
70
|
+
}}
|
|
71
|
+
>
|
|
72
|
+
{children}
|
|
73
|
+
</ComponentRegistryContext.Provider>
|
|
74
|
+
);
|
|
75
|
+
};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { Box } from '@mui/material';
|
|
2
|
+
import { JSX } from 'react';
|
|
3
|
+
import {
|
|
4
|
+
useResourceContext,
|
|
5
|
+
useRecordContext,
|
|
6
|
+
Toolbar,
|
|
7
|
+
SimpleForm,
|
|
8
|
+
} from 'react-admin';
|
|
9
|
+
|
|
10
|
+
import IDashAutoAdminResourceConfig from './interfaces/IDashAutoAdminResourceConfig';
|
|
11
|
+
|
|
12
|
+
import React from 'react';
|
|
13
|
+
import validate from './utils/validate';
|
|
14
|
+
import { ToolbarCreateButton, ToolbarDeleteButton, ToolbarSaveButton } from './toolbar/buttons/ToolbarButtons';
|
|
15
|
+
import { useDataProvider } from 'react-admin';
|
|
16
|
+
import { DashAutoAdminFormProvider } from './context/DashAutoAdminFormContext';
|
|
17
|
+
|
|
18
|
+
export interface IDashAutoAdminForm {
|
|
19
|
+
resourceConfig: IDashAutoAdminResourceConfig;
|
|
20
|
+
//schema: IDashAutoAdminAttribute[];
|
|
21
|
+
toolbar?: React.ReactElement<any>;
|
|
22
|
+
onSubmit?: (values: any) => any;
|
|
23
|
+
onError?: (error: any) => any;
|
|
24
|
+
onCancel?: (error: any) => any;
|
|
25
|
+
beforeSubmit?: (values: any) => any;
|
|
26
|
+
mode: 'create' | 'edit';
|
|
27
|
+
children?: JSX.Element;
|
|
28
|
+
isDrawer?: boolean;
|
|
29
|
+
locale?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//only to consume externally:
|
|
33
|
+
const DashAutoAdminForm: React.FC<IDashAutoAdminForm> = ({
|
|
34
|
+
resourceConfig,
|
|
35
|
+
onSubmit,
|
|
36
|
+
beforeSubmit,
|
|
37
|
+
onError,
|
|
38
|
+
//onCancel,
|
|
39
|
+
toolbar,
|
|
40
|
+
mode,
|
|
41
|
+
children,
|
|
42
|
+
}) => {
|
|
43
|
+
const resource = useResourceContext();
|
|
44
|
+
const record = useRecordContext();
|
|
45
|
+
const dataProvider = useDataProvider();
|
|
46
|
+
const debug = false;
|
|
47
|
+
|
|
48
|
+
const onCreateSave =
|
|
49
|
+
async (values) => {
|
|
50
|
+
if (debug) console.log('onCreateSave called with values:', values);
|
|
51
|
+
window.dispatchEvent(
|
|
52
|
+
new MessageEvent('dash-global-loader', { data: true }),
|
|
53
|
+
);
|
|
54
|
+
try {
|
|
55
|
+
if (beforeSubmit) {
|
|
56
|
+
if (debug) console.log('beforeSubmit called with values:', values);
|
|
57
|
+
values = beforeSubmit(values);
|
|
58
|
+
if (debug) console.log('beforeSubmit returned values:', values);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const { data } = await dataProvider.create(resource, {
|
|
62
|
+
data: values
|
|
63
|
+
});
|
|
64
|
+
if (debug) console.log('dataProvider.create returned data:', data);
|
|
65
|
+
|
|
66
|
+
if (onSubmit) {
|
|
67
|
+
if (debug) console.log('onSubmit called with data:', data);
|
|
68
|
+
onSubmit(data);
|
|
69
|
+
}
|
|
70
|
+
} catch (error) {
|
|
71
|
+
if (onError) {
|
|
72
|
+
if (debug) console.log('onError called with error:', error);
|
|
73
|
+
onError(error);
|
|
74
|
+
}
|
|
75
|
+
} finally {
|
|
76
|
+
window.dispatchEvent(
|
|
77
|
+
new MessageEvent('dash-global-loader', { data: false }),
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const onUpdateSave =
|
|
83
|
+
async (values) => {
|
|
84
|
+
if (debug) console.log('onUpdateSave called with values:', values);
|
|
85
|
+
window.dispatchEvent(
|
|
86
|
+
new MessageEvent('dash-global-loader', { data: true }),
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
if (beforeSubmit) {
|
|
91
|
+
if (debug) console.log('beforeSubmit called with values:', values);
|
|
92
|
+
values = beforeSubmit(values);
|
|
93
|
+
if (debug) console.log('beforeSubmit returned values:', values);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const { data } = await dataProvider.update(resource, {
|
|
97
|
+
id: record?.id,
|
|
98
|
+
data: values,
|
|
99
|
+
previousData: record
|
|
100
|
+
});
|
|
101
|
+
if (debug) console.log('dataProvider.update returned data:', data);
|
|
102
|
+
|
|
103
|
+
if (onSubmit) {
|
|
104
|
+
if (debug) console.log('onSubmit called with data:', data);
|
|
105
|
+
onSubmit(data);
|
|
106
|
+
}
|
|
107
|
+
} catch (error) {
|
|
108
|
+
if (onError) {
|
|
109
|
+
if (debug) console.log('onError called with error:', error);
|
|
110
|
+
onError(error);
|
|
111
|
+
}
|
|
112
|
+
} finally {
|
|
113
|
+
window.dispatchEvent(
|
|
114
|
+
new MessageEvent('dash-global-loader', { data: false }),
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
let onSave = onCreateSave;
|
|
120
|
+
|
|
121
|
+
switch (mode) {
|
|
122
|
+
case 'edit':
|
|
123
|
+
onSave = onUpdateSave;
|
|
124
|
+
break;
|
|
125
|
+
case 'create':
|
|
126
|
+
|
|
127
|
+
onSave = onCreateSave;
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const defaultToolbar = () => (
|
|
132
|
+
<Toolbar>
|
|
133
|
+
{mode === 'edit' && <ToolbarSaveButton resourceConfig={resourceConfig} />}
|
|
134
|
+
{mode === 'create' && <ToolbarCreateButton resourceConfig={resourceConfig} />}
|
|
135
|
+
<ToolbarDeleteButton resourceConfig={resourceConfig} />
|
|
136
|
+
</Toolbar>
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
return (
|
|
140
|
+
<DashAutoAdminFormProvider value={{ onSave, mode }}>
|
|
141
|
+
<Box>
|
|
142
|
+
<SimpleForm
|
|
143
|
+
toolbar={toolbar || defaultToolbar()}
|
|
144
|
+
onSubmit={onSave}
|
|
145
|
+
validate={validate(resourceConfig.schema)}
|
|
146
|
+
reValidateMode="onBlur"
|
|
147
|
+
>
|
|
148
|
+
{children}
|
|
149
|
+
</SimpleForm>
|
|
150
|
+
</Box>
|
|
151
|
+
</DashAutoAdminFormProvider>
|
|
152
|
+
);
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export default DashAutoAdminForm;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Drawer, DrawerProps } from '@mui/material';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
export interface IResizableDrawer extends DrawerProps {
|
|
5
|
+
defaultWidth: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const DashAutoAdminResizableDrawerContext = React.createContext(400);
|
|
9
|
+
|
|
10
|
+
/* TODO: W.I.P Resizable Drawer is a Work in Progress */
|
|
11
|
+
export const DashAutoAdminResizableDrawer: React.FC<IResizableDrawer> = ({
|
|
12
|
+
children,
|
|
13
|
+
defaultWidth,
|
|
14
|
+
...props
|
|
15
|
+
}) => {
|
|
16
|
+
//const classes = useStyles();
|
|
17
|
+
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
|
18
|
+
const [drawerWidth, setDrawerWidth] = React.useState(defaultWidth);
|
|
19
|
+
|
|
20
|
+
/*
|
|
21
|
+
|
|
22
|
+
const handleMouseMove = useCallback((e) => {
|
|
23
|
+
console.log('Mouse move');
|
|
24
|
+
//const newWidth = e.clientX - (window.innerWidth - document.body.offsetLeft - document.body.offsetWidth );
|
|
25
|
+
//const newWidth = e.clientX + (window.innerWidth - document.body.offsetLeft - document.body.offsetWidth );
|
|
26
|
+
const newWidth = window.innerWidth - e.clientX;
|
|
27
|
+
//if (newWidth > minDrawerWidth && newWidth < maxDrawerWidth) {
|
|
28
|
+
setDrawerWidth(newWidth);
|
|
29
|
+
//}
|
|
30
|
+
if (e.stopPropagation) e.stopPropagation();
|
|
31
|
+
if (e.preventDefault) e.preventDefault();
|
|
32
|
+
e.cancelBubble = true;
|
|
33
|
+
e.returnValue = false;
|
|
34
|
+
}, []);
|
|
35
|
+
|
|
36
|
+
const handleMouseUp = () => {
|
|
37
|
+
console.log('Mouse up');
|
|
38
|
+
document.removeEventListener('mouseup', handleMouseUp, true);
|
|
39
|
+
document.removeEventListener('mousemove', handleMouseMove, true);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const handleMouseDown = (e) => {
|
|
43
|
+
console.log('Mouse down');
|
|
44
|
+
document.addEventListener('mouseup', handleMouseUp, true);
|
|
45
|
+
document.addEventListener('mousemove', handleMouseMove, true);
|
|
46
|
+
};
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
const Dragger = () => {
|
|
50
|
+
// TODO:
|
|
51
|
+
// <div onMouseDown={(e) => handleMouseDown(e) } />
|
|
52
|
+
return <></>;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<Drawer
|
|
57
|
+
/*className={classes.drawer}*/
|
|
58
|
+
PaperProps={{ style: { width: drawerWidth } }}
|
|
59
|
+
//sx={{ zIndex: 100, width: drawerWidth }}
|
|
60
|
+
{...props}
|
|
61
|
+
>
|
|
62
|
+
<DashAutoAdminResizableDrawerContext.Provider value={drawerWidth}>
|
|
63
|
+
<Dragger />
|
|
64
|
+
|
|
65
|
+
{children}
|
|
66
|
+
</DashAutoAdminResizableDrawerContext.Provider>
|
|
67
|
+
</Drawer>
|
|
68
|
+
);
|
|
69
|
+
};
|