@dashadmin/dash-auto-admin 1.3.25 → 1.3.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,466 @@
1
+ /**
2
+ * Dash Data Provider
3
+ *
4
+ * Default data provider for Dash applications.
5
+ * This provider handles CRUD operations with the backend API.
6
+ *
7
+ * Can be extended or overridden by apps for custom behavior.
8
+ */
9
+ import type { DataProvider } from 'react-admin';
10
+ import queryString from 'query-string';
11
+
12
+ // ============================================================================
13
+ // TYPES
14
+ // ============================================================================
15
+
16
+ export interface DashDataProviderConfig {
17
+ /**
18
+ * Axios instance or hook to use for API calls
19
+ */
20
+ useAxios: () => any;
21
+
22
+ /**
23
+ * Storage utility (dashStorage from dash-utils)
24
+ */
25
+ storage: {
26
+ getItem: (key: string) => string | null;
27
+ setItem: (key: string, value: string) => void;
28
+ };
29
+
30
+ /**
31
+ * Cache invalidator hash function
32
+ */
33
+ getCacheHash?: (resource: string) => string | null;
34
+
35
+ /**
36
+ * Get resource configuration
37
+ */
38
+ getResourceConfig?: (resource: string) => any;
39
+
40
+ /**
41
+ * Process post data for a resource
42
+ */
43
+ processPostData?: (resource: string, data: any, operation: string) => any;
44
+
45
+ /**
46
+ * Process form data for multipart uploads
47
+ */
48
+ processFormData?: (resource: string, data: any) => FormData;
49
+
50
+ /**
51
+ * Process axios errors
52
+ */
53
+ processAxiosError?: (error: any, resource: string, operation: string) => any;
54
+ }
55
+
56
+ export interface DashDataProviderOverrides {
57
+ getList?: DataProvider['getList'];
58
+ getOne?: DataProvider['getOne'];
59
+ getMany?: DataProvider['getMany'];
60
+ getManyReference?: DataProvider['getManyReference'];
61
+ create?: DataProvider['create'];
62
+ update?: DataProvider['update'];
63
+ updateMany?: DataProvider['updateMany'];
64
+ delete?: DataProvider['delete'];
65
+ deleteMany?: DataProvider['deleteMany'];
66
+ }
67
+
68
+ // ============================================================================
69
+ // HELPER FUNCTIONS
70
+ // ============================================================================
71
+
72
+ const defaultProcessPostData = (resource: string, data: any, operation: string) => data;
73
+
74
+ const defaultProcessFormData = (resource: string, data: any): FormData => {
75
+ const formData = new FormData();
76
+ Object.keys(data).forEach(key => {
77
+ if (data[key] !== undefined && data[key] !== null) {
78
+ if (data[key] instanceof File) {
79
+ formData.append(key, data[key]);
80
+ } else if (typeof data[key] === 'object') {
81
+ formData.append(key, JSON.stringify(data[key]));
82
+ } else {
83
+ formData.append(key, String(data[key]));
84
+ }
85
+ }
86
+ });
87
+ return formData;
88
+ };
89
+
90
+ // ============================================================================
91
+ // FACTORY FUNCTION
92
+ // ============================================================================
93
+
94
+ /**
95
+ * Create a Dash data provider with the given configuration
96
+ *
97
+ * @param config - Configuration for the data provider
98
+ * @param overrides - Optional method overrides
99
+ * @returns DataProvider compatible with react-admin
100
+ *
101
+ * @example
102
+ * ```tsx
103
+ * import { createDashDataProvider } from 'dash-auto-admin';
104
+ *
105
+ * const dataProvider = createDashDataProvider({
106
+ * useAxios: () => axiosInstance,
107
+ * storage: dashStorage,
108
+ * // ... other config
109
+ * });
110
+ * ```
111
+ */
112
+ export const createDashDataProvider = (
113
+ config: DashDataProviderConfig,
114
+ overrides: DashDataProviderOverrides = {}
115
+ ): DataProvider => {
116
+ const {
117
+ useAxios,
118
+ storage,
119
+ getCacheHash = () => null,
120
+ getResourceConfig = () => undefined,
121
+ processPostData = defaultProcessPostData,
122
+ processFormData = defaultProcessFormData,
123
+ processAxiosError = (error) => { throw error; }
124
+ } = config;
125
+
126
+ const defaultProvider: DataProvider = {
127
+ getList: async (resource, params) => {
128
+ const tenant_id = storage.getItem('tenant_id');
129
+ const axios = useAxios();
130
+
131
+ let payload = processPostData(
132
+ resource,
133
+ { ...params.filter, tenant_id: tenant_id },
134
+ 'getList',
135
+ );
136
+
137
+ const pagination =
138
+ params.filter && !!(params.filter as any).pagination
139
+ ? (params.filter as any).pagination
140
+ : params.pagination
141
+ ? params.pagination
142
+ : false;
143
+
144
+ if (pagination) {
145
+ payload = { ...payload, pagination: true, ...pagination };
146
+ } else {
147
+ payload = { ...payload, pagination: false };
148
+ }
149
+
150
+ payload = { ...payload, ...params.meta };
151
+
152
+ const hasSort = params.sort && params.sort.field && params.sort.order;
153
+
154
+ if (hasSort && !params.meta?.removeSortFilters) {
155
+ payload = {
156
+ ...payload,
157
+ ...{ ...params.sort, order: (params.sort.order).toLowerCase() },
158
+ };
159
+ }
160
+
161
+ const hash = getCacheHash(resource);
162
+ if (hash) {
163
+ payload = { ...payload, hash };
164
+ }
165
+
166
+ const processedQuery = queryString.stringify(payload, { arrayFormat: 'bracket' });
167
+ let url = `${resource}?${processedQuery}`;
168
+
169
+ const origin = url.includes('forSelect') ? 'forSelect' : url.includes('getMany') ? 'getMany' : 'getList';
170
+
171
+ window.dispatchEvent(
172
+ new MessageEvent('auto-admin-loading-state', {
173
+ data: true,
174
+ origin: origin,
175
+ lastEventId: url,
176
+ }),
177
+ );
178
+
179
+ try {
180
+ const response = await axios.get(url);
181
+ let results: { data: any[]; total: number };
182
+
183
+ if (typeof response.data?.data?.total !== 'undefined') {
184
+ results = response.data.data;
185
+ } else if (response?.data?.data && Array.isArray(response.data.data)) {
186
+ results = { data: response.data.data, total: response.data.total || response.data.data.length };
187
+ } else if (response?.data && Array.isArray(response.data)) {
188
+ results = { data: response.data, total: response.data.length };
189
+ } else {
190
+ results = { data: [], total: 0 };
191
+ }
192
+
193
+ window.dispatchEvent(
194
+ new MessageEvent('auto-admin-loading-state', {
195
+ data: false,
196
+ origin: origin,
197
+ lastEventId: url,
198
+ }),
199
+ );
200
+
201
+ return results;
202
+ } catch (e: any) {
203
+ window.dispatchEvent(new MessageEvent('DASHGlobalError', { data: { error: e, config: { dialog: true } } }));
204
+ return { data: [], total: 0 };
205
+ } finally {
206
+ window.dispatchEvent(
207
+ new MessageEvent('auto-admin-loading-state', {
208
+ data: false,
209
+ origin: origin,
210
+ lastEventId: url,
211
+ }),
212
+ );
213
+ }
214
+ },
215
+
216
+ getOne: async (resource, params) => {
217
+ const axios = useAxios();
218
+
219
+ try {
220
+ const response = await axios.get(
221
+ `${resource}/${params.id}`,
222
+ params.meta ? { params: params.meta } : {},
223
+ );
224
+
225
+ return { data: response.data };
226
+ } catch (e: any) {
227
+ throw e;
228
+ }
229
+ },
230
+
231
+ getMany: async (resource, params) => {
232
+ const axios = useAxios();
233
+
234
+ const paramsIds =
235
+ Array.isArray(params.ids) &&
236
+ params.ids.length > 0 &&
237
+ Array.isArray(params.ids[0])
238
+ ? params.ids[0]
239
+ : params.ids;
240
+
241
+ let query: any = {
242
+ ids:
243
+ Array.isArray(paramsIds) &&
244
+ paramsIds.length > 0 &&
245
+ (paramsIds[0] as any)?.id
246
+ ? paramsIds.map((object: any) => object.id)
247
+ : paramsIds,
248
+ };
249
+
250
+ query = { ...query, pagination: false };
251
+
252
+ const hash = getCacheHash(resource);
253
+ if (hash) {
254
+ query = { ...query, hash };
255
+ }
256
+
257
+ const _query = queryString.stringify(query, { arrayFormat: 'bracket' });
258
+ const url = `${resource}/getMany?${_query}`;
259
+
260
+ try {
261
+ const response = await axios.get(url);
262
+ const results = response.data;
263
+
264
+ return {
265
+ data: results.data,
266
+ total:
267
+ results.data && results.data.total
268
+ ? results.data.total
269
+ : parseInt(response.headers['content-range']) || 0,
270
+ };
271
+ } catch (e: any) {
272
+ throw e;
273
+ }
274
+ },
275
+
276
+ getManyReference: async (resource, params) => {
277
+ const tenant_id = storage.getItem('tenant_id');
278
+ const axios = useAxios();
279
+
280
+ const pagination =
281
+ params.filter && (params.filter as any).pagination
282
+ ? (params.filter as any).pagination
283
+ : false;
284
+
285
+ let query: any = {
286
+ ...params.filter,
287
+ [params.target]: params.id,
288
+ tenant_id,
289
+ };
290
+
291
+ if (pagination) {
292
+ query = { ...query, pagination: true, ...pagination };
293
+ } else {
294
+ query = { ...query, pagination: false };
295
+ }
296
+
297
+ const url = `${resource}/getManyReference?${queryString.stringify(query, { arrayFormat: 'bracket' })}`;
298
+
299
+ try {
300
+ const response = await axios.get(url);
301
+ const results = response.data;
302
+
303
+ return {
304
+ data: results,
305
+ total:
306
+ results.data && results.data.total
307
+ ? results.data.total
308
+ : parseInt(response.headers['content-range']) || 0,
309
+ };
310
+ } catch (e: any) {
311
+ throw e;
312
+ }
313
+ },
314
+
315
+ update: async (resource, params) => {
316
+ const axios = useAxios();
317
+ const resourceConfig = getResourceConfig(resource);
318
+ const isFormData =
319
+ resourceConfig?.isFormData === true ||
320
+ params.data?.isFormData === true ||
321
+ params.meta?.isFormData === true;
322
+
323
+ const tenant_id =
324
+ params && params.data && params.data.tenant_id
325
+ ? params.data.tenant_id
326
+ : storage.getItem('tenant_id');
327
+
328
+ const resourcePath = /\/\d+(?:\/[^\/]*)?$/.test(resource)
329
+ ? resource
330
+ : (params.id ? `${resource}/${params.id}` : resource);
331
+
332
+ const postData = processPostData(
333
+ resourcePath,
334
+ { ...params.data, ...{ tenant_id: tenant_id } },
335
+ 'update',
336
+ );
337
+
338
+ let method: 'POST' | 'PUT' = params.meta?.method || 'PUT';
339
+ method = postData?.axiosMethod || method;
340
+ delete postData.axiosMethod;
341
+
342
+ if (method === "PUT") {
343
+ postData._method = "PUT";
344
+ }
345
+
346
+ try {
347
+ if (isFormData) {
348
+ const form: FormData = processFormData(resource, postData);
349
+ const response = await axios.post(resourcePath, form, {
350
+ headers: { 'Content-Type': 'multipart/form-data' },
351
+ });
352
+ return response;
353
+ }
354
+
355
+ const response = await axios.post(resourcePath, postData);
356
+ return response;
357
+ } catch (e: unknown) {
358
+ throw processAxiosError(e, resource, 'update');
359
+ }
360
+ },
361
+
362
+ create: async (resource, params) => {
363
+ const axios = useAxios();
364
+ const resourceConfig = getResourceConfig(resource);
365
+ const isFormData =
366
+ resourceConfig?.isFormData === true ||
367
+ params.data?.isFormData === true ||
368
+ params.meta?.isFormData === true;
369
+
370
+ const resourcePath = /\/[\w-]+$/.test(resource)
371
+ ? resource
372
+ : ((params.meta as any)?.id ? `${resource}/${(params.meta as any).id}` : resource);
373
+
374
+ let tenant_id = params.data?.tenant_id;
375
+ if (resource !== 'system/user' && !tenant_id) {
376
+ tenant_id = storage.getItem('tenant_id');
377
+ }
378
+
379
+ const method: 'POST' | 'PUT' = params.meta?.method || 'POST';
380
+ const action = method === 'POST' ? axios.post : axios.put;
381
+
382
+ const postData = processPostData(
383
+ resourcePath,
384
+ {
385
+ ...params.data,
386
+ ...(tenant_id ? { tenant_id: tenant_id } : {})
387
+ },
388
+ 'create',
389
+ );
390
+
391
+ try {
392
+ if (isFormData) {
393
+ const form: FormData = processFormData(resource, postData);
394
+ return await action(resourcePath, form, {
395
+ headers: { 'Content-Type': 'multipart/form-data' },
396
+ });
397
+ }
398
+
399
+ return await action(resourcePath, postData);
400
+ } catch (e: unknown) {
401
+ throw processAxiosError(e, resource, 'create');
402
+ }
403
+ },
404
+
405
+ updateMany: async (resource, params) => {
406
+ const tenant_id = storage.getItem('tenant_id');
407
+ const axios = useAxios();
408
+
409
+ const query = {
410
+ filter: JSON.stringify({ ids: params.ids }),
411
+ tenant_id,
412
+ };
413
+
414
+ const method: 'POST' | 'PUT' = params.meta?.method || 'POST';
415
+ const action = method === 'POST' ? axios.post : axios.put;
416
+
417
+ try {
418
+ const response = await action(
419
+ `${resource}/updateMany?${queryString.stringify(query, { arrayFormat: 'bracket' })}`,
420
+ params.data,
421
+ );
422
+ return response;
423
+ } catch (e: any) {
424
+ window.dispatchEvent(
425
+ new MessageEvent('dash-global-loader', { data: false }),
426
+ );
427
+ throw e;
428
+ }
429
+ },
430
+
431
+ delete: async (resource, params) => {
432
+ const tenant_id = storage.getItem('tenant_id');
433
+ const axios = useAxios();
434
+
435
+ const { data } = await axios.delete(`${resource}/${params.id}`, {
436
+ data: { tenant_id: tenant_id },
437
+ });
438
+
439
+ return { data };
440
+ },
441
+
442
+ deleteMany: async (resource, params) => {
443
+ const tenant_id = storage.getItem('tenant_id');
444
+ const axios = useAxios();
445
+
446
+ const query = {
447
+ ids: params.ids || [],
448
+ tenant_id,
449
+ };
450
+
451
+ const data = await axios.post(
452
+ `${resource}/deleteMany?${queryString.stringify(query, { arrayFormat: 'bracket' })}`,
453
+ );
454
+
455
+ return data;
456
+ },
457
+ };
458
+
459
+ // Merge default provider with overrides
460
+ return {
461
+ ...defaultProvider,
462
+ ...overrides,
463
+ };
464
+ };
465
+
466
+ export default createDashDataProvider;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Dash Providers
3
+ *
4
+ * Export all provider factories and types.
5
+ */
6
+
7
+ export {
8
+ createDashAuthProvider,
9
+ type DashAuthProviderConfig,
10
+ type DashAuthProviderOverrides
11
+ } from './DashAuthProvider';
12
+
13
+ export {
14
+ createDashDataProvider,
15
+ type DashDataProviderConfig,
16
+ type DashDataProviderOverrides
17
+ } from './DashDataProvider';
@@ -0,0 +1,59 @@
1
+ import { FC } from 'react';
2
+ import { DeleteButton } from 'react-admin';
3
+ import DashAutoAdminSaveButton from '../../DashAutoAdminSaveButton';
4
+ import { DeleteWithConfirmButton } from 'react-admin';
5
+ import { WithRecord } from 'react-admin';
6
+ import { SaveButton } from 'react-admin';
7
+ import IToolbarButton from '../../interfaces/IToolbarButton';
8
+
9
+ /**
10
+ * Renders a save button in the bottom toolbar of the admin interface. The button's behavior is controlled by the `resourceConfig.bottomToolbarSaveButton` configuration.
11
+ *
12
+ * @param props - The component props, including the `resourceConfig` object.
13
+ * @returns A save button component, either the default `SaveButton` or a custom component specified in the `resourceConfig`.
14
+ */
15
+ export const BottomToolbarSaveButton:FC<IToolbarButton> = (props) => {
16
+ const { resourceConfig } = props;
17
+
18
+ if (!resourceConfig) return <DashAutoAdminSaveButton resourceConfig={resourceConfig} />;
19
+ if (resourceConfig.bottomToolbarSaveButton) {
20
+ if (resourceConfig.bottomToolbarSaveButton?.enabled) {
21
+ const buttonProps = {
22
+ resourceConfig:resourceConfig,
23
+ ...(resourceConfig.bottomToolbarSaveButton?.props || {}),
24
+ alwaysEnable: resourceConfig?.saveButtonAlwaysEnabled === true ? true : false,
25
+ };
26
+ return resourceConfig.bottomToolbarSaveButton?.component ? <resourceConfig.bottomToolbarSaveButton.component {...buttonProps} /> : <DashAutoAdminSaveButton {...buttonProps} />;
27
+ } else {
28
+ return null;
29
+ }
30
+ }
31
+ return <DashAutoAdminSaveButton resourceConfig={resourceConfig} />;
32
+ };
33
+
34
+
35
+ /**
36
+ * Renders a delete button in the bottom toolbar of the admin interface. The button's behavior is controlled by the `resourceConfig.bottomToolbarDeleteButton` configuration.
37
+ *
38
+ * @param props - The component props, including the `resourceConfig` object.
39
+ * @returns A delete button component, either the default `DeleteButton` or a custom component specified in the `resourceConfig`.
40
+ */
41
+ export const BottomToolbarDeleteButton:FC<IToolbarButton> = (props) => {
42
+ const { resourceConfig } = props;
43
+ if (!resourceConfig) return <DeleteButton/>;
44
+
45
+ if (!!(resourceConfig?.delete !== false) && !!resourceConfig?.bottomToolbarDeleteButton) {
46
+ return <DeleteButton/>;
47
+ } else if (!!resourceConfig?.bottomToolbarDeleteButton && !!(resourceConfig?.bottomToolbarDeleteButton.enabled !== false)) {
48
+ if (!!resourceConfig.bottomToolbarDeleteButton?.props && resourceConfig.bottomToolbarDeleteButton.props?.confirm) {
49
+ return <WithRecord
50
+ render={(record) => (
51
+ <DeleteWithConfirmButton record={record} />
52
+ )}
53
+ />;
54
+ }
55
+ return resourceConfig.bottomToolbarDeleteButton?.component ? <resourceConfig.bottomToolbarDeleteButton.component {...resourceConfig.bottomToolbarDeleteButton?.props || {}} /> : <DeleteButton {...resourceConfig.bottomToolbarDeleteButton?.props || {}} />;
56
+ }
57
+
58
+ return null;
59
+ };