@dashadmin/dash-auto-admin 1.3.25 → 1.3.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/DashAutoAdminComponentRegistry.js +64 -1
- package/dist/DashAutoAdminForm.js +137 -1
- package/dist/DashAutoAdminResizableDrawer.js +63 -1
- package/dist/DashAutoAdminSaveButton.js +57 -1
- package/dist/DashAutoCreate.js +102 -1
- package/dist/DashAutoDrawer.js +256 -1
- package/dist/DashAutoEdit.js +99 -1
- package/dist/DashAutoFiltersGenerator.js +193 -1
- package/dist/DashAutoFormGroups.js +118 -1
- package/dist/DashAutoFormLayout.js +68 -1
- package/dist/DashAutoFormMuiTabs.js +291 -1
- package/dist/DashAutoFormTabs.js +132 -1
- package/dist/DashAutoGroup.js +27 -1
- package/dist/DashAutoLayout.js +31 -1
- package/dist/DashAutoList.js +218 -1
- package/dist/DashAutoPostFilterForm.js +47 -1
- package/dist/DashAutoReferenceTab.js +10 -1
- package/dist/DashAutoResource.js +77 -1
- package/dist/DashAutoResourceLayout.js +16 -1
- package/dist/DashAutoShow.js +195 -1
- package/dist/DashAutoTabbedForm.js +244 -1
- package/dist/DashAutoTabbedForm.review.js +221 -1
- package/dist/DashAutoTabs.js +11 -1
- package/dist/DashFilterWrapper.js +62 -1
- package/dist/DashRedirect.js +56 -1
- package/dist/TabbedLayout.js +38 -1
- package/dist/common/DashAutoTitle.js +33 -1
- package/dist/common/components/FabButton.js +59 -1
- package/dist/common/components/TranslatedLabel.js +60 -1
- package/dist/common/settings/Settings.js +196 -1
- package/dist/common/settings/SettingsBarIcons.js +61 -1
- package/dist/context/DashAutoAdminFormContext.js +15 -1
- package/dist/hooks/useAutoAdminLoadingStateMediator.js +36 -1
- package/dist/hooks/useAutoAdminTranslate.js +61 -1
- package/dist/hooks/useHash.js +24 -1
- package/dist/hooks/useLogger.js +20 -1
- package/dist/hooks/useRoutePathPattern.js +20 -1
- package/dist/hooks/useVirtualHash.js +28 -1
- package/dist/index.js +77 -3406
- package/dist/list/DashAutoListActions.js +57 -1
- package/dist/list/DashAutoListDatagridWrapper.js +68 -1
- package/dist/list/DashAutoListDefaultActionsWrapper.js +14 -1
- package/dist/list/DashAutoListFilterFormWithButton.js +80 -1
- package/dist/list/DashAutoListTopToolbar.js +180 -1
- package/dist/mui/AttributeToField.js +576 -1
- package/dist/mui/AttributeToInput.js +630 -1
- package/dist/mui/AutoAdminResizableDrawer.js +63 -1
- package/dist/mui/AutoDataGrid.js +120 -1
- package/dist/mui/AutoReferenceFormTab.js +53 -1
- package/dist/mui/AutoReferenceTab.js +46 -1
- package/dist/mui/AutoTabs.js +19 -1
- package/dist/mui/components/ExtendedPagination.js +34 -1
- package/dist/mui/components/ListStringField.js +25 -1
- package/dist/providers/DashAuthProvider.js +215 -1
- package/dist/providers/DashDataProvider.js +310 -1
- package/dist/providers/index.js +10 -1
- package/dist/react-admin.d.js +0 -0
- package/dist/toolbar/buttons/BottomToolbarButtons.js +65 -1
- package/dist/toolbar/buttons/DashResourceButton.js +181 -1
- package/dist/toolbar/buttons/ListButtons.js +80 -1
- package/dist/toolbar/buttons/ToolbarButtons.js +135 -1
- package/dist/types/ActionCallback.d.js +0 -0
- package/dist/utils/SimpleLogger.js +52 -1
- package/dist/utils/enumToChoices.js +5 -1
- package/dist/utils/evalActionPermission.js +11 -1
- package/dist/utils/groupByTabs.js +21 -1
- package/dist/utils/hashedGroupByTabs.js +12 -1
- package/dist/utils/invertMap.js +12 -1
- package/dist/utils/isClassComponent.js +7 -1
- package/dist/utils/isComponent.js +29 -1
- package/dist/utils/isEnum.js +5 -1
- package/dist/utils/isFC.js +8 -1
- package/dist/utils/replaceParams.js +9 -1
- package/dist/utils/validate.js +19 -1
- package/dist/wrappers/UserAction.js +60 -1
- package/dist/wrappers/index.js +4 -1
- package/package.json +135 -120
- package/src/DashAutoAdminComponentRegistry.tsx +75 -0
- package/src/DashAutoAdminForm.tsx +155 -0
- package/src/DashAutoAdminResizableDrawer.tsx +69 -0
- package/src/DashAutoAdminSaveButton.tsx +116 -0
- package/src/DashAutoCreate.tsx +118 -0
- package/src/DashAutoDrawer.tsx +288 -0
- package/src/DashAutoEdit.tsx +109 -0
- package/src/DashAutoFiltersGenerator.tsx +208 -0
- package/src/DashAutoFormGroups.tsx +146 -0
- package/src/DashAutoFormLayout.tsx.review +113 -0
- package/src/DashAutoFormMuiTabs.tsx +368 -0
- package/src/DashAutoFormTabs.tsx +177 -0
- package/src/DashAutoGroup.tsx +42 -0
- package/src/DashAutoLayout.tsx +57 -0
- package/src/DashAutoList.tsx +237 -0
- package/src/DashAutoPostFilterForm.tsx +35 -0
- package/src/DashAutoReferenceTab.tsx +9 -0
- package/src/DashAutoResource.tsx +85 -0
- package/src/DashAutoResourceLayout.tsx +50 -0
- package/src/DashAutoShow.tsx +200 -0
- package/src/DashAutoTabbedForm.review.tsx +262 -0
- package/src/DashAutoTabbedForm.tsx +324 -0
- package/src/DashAutoTabs.tsx +19 -0
- package/src/DashFilterWrapper.tsx +43 -0
- package/src/DashRedirect.tsx +46 -0
- package/src/TabbedLayout.tsx +29 -0
- package/src/common/DashAutoTitle.tsx +24 -0
- package/src/common/components/FabButton.tsx +40 -0
- package/src/common/components/TranslatedLabel.tsx +81 -0
- package/src/common/settings/Settings.tsx +236 -0
- package/src/common/settings/SettingsBarIcons.tsx +72 -0
- package/src/context/DashAutoAdminFormContext.tsx +31 -0
- package/src/hooks/useAutoAdminLoadingStateMediator.tsx +42 -0
- package/src/hooks/useAutoAdminTranslate.tsx +106 -0
- package/src/hooks/useHash.tsx +27 -0
- package/src/hooks/useLogger.tsx +23 -0
- package/src/hooks/useRoutePathPattern.tsx +24 -0
- package/src/hooks/useVirtualHash.tsx +34 -0
- package/src/index.ts +85 -0
- package/src/interfaces/ICustomResourceSubComponent.ts +11 -0
- package/src/interfaces/IDashApplicationLayoutMainAction.ts +37 -0
- package/src/interfaces/IDashApplicationLayoutMenuItem.ts +24 -0
- package/src/interfaces/IDashAutoAdminAttribute.ts +104 -0
- package/src/interfaces/IDashAutoAdminCustomFieldComponent.ts +18 -0
- package/src/interfaces/IDashAutoAdminFormOptions.ts +22 -0
- package/src/interfaces/IDashAutoAdminListActions.ts +13 -0
- package/src/interfaces/IDashAutoAdminReference.ts +16 -0
- package/src/interfaces/IDashAutoAdminResourceConfig.ts +360 -0
- package/src/interfaces/IDashAutoForm.ts +24 -0
- package/src/interfaces/IDashAutoGridButton.ts +35 -0
- package/src/interfaces/IDashAutoShow.ts +12 -0
- package/src/interfaces/IGroupExtraData.ts +8 -0
- package/src/interfaces/IRecord.ts +7 -0
- package/src/interfaces/IReferenceFilter.ts +55 -0
- package/src/interfaces/IResourceComponent.ts +8 -0
- package/src/interfaces/IToolbarButton.ts +11 -0
- package/src/list/DashAutoListActions.tsx +88 -0
- package/src/list/DashAutoListDatagridWrapper.tsx +74 -0
- package/src/list/DashAutoListDefaultActionsWrapper.tsx +31 -0
- package/src/list/DashAutoListFilterFormWithButton.tsx +93 -0
- package/src/list/DashAutoListTopToolbar.tsx +240 -0
- package/src/mui/AttributeToField.tsx +657 -0
- package/src/mui/AttributeToInput.tsx +728 -0
- package/src/mui/AutoAdminResizableDrawer.tsx +69 -0
- package/src/mui/AutoDataGrid.tsx +127 -0
- package/src/mui/AutoReferenceFormTab.tsx +51 -0
- package/src/mui/AutoReferenceTab.tsx +45 -0
- package/src/mui/AutoTabs.tsx +32 -0
- package/src/mui/components/ExtendedPagination.tsx +23 -0
- package/src/mui/components/ListStringField.tsx +32 -0
- package/src/providers/DashAuthProvider.ts +341 -0
- package/src/providers/DashDataProvider.ts +466 -0
- package/src/providers/index.ts +17 -0
- package/src/toolbar/buttons/BottomToolbarButtons.tsx +59 -0
- package/src/toolbar/buttons/DashResourceButton.tsx +223 -0
- package/src/toolbar/buttons/ListButtons.tsx +137 -0
- package/src/toolbar/buttons/ToolbarButtons.tsx +186 -0
- package/src/utils/SimpleLogger.tsx +46 -0
- package/src/utils/enumToChoices.tsx +3 -0
- package/src/utils/evalActionPermission.tsx +14 -0
- package/src/utils/groupByTabs.tsx +23 -0
- package/src/utils/hashedGroupByTabs.tsx +16 -0
- package/src/utils/invertMap.tsx +10 -0
- package/src/utils/isClassComponent.tsx +9 -0
- package/src/utils/isComponent.tsx +45 -0
- package/src/utils/isEnum.tsx +3 -0
- package/src/utils/isFC.tsx +6 -0
- package/src/utils/replaceParams.tsx +6 -0
- package/src/utils/validate.tsx +24 -0
- package/src/wrappers/UserAction.tsx +67 -0
- package/src/wrappers/index.tsx +1 -0
- /package/{dist → src}/DashAutoAdminSaveButton.tsx.bkup +0 -0
- /package/{dist/DashAutoFormLayout.tsx.review → src/DashAutoFormLayout.tsx} +0 -0
- /package/{dist → src}/DashAutoFormTabs.review +0 -0
- /package/{dist → src}/DashAutoFormTabs.tsx.formcontext.wip +0 -0
- /package/{dist → src}/mui/AttributeToField.tsx.review +0 -0
- /package/{dist → src}/mui/AttributeToInput.tsx.review +0 -0
- /package/{dist → src}/react-admin.d.ts +0 -0
- /package/{dist → src}/types/ActionCallback.d.ts +0 -0
|
@@ -0,0 +1,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 AutoAdminResizableDrawerContext = React.createContext(400);
|
|
9
|
+
|
|
10
|
+
/* TODO: W.I.P Resizable Drawer is a Work in Progress */
|
|
11
|
+
export const AutoAdminResizableDrawer: 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
|
+
<AutoAdminResizableDrawerContext.Provider value={drawerWidth}>
|
|
63
|
+
<Dragger />
|
|
64
|
+
|
|
65
|
+
{children}
|
|
66
|
+
</AutoAdminResizableDrawerContext.Provider>
|
|
67
|
+
</Drawer>
|
|
68
|
+
);
|
|
69
|
+
};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import React, { useMemo, memo, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
TextField,
|
|
5
|
+
Datagrid,
|
|
6
|
+
FunctionField,
|
|
7
|
+
} from 'react-admin';
|
|
8
|
+
|
|
9
|
+
import IDashAutoAdminAttribute from '../interfaces/IDashAutoAdminAttribute';
|
|
10
|
+
import IDashAutoAdminResourceConfig from '../interfaces/IDashAutoAdminResourceConfig';
|
|
11
|
+
|
|
12
|
+
import { AttributeToField } from './AttributeToField';
|
|
13
|
+
import { TableContainer } from '@mui/material';
|
|
14
|
+
import { ListDeleteButton, ListEditButton, ListViewButton } from '../toolbar/buttons/ListButtons';
|
|
15
|
+
|
|
16
|
+
interface AutoDataGridProps {
|
|
17
|
+
/** Schema,(optional) resolves from resourceConfig, but in some cases without schema could work, not tested. */
|
|
18
|
+
schema?: IDashAutoAdminAttribute[];
|
|
19
|
+
/** BulkActions,(optional) resolves from resourceConfig, but in some cases without schema could work, not tested. */
|
|
20
|
+
resourceConfig?: IDashAutoAdminResourceConfig;
|
|
21
|
+
className?: string;
|
|
22
|
+
bulkActions?: React.ReactNode;
|
|
23
|
+
locale?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type IAutoDataGrid = AutoDataGridProps;
|
|
27
|
+
|
|
28
|
+
// Memoize the buttons to prevent unnecessary re-renders
|
|
29
|
+
const MemoizedListViewButton = memo(ListViewButton);
|
|
30
|
+
const MemoizedListEditButton = memo(ListEditButton);
|
|
31
|
+
const MemoizedListDeleteButton = memo(ListDeleteButton);
|
|
32
|
+
|
|
33
|
+
const AutoDataGrid: React.FC<IAutoDataGrid> = ({
|
|
34
|
+
resourceConfig,
|
|
35
|
+
schema,
|
|
36
|
+
locale,
|
|
37
|
+
...dataGridProps
|
|
38
|
+
}) => {
|
|
39
|
+
const _locale = locale || resourceConfig?.locale;
|
|
40
|
+
const _schema: IDashAutoAdminAttribute[] = resourceConfig?.schema || schema;
|
|
41
|
+
|
|
42
|
+
if (!_schema || !_schema.filter)
|
|
43
|
+
throw new Error(
|
|
44
|
+
'Schema must be present as prop or as an attribute of resourceConfig object, and must be iterable',
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
// Memoize schema processing
|
|
48
|
+
const schemaIncludesId = useMemo(() =>
|
|
49
|
+
_schema.filter((attribute) => attribute.attribute === 'id').length !== 0
|
|
50
|
+
, [_schema]);
|
|
51
|
+
|
|
52
|
+
// Memoize processed dataGridProps
|
|
53
|
+
const processedDataGridProps = useMemo(() => ({
|
|
54
|
+
//...{selectedIds:[]},
|
|
55
|
+
...resourceConfig.dataGridProps,
|
|
56
|
+
...dataGridProps,
|
|
57
|
+
}), [resourceConfig.dataGridProps, dataGridProps]);
|
|
58
|
+
|
|
59
|
+
// Memoize the filtered schema for list display
|
|
60
|
+
const filteredSchema = useMemo(() =>
|
|
61
|
+
_schema.filter((attribute) => attribute.inList !== false)
|
|
62
|
+
, [_schema, _locale]);
|
|
63
|
+
|
|
64
|
+
// Default grid wrapper component
|
|
65
|
+
const DefaultGridWrapper = memo((props: { children: React.ReactNode, className?: string, gridWrapperProps?: any }) => {
|
|
66
|
+
const { children, className, gridWrapperProps } = props;
|
|
67
|
+
return (
|
|
68
|
+
<TableContainer
|
|
69
|
+
sx={{ mt: 1 }}
|
|
70
|
+
className={'dash-datagrid-wrapper '+(className || '')}
|
|
71
|
+
{...gridWrapperProps}
|
|
72
|
+
>
|
|
73
|
+
{children}
|
|
74
|
+
</TableContainer>
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const DataGridWrapper = resourceConfig.dataGridWrapper || DefaultGridWrapper;
|
|
79
|
+
const DataGridRootComponent: typeof Datagrid =
|
|
80
|
+
resourceConfig.dataGridRootComponent || Datagrid;
|
|
81
|
+
|
|
82
|
+
// Memoize the custom list buttons
|
|
83
|
+
const customListButtons = useMemo(() => {
|
|
84
|
+
if (!resourceConfig?.customListButtons) return null;
|
|
85
|
+
|
|
86
|
+
return resourceConfig.customListButtons.map((customButtonConfig, idx) => (
|
|
87
|
+
<customButtonConfig.component
|
|
88
|
+
key={'list_custom_buttton' + idx}
|
|
89
|
+
{...customButtonConfig.props}
|
|
90
|
+
/>
|
|
91
|
+
));
|
|
92
|
+
}, [resourceConfig?.customListButtons]);
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
return <DataGridWrapper className={resourceConfig?.dataGridProps?.stickyHeader ? 'dash-sticky-header' : ''}>
|
|
97
|
+
<DataGridRootComponent {...processedDataGridProps}>
|
|
98
|
+
{!schemaIncludesId && !(resourceConfig.hideSchemaId === true) && (
|
|
99
|
+
<FunctionField
|
|
100
|
+
key={'default_id_field_0'}
|
|
101
|
+
source='id'
|
|
102
|
+
sortable={true}
|
|
103
|
+
render={(record: any) => {
|
|
104
|
+
const val = record?.id;
|
|
105
|
+
// If not numeric, slice last 6 chars
|
|
106
|
+
if (val && isNaN(Number(val))) {
|
|
107
|
+
return String(val).slice(-6);
|
|
108
|
+
}
|
|
109
|
+
return val;
|
|
110
|
+
}}
|
|
111
|
+
/>
|
|
112
|
+
)}
|
|
113
|
+
{filteredSchema.map((attribute, idx) =>
|
|
114
|
+
AttributeToField('list', resourceConfig, attribute, idx)
|
|
115
|
+
)}
|
|
116
|
+
<MemoizedListViewButton key={'list_view_btn'} resourceConfig={resourceConfig} />
|
|
117
|
+
<MemoizedListEditButton key={'list_edit_btn'} resourceConfig={resourceConfig} />
|
|
118
|
+
<MemoizedListDeleteButton key={'list_delete_btn'} resourceConfig={resourceConfig} />
|
|
119
|
+
{customListButtons}
|
|
120
|
+
</DataGridRootComponent>
|
|
121
|
+
</DataGridWrapper>
|
|
122
|
+
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// Export a memoized version of the component
|
|
126
|
+
//export default memo(AutoDataGrid);
|
|
127
|
+
export default AutoDataGrid
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { FormTab, ReferenceManyField, ReferenceArrayField } from 'react-admin';
|
|
2
|
+
import { IDashAutoAdminReference } from '../interfaces/IDashAutoAdminReference';
|
|
3
|
+
|
|
4
|
+
import AutoDataGrid from './AutoDataGrid';
|
|
5
|
+
import ExtendedPagination from './components/ExtendedPagination';
|
|
6
|
+
|
|
7
|
+
const AutoReferenceFormTab = (reference: IDashAutoAdminReference) => {
|
|
8
|
+
const type = reference.type ? reference.type : 'ReferenceManyField';
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<FormTab
|
|
12
|
+
key={reference.reference}
|
|
13
|
+
label={reference.tab || reference.reference}
|
|
14
|
+
>
|
|
15
|
+
{type === 'ReferenceManyField' && (
|
|
16
|
+
<ReferenceManyField
|
|
17
|
+
fullWidth
|
|
18
|
+
reference={reference.reference}
|
|
19
|
+
//target={[...reference.target]}
|
|
20
|
+
target={reference.target}
|
|
21
|
+
//addLabel={false}
|
|
22
|
+
pagination={<ExtendedPagination />}
|
|
23
|
+
>
|
|
24
|
+
{/* TODO: replace AutoDataGrid to DashAutoList */}
|
|
25
|
+
<AutoDataGrid
|
|
26
|
+
schema={reference.schema}
|
|
27
|
+
/>
|
|
28
|
+
</ReferenceManyField>
|
|
29
|
+
)}
|
|
30
|
+
|
|
31
|
+
{type === 'ReferenceArrayField' && (
|
|
32
|
+
<ReferenceArrayField
|
|
33
|
+
fullWidth
|
|
34
|
+
reference={reference.reference}
|
|
35
|
+
//target={[...reference.target]}
|
|
36
|
+
source={reference.target}
|
|
37
|
+
//addLabel={false}
|
|
38
|
+
pagination={<ExtendedPagination />}
|
|
39
|
+
>
|
|
40
|
+
{' '}
|
|
41
|
+
{/* TODO replace AutoDataGrid to DashAutoList */}
|
|
42
|
+
<AutoDataGrid
|
|
43
|
+
schema={reference.schema} /*BulkActions={reference.BulkActions}*/
|
|
44
|
+
/>
|
|
45
|
+
</ReferenceArrayField>
|
|
46
|
+
)}
|
|
47
|
+
</FormTab>
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export default AutoReferenceFormTab;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Tab, ReferenceManyField, ReferenceArrayField } from 'react-admin';
|
|
2
|
+
import AutoDataGrid from './AutoDataGrid';
|
|
3
|
+
import ExtendedPagination from './components/ExtendedPagination';
|
|
4
|
+
import { IDashAutoAdminReference } from '../interfaces/IDashAutoAdminReference';
|
|
5
|
+
|
|
6
|
+
export const AutoReferenceTab = (reference: IDashAutoAdminReference) => {
|
|
7
|
+
const type = reference.type ? reference.type : 'ReferenceManyField';
|
|
8
|
+
return (
|
|
9
|
+
<Tab key={reference.reference} label={reference.tab || reference.reference}>
|
|
10
|
+
{type === 'ReferenceManyField' && (
|
|
11
|
+
<ReferenceManyField
|
|
12
|
+
fullWidth
|
|
13
|
+
reference={reference.reference}
|
|
14
|
+
//target={[...reference.target]}
|
|
15
|
+
target={reference.target}
|
|
16
|
+
//addLabel={false}
|
|
17
|
+
pagination={<ExtendedPagination />}
|
|
18
|
+
>
|
|
19
|
+
<AutoDataGrid
|
|
20
|
+
schema={reference?.schema}
|
|
21
|
+
bulkActions={reference?.BulkActions}
|
|
22
|
+
/>
|
|
23
|
+
</ReferenceManyField>
|
|
24
|
+
)}
|
|
25
|
+
|
|
26
|
+
{type === 'ReferenceArrayField' && (
|
|
27
|
+
<ReferenceArrayField
|
|
28
|
+
fullWidth
|
|
29
|
+
reference={reference.reference}
|
|
30
|
+
//target={[...reference.target]}
|
|
31
|
+
source={reference.target}
|
|
32
|
+
//addLabel={false}
|
|
33
|
+
pagination={<ExtendedPagination />}
|
|
34
|
+
>
|
|
35
|
+
<AutoDataGrid
|
|
36
|
+
schema={reference.schema}
|
|
37
|
+
bulkActions={reference?.BulkActions}
|
|
38
|
+
/>
|
|
39
|
+
</ReferenceArrayField>
|
|
40
|
+
)}
|
|
41
|
+
</Tab>
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export default AutoReferenceTab;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Tab, useTranslate } from 'react-admin';
|
|
2
|
+
import { AttributeToField } from './AttributeToField';
|
|
3
|
+
import IDashAutoAdminAttribute from '../interfaces/IDashAutoAdminAttribute';
|
|
4
|
+
import IDashAutoAdminFormOptions from '../interfaces/IDashAutoAdminFormOptions';
|
|
5
|
+
import IDashAutoAdminResourceConfig from '../interfaces/IDashAutoAdminResourceConfig';
|
|
6
|
+
import groupByTabs from '../utils/groupByTabs';
|
|
7
|
+
//import { TabbedShowLayout } from 'react-admin';
|
|
8
|
+
|
|
9
|
+
export const AutoTabs = (
|
|
10
|
+
resourceConfig: IDashAutoAdminResourceConfig,
|
|
11
|
+
schema: IDashAutoAdminAttribute[],
|
|
12
|
+
options?: IDashAutoAdminFormOptions,
|
|
13
|
+
) => {
|
|
14
|
+
const translate = useTranslate();
|
|
15
|
+
return groupByTabs(schema).map((groupOfAttributes) => {
|
|
16
|
+
const label = groupOfAttributes[0].tab || options?.label || '';
|
|
17
|
+
const translatedLabel = translate(`dash-auto-admin-tabs.${label}`, { _: label });
|
|
18
|
+
// console.log("TAB", label);
|
|
19
|
+
return (
|
|
20
|
+
<Tab key={'tab_' + label} label={translatedLabel}>
|
|
21
|
+
|
|
22
|
+
{groupOfAttributes
|
|
23
|
+
.filter((attribute) => attribute?.inShow !== false)
|
|
24
|
+
.map((attribute, idx) =>
|
|
25
|
+
AttributeToField('view', resourceConfig, attribute, idx, options),
|
|
26
|
+
)}
|
|
27
|
+
</Tab>
|
|
28
|
+
);
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export default AutoTabs;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React, { FC, useContext } from 'react';
|
|
2
|
+
|
|
3
|
+
import { Pagination, ListContext } from 'react-admin';
|
|
4
|
+
import { PaginationProps } from 'react-admin';
|
|
5
|
+
|
|
6
|
+
// Safe hook that doesn't throw when context is missing
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
|
+
const useSafeListContext = (): any => {
|
|
9
|
+
const context = useContext(ListContext);
|
|
10
|
+
return context ?? null;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const ExtendedPagination:FC<PaginationProps> = (props) => {
|
|
14
|
+
const list = useSafeListContext();
|
|
15
|
+
return list && list.total > list.perPage ? (
|
|
16
|
+
// @ts-ignore - pageSizeOptions prop compatibility
|
|
17
|
+
<Pagination pageSizeOptions={[25, 50, 100, 250, 500, 1000]} {...props} />
|
|
18
|
+
) : (
|
|
19
|
+
<></>
|
|
20
|
+
);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default ExtendedPagination;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Chip } from '@mui/material';
|
|
2
|
+
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import invertMap from '../../utils/invertMap';
|
|
5
|
+
|
|
6
|
+
const ListStringsField = ({
|
|
7
|
+
record,
|
|
8
|
+
source,
|
|
9
|
+
map,
|
|
10
|
+
}: {
|
|
11
|
+
record?: any;
|
|
12
|
+
source: string;
|
|
13
|
+
label: string;
|
|
14
|
+
map?: any;
|
|
15
|
+
}) => {
|
|
16
|
+
const invertedMap = invertMap(map);
|
|
17
|
+
return (
|
|
18
|
+
<>
|
|
19
|
+
{record[source].map((item: string) => [
|
|
20
|
+
<Chip
|
|
21
|
+
key={item}
|
|
22
|
+
label={invertedMap && invertedMap[item] ? invertedMap[item] : item}
|
|
23
|
+
/>,
|
|
24
|
+
<> </>,
|
|
25
|
+
])}
|
|
26
|
+
</>
|
|
27
|
+
);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
ListStringsField.defaultProps = { addLabel: true };
|
|
31
|
+
|
|
32
|
+
export default ListStringsField;
|