@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
|
@@ -1 +1,244 @@
|
|
|
1
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
var __async = (__this, __arguments, generator) => {
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
var fulfilled = (value) => {
|
|
20
|
+
try {
|
|
21
|
+
step(generator.next(value));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
reject(e);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var rejected = (value) => {
|
|
27
|
+
try {
|
|
28
|
+
step(generator.throw(value));
|
|
29
|
+
} catch (e) {
|
|
30
|
+
reject(e);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
34
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
38
|
+
import { useCallback, useMemo } from "react";
|
|
39
|
+
import {
|
|
40
|
+
useResourceContext,
|
|
41
|
+
useRecordContext,
|
|
42
|
+
TabbedForm,
|
|
43
|
+
SimpleForm
|
|
44
|
+
} from "react-admin";
|
|
45
|
+
import { DashAutoFormGroups, groupByTabs, validate } from ".";
|
|
46
|
+
import { DashAutoFormTabs } from ".";
|
|
47
|
+
import { DashAutoFormLayout } from ".";
|
|
48
|
+
import { useDataProvider } from "react-admin";
|
|
49
|
+
import { DashAutoAdminFormProvider } from "./context/DashAutoAdminFormContext";
|
|
50
|
+
import { useSelector } from "react-redux";
|
|
51
|
+
import { Loading } from "react-admin";
|
|
52
|
+
const DashAutoTabbedForm = ({
|
|
53
|
+
resourceConfig,
|
|
54
|
+
onSubmit,
|
|
55
|
+
beforeSubmit,
|
|
56
|
+
onError,
|
|
57
|
+
toolbar,
|
|
58
|
+
mode,
|
|
59
|
+
isDrawer = false,
|
|
60
|
+
locale
|
|
61
|
+
}) => {
|
|
62
|
+
var _a, _b;
|
|
63
|
+
const resource = useResourceContext();
|
|
64
|
+
const record = useRecordContext();
|
|
65
|
+
const debug = true;
|
|
66
|
+
const dataProvider = useDataProvider();
|
|
67
|
+
let formGroupMode = mode === "create" && ((_a = resourceConfig == null ? void 0 : resourceConfig.formGroupModes) == null ? void 0 : _a.create) ? resourceConfig.formGroupModes.create : mode === "edit" && ((_b = resourceConfig == null ? void 0 : resourceConfig.formGroupModes) == null ? void 0 : _b.edit) ? resourceConfig.formGroupModes.edit : (resourceConfig == null ? void 0 : resourceConfig.formGroupMode) ? resourceConfig.formGroupMode : "tabs";
|
|
68
|
+
const getVisibleTabCount = () => {
|
|
69
|
+
const tabGroups = groupByTabs(resourceConfig.schema);
|
|
70
|
+
return tabGroups.filter((group) => {
|
|
71
|
+
const filteredAttributes = group.filter((attr) => {
|
|
72
|
+
if (mode === "create") {
|
|
73
|
+
return (attr == null ? void 0 : attr.inCreate) !== false;
|
|
74
|
+
} else if (mode === "edit") {
|
|
75
|
+
return (attr == null ? void 0 : attr.inEdit) !== false;
|
|
76
|
+
}
|
|
77
|
+
return true;
|
|
78
|
+
});
|
|
79
|
+
return filteredAttributes.length > 0;
|
|
80
|
+
}).length;
|
|
81
|
+
};
|
|
82
|
+
const visibleTabCount = useMemo(() => getVisibleTabCount(), [resourceConfig.schema, mode, locale]);
|
|
83
|
+
if (formGroupMode === "tabs" && visibleTabCount <= 1) {
|
|
84
|
+
formGroupMode = "layout";
|
|
85
|
+
}
|
|
86
|
+
const formData = useSelector(
|
|
87
|
+
(state) => {
|
|
88
|
+
return state.formData || {};
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
const onCreateSave = useCallback(
|
|
92
|
+
(values) => __async(null, null, function* () {
|
|
93
|
+
if (debug) console.log("onCreateSave called with values:", values);
|
|
94
|
+
if (!resource) {
|
|
95
|
+
throw new Error("Resource is required");
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
if (beforeSubmit) {
|
|
99
|
+
values = beforeSubmit(values);
|
|
100
|
+
}
|
|
101
|
+
const { data } = yield dataProvider.create(resource, {
|
|
102
|
+
data: values
|
|
103
|
+
});
|
|
104
|
+
if (onSubmit) {
|
|
105
|
+
onSubmit(data);
|
|
106
|
+
}
|
|
107
|
+
} catch (error) {
|
|
108
|
+
if (onError) {
|
|
109
|
+
onError(error);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}),
|
|
113
|
+
[resource, beforeSubmit, dataProvider, onSubmit, onError]
|
|
114
|
+
);
|
|
115
|
+
const onUpdateSave = useCallback(
|
|
116
|
+
(values) => __async(null, null, function* () {
|
|
117
|
+
if (debug) console.log("onUpdateSave called with values:", values);
|
|
118
|
+
try {
|
|
119
|
+
if (beforeSubmit) {
|
|
120
|
+
values = beforeSubmit(values);
|
|
121
|
+
}
|
|
122
|
+
const { data } = yield dataProvider.update(resource + "/" + record.id, {
|
|
123
|
+
id: record == null ? void 0 : record.id,
|
|
124
|
+
data: values,
|
|
125
|
+
previousData: record
|
|
126
|
+
});
|
|
127
|
+
if (onSubmit) {
|
|
128
|
+
onSubmit(data);
|
|
129
|
+
}
|
|
130
|
+
} catch (error) {
|
|
131
|
+
if (onError) {
|
|
132
|
+
onError(error);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}),
|
|
136
|
+
[resource, record, beforeSubmit, dataProvider, onSubmit, onError]
|
|
137
|
+
);
|
|
138
|
+
let onSave = onCreateSave;
|
|
139
|
+
switch (mode) {
|
|
140
|
+
case "edit":
|
|
141
|
+
onSave = onUpdateSave;
|
|
142
|
+
break;
|
|
143
|
+
case "create":
|
|
144
|
+
onSave = onCreateSave;
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
const ContextComponent = useMemo(() => {
|
|
148
|
+
return resourceConfig.contextComponent || (({ children }) => /* @__PURE__ */ jsx(Fragment, { children }));
|
|
149
|
+
}, [resourceConfig.contextComponent, locale]);
|
|
150
|
+
const formContextValue = useMemo(() => ({ onSave, mode, locale }), [onSave, mode, locale]);
|
|
151
|
+
if (!formData) return /* @__PURE__ */ jsx(Loading, {});
|
|
152
|
+
if (mode === "create" && typeof (resourceConfig == null ? void 0 : resourceConfig.createComponent) === "function") {
|
|
153
|
+
return /* @__PURE__ */ jsx(
|
|
154
|
+
SimpleForm,
|
|
155
|
+
{
|
|
156
|
+
toolbar: toolbar || null,
|
|
157
|
+
onSubmit: onSave,
|
|
158
|
+
validate: validate(resourceConfig.schema),
|
|
159
|
+
reValidateMode: "onBlur",
|
|
160
|
+
className: "auto-admin-grouped-form",
|
|
161
|
+
children: /* @__PURE__ */ jsx(DashAutoAdminFormProvider, { value: formContextValue, children: /* @__PURE__ */ jsx(ContextComponent, { mode, resourceConfig, children: resourceConfig.createComponent(resourceConfig) }) })
|
|
162
|
+
},
|
|
163
|
+
"create-form"
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
if (mode === "edit" && typeof (resourceConfig == null ? void 0 : resourceConfig.editComponent) === "function") {
|
|
167
|
+
return /* @__PURE__ */ jsx(
|
|
168
|
+
SimpleForm,
|
|
169
|
+
{
|
|
170
|
+
warnWhenUnsavedChanges: true,
|
|
171
|
+
toolbar: toolbar || null,
|
|
172
|
+
onSubmit: onSave,
|
|
173
|
+
validate: validate(resourceConfig.schema),
|
|
174
|
+
reValidateMode: "onBlur",
|
|
175
|
+
className: "auto-admin-grouped-form",
|
|
176
|
+
children: /* @__PURE__ */ jsx(DashAutoAdminFormProvider, { value: formContextValue, children: /* @__PURE__ */ jsx(ContextComponent, { mode, resourceConfig, children: resourceConfig.editComponent(resourceConfig) }) })
|
|
177
|
+
},
|
|
178
|
+
"edit-form"
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
const TabbedFormWrapper = useMemo(() => {
|
|
182
|
+
const Wrapper = ({ children }) => /* @__PURE__ */ jsx(DashAutoAdminFormProvider, { value: formContextValue, children: /* @__PURE__ */ jsx(ContextComponent, { mode, resourceConfig, children }) });
|
|
183
|
+
return Wrapper;
|
|
184
|
+
}, [formContextValue, ContextComponent, mode, resourceConfig, locale]);
|
|
185
|
+
if (formGroupMode === "tabs" && groupByTabs(resourceConfig.schema).length > 1) {
|
|
186
|
+
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(
|
|
187
|
+
TabbedForm,
|
|
188
|
+
{
|
|
189
|
+
toolbar: toolbar || null,
|
|
190
|
+
onSubmit: onSave,
|
|
191
|
+
validate: validate(resourceConfig.schema),
|
|
192
|
+
className: "tabbed-form-custom dash-auto-admin-tabbed-form",
|
|
193
|
+
resetOptions: { keepDirtyValues: true },
|
|
194
|
+
syncWithLocation: resourceConfig.syncTabsWithLocation || false,
|
|
195
|
+
defaultValues: mode === "create" ? formData : __spreadValues(__spreadValues({}, record), formData),
|
|
196
|
+
component: TabbedFormWrapper,
|
|
197
|
+
children: DashAutoFormTabs({
|
|
198
|
+
schema: resourceConfig.schema,
|
|
199
|
+
resourceConfig,
|
|
200
|
+
options: { mode, isDrawer, locale }
|
|
201
|
+
})
|
|
202
|
+
},
|
|
203
|
+
"tabbed-form"
|
|
204
|
+
) });
|
|
205
|
+
}
|
|
206
|
+
if (formGroupMode === "groups") {
|
|
207
|
+
return /* @__PURE__ */ jsx(
|
|
208
|
+
SimpleForm,
|
|
209
|
+
{
|
|
210
|
+
toolbar: toolbar || null,
|
|
211
|
+
onSubmit: onSave,
|
|
212
|
+
validate: validate(resourceConfig.schema),
|
|
213
|
+
reValidateMode: "onBlur",
|
|
214
|
+
className: "auto-admin-grouped-form",
|
|
215
|
+
children: /* @__PURE__ */ jsx(DashAutoAdminFormProvider, { value: formContextValue, children: /* @__PURE__ */ jsx(ContextComponent, { mode, resourceConfig, children: DashAutoFormGroups({ schema: resourceConfig.schema, resourceConfig, options: {
|
|
216
|
+
mode,
|
|
217
|
+
isDrawer
|
|
218
|
+
} }) }) })
|
|
219
|
+
},
|
|
220
|
+
"groups-form"
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
if (formGroupMode === "layout") {
|
|
224
|
+
return /* @__PURE__ */ jsx(
|
|
225
|
+
SimpleForm,
|
|
226
|
+
{
|
|
227
|
+
toolbar: toolbar || null,
|
|
228
|
+
onSubmit: onSave,
|
|
229
|
+
validate: validate(resourceConfig.schema),
|
|
230
|
+
reValidateMode: "onBlur",
|
|
231
|
+
className: "auto-admin-grouped-form",
|
|
232
|
+
children: /* @__PURE__ */ jsx(DashAutoAdminFormProvider, { value: formContextValue, children: /* @__PURE__ */ jsx(ContextComponent, { mode, resourceConfig, children: DashAutoFormLayout({ schema: resourceConfig.schema, resourceConfig, options: {
|
|
233
|
+
mode,
|
|
234
|
+
isDrawer
|
|
235
|
+
} }) }) })
|
|
236
|
+
},
|
|
237
|
+
"layout-form"
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
var DashAutoTabbedForm_default = DashAutoTabbedForm;
|
|
242
|
+
export {
|
|
243
|
+
DashAutoTabbedForm_default as default
|
|
244
|
+
};
|
|
@@ -1 +1,221 @@
|
|
|
1
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
var __async = (__this, __arguments, generator) => {
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
var fulfilled = (value) => {
|
|
20
|
+
try {
|
|
21
|
+
step(generator.next(value));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
reject(e);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var rejected = (value) => {
|
|
27
|
+
try {
|
|
28
|
+
step(generator.throw(value));
|
|
29
|
+
} catch (e) {
|
|
30
|
+
reject(e);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
34
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
38
|
+
import { useCallback, useEffect } from "react";
|
|
39
|
+
import {
|
|
40
|
+
useResourceContext,
|
|
41
|
+
useRecordContext,
|
|
42
|
+
TabbedForm,
|
|
43
|
+
SimpleForm
|
|
44
|
+
} from "react-admin";
|
|
45
|
+
import { DashAutoFormGroups, groupByTabs, validate } from ".";
|
|
46
|
+
import { DashAutoFormTabs } from ".";
|
|
47
|
+
import { DashAutoFormLayout } from ".";
|
|
48
|
+
import { useDataProvider } from "react-admin";
|
|
49
|
+
import { useSelector } from "react-redux";
|
|
50
|
+
import { Loading } from "react-admin";
|
|
51
|
+
import { useFormContext } from "react-hook-form";
|
|
52
|
+
const DashAutoTabbedForm = ({
|
|
53
|
+
resourceConfig,
|
|
54
|
+
onSubmit,
|
|
55
|
+
beforeSubmit,
|
|
56
|
+
onError,
|
|
57
|
+
toolbar,
|
|
58
|
+
mode,
|
|
59
|
+
isDrawer = false
|
|
60
|
+
}) => {
|
|
61
|
+
var _a, _b;
|
|
62
|
+
const resource = useResourceContext();
|
|
63
|
+
const record = useRecordContext();
|
|
64
|
+
const debug = true;
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
console.log("Dash Auto Tabbed rerendered");
|
|
67
|
+
}, []);
|
|
68
|
+
const formContext = useFormContext();
|
|
69
|
+
const dataProvider = useDataProvider();
|
|
70
|
+
let formGroupMode = mode === "create" && ((_a = resourceConfig == null ? void 0 : resourceConfig.formGroupModes) == null ? void 0 : _a.create) ? resourceConfig.formGroupModes.create : mode === "edit" && ((_b = resourceConfig == null ? void 0 : resourceConfig.formGroupModes) == null ? void 0 : _b.edit) ? resourceConfig.formGroupModes.edit : (resourceConfig == null ? void 0 : resourceConfig.formGroupMode) ? resourceConfig.formGroupMode : "tabs";
|
|
71
|
+
if (formGroupMode === "tabs" && groupByTabs(resourceConfig.schema).length === 1) {
|
|
72
|
+
formGroupMode = "layout";
|
|
73
|
+
}
|
|
74
|
+
const formData = useSelector(
|
|
75
|
+
(state) => {
|
|
76
|
+
return state.formData || {};
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
const onCreateSave = useCallback(
|
|
80
|
+
(values) => __async(null, null, function* () {
|
|
81
|
+
if (debug) console.log("onCreateSave called with values:", values);
|
|
82
|
+
if (!resource) {
|
|
83
|
+
throw new Error("Resource is required");
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
if (beforeSubmit) {
|
|
87
|
+
values = beforeSubmit(values);
|
|
88
|
+
}
|
|
89
|
+
const { data } = yield dataProvider.create(resource, {
|
|
90
|
+
data: values
|
|
91
|
+
});
|
|
92
|
+
if (onSubmit) {
|
|
93
|
+
onSubmit(data);
|
|
94
|
+
}
|
|
95
|
+
} catch (error) {
|
|
96
|
+
if (onError) {
|
|
97
|
+
onError(error);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}),
|
|
101
|
+
[resource, beforeSubmit, dataProvider, onSubmit, onError]
|
|
102
|
+
);
|
|
103
|
+
const onUpdateSave = useCallback(
|
|
104
|
+
(values) => __async(null, null, function* () {
|
|
105
|
+
if (debug) console.log("onUpdateSave called with values:", values);
|
|
106
|
+
try {
|
|
107
|
+
if (beforeSubmit) {
|
|
108
|
+
values = beforeSubmit(values);
|
|
109
|
+
}
|
|
110
|
+
const { data } = yield dataProvider.update(resource + "/" + record.id, {
|
|
111
|
+
data: values
|
|
112
|
+
});
|
|
113
|
+
if (onSubmit) {
|
|
114
|
+
onSubmit(data);
|
|
115
|
+
}
|
|
116
|
+
} catch (error) {
|
|
117
|
+
if (onError) {
|
|
118
|
+
onError(error);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}),
|
|
122
|
+
[resource, record, beforeSubmit, dataProvider, onSubmit, onError]
|
|
123
|
+
);
|
|
124
|
+
let onSave = onCreateSave;
|
|
125
|
+
switch (mode) {
|
|
126
|
+
case "edit":
|
|
127
|
+
onSave = onUpdateSave;
|
|
128
|
+
break;
|
|
129
|
+
case "create":
|
|
130
|
+
onSave = onCreateSave;
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
if (!formData) return /* @__PURE__ */ jsx(Loading, {});
|
|
134
|
+
if (mode === "create" && typeof (resourceConfig == null ? void 0 : resourceConfig.createComponent) === "function") {
|
|
135
|
+
return /* @__PURE__ */ jsx(
|
|
136
|
+
SimpleForm,
|
|
137
|
+
{
|
|
138
|
+
toolbar: toolbar || null,
|
|
139
|
+
onSubmit: onSave,
|
|
140
|
+
validate: validate(resourceConfig.schema),
|
|
141
|
+
reValidateMode: "onBlur",
|
|
142
|
+
className: "auto-admin-grouped-form",
|
|
143
|
+
children: resourceConfig.createComponent(resourceConfig)
|
|
144
|
+
},
|
|
145
|
+
"create-form"
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
if (mode === "edit" && typeof (resourceConfig == null ? void 0 : resourceConfig.editComponent) === "function") {
|
|
149
|
+
return /* @__PURE__ */ jsx(
|
|
150
|
+
SimpleForm,
|
|
151
|
+
{
|
|
152
|
+
warnWhenUnsavedChanges: true,
|
|
153
|
+
toolbar: toolbar || null,
|
|
154
|
+
onSubmit: onSave,
|
|
155
|
+
validate: validate(resourceConfig.schema),
|
|
156
|
+
reValidateMode: "onBlur",
|
|
157
|
+
className: "auto-admin-grouped-form",
|
|
158
|
+
children: resourceConfig.editComponent(resourceConfig)
|
|
159
|
+
},
|
|
160
|
+
"edit-form"
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
if (formGroupMode === "tabs" && groupByTabs(resourceConfig.schema).length > 1) {
|
|
164
|
+
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(
|
|
165
|
+
TabbedForm,
|
|
166
|
+
{
|
|
167
|
+
toolbar: toolbar || null,
|
|
168
|
+
onSubmit: onSave,
|
|
169
|
+
validate: validate(resourceConfig.schema),
|
|
170
|
+
className: "tabbed-form-custom dash-auto-admin-tabbed-form",
|
|
171
|
+
resetOptions: { keepDirtyValues: true },
|
|
172
|
+
syncWithLocation: resourceConfig.syncTabsWithLocation || false,
|
|
173
|
+
defaultValues: mode === "create" ? formData : __spreadValues(__spreadValues({}, record), formData),
|
|
174
|
+
children: DashAutoFormTabs({
|
|
175
|
+
schema: resourceConfig.schema,
|
|
176
|
+
resourceConfig,
|
|
177
|
+
options: { mode, isDrawer }
|
|
178
|
+
})
|
|
179
|
+
},
|
|
180
|
+
"tabbed-form"
|
|
181
|
+
) });
|
|
182
|
+
}
|
|
183
|
+
if (formGroupMode === "groups") {
|
|
184
|
+
return /* @__PURE__ */ jsx(
|
|
185
|
+
SimpleForm,
|
|
186
|
+
{
|
|
187
|
+
toolbar: toolbar || null,
|
|
188
|
+
onSubmit: onSave,
|
|
189
|
+
validate: validate(resourceConfig.schema),
|
|
190
|
+
reValidateMode: "onBlur",
|
|
191
|
+
className: "auto-admin-grouped-form",
|
|
192
|
+
children: DashAutoFormGroups({ schema: resourceConfig.schema, resourceConfig, options: {
|
|
193
|
+
mode,
|
|
194
|
+
isDrawer
|
|
195
|
+
} })
|
|
196
|
+
},
|
|
197
|
+
"groups-form"
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
if (formGroupMode === "layout") {
|
|
201
|
+
return /* @__PURE__ */ jsx(
|
|
202
|
+
SimpleForm,
|
|
203
|
+
{
|
|
204
|
+
toolbar: toolbar || null,
|
|
205
|
+
onSubmit: onSave,
|
|
206
|
+
validate: validate(resourceConfig.schema),
|
|
207
|
+
reValidateMode: "onBlur",
|
|
208
|
+
className: "auto-admin-grouped-form",
|
|
209
|
+
children: DashAutoFormLayout({ schema: resourceConfig.schema, resourceConfig, options: {
|
|
210
|
+
mode,
|
|
211
|
+
isDrawer
|
|
212
|
+
} })
|
|
213
|
+
},
|
|
214
|
+
"layout-form"
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
var DashAutoTabbedForm_review_default = DashAutoTabbedForm;
|
|
219
|
+
export {
|
|
220
|
+
DashAutoTabbedForm_review_default as default
|
|
221
|
+
};
|
package/dist/DashAutoTabs.js
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
import{jsx
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { TabbedShowLayout } from "react-admin";
|
|
3
|
+
import { AutoTabs as MuiAutoTabbedForm } from "./mui/AutoTabs";
|
|
4
|
+
const AutoTabs = (resourceConfig, options) => {
|
|
5
|
+
const _AutoTabs = MuiAutoTabbedForm;
|
|
6
|
+
return /* @__PURE__ */ jsx(TabbedShowLayout, { children: _AutoTabs(resourceConfig, resourceConfig.schema, options) });
|
|
7
|
+
};
|
|
8
|
+
var DashAutoTabs_default = AutoTabs;
|
|
9
|
+
export {
|
|
10
|
+
DashAutoTabs_default as default
|
|
11
|
+
};
|
|
@@ -1 +1,62 @@
|
|
|
1
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
var __objRest = (source, exclude) => {
|
|
18
|
+
var target = {};
|
|
19
|
+
for (var prop in source)
|
|
20
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
21
|
+
target[prop] = source[prop];
|
|
22
|
+
if (source != null && __getOwnPropSymbols)
|
|
23
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
24
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
25
|
+
target[prop] = source[prop];
|
|
26
|
+
}
|
|
27
|
+
return target;
|
|
28
|
+
};
|
|
29
|
+
import React from "react";
|
|
30
|
+
import { useInput } from "react-admin";
|
|
31
|
+
const DashFilterWrapper = (_a) => {
|
|
32
|
+
var _b = _a, {
|
|
33
|
+
children,
|
|
34
|
+
source,
|
|
35
|
+
label,
|
|
36
|
+
alwaysOn
|
|
37
|
+
} = _b, props = __objRest(_b, [
|
|
38
|
+
"children",
|
|
39
|
+
"source",
|
|
40
|
+
"label",
|
|
41
|
+
"alwaysOn"
|
|
42
|
+
]);
|
|
43
|
+
const {
|
|
44
|
+
field: { onChange, onBlur, value },
|
|
45
|
+
fieldState: { error, invalid },
|
|
46
|
+
formState: { isSubmitted }
|
|
47
|
+
} = useInput(__spreadValues({ source }, props));
|
|
48
|
+
const childWithProps = React.cloneElement(children, __spreadValues({
|
|
49
|
+
value,
|
|
50
|
+
onChange,
|
|
51
|
+
onBlur,
|
|
52
|
+
error: error == null ? void 0 : error.message,
|
|
53
|
+
helperText: error == null ? void 0 : error.message,
|
|
54
|
+
source,
|
|
55
|
+
label
|
|
56
|
+
}, children.props));
|
|
57
|
+
return childWithProps;
|
|
58
|
+
};
|
|
59
|
+
var DashFilterWrapper_default = DashFilterWrapper;
|
|
60
|
+
export {
|
|
61
|
+
DashFilterWrapper_default as default
|
|
62
|
+
};
|
package/dist/DashRedirect.js
CHANGED
|
@@ -1 +1,56 @@
|
|
|
1
|
-
|
|
1
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
2
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
3
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
4
|
+
var __objRest = (source, exclude) => {
|
|
5
|
+
var target = {};
|
|
6
|
+
for (var prop in source)
|
|
7
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
8
|
+
target[prop] = source[prop];
|
|
9
|
+
if (source != null && __getOwnPropSymbols)
|
|
10
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
11
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
12
|
+
target[prop] = source[prop];
|
|
13
|
+
}
|
|
14
|
+
return target;
|
|
15
|
+
};
|
|
16
|
+
import { jsx } from "react/jsx-runtime";
|
|
17
|
+
import { DASHAdminSystemConstants } from "dash-constants";
|
|
18
|
+
import { useEffect } from "react";
|
|
19
|
+
import { useRedirect, Loading } from "react-admin";
|
|
20
|
+
import { useParams } from "react-router";
|
|
21
|
+
const URL_PREFIX = DASHAdminSystemConstants.system.URL_PREFIX;
|
|
22
|
+
const DashRedirect = (_a) => {
|
|
23
|
+
var _b = _a, {
|
|
24
|
+
method,
|
|
25
|
+
resourceConfig,
|
|
26
|
+
stateHashPattern = URL_PREFIX,
|
|
27
|
+
drawerMethod = "edit"
|
|
28
|
+
} = _b, _props = __objRest(_b, [
|
|
29
|
+
"method",
|
|
30
|
+
"resourceConfig",
|
|
31
|
+
"stateHashPattern",
|
|
32
|
+
"drawerMethod"
|
|
33
|
+
]);
|
|
34
|
+
const params = useParams();
|
|
35
|
+
const redirect = useRedirect();
|
|
36
|
+
const idParamName = (resourceConfig == null ? void 0 : resourceConfig.idParamName) || "id";
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
let _stateHash = stateHashPattern.replace(
|
|
39
|
+
`:${idParamName}`,
|
|
40
|
+
params[idParamName]
|
|
41
|
+
);
|
|
42
|
+
_stateHash = _stateHash.replace(":method", drawerMethod);
|
|
43
|
+
redirect(
|
|
44
|
+
method,
|
|
45
|
+
resourceConfig.model,
|
|
46
|
+
method === "edit" ? params.id : null,
|
|
47
|
+
null,
|
|
48
|
+
{ hash: _stateHash }
|
|
49
|
+
);
|
|
50
|
+
}, []);
|
|
51
|
+
return /* @__PURE__ */ jsx(Loading, {});
|
|
52
|
+
};
|
|
53
|
+
var DashRedirect_default = DashRedirect;
|
|
54
|
+
export {
|
|
55
|
+
DashRedirect_default as default
|
|
56
|
+
};
|
package/dist/TabbedLayout.js
CHANGED
|
@@ -1 +1,38 @@
|
|
|
1
|
-
|
|
1
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
2
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
3
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
4
|
+
var __objRest = (source, exclude) => {
|
|
5
|
+
var target = {};
|
|
6
|
+
for (var prop in source)
|
|
7
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
8
|
+
target[prop] = source[prop];
|
|
9
|
+
if (source != null && __getOwnPropSymbols)
|
|
10
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
11
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
12
|
+
target[prop] = source[prop];
|
|
13
|
+
}
|
|
14
|
+
return target;
|
|
15
|
+
};
|
|
16
|
+
import { jsxs } from "react/jsx-runtime";
|
|
17
|
+
import { TabbedShowLayout } from "react-admin";
|
|
18
|
+
import AutoReferenceTab from "./DashAutoReferenceTab";
|
|
19
|
+
import AutoTabs from "./DashAutoTabs";
|
|
20
|
+
const TabbedLayout = (_a) => {
|
|
21
|
+
var _b = _a, {
|
|
22
|
+
resourceConfig,
|
|
23
|
+
schema,
|
|
24
|
+
references
|
|
25
|
+
} = _b, _props = __objRest(_b, [
|
|
26
|
+
"resourceConfig",
|
|
27
|
+
"schema",
|
|
28
|
+
"references"
|
|
29
|
+
]);
|
|
30
|
+
return /* @__PURE__ */ jsxs(TabbedShowLayout, { children: [
|
|
31
|
+
AutoTabs(resourceConfig),
|
|
32
|
+
references && references.map((reference) => AutoReferenceTab(reference))
|
|
33
|
+
] });
|
|
34
|
+
};
|
|
35
|
+
var TabbedLayout_default = TabbedLayout;
|
|
36
|
+
export {
|
|
37
|
+
TabbedLayout_default as default
|
|
38
|
+
};
|