@dashadmin/dash-auto-admin 1.3.17 → 1.3.20

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 (99) hide show
  1. package/dist/DashAutoAdminComponentRegistry.js +1 -0
  2. package/dist/DashAutoAdminForm.js +1 -0
  3. package/dist/DashAutoAdminResizableDrawer.js +1 -0
  4. package/dist/DashAutoAdminSaveButton.js +1 -0
  5. package/dist/DashAutoAdminSaveButton.tsx.bkup +84 -0
  6. package/dist/DashAutoCreate.js +1 -0
  7. package/dist/DashAutoDrawer.js +1 -0
  8. package/dist/DashAutoEdit.js +1 -0
  9. package/dist/DashAutoFiltersGenerator.js +1 -0
  10. package/dist/DashAutoFormGroups.js +1 -0
  11. package/dist/DashAutoFormLayout.js +1 -0
  12. package/dist/DashAutoFormLayout.tsx.review +113 -0
  13. package/dist/DashAutoFormMuiTabs.js +1 -0
  14. package/dist/DashAutoFormTabs.js +1 -0
  15. package/dist/DashAutoFormTabs.review +170 -0
  16. package/dist/DashAutoFormTabs.tsx.formcontext.wip +234 -0
  17. package/dist/DashAutoGroup.js +1 -0
  18. package/dist/DashAutoLayout.js +1 -0
  19. package/dist/DashAutoList.js +1 -0
  20. package/dist/DashAutoPostFilterForm.js +1 -0
  21. package/dist/DashAutoReferenceTab.js +1 -0
  22. package/dist/DashAutoResource.js +1 -0
  23. package/dist/DashAutoResourceLayout.js +1 -0
  24. package/dist/DashAutoShow.js +1 -0
  25. package/dist/DashAutoTabbedForm.js +1 -0
  26. package/dist/DashAutoTabbedForm.review.js +1 -0
  27. package/dist/DashAutoTabs.js +1 -0
  28. package/dist/DashFilterWrapper.js +1 -0
  29. package/dist/DashRedirect.js +1 -0
  30. package/dist/TabbedLayout.js +1 -0
  31. package/dist/common/DashAutoTitle.js +1 -0
  32. package/dist/common/components/FabButton.js +1 -0
  33. package/dist/common/components/TranslatedLabel.js +1 -0
  34. package/dist/common/settings/Settings.js +1 -0
  35. package/dist/common/settings/SettingsBarIcons.js +1 -0
  36. package/dist/context/DashAutoAdminFormContext.js +1 -0
  37. package/dist/hooks/useAutoAdminLoadingStateMediator.js +1 -0
  38. package/dist/hooks/useAutoAdminTranslate.js +1 -0
  39. package/dist/hooks/useHash.js +1 -0
  40. package/dist/hooks/useLogger.js +1 -0
  41. package/dist/hooks/useRoutePathPattern.js +1 -0
  42. package/dist/hooks/useVirtualHash.js +1 -0
  43. package/dist/interfaces/ICustomResourceSubComponent.js +0 -0
  44. package/dist/interfaces/IDashApplicationLayoutMainAction.js +0 -0
  45. package/dist/interfaces/IDashApplicationLayoutMenuItem.js +0 -0
  46. package/dist/interfaces/IDashAutoAdminAttribute.js +0 -0
  47. package/dist/interfaces/IDashAutoAdminCustomFieldComponent.js +0 -0
  48. package/dist/interfaces/IDashAutoAdminFormOptions.js +0 -0
  49. package/dist/interfaces/IDashAutoAdminListActions.js +0 -0
  50. package/dist/interfaces/IDashAutoAdminReference.js +0 -0
  51. package/dist/interfaces/IDashAutoAdminResourceConfig.js +0 -0
  52. package/dist/interfaces/IDashAutoForm.js +0 -0
  53. package/dist/interfaces/IDashAutoGridButton.js +0 -0
  54. package/dist/interfaces/IDashAutoShow.js +0 -0
  55. package/dist/interfaces/IGroupExtraData.js +0 -0
  56. package/dist/interfaces/IRecord.js +0 -0
  57. package/dist/interfaces/IReferenceFilter.js +0 -0
  58. package/dist/interfaces/IResourceComponent.js +0 -0
  59. package/dist/interfaces/IToolbarButton.js +0 -0
  60. package/dist/list/DashAutoListActions.js +1 -0
  61. package/dist/list/DashAutoListDatagridWrapper.js +1 -0
  62. package/dist/list/DashAutoListDefaultActionsWrapper.js +1 -0
  63. package/dist/list/DashAutoListFilterFormWithButton.js +1 -0
  64. package/dist/list/DashAutoListTopToolbar.js +1 -0
  65. package/dist/mui/AttributeToField.js +1 -0
  66. package/dist/mui/AttributeToField.tsx.review +644 -0
  67. package/dist/mui/AttributeToInput.js +1 -0
  68. package/dist/mui/AttributeToInput.tsx.review +684 -0
  69. package/dist/mui/AutoAdminResizableDrawer.js +1 -0
  70. package/dist/mui/AutoDataGrid.js +1 -0
  71. package/dist/mui/AutoReferenceFormTab.js +1 -0
  72. package/dist/mui/AutoReferenceTab.js +1 -0
  73. package/dist/mui/AutoTabs.js +1 -0
  74. package/dist/mui/components/ExtendedPagination.js +1 -0
  75. package/dist/mui/components/ListStringField.js +1 -0
  76. package/dist/providers/DashAuthProvider.js +1 -0
  77. package/dist/providers/DashDataProvider.js +1 -0
  78. package/dist/providers/index.js +1 -0
  79. package/dist/react-admin.d.ts +5 -0
  80. package/dist/toolbar/buttons/BottomToolbarButtons.js +1 -0
  81. package/dist/toolbar/buttons/DashResourceButton.js +1 -0
  82. package/dist/toolbar/buttons/ListButtons.js +1 -0
  83. package/dist/toolbar/buttons/ToolbarButtons.js +1 -0
  84. package/dist/types/ActionCallback.d.ts +2 -0
  85. package/dist/utils/SimpleLogger.js +1 -0
  86. package/dist/utils/enumToChoices.js +1 -0
  87. package/dist/utils/evalActionPermission.js +1 -0
  88. package/dist/utils/groupByTabs.js +1 -0
  89. package/dist/utils/hashedGroupByTabs.js +1 -0
  90. package/dist/utils/invertMap.js +1 -0
  91. package/dist/utils/isClassComponent.js +1 -0
  92. package/dist/utils/isComponent.js +1 -0
  93. package/dist/utils/isEnum.js +1 -0
  94. package/dist/utils/isFC.js +1 -0
  95. package/dist/utils/replaceParams.js +1 -0
  96. package/dist/utils/validate.js +1 -0
  97. package/dist/wrappers/UserAction.js +1 -0
  98. package/dist/wrappers/index.js +1 -0
  99. package/package.json +14 -3
