@dashadmin/dash-auto-admin 1.3.17 → 1.3.19

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,684 @@
1
+ import {
2
+ ArrayInput,
3
+ ImageInput,
4
+ FileInput,
5
+ BooleanInput,
6
+ DateInput,
7
+ DateTimeInput,
8
+ NumberInput,
9
+ SelectArrayInput,
10
+ SelectInput,
11
+ ChipField,
12
+ ImageField,
13
+ PasswordInput,
14
+ ReferenceArrayInput,
15
+ ReferenceInput,
16
+ SimpleFormIterator,
17
+ SingleFieldList,
18
+ TextInput,
19
+ useRecordContext,
20
+ } from 'react-admin';
21
+ import { ErrorMessage } from "@hookform/error-message"
22
+
23
+ import { InputAdornment, InputLabel, TextField, Typography } from '@mui/material';
24
+ import Visibility from '@mui/icons-material/Visibility';
25
+
26
+ import IDashAutoAdminAttribute from '../interfaces/IDashAutoAdminAttribute';
27
+ import IDashAutoAdminFormOptions from '../interfaces/IDashAutoAdminFormOptions';
28
+
29
+ import { UserAction } from '../wrappers';
30
+ import { FunctionField } from 'react-admin';
31
+ import { FileField } from 'react-admin';
32
+
33
+ import React, { JSX, useEffect } from 'react';
34
+ import IDashAutoAdminResourceConfig from '../interfaces/IDashAutoAdminResourceConfig';
35
+ import IDashAutoAdminCustomFieldComponent from '../interfaces/IDashAutoAdminCustomFieldComponent';
36
+ import enumToChoices from '../utils/enumToChoices';
37
+ import isEnum from '../utils/isEnum';
38
+ import { useLocation, useParams } from 'react-router';
39
+ import replaceParams from '../utils/replaceParams';
40
+ import { useSelector } from 'react-redux';
41
+ import { IDASHAppState } from 'dash-admin-state';
42
+ import { useEditContext } from 'react-admin';
43
+ import { useFormContext } from 'react-hook-form';
44
+ import { useComponentRegistry } from '../DashAutoAdminComponentRegistry';
45
+
46
+ export interface IGroupExtraData {
47
+ name: string;
48
+ icon?: JSX.Element;
49
+ }
50
+
51
+ export interface IFieldWrapper {
52
+ method: 'list' | 'view' | 'create' | 'edit';
53
+ index: React.Key;
54
+ input: IDashAutoAdminAttribute;
55
+ children: JSX.Element;
56
+ }
57
+
58
+
59
+ const FunctionFieldWrapper = ({
60
+ index,
61
+ method,
62
+ input,
63
+ children,
64
+ ..._props
65
+ }: IFieldWrapper): JSX.Element => {
66
+ const sortable = input?.sortable === true ? true : false;
67
+
68
+ const {
69
+ formState: { errors },
70
+ } = useFormContext()
71
+
72
+
73
+ if (method === 'edit') {
74
+ return (
75
+ <div
76
+ className={`auto-admin-field auto-admin-field-${method}`}
77
+ key={index}
78
+ >
79
+ <FunctionField
80
+ //key={index}
81
+ label={input?.label || input.attribute}
82
+ sortable={sortable}
83
+ {...(sortable && { sortBy: input.listAttribute || input.attribute })}
84
+ render={(record) => {
85
+ return React.cloneElement(children, { record: record });
86
+ }}
87
+ />
88
+
89
+ {!input?.hideErrorMessage || input?.custom && <ErrorMessage
90
+ errors={errors}
91
+ name={input.attribute}
92
+ render={(error) => {
93
+ return error ? <Typography className='dash-admin-field-error' color="error" >{typeof error.message === 'string' ? error.message : typeof (error as any).message?.message === 'string' ? (error as any).message?.message : JSON.stringify(error)}</Typography> : null;
94
+ }}
95
+ />}
96
+
97
+ </div>
98
+ );
99
+ }
100
+ return (
101
+ <div className={`auto-admin-field auto-admin-field-${method}`} key={index}>
102
+ {children}
103
+ </div>
104
+ );
105
+ };
106
+
107
+ /**
108
+ * The `AttributeToInput` function is a React component that renders an input field based on the provided `IDashAutoAdminAttribute` object.
109
+ * It handles various input types, including strings, numbers, booleans, dates, and enums. The function also supports custom components, reference inputs, and array inputs.
110
+ *
111
+ * The function takes the following parameters:
112
+ * - `method`: The current operation mode, such as 'list', 'view', 'create', or 'edit'.
113
+ * - `resourceConfig`: The configuration object for the current resource.
114
+ * - `input`: The `IDashAutoAdminAttribute` object that defines the input field.
115
+ * - `index`: An optional index value for the input field.
116
+ * - `options`: An optional object that provides additional configuration and field options.
117
+ *
118
+ * The function returns a JSX element that represents the input field, wrapped in a `FunctionFieldWrapper` component. The `FunctionFieldWrapper` component handles the rendering of the input field based on the current operation mode.
119
+ */
120
+
121
+ // Safe hook to get edit context only when available
122
+ const useSafeEditContext = () => {
123
+ try {
124
+ return useEditContext();
125
+ } catch (error) {
126
+ // EditContext is not available (e.g., in create mode)
127
+ return null;
128
+ }
129
+ };
130
+
131
+ // Safe hook to get record context
132
+ const useSafeRecordContext = () => {
133
+ try {
134
+ return useRecordContext();
135
+ } catch (error) {
136
+ // RecordContext is not available
137
+ return null;
138
+ }
139
+ };
140
+
141
+ // Custom hook to get the appropriate record context
142
+ const useRecordByMethod = (method: string, mode?: string) => {
143
+ // Always call both hooks, but handle when they're not available
144
+ const editContext = useSafeEditContext();
145
+ const recordContext = useSafeRecordContext();
146
+
147
+ // Return the appropriate context based on method
148
+ if (method === 'edit' || mode === 'edit') {
149
+ return editContext;
150
+ }
151
+ return recordContext;
152
+ };
153
+ const AttributeToInput = (
154
+ method: 'list' | 'view' | 'create' | 'edit',
155
+ resourceConfig: IDashAutoAdminResourceConfig,
156
+ input: IDashAutoAdminAttribute,
157
+ index?: number,
158
+ options?: IDashAutoAdminFormOptions,
159
+ ) => {
160
+ // Get the component registry
161
+ const { components } = useComponentRegistry();
162
+
163
+ // Move all hook calls to the top level, before any conditional logic
164
+ const mode = options?.mode || 'view';
165
+ const record = useRecordByMethod(method, options?.mode);
166
+ const location = useLocation();
167
+ const params = useParams();
168
+
169
+ const typeComponentMapper = (type: string) => {
170
+ const component = components[type];
171
+
172
+ if (component) {
173
+ return { custom: true, type: "component", component };
174
+ }
175
+ return { custom: true, type: "component", component: () => <>No component for {type}</> };
176
+ };
177
+
178
+ const ComponentWrapper =
179
+ resourceConfig?.fieldWrapper &&
180
+ typeof resourceConfig.fieldWrapper === 'function'
181
+ ? resourceConfig.fieldWrapper
182
+ : ({
183
+ _record,
184
+ _method,
185
+ _attribute,
186
+ _resourceConfig,
187
+ children,
188
+ }: IDashAutoAdminCustomFieldComponent) => children;
189
+
190
+ /*
191
+ input.type != 'custom'
192
+ input.type does not contains dots
193
+ input.type dies not represents an Enum or Array.
194
+ */
195
+
196
+ if (typeof input.type === "string" && !input.type.includes(".") && !Array.isArray(input.type)) {
197
+ switch (input.type) {
198
+ case 'string':
199
+ case 'text':
200
+ case 'String':
201
+ input.type = String;
202
+ input.slotProps = {
203
+ fullWidth: input?.fieldProps?.fullWidth ?? true,
204
+ };
205
+ break;
206
+ case 'textarea':
207
+ input.type = String;
208
+ input.multiple = true;
209
+
210
+ input.slotProps = {
211
+ fullWidth: input?.fieldProps?.fullWidth ?? true,
212
+ };
213
+
214
+ input.fieldProps = {
215
+ ...(input.fieldProps || {}),
216
+ multiline: input?.fieldProps?.multiline ?? true,
217
+ rows: input?.fieldProps?.rows ?? 4,
218
+ };
219
+ break;
220
+ case 'number':
221
+ case 'Number':
222
+ case 'integer':
223
+ input.type = Number;
224
+ break;
225
+ case 'boolean':
226
+ case 'Boolean':
227
+ input.type = Boolean;
228
+ break;
229
+ case 'date':
230
+ case 'Date':
231
+ input.type = Date;
232
+ break;
233
+ case 'custom':
234
+ default:
235
+ input.custom = true;
236
+
237
+ if(typeof input?.component === "string") {
238
+ input = { ...input, ...typeComponentMapper( input.component ) };
239
+ }
240
+
241
+ }
242
+ }
243
+
244
+ if (options && options.useReadOnlyInputAsTextField && input.readOnly) {
245
+ return (
246
+ <FunctionFieldWrapper index={index} method={mode} input={input}>
247
+ <ComponentWrapper
248
+ key={index}
249
+ label={input.label}
250
+ source={input.listAttribute || input.attribute}
251
+ {...(record && { record: record })}
252
+ method={method}
253
+ attribute={input}
254
+ resourceConfig={resourceConfig}
255
+ >
256
+ <TextInput
257
+ fullWidth
258
+ {...(record && { record: record })}
259
+ key={index}
260
+ label={input.label}
261
+ source={input.listAttribute || input.attribute}
262
+ {...{
263
+ ...input.fieldProps,
264
+ editable: false,
265
+ InputProps: {
266
+ readOnly: true,
267
+ endAdornment: (
268
+ <InputAdornment position='start'>
269
+ <Visibility />
270
+ </InputAdornment>
271
+ ),
272
+ },
273
+ }}
274
+ />
275
+ </ComponentWrapper>
276
+ </FunctionFieldWrapper>
277
+ );
278
+ } else if (options && options.readOnlyComponent && input.readOnly) {
279
+ return (
280
+ <FunctionFieldWrapper index={index} method={mode} input={input}>
281
+ <ComponentWrapper
282
+ {...(record && { record: record })}
283
+ method={method}
284
+ attribute={input}
285
+ key={index}
286
+ label={input.label}
287
+ source={input.listAttribute || input.attribute}
288
+ resourceConfig={resourceConfig}
289
+ >
290
+ <options.readOnlyComponent
291
+ fullWidth
292
+ key={index}
293
+ {...(record && { record: record })}
294
+ input={input}
295
+ label={input.label}
296
+ source={input.listAttribute || input.attribute}
297
+ {...{
298
+ ...input.fieldProps,
299
+ editable: false,
300
+ InputProps: { readOnly: true },
301
+ }}
302
+ />
303
+ </ComponentWrapper>
304
+ </FunctionFieldWrapper>
305
+ );
306
+ }
307
+
308
+ /* Force the attribute name to be the label, if not label provided */
309
+ if (!input.label) input.label = input.attribute;
310
+
311
+ if (
312
+ (input.custom && input.component) ||
313
+ (input.type === 'component' && input.component)
314
+ ) {
315
+
316
+ return (
317
+ <FunctionFieldWrapper index={index} method={mode} input={input}>
318
+ <UserAction
319
+ record={record}
320
+ key={index}
321
+ method={mode}
322
+ attribute={input}
323
+ resourceConfig={resourceConfig}
324
+ />
325
+ </FunctionFieldWrapper>
326
+ );
327
+ }
328
+
329
+ if (Array.isArray(input.type) && input.type.length > 0) {
330
+ const inputType: string | IDashAutoAdminAttribute = input.type[0];
331
+ /* Array of enum values – We use a SelectArrayInput */
332
+ if (isEnum(inputType)) {
333
+ return (
334
+ <FunctionFieldWrapper index={index} method={mode} input={input}>
335
+ <SelectArrayInput
336
+ key={index}
337
+ fullWidth
338
+ label={input.label}
339
+ source={input.attribute}
340
+ choices={enumToChoices(inputType)}
341
+ {...input?.fieldProps}
342
+ onChange={e => {
343
+ if (options?.handleChange) {
344
+ options.handleChange(e);
345
+ }
346
+ if (input.fieldProps?.onChange) {
347
+ input.fieldProps.onChange(e)
348
+ }
349
+ }}
350
+ />
351
+ </FunctionFieldWrapper>
352
+ );
353
+ }
354
+ /* Recurse */
355
+
356
+ if (typeof inputType === 'string') {
357
+ const _params = {
358
+ ...params, ...(location.hash.match(/\d+/g) || []).map(Number).reduce((acc, curr, currentIndex) => {
359
+ acc[currentIndex] = curr;
360
+ return acc;
361
+ }, {})
362
+ };
363
+
364
+ const _inputType = replaceParams(_params, inputType);
365
+ const [reference, sourceName] = _inputType.split('.');
366
+ const safeIfNull = (choice: any) =>
367
+ (choice ? choice[sourceName] : '?') || '??';
368
+
369
+ if (input && input.multiple === false && input.component) {
370
+ const CustomComponent = input.component;
371
+ return (
372
+ <FunctionFieldWrapper index={index} method={mode} input={input}>
373
+ <ReferenceInput
374
+ key={index}
375
+ fullWidth
376
+ allowEmpty
377
+ filter
378
+ pagination={false}
379
+ label={input.label}
380
+ reference={reference}
381
+ source={input.attribute}
382
+ {...input.componentProps}
383
+ >
384
+ <CustomComponent
385
+ optionText={safeIfNull}
386
+ method={'edit'} // edit because its AttributeToInput
387
+ attribute={input}
388
+ onChange={e => {
389
+ if (options?.handleChange) {
390
+ options.handleChange(e);
391
+ }
392
+ if (input.fieldProps?.onChange) {
393
+ input.fieldProps.onChange(e)
394
+ }
395
+ }}
396
+ resourceConfig={resourceConfig}
397
+ />
398
+ </ReferenceInput>
399
+ </FunctionFieldWrapper>
400
+ );
401
+ }
402
+
403
+ return (
404
+ <FunctionFieldWrapper index={index} method={mode} input={input}>
405
+ <ReferenceArrayInput
406
+ key={index}
407
+ fullWidth
408
+ filter
409
+ pagination={false}
410
+ label={input.label}
411
+ reference={reference}
412
+ source={input.attribute}
413
+ {...input.componentProps}
414
+ >
415
+ <SingleFieldList>
416
+ <ChipField source={sourceName} />
417
+ </SingleFieldList>
418
+ </ReferenceArrayInput>
419
+ </FunctionFieldWrapper>
420
+ );
421
+ } else {
422
+ const inputTypeArray = input.type as IDashAutoAdminAttribute[];
423
+
424
+ return (
425
+ <FunctionFieldWrapper index={index} method={mode} input={input}>
426
+ <ArrayInput
427
+ key={index}
428
+ label={input.label}
429
+ source={input.attribute}
430
+ >
431
+ <SimpleFormIterator>
432
+ {inputTypeArray.map((attribute, idx) =>
433
+ AttributeToInput(method, resourceConfig, attribute, idx),
434
+ )}
435
+ </SimpleFormIterator>
436
+ </ArrayInput>
437
+ </FunctionFieldWrapper>
438
+ );
439
+ }
440
+ }
441
+
442
+ if (input && input.type === ImageInput) {
443
+ return (
444
+ <FunctionFieldWrapper index={index} method={mode} input={input}>
445
+ <ImageInput
446
+ key={index}
447
+ placeholder={'Arrástre una imágen o haga click aquí para seleccionar'}
448
+ source={input.attribute}
449
+ label={input.label}
450
+ accept='image/*'
451
+ {...input.fieldProps}
452
+ >
453
+ <ImageField source='src' title='title' />
454
+ </ImageInput>
455
+ </FunctionFieldWrapper>
456
+ );
457
+ }
458
+
459
+ if (input && input.type === FileInput) {
460
+ <FunctionFieldWrapper index={index} method={mode} input={input}>
461
+ <FileInput
462
+ key={index}
463
+ placeholder={'Arrástre un archivo o haga click aquí para seleccionar'}
464
+ source={input.attribute}
465
+ label={input.label}
466
+ {...input.fieldProps}
467
+ >
468
+ <FileField source='src' title='title' />
469
+ </FileInput>
470
+ </FunctionFieldWrapper>;
471
+ }
472
+
473
+ /* Special cases – Passing strings, passing enums */
474
+ if (typeof input.type === 'string') {
475
+ const _params = {
476
+ ...params, ...(location.pathname.match(/\d+/g) || []).map(Number).reduce((acc, curr, currentIndex) => {
477
+ acc[currentIndex] = curr;
478
+ return acc;
479
+ }, {})
480
+ };
481
+
482
+ const _inputType = replaceParams(_params, input.type);
483
+ const [reference, sourceName] = _inputType.split('.');
484
+ const CustomComponent = input.component || SelectInput;
485
+
486
+ if (input && input.multiple === false) {
487
+ return (
488
+ <FunctionFieldWrapper index={index} method={mode} input={input}>
489
+ <ReferenceInput
490
+ key={index}
491
+ allowEmpty
492
+ filters
493
+ label={input.label}
494
+ source={input.listAttribute || input.attribute}
495
+ reference={reference}
496
+ sort={{ field: sourceName, order: 'ASC' }}
497
+ {...input.componentProps}
498
+ >
499
+ <CustomComponent
500
+ optionText={sourceName}
501
+ method={'edit'} // edit because its AttributeToInput
502
+ attribute={input}
503
+ label={input?.label || ''}
504
+ {...input.fieldProps}
505
+ onChange={e => {
506
+ if (options?.handleChange) {
507
+ options.handleChange(e);
508
+ }
509
+ if (input.fieldProps?.onChange) {
510
+ input.fieldProps.onChange(e)
511
+ }
512
+ }}
513
+ resourceConfig={resourceConfig}
514
+ />
515
+ </ReferenceInput>
516
+ </FunctionFieldWrapper>
517
+ );
518
+ }
519
+
520
+ return (
521
+ <FunctionFieldWrapper index={index} method={mode} input={input}>
522
+ <ReferenceArrayInput
523
+ key={index}
524
+ reference={reference}
525
+ source={input.listAttribute || input.attribute}
526
+ {...input.componentProps}
527
+ >
528
+ <SelectArrayInput
529
+ optionText={sourceName}
530
+ fullWidth
531
+ label={input?.label || ''}
532
+ {...input.fieldProps}
533
+ onChange={e => {
534
+ if (options?.handleChange) {
535
+ options.handleChange(e);
536
+ }
537
+ if (input.fieldProps?.onChange) {
538
+ input.fieldProps.onChange(e)
539
+ }
540
+ }}
541
+ />
542
+ </ReferenceArrayInput>
543
+ </FunctionFieldWrapper>
544
+ );
545
+ }
546
+
547
+ switch (input.type) {
548
+ case Number:
549
+ return (
550
+ <FunctionFieldWrapper index={index} method={mode} input={input}>
551
+ <NumberInput
552
+ key={index}
553
+ fullWidth
554
+ label={input.label}
555
+ source={input.attribute}
556
+ {...input.fieldProps}
557
+ onChange={e => {
558
+ if (options?.handleChange) {
559
+ options.handleChange(e);
560
+ }
561
+ if (input.fieldProps?.onChange) {
562
+ input.fieldProps.onChange(e)
563
+ }
564
+ }}
565
+ />
566
+ </FunctionFieldWrapper>
567
+ );
568
+
569
+ case Boolean:
570
+ return <FunctionFieldWrapper index={index} method={mode} input={input}>
571
+ <div>
572
+ {input?.showLabel !== false && (
573
+ <InputLabel htmlFor={input.listAttribute || input.attribute}>
574
+ {input.label}
575
+ </InputLabel>
576
+ )}
577
+ <BooleanInput
578
+ record={record}
579
+ key={index}
580
+ id={input.listAttribute || input.attribute}
581
+ label={input.label}
582
+ source={input.listAttribute || input.attribute}
583
+ {...input.fieldProps}
584
+ onChange={e => {
585
+ if (options?.handleChange) {
586
+ options.handleChange(e);
587
+ }
588
+ if (input.fieldProps?.onChange) {
589
+ input.fieldProps.onChange(e)
590
+ }
591
+ }}
592
+ />
593
+ </div>
594
+ </FunctionFieldWrapper>
595
+
596
+
597
+ case Date:
598
+ return input.fieldProps && input.fieldProps.showTime ? (
599
+ <FunctionFieldWrapper index={index} method={mode} input={input}>
600
+ <DateTimeInput
601
+ key={index}
602
+ label={input.label}
603
+ source={input.attribute}
604
+ {...input.fieldProps}
605
+ />
606
+ </FunctionFieldWrapper>
607
+ ) : (
608
+ <FunctionFieldWrapper index={index} method={mode} input={input}>
609
+ <DateInput
610
+ key={index}
611
+ label={input.label}
612
+ source={input.attribute}
613
+ {...input.fieldProps}
614
+ onChange={e => {
615
+ if (options?.handleChange) {
616
+ options.handleChange(e);
617
+ }
618
+ if (input.fieldProps?.onChange) {
619
+ input.fieldProps.onChange(e)
620
+ }
621
+ }}
622
+ />
623
+ </FunctionFieldWrapper>
624
+ );
625
+ }
626
+ if (isEnum(input.type)) {
627
+ return (
628
+ <FunctionFieldWrapper index={index} method={mode} input={input}>
629
+ <SelectInput
630
+ key={index}
631
+ label={input.label}
632
+ source={input.attribute}
633
+ choices={enumToChoices(input.type)}
634
+ options={input.fieldProps}
635
+ onChange={e => {
636
+ if (options?.handleChange) {
637
+ options.handleChange(e);
638
+ }
639
+ if (input.fieldProps?.onChange) {
640
+ input.fieldProps.onChange(e)
641
+ }
642
+ }}
643
+ />
644
+ </FunctionFieldWrapper>
645
+ );
646
+ }
647
+
648
+ if (input.isPassword) {
649
+ const passwordProps = {
650
+ key: index,
651
+ label: input.label,
652
+ source: input.attribute,
653
+ ...(input.slotProps ? { slotProps: input.slotProps } : {})
654
+ }
655
+
656
+ return (
657
+ <FunctionFieldWrapper index={index} method={mode} input={input}>
658
+ <PasswordInput {...passwordProps} />
659
+ </FunctionFieldWrapper>
660
+ );
661
+ }
662
+ const textFieldProps = {
663
+ label: input.label,
664
+ source: input.listAttribute || input.attribute,
665
+ ...input.fieldProps,
666
+ ...input.slotProps ? { slotProps: input.slotProps } : {},
667
+ onChange: (e) => {
668
+ if (options?.handleChange) {
669
+ options.handleChange(e);
670
+ }
671
+ if (input.fieldProps?.onChange) {
672
+ input.fieldProps.onChange(e)
673
+ }
674
+ }
675
+ }
676
+
677
+ return <FunctionFieldWrapper index={index} method={mode} input={input}>
678
+ <TextInput
679
+ {...textFieldProps}
680
+ />
681
+ </FunctionFieldWrapper>
682
+ };
683
+
684
+ export default AttributeToInput;
@@ -0,0 +1 @@
1
+ import{Fragment as w,jsx as e,jsxs as D}from"react/jsx-runtime";import{Drawer as d}from"@mui/material";import t from"react";const n=t.createContext(400),u=({children:a,defaultWidth:o,...s})=>{const[r,l]=t.useState(o),i=()=>e(w,{});return e(d,{PaperProps:{style:{width:r}},...s,children:D(n.Provider,{value:r,children:[e(i,{}),a]})})};export{u as AutoAdminResizableDrawer,n as AutoAdminResizableDrawerContext};
@@ -0,0 +1 @@
1
+ import{jsx as r,jsxs as F}from"react/jsx-runtime";import{useMemo as o,memo as s}from"react";import{Datagrid as _,FunctionField as y}from"react-admin";import{AttributeToField as L}from"./AttributeToField";import{TableContainer as R}from"@mui/material";import{ListDeleteButton as I,ListEditButton as N,ListViewButton as B}from"../toolbar/buttons/ListButtons";const k=s(B),P=s(N),w=s(I),W=({resourceConfig:t,schema:n,locale:m,...d})=>{const c=m||t?.locale,i=t?.schema||n;if(!i||!i.filter)throw new Error("Schema must be present as prop or as an attribute of resourceConfig object, and must be iterable");const l=o(()=>i.filter(e=>e.attribute==="id").length!==0,[i]),p=o(()=>({...t.dataGridProps,...d}),[t.dataGridProps,d]),u=o(()=>i.filter(e=>e.inList!==!1),[i,c]),h=s(e=>{const{children:a,className:f,gridWrapperProps:G}=e;return r(R,{sx:{mt:1},className:"dash-datagrid-wrapper "+(f||""),...G,children:a})}),A=t.dataGridWrapper||h,D=t.dataGridRootComponent||_,b=o(()=>t?.customListButtons?t.customListButtons.map((e,a)=>r(e.component,{...e.props},"list_custom_buttton"+a)):null,[t?.customListButtons]);return r(A,{className:t?.dataGridProps?.stickyHeader?"dash-sticky-header":"",children:F(D,{...p,children:[!l&&t.hideSchemaId!==!0&&r(y,{source:"id",sortable:!0,render:e=>{const a=e?.id;return a&&isNaN(Number(a))?String(a).slice(-6):a}},"default_id_field_0"),u.map((e,a)=>L("list",t,e,a)),r(k,{resourceConfig:t},"list_view_btn"),r(P,{resourceConfig:t},"list_edit_btn"),r(w,{resourceConfig:t},"list_delete_btn"),b]})})};var J=W;export{J as default};
@@ -0,0 +1 @@
1
+ import{jsx as a,jsxs as o}from"react/jsx-runtime";import{FormTab as i,ReferenceManyField as l,ReferenceArrayField as d}from"react-admin";import r from"./AutoDataGrid";import n from"./components/ExtendedPagination";const f=e=>{const t=e.type?e.type:"ReferenceManyField";return o(i,{label:e.tab||e.reference,children:[t==="ReferenceManyField"&&a(l,{fullWidth:!0,reference:e.reference,target:e.target,pagination:a(n,{}),children:a(r,{schema:e.schema})}),t==="ReferenceArrayField"&&o(d,{fullWidth:!0,reference:e.reference,source:e.target,pagination:a(n,{}),children:[" ",a(r,{schema:e.schema})]})]},e.reference)};var g=f;export{g as default};