@refinedev/core 4.7.2 → 4.8.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 +33 -0
- package/dist/esm/index.js +6 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/hooks/auditLog/useLogList/index.d.ts +11 -5
- package/dist/hooks/auditLog/useLogList/index.d.ts.map +1 -1
- package/dist/hooks/data/useCustom.d.ts +6 -5
- package/dist/hooks/data/useCustom.d.ts.map +1 -1
- package/dist/hooks/data/useInfiniteList.d.ts +6 -5
- package/dist/hooks/data/useInfiniteList.d.ts.map +1 -1
- package/dist/hooks/data/useList.d.ts +6 -5
- package/dist/hooks/data/useList.d.ts.map +1 -1
- package/dist/hooks/data/useMany.d.ts +6 -5
- package/dist/hooks/data/useMany.d.ts.map +1 -1
- package/dist/hooks/data/useOne.d.ts +6 -5
- package/dist/hooks/data/useOne.d.ts.map +1 -1
- package/dist/hooks/form/useForm.d.ts +6 -6
- package/dist/hooks/form/useForm.d.ts.map +1 -1
- package/dist/hooks/show/useShow.d.ts +9 -4
- package/dist/hooks/show/useShow.d.ts.map +1 -1
- package/dist/hooks/useSelect/index.d.ts +19 -6
- package/dist/hooks/useSelect/index.d.ts.map +1 -1
- package/dist/hooks/useTable/index.d.ts +3 -3
- package/dist/hooks/useTable/index.d.ts.map +1 -1
- package/dist/iife/index.js +5 -5
- package/dist/iife/index.js.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/hooks/auditLog/useLogList/index.ts +17 -7
- package/src/hooks/data/useCustom.ts +25 -11
- package/src/hooks/data/useInfiniteList.ts +23 -11
- package/src/hooks/data/useList.ts +20 -9
- package/src/hooks/data/useMany.ts +35 -8
- package/src/hooks/data/useOne.ts +21 -8
- package/src/hooks/form/useForm.ts +18 -8
- package/src/hooks/show/useShow.ts +22 -6
- package/src/hooks/useSelect/index.ts +35 -9
- package/src/hooks/useTable/index.ts +19 -6
|
@@ -25,7 +25,7 @@ import { pickResource } from "@definitions/helpers/pick-resource";
|
|
|
25
25
|
import { useResource } from "../resource/useResource/index";
|
|
26
26
|
import { BaseListProps } from "../data/useList";
|
|
27
27
|
|
|
28
|
-
export type UseSelectProps<
|
|
28
|
+
export type UseSelectProps<TQueryFnData, TError, TData> = {
|
|
29
29
|
/**
|
|
30
30
|
* Resource name for API data interactions
|
|
31
31
|
*/
|
|
@@ -34,12 +34,16 @@ export type UseSelectProps<TData, TError> = {
|
|
|
34
34
|
* Set the option's value
|
|
35
35
|
* @default `"title"`
|
|
36
36
|
*/
|
|
37
|
-
optionLabel?: keyof
|
|
37
|
+
optionLabel?: keyof TQueryFnData extends string
|
|
38
|
+
? keyof TQueryFnData
|
|
39
|
+
: never;
|
|
38
40
|
/**
|
|
39
41
|
* Set the option's label value
|
|
40
42
|
* @default `"id"`
|
|
41
43
|
*/
|
|
42
|
-
optionValue?: keyof
|
|
44
|
+
optionValue?: keyof TQueryFnData extends string
|
|
45
|
+
? keyof TQueryFnData
|
|
46
|
+
: never;
|
|
43
47
|
/**
|
|
44
48
|
* Allow us to sort the options
|
|
45
49
|
* @deprecated Use `sorters` instead
|
|
@@ -65,7 +69,11 @@ export type UseSelectProps<TData, TError> = {
|
|
|
65
69
|
/**
|
|
66
70
|
* react-query [useQuery](https://react-query.tanstack.com/reference/useQuery) options
|
|
67
71
|
*/
|
|
68
|
-
queryOptions?: UseQueryOptions<
|
|
72
|
+
queryOptions?: UseQueryOptions<
|
|
73
|
+
GetListResponse<TQueryFnData>,
|
|
74
|
+
TError,
|
|
75
|
+
GetListResponse<TData>
|
|
76
|
+
>;
|
|
69
77
|
/**
|
|
70
78
|
* Pagination option from [`useList()`](/docs/api-reference/core/hooks/data/useList/)
|
|
71
79
|
* @type { current?: number; pageSize?: number;}
|
|
@@ -90,7 +98,10 @@ export type UseSelectProps<TData, TError> = {
|
|
|
90
98
|
/**
|
|
91
99
|
* react-query [useQuery](https://react-query.tanstack.com/reference/useQuery) options
|
|
92
100
|
*/
|
|
93
|
-
defaultValueQueryOptions?: UseQueryOptions<
|
|
101
|
+
defaultValueQueryOptions?: UseQueryOptions<
|
|
102
|
+
GetManyResponse<TQueryFnData>,
|
|
103
|
+
TError
|
|
104
|
+
>;
|
|
94
105
|
/**
|
|
95
106
|
* If defined, this callback allows us to override all filters for every search request.
|
|
96
107
|
* @default `undefined`
|
|
@@ -130,11 +141,26 @@ export type UseSelectReturnType<TData extends BaseRecord = BaseRecord> = {
|
|
|
130
141
|
options: Option[];
|
|
131
142
|
};
|
|
132
143
|
|
|
144
|
+
/**
|
|
145
|
+
* `useSelect` hook is used to fetch data from the dataProvider and return the options for the select box.
|
|
146
|
+
*
|
|
147
|
+
* It uses `getList` method as query function from the dataProvider that is
|
|
148
|
+
* passed to {@link https://refine.dev/docs/api-reference/core/components/refine-config/ `<Refine>`}.
|
|
149
|
+
*
|
|
150
|
+
* @see {@link https://refine.dev/docs/core/hooks/useSelect} for more details.
|
|
151
|
+
*
|
|
152
|
+
* @typeParam TQueryFnData - Result data returned by the query function. Extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#baserecord `BaseRecord`}
|
|
153
|
+
* @typeParam TError - Custom error object that extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#httperror `HttpError`}
|
|
154
|
+
* @typeParam TData - Result data returned by the `select` function. Extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#baserecord `BaseRecord`}. Defaults to `TQueryFnData`
|
|
155
|
+
*
|
|
156
|
+
*/
|
|
157
|
+
|
|
133
158
|
export const useSelect = <
|
|
134
|
-
|
|
159
|
+
TQueryFnData extends BaseRecord = BaseRecord,
|
|
135
160
|
TError extends HttpError = HttpError,
|
|
161
|
+
TData extends BaseRecord = TQueryFnData,
|
|
136
162
|
>(
|
|
137
|
-
props: UseSelectProps<
|
|
163
|
+
props: UseSelectProps<TQueryFnData, TError, TData>,
|
|
138
164
|
): UseSelectReturnType<TData> => {
|
|
139
165
|
const [search, setSearch] = useState<CrudFilters>([]);
|
|
140
166
|
const [options, setOptions] = useState<Option[]>([]);
|
|
@@ -193,7 +219,7 @@ export const useSelect = <
|
|
|
193
219
|
const defaultValueQueryOptions =
|
|
194
220
|
defaultValueQueryOptionsFromProps ?? (queryOptions as any);
|
|
195
221
|
|
|
196
|
-
const defaultValueQueryResult = useMany<
|
|
222
|
+
const defaultValueQueryResult = useMany<TQueryFnData, TError, TData>({
|
|
197
223
|
resource,
|
|
198
224
|
ids: defaultValues,
|
|
199
225
|
queryOptions: {
|
|
@@ -226,7 +252,7 @@ export const useSelect = <
|
|
|
226
252
|
[optionLabel, optionValue],
|
|
227
253
|
);
|
|
228
254
|
|
|
229
|
-
const queryResult = useList<
|
|
255
|
+
const queryResult = useList<TQueryFnData, TError, TData>({
|
|
230
256
|
resource,
|
|
231
257
|
sorters: pickNotDeprecated(sorters, sort),
|
|
232
258
|
filters: filters.concat(search),
|
|
@@ -42,7 +42,7 @@ import { BaseListProps } from "../data/useList";
|
|
|
42
42
|
|
|
43
43
|
type SetFilterBehavior = "merge" | "replace";
|
|
44
44
|
|
|
45
|
-
export type useTableProps<
|
|
45
|
+
export type useTableProps<TQueryFnData, TError, TData> = {
|
|
46
46
|
/**
|
|
47
47
|
* Resource name for API data interactions
|
|
48
48
|
* @default Resource name that it reads from route
|
|
@@ -139,7 +139,11 @@ export type useTableProps<TData, TError> = {
|
|
|
139
139
|
/**
|
|
140
140
|
* react-query's [useQuery](https://tanstack.com/query/v4/docs/reference/useQuery) options
|
|
141
141
|
*/
|
|
142
|
-
queryOptions?: UseQueryOptions<
|
|
142
|
+
queryOptions?: UseQueryOptions<
|
|
143
|
+
GetListResponse<TQueryFnData>,
|
|
144
|
+
TError,
|
|
145
|
+
GetListResponse<TData>
|
|
146
|
+
>;
|
|
143
147
|
/**
|
|
144
148
|
* Metadata query for dataProvider
|
|
145
149
|
*/
|
|
@@ -204,14 +208,20 @@ export type useTableReturnType<
|
|
|
204
208
|
* All features such as sorting, filtering and pagination comes as out of box.
|
|
205
209
|
*
|
|
206
210
|
* @see {@link https://refine.dev/docs/api-references/hooks/table/useTable} for more details.
|
|
211
|
+
*
|
|
212
|
+
* @typeParam TQueryFnData - Result data returned by the query function. Extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#baserecord `BaseRecord`}
|
|
213
|
+
* @typeParam TError - Custom error object that extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#httperror `HttpError`}
|
|
214
|
+
* @typeParam TData - Result data returned by the `select` function. Extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#baserecord `BaseRecord`}. Defaults to `TQueryFnData`
|
|
215
|
+
*
|
|
207
216
|
*/
|
|
208
217
|
|
|
209
218
|
const defaultPermanentFilter: CrudFilters = [];
|
|
210
219
|
const defaultPermanentSorter: CrudSorting = [];
|
|
211
220
|
|
|
212
221
|
export function useTable<
|
|
213
|
-
|
|
222
|
+
TQueryFnData extends BaseRecord = BaseRecord,
|
|
214
223
|
TError extends HttpError = HttpError,
|
|
224
|
+
TData extends BaseRecord = TQueryFnData,
|
|
215
225
|
>({
|
|
216
226
|
initialCurrent,
|
|
217
227
|
initialPageSize,
|
|
@@ -235,7 +245,10 @@ export function useTable<
|
|
|
235
245
|
meta,
|
|
236
246
|
metaData,
|
|
237
247
|
dataProviderName,
|
|
238
|
-
}: useTableProps<
|
|
248
|
+
}: useTableProps<TQueryFnData, TError, TData> = {}): useTableReturnType<
|
|
249
|
+
TData,
|
|
250
|
+
TError
|
|
251
|
+
> {
|
|
239
252
|
const { syncWithLocation: syncWithLocationContext } = useSyncWithLocation();
|
|
240
253
|
|
|
241
254
|
const syncWithLocation = syncWithLocationProp ?? syncWithLocationContext;
|
|
@@ -475,7 +488,7 @@ export function useTable<
|
|
|
475
488
|
}
|
|
476
489
|
}, [syncWithLocation, current, pageSize, sorters, filters]);
|
|
477
490
|
|
|
478
|
-
const queryResult = useList<
|
|
491
|
+
const queryResult = useList<TQueryFnData, TError, TData>({
|
|
479
492
|
resource: resourceInUse,
|
|
480
493
|
hasPagination,
|
|
481
494
|
pagination: { current, pageSize, mode: pagination?.mode },
|
|
@@ -510,7 +523,7 @@ export function useTable<
|
|
|
510
523
|
);
|
|
511
524
|
};
|
|
512
525
|
|
|
513
|
-
const setFiltersFn: useTableReturnType<
|
|
526
|
+
const setFiltersFn: useTableReturnType<TQueryFnData>["setFilters"] = (
|
|
514
527
|
setterOrFilters,
|
|
515
528
|
behavior: SetFilterBehavior = prefferedFilterBehavior,
|
|
516
529
|
) => {
|