@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.
Files changed (176) hide show
  1. package/dist/DashAutoAdminComponentRegistry.js +64 -1
  2. package/dist/DashAutoAdminForm.js +137 -1
  3. package/dist/DashAutoAdminResizableDrawer.js +63 -1
  4. package/dist/DashAutoAdminSaveButton.js +57 -1
  5. package/dist/DashAutoCreate.js +102 -1
  6. package/dist/DashAutoDrawer.js +256 -1
  7. package/dist/DashAutoEdit.js +99 -1
  8. package/dist/DashAutoFiltersGenerator.js +193 -1
  9. package/dist/DashAutoFormGroups.js +118 -1
  10. package/dist/DashAutoFormLayout.js +68 -1
  11. package/dist/DashAutoFormMuiTabs.js +291 -1
  12. package/dist/DashAutoFormTabs.js +132 -1
  13. package/dist/DashAutoGroup.js +27 -1
  14. package/dist/DashAutoLayout.js +31 -1
  15. package/dist/DashAutoList.js +218 -1
  16. package/dist/DashAutoPostFilterForm.js +47 -1
  17. package/dist/DashAutoReferenceTab.js +10 -1
  18. package/dist/DashAutoResource.js +77 -1
  19. package/dist/DashAutoResourceLayout.js +16 -1
  20. package/dist/DashAutoShow.js +195 -1
  21. package/dist/DashAutoTabbedForm.js +244 -1
  22. package/dist/DashAutoTabbedForm.review.js +221 -1
  23. package/dist/DashAutoTabs.js +11 -1
  24. package/dist/DashFilterWrapper.js +62 -1
  25. package/dist/DashRedirect.js +56 -1
  26. package/dist/TabbedLayout.js +38 -1
  27. package/dist/common/DashAutoTitle.js +33 -1
  28. package/dist/common/components/FabButton.js +59 -1
  29. package/dist/common/components/TranslatedLabel.js +60 -1
  30. package/dist/common/settings/Settings.js +196 -1
  31. package/dist/common/settings/SettingsBarIcons.js +61 -1
  32. package/dist/context/DashAutoAdminFormContext.js +15 -1
  33. package/dist/hooks/useAutoAdminLoadingStateMediator.js +36 -1
  34. package/dist/hooks/useAutoAdminTranslate.js +61 -1
  35. package/dist/hooks/useHash.js +24 -1
  36. package/dist/hooks/useLogger.js +20 -1
  37. package/dist/hooks/useRoutePathPattern.js +20 -1
  38. package/dist/hooks/useVirtualHash.js +28 -1
  39. package/dist/index.js +77 -3406
  40. package/dist/list/DashAutoListActions.js +57 -1
  41. package/dist/list/DashAutoListDatagridWrapper.js +68 -1
  42. package/dist/list/DashAutoListDefaultActionsWrapper.js +14 -1
  43. package/dist/list/DashAutoListFilterFormWithButton.js +80 -1
  44. package/dist/list/DashAutoListTopToolbar.js +180 -1
  45. package/dist/mui/AttributeToField.js +576 -1
  46. package/dist/mui/AttributeToInput.js +630 -1
  47. package/dist/mui/AutoAdminResizableDrawer.js +63 -1
  48. package/dist/mui/AutoDataGrid.js +120 -1
  49. package/dist/mui/AutoReferenceFormTab.js +53 -1
  50. package/dist/mui/AutoReferenceTab.js +46 -1
  51. package/dist/mui/AutoTabs.js +19 -1
  52. package/dist/mui/components/ExtendedPagination.js +34 -1
  53. package/dist/mui/components/ListStringField.js +25 -1
  54. package/dist/providers/DashAuthProvider.js +215 -1
  55. package/dist/providers/DashDataProvider.js +310 -1
  56. package/dist/providers/index.js +10 -1
  57. package/dist/react-admin.d.js +0 -0
  58. package/dist/toolbar/buttons/BottomToolbarButtons.js +65 -1
  59. package/dist/toolbar/buttons/DashResourceButton.js +181 -1
  60. package/dist/toolbar/buttons/ListButtons.js +80 -1
  61. package/dist/toolbar/buttons/ToolbarButtons.js +135 -1
  62. package/dist/types/ActionCallback.d.js +0 -0
  63. package/dist/utils/SimpleLogger.js +52 -1
  64. package/dist/utils/enumToChoices.js +5 -1
  65. package/dist/utils/evalActionPermission.js +11 -1
  66. package/dist/utils/groupByTabs.js +21 -1
  67. package/dist/utils/hashedGroupByTabs.js +12 -1
  68. package/dist/utils/invertMap.js +12 -1
  69. package/dist/utils/isClassComponent.js +7 -1
  70. package/dist/utils/isComponent.js +29 -1
  71. package/dist/utils/isEnum.js +5 -1
  72. package/dist/utils/isFC.js +8 -1
  73. package/dist/utils/replaceParams.js +9 -1
  74. package/dist/utils/validate.js +19 -1
  75. package/dist/wrappers/UserAction.js +60 -1
  76. package/dist/wrappers/index.js +4 -1
  77. package/package.json +135 -120
  78. package/src/DashAutoAdminComponentRegistry.tsx +75 -0
  79. package/src/DashAutoAdminForm.tsx +155 -0
  80. package/src/DashAutoAdminResizableDrawer.tsx +69 -0
  81. package/src/DashAutoAdminSaveButton.tsx +116 -0
  82. package/src/DashAutoCreate.tsx +118 -0
  83. package/src/DashAutoDrawer.tsx +288 -0
  84. package/src/DashAutoEdit.tsx +109 -0
  85. package/src/DashAutoFiltersGenerator.tsx +208 -0
  86. package/src/DashAutoFormGroups.tsx +146 -0
  87. package/src/DashAutoFormLayout.tsx.review +113 -0
  88. package/src/DashAutoFormMuiTabs.tsx +368 -0
  89. package/src/DashAutoFormTabs.tsx +177 -0
  90. package/src/DashAutoGroup.tsx +42 -0
  91. package/src/DashAutoLayout.tsx +57 -0
  92. package/src/DashAutoList.tsx +237 -0
  93. package/src/DashAutoPostFilterForm.tsx +35 -0
  94. package/src/DashAutoReferenceTab.tsx +9 -0
  95. package/src/DashAutoResource.tsx +85 -0
  96. package/src/DashAutoResourceLayout.tsx +50 -0
  97. package/src/DashAutoShow.tsx +200 -0
  98. package/src/DashAutoTabbedForm.review.tsx +262 -0
  99. package/src/DashAutoTabbedForm.tsx +324 -0
  100. package/src/DashAutoTabs.tsx +19 -0
  101. package/src/DashFilterWrapper.tsx +43 -0
  102. package/src/DashRedirect.tsx +46 -0
  103. package/src/TabbedLayout.tsx +29 -0
  104. package/src/common/DashAutoTitle.tsx +24 -0
  105. package/src/common/components/FabButton.tsx +40 -0
  106. package/src/common/components/TranslatedLabel.tsx +81 -0
  107. package/src/common/settings/Settings.tsx +236 -0
  108. package/src/common/settings/SettingsBarIcons.tsx +72 -0
  109. package/src/context/DashAutoAdminFormContext.tsx +31 -0
  110. package/src/hooks/useAutoAdminLoadingStateMediator.tsx +42 -0
  111. package/src/hooks/useAutoAdminTranslate.tsx +106 -0
  112. package/src/hooks/useHash.tsx +27 -0
  113. package/src/hooks/useLogger.tsx +23 -0
  114. package/src/hooks/useRoutePathPattern.tsx +24 -0
  115. package/src/hooks/useVirtualHash.tsx +34 -0
  116. package/src/index.ts +85 -0
  117. package/src/interfaces/ICustomResourceSubComponent.ts +11 -0
  118. package/src/interfaces/IDashApplicationLayoutMainAction.ts +37 -0
  119. package/src/interfaces/IDashApplicationLayoutMenuItem.ts +24 -0
  120. package/src/interfaces/IDashAutoAdminAttribute.ts +104 -0
  121. package/src/interfaces/IDashAutoAdminCustomFieldComponent.ts +18 -0
  122. package/src/interfaces/IDashAutoAdminFormOptions.ts +22 -0
  123. package/src/interfaces/IDashAutoAdminListActions.ts +13 -0
  124. package/src/interfaces/IDashAutoAdminReference.ts +16 -0
  125. package/src/interfaces/IDashAutoAdminResourceConfig.ts +360 -0
  126. package/src/interfaces/IDashAutoForm.ts +24 -0
  127. package/src/interfaces/IDashAutoGridButton.ts +35 -0
  128. package/src/interfaces/IDashAutoShow.ts +12 -0
  129. package/src/interfaces/IGroupExtraData.ts +8 -0
  130. package/src/interfaces/IRecord.ts +7 -0
  131. package/src/interfaces/IReferenceFilter.ts +55 -0
  132. package/src/interfaces/IResourceComponent.ts +8 -0
  133. package/src/interfaces/IToolbarButton.ts +11 -0
  134. package/src/list/DashAutoListActions.tsx +88 -0
  135. package/src/list/DashAutoListDatagridWrapper.tsx +74 -0
  136. package/src/list/DashAutoListDefaultActionsWrapper.tsx +31 -0
  137. package/src/list/DashAutoListFilterFormWithButton.tsx +93 -0
  138. package/src/list/DashAutoListTopToolbar.tsx +240 -0
  139. package/src/mui/AttributeToField.tsx +657 -0
  140. package/src/mui/AttributeToInput.tsx +728 -0
  141. package/src/mui/AutoAdminResizableDrawer.tsx +69 -0
  142. package/src/mui/AutoDataGrid.tsx +127 -0
  143. package/src/mui/AutoReferenceFormTab.tsx +51 -0
  144. package/src/mui/AutoReferenceTab.tsx +45 -0
  145. package/src/mui/AutoTabs.tsx +32 -0
  146. package/src/mui/components/ExtendedPagination.tsx +23 -0
  147. package/src/mui/components/ListStringField.tsx +32 -0
  148. package/src/providers/DashAuthProvider.ts +341 -0
  149. package/src/providers/DashDataProvider.ts +466 -0
  150. package/src/providers/index.ts +17 -0
  151. package/src/toolbar/buttons/BottomToolbarButtons.tsx +59 -0
  152. package/src/toolbar/buttons/DashResourceButton.tsx +223 -0
  153. package/src/toolbar/buttons/ListButtons.tsx +137 -0
  154. package/src/toolbar/buttons/ToolbarButtons.tsx +186 -0
  155. package/src/utils/SimpleLogger.tsx +46 -0
  156. package/src/utils/enumToChoices.tsx +3 -0
  157. package/src/utils/evalActionPermission.tsx +14 -0
  158. package/src/utils/groupByTabs.tsx +23 -0
  159. package/src/utils/hashedGroupByTabs.tsx +16 -0
  160. package/src/utils/invertMap.tsx +10 -0
  161. package/src/utils/isClassComponent.tsx +9 -0
  162. package/src/utils/isComponent.tsx +45 -0
  163. package/src/utils/isEnum.tsx +3 -0
  164. package/src/utils/isFC.tsx +6 -0
  165. package/src/utils/replaceParams.tsx +6 -0
  166. package/src/utils/validate.tsx +24 -0
  167. package/src/wrappers/UserAction.tsx +67 -0
  168. package/src/wrappers/index.tsx +1 -0
  169. /package/{dist → src}/DashAutoAdminSaveButton.tsx.bkup +0 -0
  170. /package/{dist/DashAutoFormLayout.tsx.review → src/DashAutoFormLayout.tsx} +0 -0
  171. /package/{dist → src}/DashAutoFormTabs.review +0 -0
  172. /package/{dist → src}/DashAutoFormTabs.tsx.formcontext.wip +0 -0
  173. /package/{dist → src}/mui/AttributeToField.tsx.review +0 -0
  174. /package/{dist → src}/mui/AttributeToInput.tsx.review +0 -0
  175. /package/{dist → src}/react-admin.d.ts +0 -0
  176. /package/{dist → src}/types/ActionCallback.d.ts +0 -0
