@refinedev/core 4.8.3 → 4.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +69 -0
- package/dist/definitions/helpers/router/compose-route.d.ts +2 -2
- package/dist/definitions/helpers/router/compose-route.d.ts.map +1 -1
- package/dist/definitions/helpers/router/prepare-route-params.d.ts +1 -2
- package/dist/definitions/helpers/router/prepare-route-params.d.ts.map +1 -1
- package/dist/esm/index.js +6 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/hooks/breadcrumb/index.d.ts.map +1 -1
- package/dist/hooks/data/useCreate.d.ts.map +1 -1
- package/dist/hooks/data/useCreateMany.d.ts.map +1 -1
- package/dist/hooks/data/useCustom.d.ts.map +1 -1
- package/dist/hooks/data/useCustomMutation.d.ts.map +1 -1
- package/dist/hooks/data/useDelete.d.ts.map +1 -1
- package/dist/hooks/data/useDeleteMany.d.ts.map +1 -1
- package/dist/hooks/data/useInfiniteList.d.ts.map +1 -1
- package/dist/hooks/data/useList.d.ts.map +1 -1
- package/dist/hooks/data/useMany.d.ts.map +1 -1
- package/dist/hooks/data/useOne.d.ts.map +1 -1
- package/dist/hooks/data/useUpdate.d.ts.map +1 -1
- package/dist/hooks/data/useUpdateMany.d.ts.map +1 -1
- package/dist/hooks/form/useForm.d.ts.map +1 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/navigation/index.d.ts.map +1 -1
- package/dist/hooks/router/use-get-to-path/index.d.ts.map +1 -1
- package/dist/hooks/show/useShow.d.ts.map +1 -1
- package/dist/hooks/useMeta/index.d.ts +33 -0
- package/dist/hooks/useMeta/index.d.ts.map +1 -0
- package/dist/hooks/useSelect/index.d.ts.map +1 -1
- package/dist/hooks/useTable/index.d.ts.map +1 -1
- package/dist/iife/index.js +6 -6
- package/dist/iife/index.js.map +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/definitions/helpers/router/__tests__/compose-route.ts +9 -5
- package/src/definitions/helpers/router/__tests__/prepare-route-params.ts +5 -2
- package/src/definitions/helpers/router/compose-route.ts +16 -5
- package/src/definitions/helpers/router/prepare-route-params.ts +4 -16
- package/src/hooks/breadcrumb/index.ts +6 -1
- package/src/hooks/data/useCreate.ts +8 -4
- package/src/hooks/data/useCreateMany.ts +10 -5
- package/src/hooks/data/useCustom.ts +20 -6
- package/src/hooks/data/useCustomMutation.ts +8 -2
- package/src/hooks/data/useDelete.ts +10 -3
- package/src/hooks/data/useDeleteMany.ts +10 -6
- package/src/hooks/data/useInfiniteList.ts +8 -4
- package/src/hooks/data/useList.ts +11 -6
- package/src/hooks/data/useMany.ts +23 -17
- package/src/hooks/data/useOne.ts +21 -14
- package/src/hooks/data/useUpdate.ts +10 -4
- package/src/hooks/data/useUpdateMany.ts +10 -5
- package/src/hooks/form/useForm.ts +13 -6
- package/src/hooks/index.ts +1 -0
- package/src/hooks/navigation/index.ts +54 -19
- package/src/hooks/router/use-get-to-path/index.ts +6 -1
- package/src/hooks/show/useShow.ts +14 -3
- package/src/hooks/useMeta/index.ts +26 -0
- package/src/hooks/useSelect/index.ts +11 -5
- package/src/hooks/useTable/index.ts +9 -3
package/src/hooks/data/useOne.ts
CHANGED
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
useHandleNotification,
|
|
22
22
|
useDataProvider,
|
|
23
23
|
useOnError,
|
|
24
|
+
useMeta,
|
|
24
25
|
} from "@hooks";
|
|
25
26
|
import {
|
|
26
27
|
queryKeys,
|
|
@@ -102,22 +103,28 @@ export const useOne = <
|
|
|
102
103
|
> => {
|
|
103
104
|
const { resources } = useResource();
|
|
104
105
|
const dataProvider = useDataProvider();
|
|
106
|
+
const translate = useTranslate();
|
|
107
|
+
const authProvider = useActiveAuthProvider();
|
|
108
|
+
const { mutate: checkError } = useOnError({
|
|
109
|
+
v3LegacyAuthProviderCompatible: Boolean(authProvider?.isLegacy),
|
|
110
|
+
});
|
|
111
|
+
const handleNotification = useHandleNotification();
|
|
112
|
+
const getMeta = useMeta();
|
|
113
|
+
|
|
114
|
+
const preferredMeta = pickNotDeprecated(meta, metaData);
|
|
115
|
+
|
|
105
116
|
const queryKey = queryKeys(
|
|
106
117
|
resource,
|
|
107
118
|
pickDataProvider(resource, dataProviderName, resources),
|
|
108
|
-
|
|
109
|
-
|
|
119
|
+
preferredMeta,
|
|
120
|
+
preferredMeta,
|
|
110
121
|
);
|
|
111
122
|
|
|
112
123
|
const { getOne } = dataProvider(
|
|
113
124
|
pickDataProvider(resource, dataProviderName, resources),
|
|
114
125
|
);
|
|
115
|
-
|
|
116
|
-
const
|
|
117
|
-
const { mutate: checkError } = useOnError({
|
|
118
|
-
v3LegacyAuthProviderCompatible: Boolean(authProvider?.isLegacy),
|
|
119
|
-
});
|
|
120
|
-
const handleNotification = useHandleNotification();
|
|
126
|
+
|
|
127
|
+
const combinedMeta = getMeta({ meta: preferredMeta });
|
|
121
128
|
|
|
122
129
|
useResourceSubscription({
|
|
123
130
|
resource,
|
|
@@ -126,8 +133,8 @@ export const useOne = <
|
|
|
126
133
|
params: {
|
|
127
134
|
ids: id ? [id] : [],
|
|
128
135
|
id: id,
|
|
129
|
-
meta:
|
|
130
|
-
metaData:
|
|
136
|
+
meta: combinedMeta,
|
|
137
|
+
metaData: combinedMeta,
|
|
131
138
|
subscriptionType: "useOne",
|
|
132
139
|
...liveParams,
|
|
133
140
|
},
|
|
@@ -150,7 +157,7 @@ export const useOne = <
|
|
|
150
157
|
resource: resource!,
|
|
151
158
|
id: id!,
|
|
152
159
|
meta: {
|
|
153
|
-
...(
|
|
160
|
+
...(combinedMeta || {}),
|
|
154
161
|
queryContext: {
|
|
155
162
|
queryKey,
|
|
156
163
|
pageParam,
|
|
@@ -158,7 +165,7 @@ export const useOne = <
|
|
|
158
165
|
},
|
|
159
166
|
},
|
|
160
167
|
metaData: {
|
|
161
|
-
...(
|
|
168
|
+
...(combinedMeta || {}),
|
|
162
169
|
queryContext: {
|
|
163
170
|
queryKey,
|
|
164
171
|
pageParam,
|
|
@@ -181,7 +188,7 @@ export const useOne = <
|
|
|
181
188
|
data,
|
|
182
189
|
{
|
|
183
190
|
id,
|
|
184
|
-
...(
|
|
191
|
+
...(combinedMeta || {}),
|
|
185
192
|
},
|
|
186
193
|
resource,
|
|
187
194
|
)
|
|
@@ -199,7 +206,7 @@ export const useOne = <
|
|
|
199
206
|
err,
|
|
200
207
|
{
|
|
201
208
|
id,
|
|
202
|
-
...(
|
|
209
|
+
...(combinedMeta || {}),
|
|
203
210
|
},
|
|
204
211
|
resource,
|
|
205
212
|
)
|
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
useLog,
|
|
32
32
|
useInvalidate,
|
|
33
33
|
useOnError,
|
|
34
|
+
useMeta,
|
|
34
35
|
} from "@hooks";
|
|
35
36
|
import {
|
|
36
37
|
queryKeys,
|
|
@@ -156,6 +157,7 @@ export const useUpdate = <
|
|
|
156
157
|
const { notificationDispatch } = useCancelNotification();
|
|
157
158
|
const handleNotification = useHandleNotification();
|
|
158
159
|
const invalidateStore = useInvalidate();
|
|
160
|
+
const getMeta = useMeta();
|
|
159
161
|
|
|
160
162
|
const mutation = useMutation<
|
|
161
163
|
UpdateResponse<TData>,
|
|
@@ -174,6 +176,10 @@ export const useUpdate = <
|
|
|
174
176
|
metaData,
|
|
175
177
|
dataProviderName,
|
|
176
178
|
}) => {
|
|
179
|
+
const combinedMeta = getMeta({
|
|
180
|
+
meta: pickNotDeprecated(meta, metaData),
|
|
181
|
+
});
|
|
182
|
+
|
|
177
183
|
const mutationModePropOrContext =
|
|
178
184
|
mutationMode ?? mutationModeContext;
|
|
179
185
|
|
|
@@ -187,8 +193,8 @@ export const useUpdate = <
|
|
|
187
193
|
resource,
|
|
188
194
|
id,
|
|
189
195
|
variables: values,
|
|
190
|
-
meta:
|
|
191
|
-
metaData:
|
|
196
|
+
meta: combinedMeta,
|
|
197
|
+
metaData: combinedMeta,
|
|
192
198
|
});
|
|
193
199
|
}
|
|
194
200
|
const updatePromise = new Promise<UpdateResponse<TData>>(
|
|
@@ -205,8 +211,8 @@ export const useUpdate = <
|
|
|
205
211
|
resource,
|
|
206
212
|
id,
|
|
207
213
|
variables: values,
|
|
208
|
-
meta:
|
|
209
|
-
metaData:
|
|
214
|
+
meta: combinedMeta,
|
|
215
|
+
metaData: combinedMeta,
|
|
210
216
|
})
|
|
211
217
|
.then((result) => resolve(result))
|
|
212
218
|
.catch((err) => reject(err));
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
useInvalidate,
|
|
18
18
|
useLog,
|
|
19
19
|
useOnError,
|
|
20
|
+
useMeta,
|
|
20
21
|
} from "@hooks";
|
|
21
22
|
import { ActionTypes } from "@contexts/undoableQueue";
|
|
22
23
|
import {
|
|
@@ -118,7 +119,6 @@ export const useUpdateMany = <
|
|
|
118
119
|
const queryClient = useQueryClient();
|
|
119
120
|
const dataProvider = useDataProvider();
|
|
120
121
|
const translate = useTranslate();
|
|
121
|
-
|
|
122
122
|
const {
|
|
123
123
|
mutationMode: mutationModeContext,
|
|
124
124
|
undoableTimeout: undoableTimeoutContext,
|
|
@@ -132,6 +132,7 @@ export const useUpdateMany = <
|
|
|
132
132
|
const handleNotification = useHandleNotification();
|
|
133
133
|
const invalidateStore = useInvalidate();
|
|
134
134
|
const { log } = useLog();
|
|
135
|
+
const getMeta = useMeta();
|
|
135
136
|
|
|
136
137
|
const mutation = useMutation<
|
|
137
138
|
UpdateManyResponse<TData>,
|
|
@@ -150,6 +151,10 @@ export const useUpdateMany = <
|
|
|
150
151
|
metaData,
|
|
151
152
|
dataProviderName,
|
|
152
153
|
}: UpdateManyParams<TData, TError, TVariables>) => {
|
|
154
|
+
const combinedMeta = getMeta({
|
|
155
|
+
meta: pickNotDeprecated(meta, metaData),
|
|
156
|
+
});
|
|
157
|
+
|
|
153
158
|
const mutationModePropOrContext =
|
|
154
159
|
mutationMode ?? mutationModeContext;
|
|
155
160
|
|
|
@@ -166,8 +171,8 @@ export const useUpdateMany = <
|
|
|
166
171
|
resource,
|
|
167
172
|
ids,
|
|
168
173
|
variables: values,
|
|
169
|
-
meta:
|
|
170
|
-
metaData:
|
|
174
|
+
meta: combinedMeta,
|
|
175
|
+
metaData: combinedMeta,
|
|
171
176
|
});
|
|
172
177
|
} else {
|
|
173
178
|
return handleMultiple(
|
|
@@ -176,8 +181,8 @@ export const useUpdateMany = <
|
|
|
176
181
|
resource,
|
|
177
182
|
id,
|
|
178
183
|
variables: values,
|
|
179
|
-
meta:
|
|
180
|
-
metaData:
|
|
184
|
+
meta: combinedMeta,
|
|
185
|
+
metaData: combinedMeta,
|
|
181
186
|
}),
|
|
182
187
|
),
|
|
183
188
|
);
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
useMutationMode,
|
|
13
13
|
useOne,
|
|
14
14
|
useRefineContext,
|
|
15
|
+
useMeta,
|
|
15
16
|
} from "@hooks";
|
|
16
17
|
|
|
17
18
|
import {
|
|
@@ -240,6 +241,7 @@ export const useForm = <
|
|
|
240
241
|
action: legacyActionFromRoute,
|
|
241
242
|
id: legacyIdFromParams,
|
|
242
243
|
} = useParams<ResourceRouterParams>();
|
|
244
|
+
const getMeta = useMeta();
|
|
243
245
|
|
|
244
246
|
const newResourceNameFromRouter =
|
|
245
247
|
typeof resourceFromRouter === "string"
|
|
@@ -332,6 +334,11 @@ export const useForm = <
|
|
|
332
334
|
}
|
|
333
335
|
}
|
|
334
336
|
|
|
337
|
+
const combinedMeta = getMeta({
|
|
338
|
+
resource,
|
|
339
|
+
meta: pickNotDeprecated(meta, metaData),
|
|
340
|
+
});
|
|
341
|
+
|
|
335
342
|
const { mutationMode: mutationModeContext } = useMutationMode();
|
|
336
343
|
const mutationMode = mutationModeProp ?? mutationModeContext;
|
|
337
344
|
|
|
@@ -369,8 +376,8 @@ export const useForm = <
|
|
|
369
376
|
liveMode,
|
|
370
377
|
onLiveEvent,
|
|
371
378
|
liveParams,
|
|
372
|
-
meta:
|
|
373
|
-
metaData:
|
|
379
|
+
meta: combinedMeta,
|
|
380
|
+
metaData: combinedMeta,
|
|
374
381
|
dataProviderName,
|
|
375
382
|
});
|
|
376
383
|
|
|
@@ -423,8 +430,8 @@ export const useForm = <
|
|
|
423
430
|
resource: resource.name,
|
|
424
431
|
successNotification,
|
|
425
432
|
errorNotification,
|
|
426
|
-
meta:
|
|
427
|
-
metaData:
|
|
433
|
+
meta: combinedMeta,
|
|
434
|
+
metaData: combinedMeta,
|
|
428
435
|
dataProviderName,
|
|
429
436
|
invalidates,
|
|
430
437
|
},
|
|
@@ -464,8 +471,8 @@ export const useForm = <
|
|
|
464
471
|
undoableTimeout,
|
|
465
472
|
successNotification,
|
|
466
473
|
errorNotification,
|
|
467
|
-
meta:
|
|
468
|
-
metaData:
|
|
474
|
+
meta: combinedMeta,
|
|
475
|
+
metaData: combinedMeta,
|
|
469
476
|
dataProviderName,
|
|
470
477
|
invalidates,
|
|
471
478
|
};
|
package/src/hooks/index.ts
CHANGED
|
@@ -59,7 +59,12 @@ export const useNavigation = () => {
|
|
|
59
59
|
return "";
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
return composeRoute(
|
|
62
|
+
return composeRoute(
|
|
63
|
+
createActionRoute.route,
|
|
64
|
+
resourceItem?.meta,
|
|
65
|
+
parsed,
|
|
66
|
+
meta,
|
|
67
|
+
);
|
|
63
68
|
} else {
|
|
64
69
|
const resourceItem =
|
|
65
70
|
typeof resource === "string"
|
|
@@ -76,7 +81,12 @@ export const useNavigation = () => {
|
|
|
76
81
|
}
|
|
77
82
|
|
|
78
83
|
return go({
|
|
79
|
-
to: composeRoute(
|
|
84
|
+
to: composeRoute(
|
|
85
|
+
createActionRoute,
|
|
86
|
+
resourceItem?.meta,
|
|
87
|
+
parsed,
|
|
88
|
+
meta,
|
|
89
|
+
),
|
|
80
90
|
type: "path",
|
|
81
91
|
}) as string;
|
|
82
92
|
}
|
|
@@ -107,10 +117,15 @@ export const useNavigation = () => {
|
|
|
107
117
|
return "";
|
|
108
118
|
}
|
|
109
119
|
|
|
110
|
-
return composeRoute(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
120
|
+
return composeRoute(
|
|
121
|
+
editActionRoute.route,
|
|
122
|
+
resourceItem?.meta,
|
|
123
|
+
parsed,
|
|
124
|
+
{
|
|
125
|
+
...meta,
|
|
126
|
+
id: encodedId,
|
|
127
|
+
},
|
|
128
|
+
);
|
|
114
129
|
} else {
|
|
115
130
|
const resourceItem =
|
|
116
131
|
typeof resource === "string"
|
|
@@ -127,7 +142,7 @@ export const useNavigation = () => {
|
|
|
127
142
|
}
|
|
128
143
|
|
|
129
144
|
return go({
|
|
130
|
-
to: composeRoute(editActionRoute, parsed, {
|
|
145
|
+
to: composeRoute(editActionRoute, resourceItem?.meta, parsed, {
|
|
131
146
|
...meta,
|
|
132
147
|
id: encodedId,
|
|
133
148
|
}),
|
|
@@ -162,10 +177,15 @@ export const useNavigation = () => {
|
|
|
162
177
|
return "";
|
|
163
178
|
}
|
|
164
179
|
|
|
165
|
-
return composeRoute(
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
180
|
+
return composeRoute(
|
|
181
|
+
cloneActionRoute.route,
|
|
182
|
+
resourceItem?.meta,
|
|
183
|
+
parsed,
|
|
184
|
+
{
|
|
185
|
+
...meta,
|
|
186
|
+
id: encodedId,
|
|
187
|
+
},
|
|
188
|
+
);
|
|
169
189
|
} else {
|
|
170
190
|
const resourceItem =
|
|
171
191
|
typeof resource === "string"
|
|
@@ -182,7 +202,7 @@ export const useNavigation = () => {
|
|
|
182
202
|
}
|
|
183
203
|
|
|
184
204
|
return go({
|
|
185
|
-
to: composeRoute(cloneActionRoute, parsed, {
|
|
205
|
+
to: composeRoute(cloneActionRoute, resourceItem?.meta, parsed, {
|
|
186
206
|
...meta,
|
|
187
207
|
id: encodedId,
|
|
188
208
|
}),
|
|
@@ -216,10 +236,15 @@ export const useNavigation = () => {
|
|
|
216
236
|
return "";
|
|
217
237
|
}
|
|
218
238
|
|
|
219
|
-
return composeRoute(
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
239
|
+
return composeRoute(
|
|
240
|
+
showActionRoute.route,
|
|
241
|
+
resourceItem?.meta,
|
|
242
|
+
parsed,
|
|
243
|
+
{
|
|
244
|
+
...meta,
|
|
245
|
+
id: encodedId,
|
|
246
|
+
},
|
|
247
|
+
);
|
|
223
248
|
} else {
|
|
224
249
|
const resourceItem =
|
|
225
250
|
typeof resource === "string"
|
|
@@ -236,7 +261,7 @@ export const useNavigation = () => {
|
|
|
236
261
|
}
|
|
237
262
|
|
|
238
263
|
return go({
|
|
239
|
-
to: composeRoute(showActionRoute, parsed, {
|
|
264
|
+
to: composeRoute(showActionRoute, resourceItem?.meta, parsed, {
|
|
240
265
|
...meta,
|
|
241
266
|
id: encodedId,
|
|
242
267
|
}),
|
|
@@ -268,7 +293,12 @@ export const useNavigation = () => {
|
|
|
268
293
|
return "";
|
|
269
294
|
}
|
|
270
295
|
|
|
271
|
-
return composeRoute(
|
|
296
|
+
return composeRoute(
|
|
297
|
+
listActionRoute.route,
|
|
298
|
+
resourceItem?.meta,
|
|
299
|
+
parsed,
|
|
300
|
+
meta,
|
|
301
|
+
);
|
|
272
302
|
} else {
|
|
273
303
|
const resourceItem =
|
|
274
304
|
typeof resource === "string"
|
|
@@ -285,7 +315,12 @@ export const useNavigation = () => {
|
|
|
285
315
|
}
|
|
286
316
|
|
|
287
317
|
return go({
|
|
288
|
-
to: composeRoute(
|
|
318
|
+
to: composeRoute(
|
|
319
|
+
listActionRoute,
|
|
320
|
+
resourceItem?.meta,
|
|
321
|
+
parsed,
|
|
322
|
+
meta,
|
|
323
|
+
),
|
|
289
324
|
type: "path",
|
|
290
325
|
}) as string;
|
|
291
326
|
}
|
|
@@ -49,7 +49,12 @@ export const useGetToPath = (): GetToPathFn => {
|
|
|
49
49
|
return undefined;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
const composed = composeRoute(
|
|
52
|
+
const composed = composeRoute(
|
|
53
|
+
actionRoute,
|
|
54
|
+
selectedResource?.meta,
|
|
55
|
+
parsed,
|
|
56
|
+
meta,
|
|
57
|
+
);
|
|
53
58
|
|
|
54
59
|
return composed;
|
|
55
60
|
},
|
|
@@ -2,7 +2,12 @@ import React, { useState } from "react";
|
|
|
2
2
|
import { QueryObserverResult, UseQueryOptions } from "@tanstack/react-query";
|
|
3
3
|
import warnOnce from "warn-once";
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
useMeta,
|
|
7
|
+
useOne,
|
|
8
|
+
useResourceWithRoute,
|
|
9
|
+
useRouterContext,
|
|
10
|
+
} from "@hooks";
|
|
6
11
|
|
|
7
12
|
import {
|
|
8
13
|
ResourceRouterParams,
|
|
@@ -112,6 +117,7 @@ export const useShow = <
|
|
|
112
117
|
|
|
113
118
|
const { resource: legacyResourceFromRoute, id: legacyIdFromParams } =
|
|
114
119
|
useParams<ResourceRouterParams>();
|
|
120
|
+
const getMeta = useMeta();
|
|
115
121
|
|
|
116
122
|
const newResourceNameFromRouter = resourceFromRouter?.name;
|
|
117
123
|
|
|
@@ -179,6 +185,11 @@ export const useShow = <
|
|
|
179
185
|
}
|
|
180
186
|
}
|
|
181
187
|
|
|
188
|
+
const combinedMeta = getMeta({
|
|
189
|
+
resource,
|
|
190
|
+
meta: pickNotDeprecated(meta, metaData),
|
|
191
|
+
});
|
|
192
|
+
|
|
182
193
|
warnOnce(
|
|
183
194
|
Boolean(resourceFromProp) && !Boolean(id),
|
|
184
195
|
`[useShow]: resource: "${resourceName}", id: ${id} \n\n` +
|
|
@@ -195,8 +206,8 @@ export const useShow = <
|
|
|
195
206
|
},
|
|
196
207
|
successNotification,
|
|
197
208
|
errorNotification,
|
|
198
|
-
meta:
|
|
199
|
-
metaData:
|
|
209
|
+
meta: combinedMeta,
|
|
210
|
+
metaData: combinedMeta,
|
|
200
211
|
liveMode,
|
|
201
212
|
onLiveEvent,
|
|
202
213
|
dataProviderName,
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useParsed } from "@hooks/router";
|
|
2
|
+
import { sanitizeResource } from "@definitions/helpers/sanitize-resource";
|
|
3
|
+
import { IResourceItem, MetaQuery } from "../../interfaces";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Hook that returns a function to get meta.
|
|
7
|
+
* The meta is a combination of the resource meta, hook meta and query params.
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export const useMeta = () => {
|
|
11
|
+
const { params } = useParsed();
|
|
12
|
+
|
|
13
|
+
const getMetaFn = ({
|
|
14
|
+
resource,
|
|
15
|
+
meta: metaFromProp,
|
|
16
|
+
}: {
|
|
17
|
+
resource?: IResourceItem;
|
|
18
|
+
meta?: MetaQuery;
|
|
19
|
+
} = {}) => {
|
|
20
|
+
const { meta } = sanitizeResource(resource ?? {});
|
|
21
|
+
|
|
22
|
+
return { ...meta, ...params, ...metaFromProp };
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return getMetaFn;
|
|
26
|
+
};
|
|
@@ -4,7 +4,7 @@ import uniqBy from "lodash/uniqBy";
|
|
|
4
4
|
import debounce from "lodash/debounce";
|
|
5
5
|
import get from "lodash/get";
|
|
6
6
|
|
|
7
|
-
import { useList, useMany } from "@hooks";
|
|
7
|
+
import { useList, useMany, useMeta } from "@hooks";
|
|
8
8
|
import {
|
|
9
9
|
CrudSorting,
|
|
10
10
|
Option,
|
|
@@ -192,6 +192,7 @@ export const useSelect = <
|
|
|
192
192
|
} = props;
|
|
193
193
|
|
|
194
194
|
const { resources } = useResource();
|
|
195
|
+
const getMeta = useMeta();
|
|
195
196
|
|
|
196
197
|
/**
|
|
197
198
|
* Since `identifier` is an optional but prioritized way to match resources, users can provide identifier instead of resource name.
|
|
@@ -200,6 +201,11 @@ export const useSelect = <
|
|
|
200
201
|
|
|
201
202
|
const resource = pickedResource?.name ?? resourceFromProps;
|
|
202
203
|
|
|
204
|
+
const combinedMeta = getMeta({
|
|
205
|
+
resource: pickedResource,
|
|
206
|
+
meta: pickNotDeprecated(meta, metaData),
|
|
207
|
+
});
|
|
208
|
+
|
|
203
209
|
const defaultValues = Array.isArray(defaultValue)
|
|
204
210
|
? defaultValue
|
|
205
211
|
: [defaultValue];
|
|
@@ -232,8 +238,8 @@ export const useSelect = <
|
|
|
232
238
|
defaultValueQueryOptions?.onSuccess?.(data);
|
|
233
239
|
},
|
|
234
240
|
},
|
|
235
|
-
meta:
|
|
236
|
-
metaData:
|
|
241
|
+
meta: combinedMeta,
|
|
242
|
+
metaData: combinedMeta,
|
|
237
243
|
liveMode: "off",
|
|
238
244
|
dataProviderName,
|
|
239
245
|
});
|
|
@@ -271,8 +277,8 @@ export const useSelect = <
|
|
|
271
277
|
},
|
|
272
278
|
successNotification,
|
|
273
279
|
errorNotification,
|
|
274
|
-
meta:
|
|
275
|
-
metaData:
|
|
280
|
+
meta: combinedMeta,
|
|
281
|
+
metaData: combinedMeta,
|
|
276
282
|
liveMode,
|
|
277
283
|
liveParams,
|
|
278
284
|
onLiveEvent,
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
useRouterType,
|
|
15
15
|
useResource,
|
|
16
16
|
useParsed,
|
|
17
|
+
useMeta,
|
|
17
18
|
} from "@hooks";
|
|
18
19
|
import {
|
|
19
20
|
stringifyTableParams,
|
|
@@ -258,7 +259,7 @@ export function useTable<
|
|
|
258
259
|
const routerType = useRouterType();
|
|
259
260
|
const { useLocation } = useRouterContext();
|
|
260
261
|
const { search, pathname } = useLocation();
|
|
261
|
-
|
|
262
|
+
const getMeta = useMeta();
|
|
262
263
|
const parsedParams = useParsed();
|
|
263
264
|
|
|
264
265
|
const hasPaginationString = hasPagination === false ? "off" : "server";
|
|
@@ -337,6 +338,11 @@ export function useTable<
|
|
|
337
338
|
|
|
338
339
|
const { resource } = useResource(resourceFromProp);
|
|
339
340
|
|
|
341
|
+
const combinedMeta = getMeta({
|
|
342
|
+
resource,
|
|
343
|
+
meta: preferredMeta,
|
|
344
|
+
});
|
|
345
|
+
|
|
340
346
|
const resourceInUse = resource?.name;
|
|
341
347
|
|
|
342
348
|
React.useEffect(() => {
|
|
@@ -497,8 +503,8 @@ export function useTable<
|
|
|
497
503
|
queryOptions,
|
|
498
504
|
successNotification,
|
|
499
505
|
errorNotification,
|
|
500
|
-
meta:
|
|
501
|
-
metaData:
|
|
506
|
+
meta: combinedMeta,
|
|
507
|
+
metaData: combinedMeta,
|
|
502
508
|
liveMode,
|
|
503
509
|
liveParams,
|
|
504
510
|
onLiveEvent,
|