@@ -0,0 +1,644 @@
1
+ import { InputLabel } from '@mui/material';
2
+
3
+ import {
4
+ ImageInput,
5
+ FileInput,
6
+ DateTimeInput,
7
+ ArrayField,
8
+ BooleanField,
9
+ ChipField,
10
+ Datagrid,
11
+ DateField,
12
+ NumberField,
13
+ ImageField,
14
+ ReferenceArrayField,
15
+ ReferenceField,
16
+ SingleFieldList,
17
+ TextField,
18
+ FileField,
19
+ FunctionField,
20
+ } from 'react-admin';
21
+
22
+ import IDashAutoAdminAttribute from '../interfaces/IDashAutoAdminAttribute';
23
+ import IDashAutoAdminFormOptions from '../interfaces/IDashAutoAdminFormOptions';
24
+
25
+ import { UserAction } from '../wrappers';
26
+ import ListStringsField from './components/ListStringField';
27
+ import IRecord from '../interfaces/IRecord';
28
+ import React from 'react';
29
+ import IDashAutoAdminResourceConfig from '../interfaces/IDashAutoAdminResourceConfig';
30
+ import IDashAutoAdminCustomFieldComponent from '../interfaces/IDashAutoAdminCustomFieldComponent';
31
+ import isEnum from '../utils/isEnum';
32
+ import replaceParams from '../utils/replaceParams';
33
+ import { useParams } from 'react-router';
34
+ import { useComponentRegistry } from '../DashAutoAdminComponentRegistry';
35
+
36
+ export const AttributeToField = (
37
+ method: 'view' | 'list' | 'create' | 'edit',
38
+ resourceConfig: IDashAutoAdminResourceConfig,
39
+ input: IDashAutoAdminAttribute,
40
+ index?: number,
41
+ options?: IDashAutoAdminFormOptions,
42
+ resource?: string,
43
+ record?: IRecord,
44
+ ) => {
45
+ // Get the component registry
46
+ const { components } = useComponentRegistry();
47
+
48
+ const params = useParams();
49
+
50
+ const sortableField = input.sortable === true ? true : false;
51
+
52
+ const typeComponentMapper = (type: string) => {
53
+ const component = components[type];
54
+
55
+
56
+ if (component) {
57
+ return { custom: true, type: "component", component };
58
+ }
59
+
60
+ return { custom: true, type: "component", component: () => <>No component for {type}</> };
61
+ };
62
+
63
+ const ComponentWrapper =
64
+ resourceConfig?.fieldWrapper &&
65
+ typeof resourceConfig.fieldWrapper === 'function'
66
+ ? resourceConfig.fieldWrapper
67
+ : ({
68
+ _record,
69
+ _method,
70
+ _attribute,
71
+ _resourceConfig,
72
+ children,
73
+ }: IDashAutoAdminCustomFieldComponent) => {
74
+ return children;
75
+ };
76
+
77
+ record = options?.record ? options.record : record;
78
+
79
+ if (
80
+ options &&
81
+ options.useReadOnlyInputAsTextField === true &&
82
+ input.readOnly
83
+ ) {
84
+ return (
85
+ <ComponentWrapper
86
+ key={index}
87
+ label={input.label}
88
+ sortable={sortableField}
89
+ source={input.listAttribute ? input.listAttribute : input.attribute}
90
+ {...(record && { record: record })}
91
+ method={method}
92
+ attribute={input}
93
+ resourceConfig={resourceConfig}
94
+ >
95
+ <TextField
96
+ {...(record && { record: record })}
97
+ sortable={sortableField}
98
+ {...(sortableField && {
99
+ sortBy: input.listAttribute || input.attribute,
100
+ })}
101
+ key={index}
102
+ label={input.label}
103
+ source={input.listAttribute ? input.listAttribute : input.attribute}
104
+ {...{
105
+ ...input.fieldProps,
106
+ editable: false,
107
+ InputProps: { readOnly: true },
108
+ }}
109
+ disabled
110
+ />
111
+ </ComponentWrapper>
112
+ );
113
+ } else if (options && options.readOnlyComponent && input.readOnly) {
114
+ return (
115
+ <ComponentWrapper
116
+ {...(record && { record: record })}
117
+ method={method}
118
+ attribute={input}
119
+ key={index}
120
+ label={input.label}
121
+ sortable={sortableField}
122
+ source={input.listAttribute ? input.listAttribute : input.attribute}
123
+ resourceConfig={resourceConfig}
124
+ >
125
+ <options.readOnlyComponent
126
+ key={index}
127
+ {...(record && { record: record })}
128
+ sortable={sortableField}
129
+ {...(sortableField && {
130
+ sortBy: input.listAttribute || input.attribute,
131
+ })}
132
+ input={input}
133
+ label={input.label}
134
+ source={input.listAttribute ? input.listAttribute : input.attribute}
135
+ {...{
136
+ ...input.fieldProps,
137
+ editable: false,
138
+ InputProps: { readOnly: true },
139
+ }}
140
+ />
141
+ </ComponentWrapper>
142
+ );
143
+ }
144
+
145
+ // Check if input type is a string and not an array or enum
146
+
147
+ if (typeof input.type === "string" && !input.type.includes(".") && !Array.isArray(input.type)) {
148
+ switch (input.type) {
149
+ case 'string':
150
+ case 'text':
151
+ case 'String':
152
+ input.type = String;
153
+ break;
154
+ case 'number':
155
+ case 'Number':
156
+ case 'integer':
157
+ input.type = Number;
158
+ break;
159
+ case 'boolean':
160
+ case 'Boolean':
161
+ input.type = Boolean;
162
+ break;
163
+ case 'date':
164
+ case 'Date':
165
+ input.type = Date;
166
+ break;
167
+ case 'custom':
168
+ default:
169
+
170
+ input.custom = true;
171
+ if(typeof input?.component === "string") {
172
+ input = { ...input, ...typeComponentMapper( input.component ) };
173
+ }
174
+ break;
175
+ }
176
+ }
177
+
178
+ // CUSTOM COMPONENT
179
+ if (
180
+ (input.custom && input.component) ||
181
+ (input.type === 'component' && input.component)
182
+ ) {
183
+
184
+ return (
185
+ <FunctionField
186
+ key={`function_field_${index}`}
187
+ label={input.label}
188
+ sortable={sortableField}
189
+ {...(sortableField && {
190
+ sortBy: input.listAttribute || input.attribute,
191
+ })}
192
+ render={(r) => {
193
+ return <ComponentWrapper
194
+ {...(r && { record: r })}
195
+ method={method}
196
+ attribute={input}
197
+ key={index}
198
+ label={input.label}
199
+ sortable={sortableField}
200
+ source={
201
+ input.listAttribute ? input.listAttribute : input.attribute
202
+ }
203
+ resourceConfig={resourceConfig}
204
+ >
205
+ <UserAction
206
+ key={`custom_component_${index}`}
207
+ {...(r && { record: r })}
208
+ method={method}
209
+ attribute={input}
210
+ resourceConfig={resourceConfig}
211
+ />
212
+ </ComponentWrapper>
213
+
214
+ }}
215
+ />
216
+ );
217
+ }
218
+
219
+ if (Array.isArray(input.type) && input.type.length > 0) {
220
+ const inputType: string | IDashAutoAdminAttribute = input.type[0];
221
+
222
+ /* Force the label to be the attribute name */
223
+ if (!input.label) {
224
+ input.label = input.attribute;
225
+ }
226
+ /* Array of enum values – We use a SelectArrayInput */
227
+ if (isEnum(inputType)) {
228
+ return (
229
+ <ComponentWrapper
230
+ {...(record && { record: record })}
231
+ method={method}
232
+ attribute={input}
233
+ key={index}
234
+ label={input.label}
235
+ sortable={sortableField}
236
+ source={input.listAttribute ? input.listAttribute : input.attribute}
237
+ resourceConfig={resourceConfig}
238
+ >
239
+ <ListStringsField
240
+ key={index}
241
+ label={input.label}
242
+ source={input.listAttribute ? input.listAttribute : input.attribute}
243
+ map={inputType}
244
+ />
245
+ </ComponentWrapper>
246
+ );
247
+ }
248
+
249
+ if (typeof inputType === 'string') {
250
+ const _params = {...params,...(location.hash.match(/\d+/g) || []).map(Number).reduce((acc, curr, index) => {
251
+ acc[index] = curr;
252
+ return acc;
253
+ }, {})};
254
+
255
+ const _inputType = replaceParams(_params,inputType);
256
+
257
+ const [reference, sourceName] = _inputType.split('.');
258
+
259
+ return (
260
+ <ComponentWrapper
261
+ {...(record && { record: record })}
262
+ method={method}
263
+ attribute={input}
264
+ key={index}
265
+ label={input.label}
266
+ sortable={sortableField}
267
+ source={input.listAttribute ? input.listAttribute : input.attribute}
268
+ resourceConfig={resourceConfig}
269
+ >
270
+ <>
271
+ <ReferenceArrayField
272
+ key={index}
273
+ sortable={sortableField}
274
+ {...(sortableField && {
275
+ sortBy: input.listAttribute || input.attribute,
276
+ })}
277
+ label={input.label}
278
+ source={
279
+ input.listAttribute ? input.listAttribute : input.attribute
280
+ }
281
+ reference={reference}
282
+ >
283
+ <SingleFieldList>
284
+ <ChipField source={sourceName} />
285
+ </SingleFieldList>
286
+ </ReferenceArrayField>
287
+ </>
288
+ </ComponentWrapper>
289
+ );
290
+ } else {
291
+ const inputTypeArray = input.type as IDashAutoAdminAttribute[];
292
+ return (
293
+ <ComponentWrapper
294
+ {...(record && { record: record })}
295
+ method={method}
296
+ attribute={input}
297
+ key={index}
298
+ label={input.label}
299
+ sortable={sortableField}
300
+ source={input.listAttribute ? input.listAttribute : input.attribute}
301
+ resourceConfig={resourceConfig}
302
+ >
303
+ <>
304
+ <ArrayField
305
+ key={index}
306
+ sortable={sortableField}
307
+ {...(sortableField && {
308
+ sortBy: input.listAttribute || input.attribute,
309
+ })}
310
+ label={input.label}
311
+ source={
312
+ input.listAttribute ? input.listAttribute : input.attribute
313
+ }
314
+ >
315
+ <Datagrid>
316
+ {inputTypeArray.map((attribute, idx) =>
317
+ AttributeToField(
318
+ method,
319
+ resourceConfig,
320
+ attribute,
321
+ idx,
322
+ options,
323
+ ),
324
+ )}
325
+ </Datagrid>
326
+ </ArrayField>
327
+ </>
328
+ </ComponentWrapper>
329
+ );
330
+ }
331
+ }
332
+
333
+ if (typeof input.type === 'string') {
334
+ const _params = {...params,...(location.hash.match(/\d+/g) || []).map(Number).reduce((acc, curr, index) => {
335
+ acc[index] = curr;
336
+ return acc;
337
+ }, {})};
338
+
339
+ const _inputType = replaceParams(_params,input.type);
340
+ const [reference, sourceName] = _inputType.split('.');
341
+
342
+ if (input && input.multiple === false) {
343
+ const componentWrapperProps = {
344
+ ...(record && { record: record }),
345
+ method,
346
+ attribute: input,
347
+ label: input.label,
348
+ sortable: sortableField,
349
+ source: input.listAttribute ? input.listAttribute : input.attribute,
350
+ resourceConfig
351
+ }
352
+
353
+ const componentProps = {
354
+ ...(record && { record: record }),
355
+ sortable: sortableField,
356
+ ...(sortableField && {
357
+ sortBy: input.listAttribute || input.attribute,
358
+ }),
359
+ label: input.label,
360
+ link: 'show',
361
+ source: input.listAttribute ? input.listAttribute : input.attribute,
362
+ reference: reference
363
+ }
364
+
365
+ return <ComponentWrapper
366
+ {...componentWrapperProps}
367
+ >
368
+ <ReferenceField
369
+ {...componentProps}
370
+ />
371
+ </ComponentWrapper>
372
+ }
373
+
374
+ const componentWrapperProps = {
375
+ ...(record && { record: record }),
376
+ method: method,
377
+ attribute: input,
378
+ label: input.label,
379
+ sortable: sortableField,
380
+ source: input.listAttribute ? input.listAttribute : input.attribute,
381
+ resourceConfig: resourceConfig
382
+ }
383
+
384
+ const componentProps = {
385
+ ...(record && { record: record }),
386
+ sortable: sortableField,
387
+ ...(sortableField && {
388
+ sortBy: input.listAttribute || input.attribute,
389
+ }),
390
+ label: input.label,
391
+ source: input.listAttribute ? input.listAttribute : input.attribute,
392
+ reference: reference
393
+ }
394
+ return (
395
+ <ComponentWrapper {...componentWrapperProps} >
396
+ <ReferenceArrayField {...componentProps} >
397
+ <SingleFieldList>
398
+ <ChipField source={sourceName} />
399
+ </SingleFieldList>
400
+ </ReferenceArrayField>
401
+ </ComponentWrapper>
402
+ );
403
+ }
404
+
405
+ switch (input.type) {
406
+ case Number:
407
+ return (
408
+ <FunctionField
409
+ label={input.label}
410
+ sortable={sortableField}
411
+ {...(sortableField && {
412
+ sortBy: input.listAttribute || input.attribute,
413
+ })}
414
+ key={`function_field_${index}`}
415
+ render={(r) => {
416
+ return (
417
+ <ComponentWrapper
418
+ {...(r && { record: r })}
419
+ method={method}
420
+ attribute={input}
421
+ key={index}
422
+ label={input.label}
423
+ sortable={sortableField}
424
+ source={
425
+ input.listAttribute ? input.listAttribute : input.attribute
426
+ }
427
+ resourceConfig={resourceConfig}
428
+ >
429
+ <NumberField
430
+ key={`number_field_${index}`}
431
+ label={input.label}
432
+ {...(record && { record: record })}
433
+ sortable={input.sortable === true ? true : false}
434
+ source={
435
+ input.listAttribute ? input.listAttribute : input.attribute
436
+ }
437
+ {...input.fieldProps}
438
+ />
439
+ </ComponentWrapper>
440
+ );
441
+ }}
442
+ />
443
+ );
444
+
445
+ case Boolean:
446
+ return record ? (
447
+ <>
448
+ {input?.showLabel !== false && (
449
+ <ComponentWrapper
450
+ {...(record && { record: record })}
451
+ method={method}
452
+ attribute={input}
453
+ key={index}
454
+ label={input.label}
455
+ sortable={sortableField}
456
+ source={
457
+ input.listAttribute ? input.listAttribute : input.attribute
458
+ }
459
+ resourceConfig={resourceConfig}
460
+ >
461
+ <InputLabel
462
+ htmlFor={
463
+ input.listAttribute ? input.listAttribute : input.attribute
464
+ }
465
+ >
466
+ {input.label}
467
+ </InputLabel>
468
+ </ComponentWrapper>
469
+ )}
470
+ <ComponentWrapper
471
+ {...(record && { record: record })}
472
+ method={method}
473
+ attribute={input}
474
+ key={index}
475
+ label={input.label}
476
+ sortable={sortableField}
477
+ source={input.listAttribute ? input.listAttribute : input.attribute}
478
+ resourceConfig={resourceConfig}
479
+ >
480
+ <BooleanField
481
+ sortable={sortableField}
482
+ {...(sortableField && {
483
+ sortBy: input.listAttribute || input.attribute,
484
+ })}
485
+ record={record}
486
+ key={index}
487
+ id={input.listAttribute ? input.listAttribute : input.attribute}
488
+ label={input.label}
489
+ source={
490
+ input.listAttribute ? input.listAttribute : input.attribute
491
+ }
492
+ {...input.fieldProps}
493
+ />
494
+ </ComponentWrapper>
495
+ </>
496
+ ) : (
497
+ <FunctionField
498
+ label={input.label}
499
+ sortable={sortableField}
500
+ {...(sortableField && {
501
+ sortBy: input.listAttribute || input.attribute,
502
+ })}
503
+ render={(r) => (
504
+ <>
505
+ <ComponentWrapper
506
+ {...(r && { record: r })}
507
+ method={method}
508
+ attribute={input}
509
+ key={index}
510
+ label={input.label}
511
+ sortable={sortableField}
512
+ source={
513
+ input.listAttribute ? input.listAttribute : input.attribute
514
+ }
515
+ resourceConfig={resourceConfig}
516
+ >
517
+ <BooleanField
518
+ record={record}
519
+ key={index}
520
+ id={
521
+ input.listAttribute ? input.listAttribute : input.attribute
522
+ }
523
+ label={input.label}
524
+ source={
525
+ input.listAttribute ? input.listAttribute : input.attribute
526
+ }
527
+ {...input.fieldProps}
528
+ />
529
+ </ComponentWrapper>
530
+ </>
531
+ )}
532
+ />
533
+ );
534
+
535
+ case DateTimeInput:
536
+ case Date:
537
+ return (
538
+ <ComponentWrapper
539
+ {...(record && { record: record })}
540
+ method={method}
541
+ attribute={input}
542
+ label={input.label}
543
+ sortable={sortableField}
544
+ source={input.listAttribute ? input.listAttribute : input.attribute}
545
+ key={index}
546
+ resourceConfig={resourceConfig}
547
+ >
548
+ <DateField
549
+ {...(record && { record: record })}
550
+ key={index}
551
+ sortable={sortableField}
552
+ {...(sortableField && {
553
+ sortBy: input.listAttribute || input.attribute,
554
+ })}
555
+ label={input.label}
556
+ showTime={
557
+ (input.fieldProps && input.fieldProps.showTime) || false
558
+ }
559
+ source={input.listAttribute ? input.listAttribute : input.attribute}
560
+ {...input.fieldProps}
561
+ />
562
+ </ComponentWrapper>
563
+ );
564
+
565
+ case ImageInput:
566
+ return (
567
+ <ComponentWrapper
568
+ {...(record && { record: record })}
569
+ method={method}
570
+ attribute={input}
571
+ key={index}
572
+ label={input.label}
573
+ sortable={sortableField}
574
+ source={input.listAttribute ? input.listAttribute : input.attribute}
575
+ resourceConfig={resourceConfig}
576
+ >
577
+ <ImageField
578
+ {...(record && { record: record })}
579
+ sortable={sortableField}
580
+ {...(sortableField && {
581
+ sortBy: input.listAttribute || input.attribute,
582
+ })}
583
+ key={index}
584
+ source={input.attribute}
585
+ label={input.label}
586
+ />
587
+ </ComponentWrapper>
588
+ );
589
+
590
+ case FileInput:
591
+ return (
592
+ <ComponentWrapper
593
+ {...(record && { record: record })}
594
+ method={method}
595
+ attribute={input}
596
+ key={index}
597
+ label={input.label}
598
+ sortable={sortableField}
599
+ source={input.listAttribute ? input.listAttribute : input.attribute}
600
+ resourceConfig={resourceConfig}
601
+ >
602
+ <FileField
603
+ {...(record && { record: record })}
604
+ sortable={sortableField}
605
+ {...(sortableField && {
606
+ sortBy: input.listAttribute || input.attribute,
607
+ })}
608
+ key={index}
609
+ source={input.listAttribute ?? input.attribute}
610
+ title={input.listAttribute}
611
+ download={true}
612
+ />
613
+ </ComponentWrapper>
614
+ );
615
+ }
616
+
617
+ const textFieldProps = {
618
+ ...(record && { record: record }),
619
+ sortable: sortableField,
620
+ ...(sortableField && {
621
+ sortBy: input.listAttribute || input.attribute,
622
+ }),
623
+ label: input.label,
624
+ source: input.listAttribute ? input.listAttribute : input.attribute,
625
+ ...input.fieldProps,
626
+ ...(input.slotProps ? { slotProps: input.slotProps } : {})
627
+ }
628
+
629
+ return (
630
+ <ComponentWrapper
631
+ label={input.label}
632
+ sortable={sortableField}
633
+ source={input.listAttribute ? input.listAttribute : input.attribute}
634
+ {...(record && { record: record })}
635
+ method={method}
636
+ attribute={input}
637
+ resourceConfig={resourceConfig}
638
+ >
639
+ <TextField
640
+ {...textFieldProps}
641
+ />
642
+ </ComponentWrapper>
643
+ );
644
+ };
@@ -0,0 +1 @@
1
+ import{Fragment as fe,jsx as r,jsxs as A}from"react/jsx-runtime";import{createElement as v}from"react";import{ArrayInput as L,ImageInput as W,FileInput as k,BooleanInput as U,DateInput as J,DateTimeInput as M,NumberInput as X,SelectArrayInput as D,SelectInput as C,ChipField as $,ImageField as q,PasswordInput as x,ReferenceArrayInput as T,ReferenceInput as S,SimpleFormIterator as K,SingleFieldList as V,TextInput as E,useRecordContext as j}from"react-admin";import{ErrorMessage as z}from"@hookform/error-message";import{InputAdornment as H,InputLabel as Q,Typography as Y}from"@mui/material";import Z from"@mui/icons-material/Visibility";import{UserAction as ee}from"../wrappers";import{FunctionField as re}from"react-admin";import{FileField as te}from"react-admin";import oe from"react";import R from"../utils/enumToChoices";import w from"../utils/isEnum";import{useLocation as ae,useParams as le}from"react-router";import N from"../utils/replaceParams";import{useEditContext as se}from"react-admin";import{useFormContext as ne}from"react-hook-form";import{useComponentRegistry as ce}from"../DashAutoAdminComponentRegistry";const s=({index:d,method:n,input:e,children:t,...l})=>{const y=e?.sortable===!0,{formState:{errors:g}}=ne();return n==="edit"?A("div",{className:`auto-admin-field auto-admin-field-${n}`,children:[r(re,{label:e?.label||e.attribute,sortable:y,...y&&{sortBy:e.listAttribute||e.attribute},render:o=>oe.cloneElement(t,{record:o})}),!e?.hideErrorMessage||e?.custom&&r(z,{errors:g,name:e.attribute,render:o=>o?r(Y,{className:"dash-admin-field-error",color:"error",children:typeof o.message=="string"?o.message:typeof o.message?.message=="string"?o.message?.message:JSON.stringify(o)}):null})]},d):r("div",{className:`auto-admin-field auto-admin-field-${n}`,children:t},d)},de=()=>{try{return se()}catch{return null}},me=()=>{try{return j()}catch{return null}},ie=(d,n)=>{const e=de(),t=me();return d==="edit"||n==="edit"?e:t},O=(d,n,e,t,l)=>{const{components:g}=ce(),o=l?.mode||"view",f=ie(d,l?.mode),P=ae(),F=le(),B=a=>{const m=g[a];return m?{custom:!0,type:"component",component:m}:{custom:!0,type:"component",component:()=>A(fe,{children:["No component for ",a]})}},I=n?.fieldWrapper&&typeof n.fieldWrapper=="function"?n.fieldWrapper:({_record:a,_method:m,_attribute:b,_resourceConfig:h,children:p})=>p;if(typeof e.type=="string"&&!e.type.includes(".")&&!Array.isArray(e.type))switch(e.type){case"string":case"text":case"String":e.type=String,e.slotProps={fullWidth:e?.fieldProps?.fullWidth??!0};break;case"textarea":e.type=String,e.multiple=!0,e.slotProps={fullWidth:e?.fieldProps?.fullWidth??!0},e.fieldProps={...e.fieldProps||{},multiline:e?.fieldProps?.multiline??!0,rows:e?.fieldProps?.rows??4};break;case"number":case"Number":case"integer":e.type=Number;break;case"boolean":case"Boolean":e.type=Boolean;break;case"date":case"Date":e.type=Date;break;default:if(e.custom=!0,typeof e?.component=="string"){const a=B(e.component);e={...e,...a}}}if(l&&l.useReadOnlyInputAsTextField&&e.readOnly)return r(s,{index:t,method:o,input:e,children:r(I,{label:e.label,source:e.listAttribute||e.attribute,...f&&{record:f},method:d,attribute:e,resourceConfig:n,children:v(E,{fullWidth:!0,...f&&{record:f},key:t,label:e.label,source:e.listAttribute||e.attribute,...e.fieldProps,editable:!1,InputProps:{readOnly:!0,endAdornment:r(H,{position:"start",children:r(Z,{})})}})},t)});if(l&&l.readOnlyComponent&&e.readOnly)return r(s,{index:t,method:o,input:e,children:v(I,{...f&&{record:f},method:d,attribute:e,key:t,label:e.label,source:e.listAttribute||e.attribute,resourceConfig:n},r(l.readOnlyComponent,{fullWidth:!0,...f&&{record:f},input:e,label:e.label,source:e.listAttribute||e.attribute,...e.fieldProps,editable:!1,InputProps:{readOnly:!0}},t))});if(e.label||(e.label=e.attribute),e.custom&&e.component||e.type==="component"&&e.component)return r(s,{index:t,method:o,input:e,children:r(ee,{record:f,method:o,attribute:e,resourceConfig:n},t)});if(Array.isArray(e.type)&&e.type.length>0){const a=e.type[0];if(w(a))return r(s,{index:t,method:o,input:e,children:r(D,{fullWidth:!0,label:e.label,source:e.attribute,choices:R(a),...e?.fieldProps,onChange:m=>{l?.handleChange&&l.handleChange(m),e.fieldProps?.onChange&&e.fieldProps.onChange(m)}},t)});if(typeof a=="string"){const m={...F,...(P.hash.match(/\d+/g)||[]).map(Number).reduce((c,u,G)=>(c[G]=u,c),{})},b=N(m,a),[h,p]=b.split("."),i=c=>(c?c[p]:"?")||"??";if(e&&e.multiple===!1&&e.component){const c=e.component;return r(s,{index:t,method:o,input:e,children:r(S,{fullWidth:!0,allowEmpty:!0,filter:!0,pagination:!1,label:e.label,reference:h,source:e.attribute,...e.componentProps,children:r(c,{optionText:i,method:d,attribute:e,onChange:u=>{l?.handleChange&&l.handleChange(u),e.fieldProps?.onChange&&e.fieldProps.onChange(u)},resourceConfig:n})},t)})}return r(s,{index:t,method:o,input:e,children:r(T,{fullWidth:!0,filter:!0,pagination:!1,label:e.label,reference:h,source:e.attribute,...e.componentProps,children:r(V,{...e.fieldProps,children:r($,{source:p})})},t)})}else{const m=e.type;return r(s,{index:t,method:o,input:e,children:r(L,{label:e.label,source:e.attribute,...e.componentProps,children:r(K,{children:m.map((b,h)=>O(d,n,b,h))})},t)})}}if(e&&e.type===W)return r(s,{index:t,method:o,input:e,children:r(W,{placeholder:"Arr\xE1stre una im\xE1gen o haga click aqu\xED para seleccionar",source:e.attribute,label:e.label,accept:"image/*",...e.fieldProps,children:r(q,{source:"src",title:"title"})},t)});if(e&&e.type===k&&(k,{source:e.attribute,label:e.label,...e.fieldProps,children:te}),typeof e.type=="string"){if(e.type==="select"&&Array.isArray(e.options)&&e.options.length>0){const i=e.options.map(c=>({id:c.id,name:c.name}));return r(s,{index:t,method:o,input:e,children:r(C,{fullWidth:!0,label:e.label,source:e.listAttribute||e.attribute,choices:i,...e.fieldProps,onChange:c=>{l?.handleChange&&l.handleChange(c),e.fieldProps?.onChange&&e.fieldProps.onChange(c)},...e.componentProps},t)})}if(e.type==="select"&&(!e.options||e.options.length===0))return console.warn(`Select field "${e.attribute}" has no options defined. Skipping render.`),null;const a={...F,...(P.pathname.match(/\d+/g)||[]).map(Number).reduce((i,c,u)=>(i[u]=c,i),{})},m=N(a,e.type),[b,h]=m.split("."),p=e.component||C;return e&&e.multiple===!1?r(s,{index:t,method:o,input:e,children:r(S,{allowEmpty:!0,filters:!0,label:e.label,source:e.listAttribute||e.attribute,reference:b,sort:{field:h,order:"ASC"},...e.componentProps,children:r(p,{optionText:h,method:d,attribute:e,label:e?.label||"",...e.fieldProps,onChange:i=>{l?.handleChange&&l.handleChange(i),e.fieldProps?.onChange&&e.fieldProps.onChange(i)},resourceConfig:n})},t)}):r(s,{index:t,method:o,input:e,children:r(T,{reference:b,source:e.listAttribute||e.attribute,...e.componentProps,children:r(D,{optionText:h,fullWidth:!0,label:e?.label||"",...e.fieldProps,onChange:i=>{l?.handleChange&&l.handleChange(i),e.fieldProps?.onChange&&e.fieldProps.onChange(i)}})},t)})}switch(e.type){case Number:return r(s,{index:t,method:o,input:e,children:r(X,{fullWidth:!0,label:e.label,source:e.attribute,...e.fieldProps,onChange:a=>{l?.handleChange&&l.handleChange(a),e.fieldProps?.onChange&&e.fieldProps.onChange(a)}},t)});case Boolean:return r(s,{index:t,method:o,input:e,children:A("div",{children:[e?.showLabel!==!1&&r(Q,{htmlFor:e.listAttribute||e.attribute,children:e.label}),r(U,{record:f,id:e.listAttribute||e.attribute,label:e.label,source:e.listAttribute||e.attribute,...e.fieldProps,onChange:a=>{l?.handleChange&&l.handleChange(a),e.fieldProps?.onChange&&e.fieldProps.onChange(a)}},t)]})});case Date:return e.fieldProps&&e.fieldProps.showTime?r(s,{index:t,method:o,input:e,children:r(M,{label:e.label,source:e.attribute,...e.fieldProps},t)}):r(s,{index:t,method:o,input:e,children:r(J,{label:e.label,source:e.attribute,...e.fieldProps,onChange:a=>{l?.handleChange&&l.handleChange(a),e.fieldProps?.onChange&&e.fieldProps.onChange(a)}},t)})}if(w(e.type))return r(s,{index:t,method:o,input:e,children:r(C,{label:e.label,source:e.attribute,choices:R(e.type),InputProps:e.fieldOptions,onChange:a=>{l?.handleChange&&l.handleChange(a),e.fieldProps?.onChange&&e.fieldProps.onChange(a)}},t)});if(e.isPassword){const a={key:t,label:e.label,source:e.attribute,...e.slotProps?{slotProps:e.slotProps}:{}};return r(s,{index:t,method:o,input:e,children:r(x,{...a})})}const _={label:e.label,source:e.listAttribute||e.attribute,...e.fieldProps,...e.slotProps?{slotProps:e.slotProps}:{},onChange:a=>{l?.handleChange&&l.handleChange(a),e.fieldProps?.onChange&&e.fieldProps.onChange(a)}};return r(s,{index:t,method:o,input:e,children:r(E,{..._})})};var Me=O;export{Me as default};