@@ -0,0 +1,208 @@
1
+ import React, { JSX } from 'react';
2
+ import IReferenceFilter from './interfaces/IReferenceFilter';
3
+
4
+ import { TextInput, ReferenceInput, SelectInput, DateInput } from 'react-admin';
5
+
6
+ import IDashAutoAdminResourceConfig from './interfaces/IDashAutoAdminResourceConfig';
7
+
8
+ import { SelectArrayInput } from 'react-admin';
9
+
10
+ export const generateFilter = (
11
+ r: IReferenceFilter,
12
+ idx: React.Key,
13
+ ): JSX.Element => {
14
+ const {
15
+ label,
16
+ source,
17
+ reference,
18
+ optionText,
19
+ alwaysOn = true,
20
+ referenceComponent,
21
+ fieldProps = {},
22
+ slotProps = {},
23
+ inputOptions = {},
24
+ multiple = false,
25
+ date = false,
26
+ } = r;
27
+
28
+ // DEBUG: Log the filter configuration
29
+ console.log('🔧 DashAutoFiltersGenerator DEBUG - generateFilter called:', {
30
+ idx,
31
+ label,
32
+ source,
33
+ reference,
34
+ hasReferenceComponent: !!referenceComponent,
35
+ fieldProps,
36
+ timestamp: new Date().toISOString()
37
+ });
38
+
39
+ if (referenceComponent && !reference) {
40
+ console.log('🔧 DashAutoFiltersGenerator DEBUG - Rendering with reference component (no reference):', {
41
+ idx,
42
+ source,
43
+ label,
44
+ referenceComponent: referenceComponent.name,
45
+ fieldProps,
46
+ timestamp: new Date().toISOString()
47
+ });
48
+
49
+ const ReferenceComponent = referenceComponent;
50
+
51
+ // Use only fieldProps for all component props
52
+ const finalProps = {
53
+ source,
54
+ label,
55
+ alwaysOn,
56
+ ...fieldProps, // fieldProps contains all component-specific props
57
+ };
58
+
59
+ console.log('🔧 DashAutoFiltersGenerator DEBUG - Final props for reference component (DETAILED):', {
60
+ idx,
61
+ source,
62
+ label,
63
+ finalProps,
64
+ fieldPropsResource: fieldProps?.resource,
65
+ timestamp: new Date().toISOString()
66
+ });
67
+
68
+ return (
69
+ <ReferenceComponent
70
+ key={idx}
71
+ {...finalProps}
72
+ />
73
+ );
74
+ }
75
+
76
+ // If not reference provided uses SelectArrayInput if multiple, or SelectInput if not.
77
+ let ReferenceComponent = referenceComponent || SelectInput;
78
+
79
+ if (reference && typeof reference === 'object') {
80
+ if (multiple && !referenceComponent) {
81
+ ReferenceComponent = SelectArrayInput;
82
+ }
83
+
84
+ console.log('🔗 DashAutoFiltersGenerator DEBUG - Rendering with object reference:', {
85
+ idx,
86
+ source,
87
+ label,
88
+ reference,
89
+ ReferenceComponent: ReferenceComponent.name,
90
+ timestamp: new Date().toISOString()
91
+ });
92
+
93
+ return (
94
+ <ReferenceComponent
95
+ key={idx}
96
+ choices={reference}
97
+ label={label}
98
+ source={source}
99
+ alwaysOn={alwaysOn}
100
+ {...fieldProps}
101
+ />
102
+ );
103
+ }
104
+
105
+ if (reference) {
106
+ console.log('🔗 DashAutoFiltersGenerator DEBUG - Rendering ReferenceInput:', {
107
+ idx,
108
+ source,
109
+ label,
110
+ reference,
111
+ ReferenceComponent: ReferenceComponent.name,
112
+ inputOptions,
113
+ fieldProps,
114
+ timestamp: new Date().toISOString()
115
+ });
116
+
117
+ return (
118
+ <ReferenceInput
119
+ key={idx}
120
+ label={label}
121
+ source={source}
122
+ reference={reference}
123
+ allowEmpty
124
+ alwaysOn={alwaysOn}
125
+ {...inputOptions}
126
+ >
127
+ <ReferenceComponent
128
+ label={label}
129
+ optionText={optionText}
130
+ {...fieldProps}
131
+ />
132
+ </ReferenceInput>
133
+ );
134
+ }
135
+
136
+ if (date) {
137
+ console.log('📅 DashAutoFiltersGenerator DEBUG - Rendering DateInput:', {
138
+ idx,
139
+ source,
140
+ label,
141
+ fieldProps,
142
+ timestamp: new Date().toISOString()
143
+ });
144
+
145
+ return (
146
+ <DateInput
147
+ key={idx}
148
+ placeholder='Date'
149
+ label={label}
150
+ source={source}
151
+ alwaysOn={alwaysOn}
152
+ {...fieldProps}
153
+ />
154
+ );
155
+ }
156
+
157
+ console.log('📝 DashAutoFiltersGenerator DEBUG - Rendering TextInput (default):', {
158
+ idx,
159
+ source,
160
+ label,
161
+ fieldProps,
162
+ slotProps,
163
+ timestamp: new Date().toISOString()
164
+ });
165
+
166
+ return (
167
+ <TextInput
168
+ key={idx}
169
+ label={label}
170
+ source={source}
171
+ alwaysOn={alwaysOn}
172
+ {...fieldProps}
173
+ {...(slotProps ? { slotProps: slotProps } : {})}
174
+ />
175
+ );
176
+ };
177
+
178
+ const dashAutoFiltersGenerator = (
179
+ resourceConfig: IDashAutoAdminResourceConfig,
180
+ locale?: string,
181
+ ): JSX.Element[] => {
182
+ const referenceFilters: IReferenceFilter[] =
183
+ resourceConfig?.referenceFilters || [];
184
+ const filters: JSX.Element[] = [];
185
+
186
+ console.log('🏭 DashAutoFiltersGenerator DEBUG - dashAutoFiltersGenerator called:', {
187
+ resourceConfig: resourceConfig?.model || 'unknown',
188
+ filtersCount: referenceFilters.length,
189
+ filters: referenceFilters.map(f => ({
190
+ id: f.id,
191
+ source: f.source,
192
+ label: f.label,
193
+ hasReferenceComponent: !!f.referenceComponent,
194
+ fieldProps: f.fieldProps
195
+ })),
196
+ timestamp: new Date().toISOString()
197
+ });
198
+
199
+ if (referenceFilters && referenceFilters.length > 0) {
200
+ referenceFilters.forEach((r, idx) => {
201
+ filters.push(generateFilter(r, idx));
202
+ });
203
+ }
204
+
205
+ return filters;
206
+ };
207
+
208
+ export default dashAutoFiltersGenerator;
@@ -0,0 +1,146 @@
1
+ import { AutoAdminSettings } from '.';
2
+ import IDashAutoAdminAttribute from './interfaces/IDashAutoAdminAttribute';
3
+ import IDashAutoAdminFormOptions from './interfaces/IDashAutoAdminFormOptions';
4
+ import IDashAutoAdminResourceConfig from './interfaces/IDashAutoAdminResourceConfig';
5
+ import groupByTabs from './utils/groupByTabs';
6
+ import { default as AttributeToInput } from './mui/AttributeToInput';
7
+ import React from 'react';
8
+ import { TranslatedLabel } from './common/components/TranslatedLabel';
9
+
10
+ // TODO: DEFAULT_TAB_LABEL should be get from a React Auto Admin config class.
11
+
12
+ interface IAutoForm {
13
+ schema: IDashAutoAdminAttribute[],
14
+ resourceConfig: IDashAutoAdminResourceConfig,
15
+ options?: IDashAutoAdminFormOptions,
16
+ }
17
+
18
+ const DashAutoFormGroups = ({
19
+ schema,
20
+ resourceConfig,
21
+ options
22
+ }: IAutoForm) => {
23
+ const DEFAULT_TAB_LABEL = AutoAdminSettings?.defaultTabName || resourceConfig.label;
24
+
25
+ // Helper to render translated legend
26
+ const renderLegend = (label: string | undefined) => (
27
+ <legend>
28
+ <TranslatedLabel label={label} fallback={DEFAULT_TAB_LABEL} />
29
+ </legend>
30
+ );
31
+
32
+ const isDrawer = options?.isDrawer === true ? true : false;
33
+
34
+ switch (options?.mode) {
35
+ case 'create':
36
+ return groupByTabs(schema).map((groupOfAttributes, idx) => {
37
+ let attributes = groupOfAttributes;
38
+ if (isDrawer)
39
+ attributes = attributes.filter(
40
+ (attribute) => attribute?.inDrawer !== false,
41
+ );
42
+ const filteredAttributes = attributes.filter((attribute) => attribute?.inCreate !== false);
43
+ return filteredAttributes.length ? (
44
+ <fieldset key={`auto-admin-fieldset-${idx}`}>
45
+ {filteredAttributes.length > 0 && renderLegend(attributes[0].tab || options?.label)}
46
+ {filteredAttributes.map(
47
+ (attribute, i) =>
48
+ React.cloneElement(
49
+ AttributeToInput(
50
+ options.mode,
51
+ resourceConfig,
52
+ attribute,
53
+ i,
54
+ options,
55
+ ),
56
+ { key: `create-${idx}-${i}` },
57
+ ),
58
+ )}
59
+ </fieldset>
60
+ ) : null;
61
+ });
62
+
63
+ case 'edit':
64
+ return groupByTabs(schema).map((groupOfAttributes, idx) => {
65
+ let attributes = groupOfAttributes;
66
+ if (isDrawer)
67
+ attributes = attributes.filter(
68
+ (attribute) => attribute?.inDrawer !== false,
69
+ );
70
+ const filteredAttributes = attributes.filter((attribute) => attribute?.inEdit !== false);
71
+ return filteredAttributes.length ? (
72
+ <fieldset key={`auto-admin-fieldset-${idx}`}>
73
+ {filteredAttributes.length > 0 && renderLegend(attributes[0].tab || options?.label)}
74
+ {filteredAttributes.map((attribute, i) =>
75
+ React.cloneElement(
76
+ AttributeToInput(
77
+ options.mode,
78
+ resourceConfig,
79
+ attribute,
80
+ i,
81
+ options,
82
+ ),
83
+ { key: `edit-${idx}-${i}` },
84
+ ),
85
+ )}
86
+ </fieldset>
87
+ ) : null;
88
+ });
89
+
90
+ case 'view':
91
+ return groupByTabs(schema).map((groupOfAttributes, idx) => {
92
+ let attributes = groupOfAttributes;
93
+ if (isDrawer)
94
+ attributes = attributes.filter(
95
+ (attribute) => attribute?.inDrawer !== false,
96
+ );
97
+ const filteredAttributes = attributes.filter((attribute) => attribute?.inShow !== false);
98
+ return filteredAttributes.length ? (
99
+ <fieldset key={`auto-admin-fieldset-${idx}`}>
100
+ {filteredAttributes.length > 0 && renderLegend(attributes[0].tab || options?.label)}
101
+ {filteredAttributes.map((attribute, i) =>
102
+ React.cloneElement(
103
+ AttributeToInput(
104
+ options.mode,
105
+ resourceConfig,
106
+ attribute,
107
+ i,
108
+ options,
109
+ ),
110
+ { key: `view-${idx}-${i}` },
111
+ ),
112
+ )}
113
+ </fieldset>
114
+ ) : null;
115
+ });
116
+
117
+ case 'list':
118
+ return groupByTabs(schema).map((groupOfAttributes, idx) => {
119
+ let attributes = groupOfAttributes;
120
+ if (isDrawer)
121
+ attributes = attributes.filter(
122
+ (attribute) => attribute?.inDrawer !== false,
123
+ );
124
+ const filteredAttributes = attributes.filter((attribute) => attribute?.inShow !== false);
125
+ return filteredAttributes.length ? (
126
+ <fieldset key={`auto-admin-fieldset-${idx}`}>
127
+ {filteredAttributes.length > 0 && renderLegend(attributes[0].tab || options?.label)}
128
+ {filteredAttributes.map((attribute, i) =>
129
+ React.cloneElement(
130
+ AttributeToInput(
131
+ options.mode,
132
+ resourceConfig,
133
+ attribute,
134
+ i,
135
+ options,
136
+ ),
137
+ { key: `list-${idx}-${i}` },
138
+ ),
139
+ )}
140
+ </fieldset>
141
+ ) : null;
142
+ });
143
+ }
144
+ };
145
+
146
+ export default DashAutoFormGroups;
@@ -0,0 +1,113 @@
1
+ import { JSX } from 'react';
2
+ import { DashAutoFormTabs } from '.';
3
+ import IDashAutoAdminAttribute from './interfaces/IDashAutoAdminAttribute';
4
+ import IDashAutoAdminFormOptions from './interfaces/IDashAutoAdminFormOptions';
5
+ import IDashAutoAdminResourceConfig from './interfaces/IDashAutoAdminResourceConfig';
6
+
7
+ import { default as AttributeToInput } from './mui/AttributeToInput';
8
+ import hashedGroupByTabs from './utils/hashedGroupByTabs';
9
+
10
+ interface IAutoForm {
11
+ schema: IDashAutoAdminAttribute[],
12
+ resourceConfig: IDashAutoAdminResourceConfig,
13
+ options?: IDashAutoAdminFormOptions,
14
+ }
15
+
16
+ const DashAutoFormLayout = ({
17
+ schema,
18
+ resourceConfig,
19
+ options
20
+ }: IAutoForm) => {
21
+ const groupedTabs = hashedGroupByTabs(schema || []);
22
+
23
+ const renderEdit = (tab: string): JSX.Element[] => {
24
+ const groupedAttributesByTab = groupedTabs[tab] ? groupedTabs[tab] : [];
25
+ return groupedAttributesByTab
26
+ .filter((attribute) => attribute?.inEdit !== false)
27
+ .map((attribute, idx) =>
28
+ AttributeToInput('edit', resourceConfig, attribute, idx, options),
29
+ );
30
+ };
31
+
32
+ const renderCreate = (tab: string): JSX.Element[] => {
33
+ const groupedAttributesByTab = groupedTabs[tab] ? groupedTabs[tab] : [];
34
+ return groupedAttributesByTab
35
+ .filter((attribute) => attribute?.inCreate !== false)
36
+ .map((attribute, idx) =>
37
+ AttributeToInput('create', resourceConfig, attribute, idx, options),
38
+ );
39
+ };
40
+
41
+ /*
42
+ const renderShow = (tab: string): JSX.Element[] => {
43
+ const groupedAttributesByTab = groupedTabs.hasOwnProperty(tab) ? groupedTabs[tab] : [];
44
+ return groupedAttributesByTab.filter(attribute => attribute?.inShow !== false).map((attribute, idx) => AttributeToInput(attribute, idx, options))
45
+ }*/
46
+
47
+ /*
48
+ return groupByTabs(schema).map((groupOfAttributes, idx) => (
49
+ <fieldset key={"fieldset-" + idx}>
50
+ <legend>{groupOfAttributes[0].tab || (options?.label || 'Datos')}</legend>
51
+ {groupOfAttributes.filter(attribute => attribute?.inEdit !== false).map((attribute, idx) => AttributeToInput(attribute, idx, options))}
52
+ </fieldset>
53
+ ))
54
+
55
+ */
56
+
57
+ switch (options.mode) {
58
+ case 'create':
59
+ if (
60
+ !resourceConfig?.createLayout ||
61
+ typeof resourceConfig.createLayout !== 'function'
62
+ ) {
63
+ console.warn(
64
+ '⚠️ createLayout must be present and be a function in the resource definition when using formGroupMode layout, fallback to tabs',
65
+ );
66
+
67
+ return DashAutoFormTabs({
68
+ schema: schema,
69
+ resourceConfig: resourceConfig,
70
+ options: options,
71
+ });
72
+ }
73
+
74
+ return resourceConfig.createLayout(renderCreate);
75
+
76
+ case 'edit':
77
+ if (
78
+ !resourceConfig?.editLayout ||
79
+ typeof resourceConfig.editLayout !== 'function'
80
+ ) {
81
+ console.warn(
82
+ '⚠️ createLayout must be present and be a function in the resource definition when using formGroupMode layout, fallback to tabs',
83
+ );
84
+
85
+ return DashAutoFormTabs({
86
+ schema: schema,
87
+ resourceConfig: resourceConfig,
88
+ options: options,
89
+ });
90
+ }
91
+
92
+ return resourceConfig.editLayout(renderEdit);
93
+
94
+ /*case "view":
95
+ case "list":
96
+ if (!resource.showLayout || typeof resource.showLayout !== "function") {
97
+ console.error("showLayout must be present and be a function in the resource definition when using formGroupMode layout, fallback to tabs");
98
+ return AutoFormTabs({
99
+ schema: schema,
100
+ resource: resource,
101
+ options: { mode: options.mode },
102
+ })
103
+ }
104
+
105
+ return resource.createLayout(renderShow)
106
+ */
107
+
108
+ default:
109
+ return <>mode not allowed</>;
110
+ }
111
+ };
112
+
113
+ export default DashAutoFormLayout;