@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,45 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
export function isClassComponent(component) {
|
|
4
|
+
return (
|
|
5
|
+
typeof component === 'function' && !!component.prototype.isReactComponent
|
|
6
|
+
);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function isFunctionComponent(component) {
|
|
10
|
+
return (
|
|
11
|
+
typeof component === 'function' &&
|
|
12
|
+
String(component).includes('return React.createElement')
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function isReactComponent(component) {
|
|
17
|
+
return isClassComponent(component) || isFunctionComponent(component);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function isElement(element) {
|
|
21
|
+
return React.isValidElement(element);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function isDOMTypeElement(element) {
|
|
25
|
+
return isElement(element) && typeof element.type === 'string';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function isCompositeTypeElement(element) {
|
|
29
|
+
return isElement(element) && typeof element.type === 'function';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default isReactComponent;
|
|
33
|
+
|
|
34
|
+
/*const isComponent = (Component) => {
|
|
35
|
+
|
|
36
|
+
if (typeof Component === "undefined") return false;
|
|
37
|
+
return !!Component.name
|
|
38
|
+
return (
|
|
39
|
+
typeof Component === 'function' // can be various things
|
|
40
|
+
&& !(
|
|
41
|
+
Component.prototype // native arrows don't have prototypes
|
|
42
|
+
&& Component.prototype.isReactComponent // special property
|
|
43
|
+
)
|
|
44
|
+
);
|
|
45
|
+
}*/
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
function replaceParams(params: { [key: string]: string }, str: string): string {
|
|
2
|
+
delete params["*"];
|
|
3
|
+
const regex = new RegExp(`{(${Object.keys(params).join("|")})+}`, "g");
|
|
4
|
+
return str.replace(regex, (match, param) => params[param]);
|
|
5
|
+
}
|
|
6
|
+
export default replaceParams;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { JSX } from 'react';
|
|
2
|
+
import IDashAutoAdminAttribute from '../interfaces/IDashAutoAdminAttribute';
|
|
3
|
+
|
|
4
|
+
const validate =
|
|
5
|
+
(schema: IDashAutoAdminAttribute[]) =>
|
|
6
|
+
(values: { [field: string]: string | JSX.Element }) => {
|
|
7
|
+
const errors: { [field: string]: string | JSX.Element } = {};
|
|
8
|
+
schema.forEach((field) => {
|
|
9
|
+
if (field.validate) {
|
|
10
|
+
try {
|
|
11
|
+
field.validate(values[field.attribute], values);
|
|
12
|
+
} catch (error) {
|
|
13
|
+
let message = 'Error';
|
|
14
|
+
if (error instanceof Error) message = error.message;
|
|
15
|
+
|
|
16
|
+
errors[field.attribute] = message;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
return errors;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default validate;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { WithRecord, Button } from 'react-admin';
|
|
2
|
+
import IDashAutoAdminAttribute from '../interfaces/IDashAutoAdminAttribute';
|
|
3
|
+
import IDashAutoAdminCustomFieldComponent from '../interfaces/IDashAutoAdminCustomFieldComponent';
|
|
4
|
+
import ActionCallback from '../types/ActionCallback';
|
|
5
|
+
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import isFC from '../utils/isFC';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A React functional component that renders a user action based on the provided attribute.
|
|
11
|
+
*
|
|
12
|
+
* If the attribute has a custom component, it will render that component with the provided props.
|
|
13
|
+
* If the attribute has an action callback, it will render a button that calls the callback when clicked.
|
|
14
|
+
*
|
|
15
|
+
* @param param0 - An object containing the following properties:
|
|
16
|
+
* - attribute: An IDashAutoAdminAttribute object that defines the user action.
|
|
17
|
+
* - method: The method type ('list', 'view', 'edit', or 'create') for the user action.
|
|
18
|
+
* - record: An optional record object to pass to the custom component or action callback.
|
|
19
|
+
* @returns A React element representing the user action, or null if the attribute is not valid.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
const UserAction: React.FC<IDashAutoAdminCustomFieldComponent> = (props) => {
|
|
24
|
+
const { method, attribute, resourceConfig, record, options } = props;
|
|
25
|
+
const DEBUG = false;
|
|
26
|
+
|
|
27
|
+
DEBUG && console.log('🔧 UserAction - component:', attribute.component);
|
|
28
|
+
DEBUG && console.log('🔧 UserAction - isFC(attribute.component):', isFC(attribute.component));
|
|
29
|
+
DEBUG && console.log('🔧 UserAction - method:', method);
|
|
30
|
+
|
|
31
|
+
const locale = options?.locale || (props as any).locale;
|
|
32
|
+
|
|
33
|
+
if (attribute.component && isFC(attribute.component)) {
|
|
34
|
+
DEBUG && console.log('🔧 UserAction - Rendering custom component');
|
|
35
|
+
|
|
36
|
+
const Action = attribute.component as React.FC<IDashAutoAdminCustomFieldComponent>;
|
|
37
|
+
|
|
38
|
+
return <Action
|
|
39
|
+
method={method}
|
|
40
|
+
attribute={attribute}
|
|
41
|
+
resourceConfig={resourceConfig}
|
|
42
|
+
{...record && { record: record }}
|
|
43
|
+
{...attribute?.componentProps}
|
|
44
|
+
locale={locale}
|
|
45
|
+
options={options}
|
|
46
|
+
/>
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (typeof attribute.action === 'function') {
|
|
50
|
+
|
|
51
|
+
const callback = attribute.action as ActionCallback;
|
|
52
|
+
return (
|
|
53
|
+
<WithRecord
|
|
54
|
+
label={attribute.label}
|
|
55
|
+
render={(record) => (
|
|
56
|
+
<Button value={attribute.label} onClick={() => callback(record.id)}>
|
|
57
|
+
<>{attribute.label}</>
|
|
58
|
+
</Button>
|
|
59
|
+
)}
|
|
60
|
+
/>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return null;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export default UserAction;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as UserAction } from './UserAction';
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|