@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,223 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { memo } from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import {DASHAppConstants} from 'dash-constants';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
useResourceContext,
|
|
8
|
+
useRecordContext,
|
|
9
|
+
useRedirect,
|
|
10
|
+
|
|
11
|
+
} from 'react-admin';
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
RaRecord
|
|
15
|
+
} from 'react-admin/src';
|
|
16
|
+
|
|
17
|
+
import useVirtualHash from '../../hooks/useVirtualHash';
|
|
18
|
+
import IDashAutoAdminResourceConfig from '../../interfaces/IDashAutoAdminResourceConfig';
|
|
19
|
+
import { IconButton, Tooltip } from '@mui/material';
|
|
20
|
+
|
|
21
|
+
import { Add, Edit, Visibility, Delete } from '@mui/icons-material'
|
|
22
|
+
import { DeleteWithConfirmButton } from 'react-admin';
|
|
23
|
+
import { useNavigate } from 'react-router';
|
|
24
|
+
const URL_PREFIX = DASHAppConstants.system.URL_PREFIX;
|
|
25
|
+
/* @ts-ignore Expected Cannot use namespace 'RaRecord' as a type.ts(2709) */
|
|
26
|
+
interface Props<RecordType extends RaRecord = any> {
|
|
27
|
+
label?: string;
|
|
28
|
+
record?: RecordType;
|
|
29
|
+
resource?: string;
|
|
30
|
+
navigate?: (record?: RecordType) => string;
|
|
31
|
+
navigation?: 'redirect' | 'virtualhash';
|
|
32
|
+
mode: 'show' | 'create' | 'edit' | 'destroy' | 'custom';
|
|
33
|
+
size?: 'small' | 'medium' | 'large';
|
|
34
|
+
scrollToTop?: boolean;
|
|
35
|
+
resourceConfig?: IDashAutoAdminResourceConfig;
|
|
36
|
+
children?: React.JSX.Element;
|
|
37
|
+
showIcon?: boolean;
|
|
38
|
+
title?: string;
|
|
39
|
+
icon?: React.JSX.Element;
|
|
40
|
+
}
|
|
41
|
+
/* @ts-ignore Expected Cannot use namespace 'RaRecord' as a type.ts(2709) */
|
|
42
|
+
export type ShowButtonProps<RecordType extends RaRecord = any> =
|
|
43
|
+
Props<RecordType> /*& ButtonProps*/;
|
|
44
|
+
|
|
45
|
+
/* @ts-ignore Expected Cannot use namespace 'RaRecord' as a type.ts(2709) */
|
|
46
|
+
export type IQuickButton<RecordType extends RaRecord = any> = ShowButtonProps<RecordType>;
|
|
47
|
+
|
|
48
|
+
const scrollStates = {
|
|
49
|
+
true: { _scrollToTop: true },
|
|
50
|
+
false: {},
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const inferModeFromUrl = (url: String) => {
|
|
54
|
+
|
|
55
|
+
if (url.includes('create')) return 'create';
|
|
56
|
+
if (url.includes('edit')) return 'edit';
|
|
57
|
+
return 'show';
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
/* @ts-ignore Expected Cannot use namespace 'RaRecord' as a type.ts(2709) */
|
|
61
|
+
const DashResourceButton = <RecordType extends RaRecord = any>(
|
|
62
|
+
props: IQuickButton<RecordType>,
|
|
63
|
+
) => {
|
|
64
|
+
const redirect = useRedirect();
|
|
65
|
+
//const redirect = useNavigate();
|
|
66
|
+
|
|
67
|
+
const ComponentType = props.children?.type || IconButton;
|
|
68
|
+
const componentProps = { ...props, ...props.children?.props };
|
|
69
|
+
|
|
70
|
+
let {
|
|
71
|
+
navigate,
|
|
72
|
+
scrollToTop,
|
|
73
|
+
mode,
|
|
74
|
+
size,
|
|
75
|
+
navigation,
|
|
76
|
+
resourceConfig,
|
|
77
|
+
record: _inputRecord,
|
|
78
|
+
resource: _inputResource,
|
|
79
|
+
showIcon = true,
|
|
80
|
+
title,
|
|
81
|
+
icon,
|
|
82
|
+
...rest
|
|
83
|
+
} = componentProps;
|
|
84
|
+
|
|
85
|
+
const resource = _inputResource || useResourceContext();
|
|
86
|
+
const record = _inputRecord || useRecordContext();
|
|
87
|
+
if (!size) { size = 'small' }
|
|
88
|
+
|
|
89
|
+
/*if(navigate && !mode) {
|
|
90
|
+
mode = inferModeFromUrl(navigate(record));
|
|
91
|
+
} */
|
|
92
|
+
|
|
93
|
+
if (!navigation) {
|
|
94
|
+
|
|
95
|
+
navigation = resourceConfig?.drawer ?
|
|
96
|
+
(mode === 'edit' && resourceConfig.drawerOptions?.edit === false) ? 'redirect' :
|
|
97
|
+
(mode === 'show' && resourceConfig.drawerOptions?.show === false) ? 'redirect' :
|
|
98
|
+
(mode === 'create' && resourceConfig.drawerOptions?.create === false) ? 'redirect' :
|
|
99
|
+
'virtualhash'
|
|
100
|
+
: 'redirect';
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (!navigate) {
|
|
104
|
+
navigate = (_record) => {
|
|
105
|
+
const url = `${URL_PREFIX}${resource}/${navigation === 'virtualhash' ? 'inline' : ''}${mode === 'edit' ? '/' + _record.id + '/edit' : mode === 'show' ? '/' + _record.id + '/show' : mode === 'create' ? '/create' : ''}`;
|
|
106
|
+
return url;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
//if (!record) return null;
|
|
112
|
+
|
|
113
|
+
const { setVirtualHash } = useVirtualHash();
|
|
114
|
+
|
|
115
|
+
const handleOnClick = (e: React.MouseEvent) => {
|
|
116
|
+
|
|
117
|
+
e.preventDefault();
|
|
118
|
+
e.stopPropagation();
|
|
119
|
+
|
|
120
|
+
if(componentProps.onClick) {
|
|
121
|
+
componentProps.onClick(e);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (navigation === 'virtualhash') {
|
|
125
|
+
|
|
126
|
+
const vhash = navigate(record);
|
|
127
|
+
//const vhash = `${URL_PREFIX}${resource}/${navigate ? navigate(record) : record.id}`;
|
|
128
|
+
|
|
129
|
+
setVirtualHash(vhash);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (navigation === 'redirect') {
|
|
133
|
+
|
|
134
|
+
if (mode === "create") {
|
|
135
|
+
redirect(mode, resource)
|
|
136
|
+
} else {
|
|
137
|
+
redirect(mode, resource, record.id);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const _styles = size === 'small' ? {
|
|
145
|
+
'& .MuiButton-startIcon': { margin: 0 },
|
|
146
|
+
'& .MuiButton-text': { paddingLeft: '4px' },
|
|
147
|
+
borderRadius: '50% !important',
|
|
148
|
+
padding: 0,
|
|
149
|
+
minWidth: '30px',
|
|
150
|
+
width: '30px',
|
|
151
|
+
height: '30px',
|
|
152
|
+
overflow: 'hidden'
|
|
153
|
+
} : {}
|
|
154
|
+
|
|
155
|
+
const _label = size === 'small' ? '' : props?.label;
|
|
156
|
+
|
|
157
|
+
if (mode === "destroy") {
|
|
158
|
+
return <Tooltip title={props?.label}><DeleteWithConfirmButton label={_label} sx={{ ..._styles }} size={size} record={record} /></Tooltip>
|
|
159
|
+
} else if (mode === "custom") {
|
|
160
|
+
// Remove title prop from rest to avoid conflict with Tooltip
|
|
161
|
+
const { title, ...restWithoutTitle } = rest as any;
|
|
162
|
+
return <Tooltip title={props?.label}><ComponentType
|
|
163
|
+
onClick={(e) => handleOnClick(e)}
|
|
164
|
+
state={scrollStates[String(scrollToTop)]}
|
|
165
|
+
size={size}
|
|
166
|
+
{...restWithoutTitle}
|
|
167
|
+
/></Tooltip>
|
|
168
|
+
} else {
|
|
169
|
+
// If showIcon is false and children are provided, render children with click handler
|
|
170
|
+
if (!showIcon && props.children) {
|
|
171
|
+
return React.cloneElement(props.children, {
|
|
172
|
+
onClick: (e: React.MouseEvent) => handleOnClick(e),
|
|
173
|
+
...props.children.props
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// For cases with no children, we need to keep the title prop
|
|
178
|
+
const { title, ...restWithoutTitle } = rest as any;
|
|
179
|
+
|
|
180
|
+
const button = <ComponentType
|
|
181
|
+
onClick={(e) => handleOnClick(e)}
|
|
182
|
+
state={scrollStates[String(scrollToTop)]}
|
|
183
|
+
size={size}
|
|
184
|
+
title={props.children ? undefined : title} // Keep title only when no children
|
|
185
|
+
{...restWithoutTitle}
|
|
186
|
+
>
|
|
187
|
+
{showIcon && (
|
|
188
|
+
icon ? icon :
|
|
189
|
+
mode === 'edit' ? <Edit /> :
|
|
190
|
+
mode === 'show' ? <Visibility /> :
|
|
191
|
+
mode === 'create' ? <Add /> :
|
|
192
|
+
mode
|
|
193
|
+
)}
|
|
194
|
+
</ComponentType>
|
|
195
|
+
|
|
196
|
+
return <Tooltip title={props?.label || ''}>
|
|
197
|
+
{button}
|
|
198
|
+
</Tooltip>;
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
DashResourceButton.propTypes = {
|
|
203
|
+
icon: PropTypes.element,
|
|
204
|
+
label: PropTypes.string,
|
|
205
|
+
record: PropTypes.any,
|
|
206
|
+
scrollToTop: PropTypes.bool,
|
|
207
|
+
navigate: PropTypes.func,
|
|
208
|
+
navigation: PropTypes.string,
|
|
209
|
+
children: PropTypes.element,
|
|
210
|
+
showIcon: PropTypes.bool,
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
export default memo(
|
|
214
|
+
DashResourceButton,
|
|
215
|
+
(props: ShowButtonProps, nextProps: ShowButtonProps) =>
|
|
216
|
+
props.resource === nextProps.resource &&
|
|
217
|
+
(props.record && nextProps.record
|
|
218
|
+
? props.record.id === nextProps.record.id
|
|
219
|
+
: props.record == nextProps.record) && // eslint-disable-line eqeqeq
|
|
220
|
+
props.label === nextProps.label &&
|
|
221
|
+
props.showIcon === nextProps.showIcon &&
|
|
222
|
+
props.icon === nextProps.icon,
|
|
223
|
+
);
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { EditButton } from 'react-admin';
|
|
3
|
+
import { DeleteButton } from 'react-admin';
|
|
4
|
+
import { DeleteWithConfirmButton } from 'react-admin';
|
|
5
|
+
import { WithRecord } from 'react-admin';
|
|
6
|
+
import { ShowButton } from 'react-admin';
|
|
7
|
+
import IToolbarButton from '../../interfaces/IToolbarButton';
|
|
8
|
+
import DashResourceButton from './DashResourceButton';
|
|
9
|
+
/**
|
|
10
|
+
* Renders a view button for a list of resources, based on the provided resource configuration.
|
|
11
|
+
* If the resource configuration does not have a `view` property set to `false`, and there is no `listViewButton` property,
|
|
12
|
+
* a default `ShowButton` component is rendered.
|
|
13
|
+
* If the `listViewButton` property is enabled, either the custom component specified in `listViewButton.component` is rendered,
|
|
14
|
+
* or a default `ShowButton` component is rendered with the props specified in `listViewButton.props`.
|
|
15
|
+
* If the `listViewButton` property is not enabled, `null` is returned.
|
|
16
|
+
*
|
|
17
|
+
* @param props - The props for the `ListViewButton` component.
|
|
18
|
+
* @param props.resourceConfig - The resource configuration object.
|
|
19
|
+
* @returns {React.ReactElement} A React component.
|
|
20
|
+
*/
|
|
21
|
+
export const ListViewButton:FC<IToolbarButton> = (props) => {
|
|
22
|
+
const { resourceConfig } = props;
|
|
23
|
+
let Component = ShowButton;
|
|
24
|
+
if (!resourceConfig) return <Component/>;
|
|
25
|
+
if ( resourceConfig.listViewButton) {
|
|
26
|
+
if ( resourceConfig.listViewButton.component ) Component = resourceConfig.listViewButton.component;
|
|
27
|
+
if (resourceConfig.listViewButton.enabled === false || resourceConfig?.view === false) return <></>;
|
|
28
|
+
if(!resourceConfig.listViewButton?.size) { resourceConfig.listViewButton.size = 'small' };
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
/*const btnProps = {
|
|
34
|
+
...resourceConfig.listViewButton?.props || {},
|
|
35
|
+
...(resourceConfig.drawer === true && resourceConfig.drawerOptions?.view !== false ? {
|
|
36
|
+
mode: 'show',
|
|
37
|
+
navigation: 'virtualhash',
|
|
38
|
+
navigate: (record) => {
|
|
39
|
+
|
|
40
|
+
return 'inline/' + record.id + '/show';
|
|
41
|
+
},
|
|
42
|
+
} : {}),
|
|
43
|
+
};*/
|
|
44
|
+
|
|
45
|
+
const btnProps = {
|
|
46
|
+
mode: 'show',
|
|
47
|
+
resourceConfig: resourceConfig,
|
|
48
|
+
...resourceConfig.listViewButton?.props || {},
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//if (resourceConfig.drawer === true && resourceConfig.drawerOptions?.view !== false) {
|
|
53
|
+
//return <DashResourceButton {...btnProps} ><Component /></DashResourceButton>;
|
|
54
|
+
//}
|
|
55
|
+
|
|
56
|
+
//return <Component {...btnProps} />;
|
|
57
|
+
|
|
58
|
+
return <DashResourceButton {...btnProps} resourceConfig={resourceConfig} {...resourceConfig.listDeleteButton?.props || {}} />;
|
|
59
|
+
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Renders an edit button for a list of resources, based on the provided resource configuration.
|
|
65
|
+
* If the resource configuration does not have an `edit` property set to `false`, and there is no `listEditButton` property,
|
|
66
|
+
* a default `EditButton` component is rendered.
|
|
67
|
+
* If the `listEditButton` property is enabled, either the custom component specified in `listEditButton.component` is rendered,
|
|
68
|
+
* or a default `EditButton` component is rendered with the props specified in `listEditButton.props`.
|
|
69
|
+
* If the `listEditButton` property is not enabled, `null` is returned.
|
|
70
|
+
*
|
|
71
|
+
* @param props - The props for the `ListEditButton` component.
|
|
72
|
+
* @param props.resourceConfig - The resource configuration object.
|
|
73
|
+
* @returns {React.ReactElement} A React component.
|
|
74
|
+
*/
|
|
75
|
+
export const ListEditButton:FC<IToolbarButton> = (props) => {
|
|
76
|
+
const { resourceConfig } = props;
|
|
77
|
+
let Component = EditButton;
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
if (!resourceConfig) {
|
|
81
|
+
return <Component />;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
if ( resourceConfig.listEditButton) {
|
|
86
|
+
if ( resourceConfig.listEditButton.component ) Component = resourceConfig.listEditButton.component;
|
|
87
|
+
if (resourceConfig.listEditButton.enabled === false || resourceConfig?.edit === false) return <></>;
|
|
88
|
+
if(resourceConfig.listViewButton && !resourceConfig.listViewButton?.size) { resourceConfig.listViewButton.size = 'small' };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return <DashResourceButton mode='edit' resourceConfig={resourceConfig} {...resourceConfig.listViewButton?.props || {}} />;
|
|
92
|
+
|
|
93
|
+
//if (resourceConfig.drawer === true && resourceConfig.drawerOptions?.edit !== false) {
|
|
94
|
+
//return <DashResourceButton mode='edit' resourceConfig={resourceConfig} {...resourceConfig.listViewButton?.props || {}} ><Component /></DashResourceButton>;
|
|
95
|
+
//}
|
|
96
|
+
|
|
97
|
+
//return <Component />;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Renders a delete button for a list of resources, based on the provided resource configuration.
|
|
102
|
+
* If the resource configuration does not have a `delete` property set to `false`, and there is no `listDeleteButton` property,
|
|
103
|
+
* a default `DeleteButton` component is rendered.
|
|
104
|
+
* If the `listDeleteButton` property is enabled, either the custom component specified in `listDeleteButton.component` is rendered,
|
|
105
|
+
* or a default `DeleteButton` component is rendered with the props specified in `listDeleteButton.props`.
|
|
106
|
+
* If the `listDeleteButton` property is not enabled, `null` is returned.
|
|
107
|
+
* If the `listDeleteButton.props.confirm` property is set, a `DeleteWithConfirmButton` component is rendered instead.
|
|
108
|
+
*
|
|
109
|
+
* @param props - The props for the `ListDeleteButton` component.
|
|
110
|
+
* @param props.resourceConfig - The resource configuration object.
|
|
111
|
+
* @returns {React.ReactElement} A React component.
|
|
112
|
+
*/
|
|
113
|
+
export const ListDeleteButton:FC<IToolbarButton> = (props) => {
|
|
114
|
+
const { resourceConfig } = props;
|
|
115
|
+
let Component = DeleteButton;
|
|
116
|
+
if (!resourceConfig) return <Component/>;
|
|
117
|
+
if ( resourceConfig.listDeleteButton) {
|
|
118
|
+
if ( resourceConfig.listDeleteButton.component ) Component = resourceConfig.listDeleteButton.component;
|
|
119
|
+
if (resourceConfig.listDeleteButton.enabled === false || resourceConfig?.delete === false) return <></>;
|
|
120
|
+
if(!resourceConfig.listViewButton?.size) { resourceConfig.listViewButton.size = 'small' };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
/*if (resourceConfig.listDeleteButton?.confirm) {
|
|
125
|
+
return <WithRecord
|
|
126
|
+
render={(record) => (
|
|
127
|
+
<DeleteWithConfirmButton {...resourceConfig.listDeleteButton?.props || {}} record={record} />
|
|
128
|
+
)}
|
|
129
|
+
/>;
|
|
130
|
+
}
|
|
131
|
+
return <DeleteButton {...resourceConfig.listDeleteButton?.props || {}} />;*/
|
|
132
|
+
|
|
133
|
+
//return <DashResourceButton mode='destroy' resourceConfig={resourceConfig} {...resourceConfig.listDeleteButton?.props || {}} ><Component /></DashResourceButton>;
|
|
134
|
+
|
|
135
|
+
return <DashResourceButton mode='destroy' resourceConfig={resourceConfig} {...resourceConfig.listDeleteButton?.props || {}} />;
|
|
136
|
+
|
|
137
|
+
};
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { CreateButton } from 'react-admin';
|
|
2
|
+
import { FC } from 'react';
|
|
3
|
+
import { ExportButton } from 'react-admin';
|
|
4
|
+
import { ListButton } from 'react-admin';
|
|
5
|
+
import { EditButton } from 'react-admin';
|
|
6
|
+
import { DeleteButton } from 'react-admin';
|
|
7
|
+
import DashAutoAdminSaveButton from '../../DashAutoAdminSaveButton';
|
|
8
|
+
import { DeleteWithConfirmButton } from 'react-admin';
|
|
9
|
+
import { WithRecord } from 'react-admin';
|
|
10
|
+
import { SaveButton } from 'react-admin';
|
|
11
|
+
import IToolbarButton from '../../interfaces/IToolbarButton';
|
|
12
|
+
import IAutoGridButton from '../../interfaces/IDashAutoGridButton';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Checks if the current mode enables the display of a button.
|
|
16
|
+
*
|
|
17
|
+
* @param modes - An optional object that specifies which modes should enable the button.
|
|
18
|
+
* @param mode - The current mode of the application.
|
|
19
|
+
* @returns `true` if the button should be displayed, `false` otherwise.
|
|
20
|
+
*/
|
|
21
|
+
const checkIfModeEnablesButton = (modes?:IAutoGridButton['modes'], mode?:IToolbarButton['mode']) => {
|
|
22
|
+
if (!modes) return true;
|
|
23
|
+
if (!mode) return true;
|
|
24
|
+
if (modes[mode] === false) return false;
|
|
25
|
+
return true;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Renders a toolbar save button based on the provided resource configuration.
|
|
31
|
+
*
|
|
32
|
+
* The button is only rendered if the `toolbarSaveButton` property is defined and enabled.
|
|
33
|
+
* The button is further conditionally rendered based on the current mode and the `modes` property of the `toolbarSaveButton`.
|
|
34
|
+
*
|
|
35
|
+
* If the `toolbarSaveButton` is enabled and the current mode allows it, the button can either be a custom component or a default `AutoAdminSaveButton` component.
|
|
36
|
+
*
|
|
37
|
+
* @param props - The component props, including the `resourceConfig` and the current `mode`.
|
|
38
|
+
* @returns The rendered toolbar save button or `null` if the button should not be rendered.
|
|
39
|
+
*/
|
|
40
|
+
export const ToolbarSaveButton:FC<IToolbarButton> = (props) => {
|
|
41
|
+
|
|
42
|
+
const { resourceConfig, mode } = props;
|
|
43
|
+
|
|
44
|
+
if (!resourceConfig) { return <SaveButton/>; }
|
|
45
|
+
if(!resourceConfig.toolbarSaveButton) { return <SaveButton/>; }
|
|
46
|
+
|
|
47
|
+
if (resourceConfig.toolbarSaveButton?.enabled) {
|
|
48
|
+
if (checkIfModeEnablesButton(resourceConfig.toolbarSaveButton.modes, mode)) {
|
|
49
|
+
const buttonProps = {
|
|
50
|
+
...(resourceConfig.toolbarSaveButton?.props || {}),
|
|
51
|
+
alwaysEnable: resourceConfig?.saveButtonAlwaysEnabled === true ? true : false,
|
|
52
|
+
};
|
|
53
|
+
return resourceConfig.toolbarSaveButton?.component ? <resourceConfig.toolbarSaveButton.component {...buttonProps} /> : <DashAutoAdminSaveButton {...buttonProps} />;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return null;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Renders a toolbar list button based on the provided resource configuration.
|
|
62
|
+
*
|
|
63
|
+
* The button is only rendered if the `list` property in the resource configuration is not `false` and the `toolbarListButton` property is defined.
|
|
64
|
+
* The button is further conditionally rendered based on the current mode and the `modes` property of the `toolbarListButton`.
|
|
65
|
+
*
|
|
66
|
+
* If the `toolbarListButton` is enabled and the current mode allows it, the button can either be a custom component or a default `ListButton` component.
|
|
67
|
+
*
|
|
68
|
+
* @param props - The component props, including the `resourceConfig` and the current `mode`.
|
|
69
|
+
* @returns The rendered toolbar list button or `null` if the button should not be rendered.
|
|
70
|
+
*/
|
|
71
|
+
export const ToolbarListButton:FC<IToolbarButton> = (props) => {
|
|
72
|
+
const { resourceConfig, mode } = props;
|
|
73
|
+
if (!resourceConfig) return <ListButton/>;
|
|
74
|
+
if (!!(resourceConfig?.list !== false) && (resourceConfig?.toolbarListButton && !!(resourceConfig?.toolbarListButton.enabled !== false))) {
|
|
75
|
+
return checkIfModeEnablesButton(resourceConfig.toolbarListButton.modes, mode) ? <ListButton/> : null;
|
|
76
|
+
} else if (resourceConfig.toolbarListButton?.enabled) {
|
|
77
|
+
if (checkIfModeEnablesButton(resourceConfig.toolbarEditButton.modes, mode)) {
|
|
78
|
+
return resourceConfig.toolbarListButton?.component ? <resourceConfig.toolbarListButton.component {...resourceConfig.toolbarListButton?.props || {}} /> : <ListButton {...resourceConfig.toolbarListButton?.props || {}} />;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Renders a toolbar edit button based on the provided resource configuration.
|
|
86
|
+
*
|
|
87
|
+
* The button is only rendered if the `edit` property in the resource configuration is not `false` and the `toolbarEditButton` property is defined.
|
|
88
|
+
* The button is further conditionally rendered based on the current mode and the `modes` property of the `toolbarEditButton`.
|
|
89
|
+
*
|
|
90
|
+
* If the `toolbarEditButton` is enabled and the current mode allows it, the button can either be a custom component or a default `EditButton` component.
|
|
91
|
+
*
|
|
92
|
+
* @param props - The component props, including the `resourceConfig` and the current `mode`.
|
|
93
|
+
* @returns The rendered toolbar edit button or `null` if the button should not be rendered.
|
|
94
|
+
*/
|
|
95
|
+
export const ToolbarEditButton:FC<IToolbarButton> = (props) => {
|
|
96
|
+
const { resourceConfig, mode } = props;
|
|
97
|
+
if (!resourceConfig) return <EditButton/>;
|
|
98
|
+
if (!!(resourceConfig?.edit !== false) && (resourceConfig?.toolbarEditButton && !!(resourceConfig?.toolbarEditButton.enabled !== false))) {
|
|
99
|
+
return checkIfModeEnablesButton(resourceConfig.toolbarEditButton.modes, mode) ? <EditButton/> : null;
|
|
100
|
+
} else if (resourceConfig.toolbarEditButton?.enabled) {
|
|
101
|
+
if (checkIfModeEnablesButton(resourceConfig.toolbarEditButton.modes, mode)) {
|
|
102
|
+
return resourceConfig.toolbarEditButton?.component ? <resourceConfig.toolbarEditButton.component {...resourceConfig.toolbarEditButton?.props || {}} /> : <EditButton {...resourceConfig.toolbarEditButton?.props || {}} />;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return null;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Renders a toolbar create button based on the provided resource configuration.
|
|
110
|
+
*
|
|
111
|
+
* The button is only rendered if the `create` property in the resource configuration is not `false` and the `toolbarCreateButton` property is defined.
|
|
112
|
+
* The button is further conditionally rendered based on the current mode and the `modes` property of the `toolbarCreateButton`.
|
|
113
|
+
*
|
|
114
|
+
* If the `toolbarCreateButton` is enabled and the current mode allows it, the button can either be a custom component or a default `CreateButton` component.
|
|
115
|
+
*
|
|
116
|
+
* @param props - The component props, including the `resourceConfig` and the current `mode`.
|
|
117
|
+
* @returns The rendered toolbar create button or `null` if the button should not be rendered.
|
|
118
|
+
*/
|
|
119
|
+
export const ToolbarCreateButton:FC<IToolbarButton> = (props) => {
|
|
120
|
+
const { resourceConfig, mode } = props;
|
|
121
|
+
if (!resourceConfig) return <CreateButton/>;
|
|
122
|
+
if (!!(resourceConfig?.create !== false) && (resourceConfig?.toolbarCreateButton && !!(resourceConfig?.toolbarCreateButton.enabled !== false))) {
|
|
123
|
+
return checkIfModeEnablesButton(resourceConfig.toolbarCreateButton.modes, mode) ? <CreateButton/> : null;
|
|
124
|
+
} else if (resourceConfig.toolbarCreateButton?.enabled) {
|
|
125
|
+
if (checkIfModeEnablesButton(resourceConfig.toolbarCreateButton.modes, mode)) {
|
|
126
|
+
return resourceConfig.toolbarCreateButton?.component ? <resourceConfig.toolbarCreateButton.component {...resourceConfig.toolbarCreateButton?.props || {}} /> : <CreateButton {...resourceConfig.toolbarCreateButton?.props || {}} />;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return null;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Renders a toolbar delete button based on the provided resource configuration.
|
|
134
|
+
*
|
|
135
|
+
* The button is only rendered if the `delete` property in the resource configuration is not `false` and the `toolbarDeleteButton` property is defined.
|
|
136
|
+
* The button is further conditionally rendered based on the current mode and the `modes` property of the `toolbarDeleteButton`.
|
|
137
|
+
*
|
|
138
|
+
* If the `toolbarDeleteButton` is enabled and the current mode allows it, the button can either be a custom component or a default `DeleteButton` component.
|
|
139
|
+
* If the `toolbarDeleteButton` has a `confirm` property, the button will be rendered with a confirmation dialog.
|
|
140
|
+
*
|
|
141
|
+
* @param props - The component props, including the `resourceConfig` and the current `mode`.
|
|
142
|
+
* @returns The rendered toolbar delete button or `null` if the button should not be rendered.
|
|
143
|
+
*/
|
|
144
|
+
export const ToolbarDeleteButton:FC<IToolbarButton> = (props) => {
|
|
145
|
+
const { resourceConfig, mode } = props;
|
|
146
|
+
if (!resourceConfig) return <DeleteButton/>;
|
|
147
|
+
if (!!(resourceConfig?.delete !== false) && !!resourceConfig?.toolbarDeleteButton) {
|
|
148
|
+
return checkIfModeEnablesButton(resourceConfig.toolbarDeleteButton.modes, mode) ? <DeleteButton/> : null;
|
|
149
|
+
} else if (!!resourceConfig?.toolbarDeleteButton && !!(resourceConfig?.toolbarDeleteButton.enabled !== false)) {
|
|
150
|
+
if (checkIfModeEnablesButton(resourceConfig.toolbarCreateButton.modes, mode)) {
|
|
151
|
+
if (!!resourceConfig.toolbarDeleteButton?.props && resourceConfig.toolbarDeleteButton.props?.confirm) {
|
|
152
|
+
return <WithRecord
|
|
153
|
+
render={(record) => (
|
|
154
|
+
<DeleteWithConfirmButton record={record} />
|
|
155
|
+
)}
|
|
156
|
+
/>;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return resourceConfig.toolbarDeleteButton?.component ? <resourceConfig.toolbarDeleteButton.component {...resourceConfig.toolbarDeleteButton?.props || {}} /> : <DeleteButton {...resourceConfig.toolbarDeleteButton?.props || {}} />;
|
|
160
|
+
}
|
|
161
|
+
return null;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Renders a toolbar export button based on the provided resource configuration.
|
|
166
|
+
*
|
|
167
|
+
* The button is only rendered if the `exporter` property in the resource configuration is not `false` and the `toolbarExportButton` property is defined.
|
|
168
|
+
* The button is further conditionally rendered based on the current mode and the `modes` property of the `toolbarExportButton`.
|
|
169
|
+
*
|
|
170
|
+
* If the `toolbarExportButton` is enabled and the current mode allows it, the button can either be a custom component or a default `ExportButton` component.
|
|
171
|
+
*
|
|
172
|
+
* @param props - The component props, including the `resourceConfig` and the current `mode`.
|
|
173
|
+
* @returns The rendered toolbar export button or `null` if the button should not be rendered.
|
|
174
|
+
*/
|
|
175
|
+
export const ToolbarExportButton:FC<IToolbarButton> = (props) => {
|
|
176
|
+
const { resourceConfig, mode } = props;
|
|
177
|
+
if (!resourceConfig) return <ExportButton/>;
|
|
178
|
+
if (!!(resourceConfig?.exporter !== false) && (resourceConfig?.toolbarExportButton && !!(resourceConfig?.toolbarExportButton.enabled !== false))) {
|
|
179
|
+
return checkIfModeEnablesButton(resourceConfig.toolbarExportButton.modes, mode) ? <ExportButton/> : null;
|
|
180
|
+
} else if (resourceConfig.toolbarExportButton?.enabled) {
|
|
181
|
+
if (checkIfModeEnablesButton(resourceConfig.toolbarExportButton.modes, mode)) {
|
|
182
|
+
return resourceConfig.toolbarExportButton?.component ? <resourceConfig.toolbarExportButton.component {...resourceConfig.toolbarExportButton?.props || {}} /> : <ExportButton {...resourceConfig.toolbarExportButton?.props || {}} />;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return null;
|
|
186
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export class SimpleLogger {
|
|
2
|
+
private loggerID = Math.random().toString(32).slice(2, 6);
|
|
3
|
+
|
|
4
|
+
constructor(private prefix: string, private debug: boolean) {}
|
|
5
|
+
|
|
6
|
+
private getLogString() {
|
|
7
|
+
return `ReactAutoAdmin | ${this.prefix} [${this.loggerID}]`;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
public get log() {
|
|
11
|
+
if (!this.debug) {
|
|
12
|
+
return () => {};
|
|
13
|
+
}
|
|
14
|
+
const boundLogFn: (...any) => void = console.log.bind(
|
|
15
|
+
console,
|
|
16
|
+
`⚪ ${this.getLogString()}`,
|
|
17
|
+
);
|
|
18
|
+
return boundLogFn;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public get warn() {
|
|
22
|
+
if (!this.debug) {
|
|
23
|
+
return () => {};
|
|
24
|
+
}
|
|
25
|
+
const boundLogFn: (...any) => void = console.warn.bind(
|
|
26
|
+
console,
|
|
27
|
+
`🟡 ${this.getLogString()}`,
|
|
28
|
+
);
|
|
29
|
+
return boundLogFn;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public get error() {
|
|
33
|
+
if (!this.debug) {
|
|
34
|
+
return () => {};
|
|
35
|
+
}
|
|
36
|
+
const boundLogFn: (...any) => void = console.error.bind(
|
|
37
|
+
console,
|
|
38
|
+
`🔴 ${this.getLogString()}`,
|
|
39
|
+
);
|
|
40
|
+
return boundLogFn;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
setEnabled(logging: boolean) {
|
|
44
|
+
this.debug = logging;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import IDashAutoAdminResourceConfig from '../interfaces/IDashAutoAdminResourceConfig';
|
|
2
|
+
|
|
3
|
+
const evalActionPermission = (
|
|
4
|
+
resourceConfig: IDashAutoAdminResourceConfig,
|
|
5
|
+
action?: any,
|
|
6
|
+
): boolean => {
|
|
7
|
+
let result = true;
|
|
8
|
+
if (action === null || action === undefined) return true;
|
|
9
|
+
if (!action) return false;
|
|
10
|
+
if (typeof action === 'function') result = action(resourceConfig);
|
|
11
|
+
return result;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default evalActionPermission;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import IDashAutoAdminAttribute from '../interfaces/IDashAutoAdminAttribute';
|
|
2
|
+
|
|
3
|
+
const groupByTabs = (
|
|
4
|
+
schema: IDashAutoAdminAttribute[],
|
|
5
|
+
): IDashAutoAdminAttribute[][] => {
|
|
6
|
+
const tabs: IDashAutoAdminAttribute[][] = [];
|
|
7
|
+
schema.forEach((attribute) => {
|
|
8
|
+
let added = false;
|
|
9
|
+
tabs.forEach((tab) => {
|
|
10
|
+
const name = tab[0].tab;
|
|
11
|
+
if (name === attribute.tab) {
|
|
12
|
+
tab.push(attribute);
|
|
13
|
+
added = true;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
if (!added) {
|
|
17
|
+
tabs.push([attribute]);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
return tabs;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default groupByTabs;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import IDashAutoAdminAttribute from '../interfaces/IDashAutoAdminAttribute';
|
|
2
|
+
|
|
3
|
+
const hasehdGroupByTabs = (
|
|
4
|
+
schema: IDashAutoAdminAttribute[],
|
|
5
|
+
): Array<{ [key: string]: IDashAutoAdminAttribute[] }> => {
|
|
6
|
+
const tabs: Array<{ [key: string]: IDashAutoAdminAttribute[] }> = [];
|
|
7
|
+
const availabletabs = [...new Set(schema.map((item) => item.tab))];
|
|
8
|
+
|
|
9
|
+
availabletabs.forEach((tab) => {
|
|
10
|
+
tabs[tab] = schema.filter((item) => item.tab === tab);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
return tabs;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default hasehdGroupByTabs;
|