@refinedev/core 4.52.0 → 4.54.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.
Files changed (85) hide show
  1. package/CHANGELOG.md +363 -2
  2. package/dist/components/pages/auth/components/login/index.d.cts.map +1 -1
  3. package/dist/components/pages/auth/components/login/index.d.ts.map +1 -1
  4. package/dist/definitions/types/index.d.cts +12 -0
  5. package/dist/definitions/types/index.d.cts.map +1 -0
  6. package/dist/definitions/types/index.d.mts +12 -0
  7. package/dist/definitions/types/index.d.mts.map +12 -0
  8. package/dist/definitions/types/index.d.ts +12 -0
  9. package/dist/definitions/types/index.d.ts.map +1 -0
  10. package/dist/hooks/data/useCreate.d.cts +7 -6
  11. package/dist/hooks/data/useCreate.d.cts.map +1 -1
  12. package/dist/hooks/data/useCreate.d.mts +7 -6
  13. package/dist/hooks/data/useCreate.d.mts.map +7 -6
  14. package/dist/hooks/data/useCreate.d.ts +7 -6
  15. package/dist/hooks/data/useCreate.d.ts.map +1 -1
  16. package/dist/hooks/data/useCreateMany.d.cts +9 -9
  17. package/dist/hooks/data/useCreateMany.d.cts.map +1 -1
  18. package/dist/hooks/data/useCreateMany.d.mts +9 -9
  19. package/dist/hooks/data/useCreateMany.d.mts.map +9 -9
  20. package/dist/hooks/data/useCreateMany.d.ts +9 -9
  21. package/dist/hooks/data/useCreateMany.d.ts.map +1 -1
  22. package/dist/hooks/data/useUpdate.d.cts +8 -7
  23. package/dist/hooks/data/useUpdate.d.cts.map +1 -1
  24. package/dist/hooks/data/useUpdate.d.mts +8 -7
  25. package/dist/hooks/data/useUpdate.d.mts.map +8 -7
  26. package/dist/hooks/data/useUpdate.d.ts +8 -7
  27. package/dist/hooks/data/useUpdate.d.ts.map +1 -1
  28. package/dist/hooks/data/useUpdateMany.d.cts +9 -9
  29. package/dist/hooks/data/useUpdateMany.d.cts.map +1 -1
  30. package/dist/hooks/data/useUpdateMany.d.mts +9 -9
  31. package/dist/hooks/data/useUpdateMany.d.mts.map +9 -9
  32. package/dist/hooks/data/useUpdateMany.d.ts +9 -9
  33. package/dist/hooks/data/useUpdateMany.d.ts.map +1 -1
  34. package/dist/hooks/form/index.d.cts.map +1 -1
  35. package/dist/hooks/form/index.d.ts.map +1 -1
  36. package/dist/hooks/form/types.d.cts +8 -0
  37. package/dist/hooks/form/types.d.cts.map +1 -1
  38. package/dist/hooks/form/types.d.mts +8 -0
  39. package/dist/hooks/form/types.d.mts.map +8 -0
  40. package/dist/hooks/form/types.d.ts +8 -0
  41. package/dist/hooks/form/types.d.ts.map +1 -1
  42. package/dist/hooks/show/index.d.cts.map +1 -1
  43. package/dist/hooks/show/index.d.ts.map +1 -1
  44. package/dist/hooks/show/types.d.cts +4 -0
  45. package/dist/hooks/show/types.d.cts.map +1 -1
  46. package/dist/hooks/show/types.d.mts +4 -0
  47. package/dist/hooks/show/types.d.mts.map +4 -0
  48. package/dist/hooks/show/types.d.ts +4 -0
  49. package/dist/hooks/show/types.d.ts.map +1 -1
  50. package/dist/hooks/useSelect/index.d.cts +10 -2
  51. package/dist/hooks/useSelect/index.d.cts.map +1 -1
  52. package/dist/hooks/useSelect/index.d.mts +10 -2
  53. package/dist/hooks/useSelect/index.d.mts.map +10 -2
  54. package/dist/hooks/useSelect/index.d.ts +10 -2
  55. package/dist/hooks/useSelect/index.d.ts.map +1 -1
  56. package/dist/hooks/useTable/index.d.cts +4 -0
  57. package/dist/hooks/useTable/index.d.cts.map +1 -1
  58. package/dist/hooks/useTable/index.d.mts +4 -0
  59. package/dist/hooks/useTable/index.d.mts.map +4 -0
  60. package/dist/hooks/useTable/index.d.ts +4 -0
  61. package/dist/hooks/useTable/index.d.ts.map +1 -1
  62. package/dist/index.cjs +10 -10
  63. package/dist/index.cjs.map +1 -1
  64. package/dist/index.mjs +10 -10
  65. package/dist/index.mjs.map +1 -1
  66. package/package.json +2 -2
  67. package/src/components/pages/auth/components/login/index.tsx +7 -2
  68. package/src/definitions/types/index.ts +40 -0
  69. package/src/hooks/data/useCreate.ts +93 -32
  70. package/src/hooks/data/useCreateMany.ts +96 -33
  71. package/src/hooks/data/useUpdate.ts +137 -53
  72. package/src/hooks/data/useUpdateMany.ts +140 -51
  73. package/src/hooks/form/index.ts +2 -0
  74. package/src/hooks/form/types.ts +10 -0
  75. package/src/hooks/show/index.ts +1 -0
  76. package/src/hooks/show/types.ts +4 -0
  77. package/src/hooks/useSelect/index.ts +50 -28
  78. package/src/hooks/useTable/index.ts +5 -0
  79. package/dist/hooks/show/useShow.d.cts +0 -57
  80. package/dist/hooks/show/useShow.d.cts.map +0 -1
  81. package/dist/hooks/show/useShow.d.mts +0 -57
  82. package/dist/hooks/show/useShow.d.mts.map +0 -57
  83. package/dist/hooks/show/useShow.d.ts +0 -57
  84. package/dist/hooks/show/useShow.d.ts.map +0 -1
  85. package/src/hooks/show/useShow.ts +0 -179
@@ -1,4 +1,4 @@
1
- import { useCallback, useMemo, useState } from "react";
1
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
2
2
 
3
3
  import type {
4
4
  QueryObserverResult,
@@ -45,16 +45,16 @@ export type UseSelectProps<TQueryFnData, TError, TData> = {
45
45
  * Set the option's label value
46
46
  * @default `"title"`
47
47
  */
48
- optionLabel?: keyof TData extends string
49
- ? keyof TData
50
- : never | ((item: TData) => string);
48
+ optionLabel?:
49
+ | (keyof TData extends string ? keyof TData : never)
50
+ | ((item: TData) => string);
51
51
  /**
52
52
  * Set the option's value
53
53
  * @default `"id"`
54
54
  */
55
- optionValue?: keyof TData extends string
56
- ? keyof TData
57
- : never | ((item: TData) => string);
55
+ optionValue?:
56
+ | (keyof TData extends string ? keyof TData : never)
57
+ | ((item: TData) => string);
58
58
  /**
59
59
  * Field name to search for.
60
60
  * @description If provided `optionLabel` is a string, uses `optionLabel`'s value.
@@ -170,7 +170,15 @@ export type UseSelectReturnType<
170
170
  TError extends HttpError = HttpError,
171
171
  TOption extends BaseOption = BaseOption,
172
172
  > = {
173
+ query: QueryObserverResult<GetListResponse<TData>, TError>;
174
+ defaultValueQuery: QueryObserverResult<GetManyResponse<TData>>;
175
+ /**
176
+ * @deprecated Use `query` instead
177
+ */
173
178
  queryResult: QueryObserverResult<GetListResponse<TData>, TError>;
179
+ /**
180
+ * @deprecated Use `defaultValueQuery` instead
181
+ */
174
182
  defaultValueQueryResult: QueryObserverResult<GetManyResponse<TData>>;
175
183
  onSearch: (value: string) => void;
176
184
  options: TOption[];
@@ -343,26 +351,6 @@ export const useSelect = <
343
351
  dataProviderName,
344
352
  });
345
353
 
346
- const onSearch = (value: string) => {
347
- if (onSearchFromProp) {
348
- setSearch(onSearchFromProp(value));
349
- return;
350
- }
351
-
352
- if (!value) {
353
- setSearch([]);
354
- return;
355
- }
356
-
357
- setSearch([
358
- {
359
- field: searchField,
360
- operator: "contains",
361
- value,
362
- },
363
- ]);
364
- };
365
-
366
354
  const { elapsedTime } = useLoadingOvertime({
367
355
  isLoading: queryResult.isFetching || defaultValueQueryResult.isFetching,
368
356
  interval: overtimeOptions?.interval,
@@ -380,11 +368,45 @@ export const useSelect = <
380
368
  [options, selectedOptions],
381
369
  );
382
370
 
371
+ /**
372
+ * To avoid any changes in the `onSearch` callback,
373
+ * We're storing `onSearchFromProp` in a ref and accessing it in the `onSearch` callback.
374
+ */
375
+ const onSearchFromPropRef = useRef(onSearchFromProp);
376
+
377
+ const onSearch = useMemo(() => {
378
+ return debounce((value: string) => {
379
+ if (onSearchFromPropRef.current) {
380
+ setSearch(onSearchFromPropRef.current(value));
381
+ return;
382
+ }
383
+
384
+ if (!value) {
385
+ setSearch([]);
386
+ return;
387
+ }
388
+
389
+ setSearch([
390
+ {
391
+ field: searchField,
392
+ operator: "contains",
393
+ value,
394
+ },
395
+ ]);
396
+ }, debounceValue);
397
+ }, [searchField, debounceValue]);
398
+
399
+ useEffect(() => {
400
+ onSearchFromPropRef.current = onSearchFromProp;
401
+ }, [onSearchFromProp]);
402
+
383
403
  return {
384
404
  queryResult,
385
405
  defaultValueQueryResult,
406
+ query: queryResult,
407
+ defaultValueQuery: defaultValueQueryResult,
386
408
  options: combinedOptions,
387
- onSearch: debounce(onSearch, debounceValue),
409
+ onSearch,
388
410
  overtime: { elapsedTime },
389
411
  };
390
412
  };
@@ -201,6 +201,10 @@ export type useTableReturnType<
201
201
  TData extends BaseRecord = BaseRecord,
202
202
  TError extends HttpError = HttpError,
203
203
  > = {
204
+ tableQuery: QueryObserverResult<GetListResponse<TData>, TError>;
205
+ /**
206
+ * @deprecated `tableQueryResult` is deprecated. Use `tableQuery` instead.
207
+ */
204
208
  tableQueryResult: QueryObserverResult<GetListResponse<TData>, TError>;
205
209
  /**
206
210
  * @deprecated `sorter` is deprecated. Use `sorters` instead.
@@ -559,6 +563,7 @@ export function useTable<
559
563
 
560
564
  return {
561
565
  tableQueryResult: queryResult,
566
+ tableQuery: queryResult,
562
567
  sorters,
563
568
  setSorters: setSortWithUnion,
564
569
  sorter: sorters,
@@ -1,57 +0,0 @@
1
- import React from "react";
2
- import type { QueryObserverResult, UseQueryOptions } from "@tanstack/react-query";
3
- import type { BaseKey, BaseRecord, GetOneResponse, HttpError, MetaQuery, Prettify } from "../../contexts/data/types";
4
- import type { LiveModeProps } from "../../contexts/live/types";
5
- import type { SuccessErrorNotification } from "../../contexts/notification/types";
6
- import { type UseLoadingOvertimeOptionsProps, type UseLoadingOvertimeReturnType } from "../useLoadingOvertime";
7
- export type useShowReturnType<TData extends BaseRecord = BaseRecord, TError extends HttpError = HttpError> = {
8
- queryResult: QueryObserverResult<GetOneResponse<TData>, TError>;
9
- showId?: BaseKey;
10
- setShowId: React.Dispatch<React.SetStateAction<BaseKey | undefined>>;
11
- } & UseLoadingOvertimeReturnType;
12
- export type useShowProps<TQueryFnData extends BaseRecord = BaseRecord, TError extends HttpError = HttpError, TData extends BaseRecord = TQueryFnData> = {
13
- /**
14
- * Resource name for API data interactions
15
- * @default Reads `:resource` from the URL
16
- */
17
- resource?: string;
18
- /**
19
- * Data item ID for API data interactions
20
- * @default Reads `:id` from the URL
21
- */
22
- id?: BaseKey;
23
- /**
24
- * react-query's [useQuery](https://tanstack.com/query/v4/docs/reference/useQuery) options
25
- */
26
- queryOptions?: UseQueryOptions<GetOneResponse<TQueryFnData>, TError, GetOneResponse<TData>>;
27
- /**
28
- * Additional meta data to pass to the data provider's `getOne`
29
- */
30
- meta?: MetaQuery;
31
- /**
32
- * Additional meta data to pass to the data provider's `getOne`
33
- * @deprecated `metaData` is deprecated with refine@4, refine will pass `meta` instead, however, we still support `metaData` for backward compatibility.
34
- */
35
- metaData?: MetaQuery;
36
- /**
37
- * Target data provider name for API call to be made
38
- * @default `"default"`
39
- */
40
- dataProviderName?: string;
41
- } & LiveModeProps & SuccessErrorNotification<GetOneResponse<TData>, TError, Prettify<{
42
- id?: BaseKey;
43
- } & MetaQuery>> & UseLoadingOvertimeOptionsProps;
44
- /**
45
- * `useShow` hook allows you to fetch the desired record.
46
- * It uses `getOne` method as query function from the dataProvider that is
47
- * passed to {@link https://refine.dev/docs/api-reference/core/components/refine-config/ `<Refine>`}.
48
- *
49
- * @see {@link https://refine.dev/docs/api-reference/core/hooks/show/useShow} for more details.
50
- *
51
- * @typeParam TQueryFnData - Result data returned by the query function. Extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#baserecord `BaseRecord`}
52
- * @typeParam TError - Custom error object that extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#httperror `HttpError`}
53
- * @typeParam TData - Result data returned by the `select` function. Extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#baserecord `BaseRecord`}. Defaults to `TQueryFnData`
54
- *
55
- */
56
- export declare const useShow: <TQueryFnData extends BaseRecord = BaseRecord, TError extends HttpError = HttpError, TData extends BaseRecord = TQueryFnData>({ resource: resourceFromProp, id, successNotification, errorNotification, meta, metaData, liveMode, onLiveEvent, dataProviderName, queryOptions, overtimeOptions, }?: useShowProps<TQueryFnData, TError, TData>) => useShowReturnType<TData, TError>;
57
- //# sourceMappingURL=useShow.d.ts.map
@@ -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;IACH,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB;;;OAGG;IACH,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,GAAG,aAAa,GACf,wBAAwB,CACtB,cAAc,CAAC,KAAK,CAAC,EACrB,MAAM,EACN,QAAQ,CAAC;IAAE,EAAE,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,SAAS,CAAC,CACvC,GACD,8BAA8B,CAAC;AAEjC;;;;;;;;;;;GAWG;AAEH,eAAO,MAAM,OAAO,sSAgBjB,aAAa,YAAY,EAAE,MAAM,EAAE,KAAK,CAAC,KAAQ,kBAClD,KAAK,EACL,MAAM,CAiEP,CAAC"}
@@ -1,57 +0,0 @@
1
- import React from "react";
2
- import type { QueryObserverResult, UseQueryOptions } from "@tanstack/react-query";
3
- import type { BaseKey, BaseRecord, GetOneResponse, HttpError, MetaQuery, Prettify } from "../../contexts/data/types";
4
- import type { LiveModeProps } from "../../contexts/live/types";
5
- import type { SuccessErrorNotification } from "../../contexts/notification/types";
6
- import { type UseLoadingOvertimeOptionsProps, type UseLoadingOvertimeReturnType } from "../useLoadingOvertime";
7
- export type useShowReturnType<TData extends BaseRecord = BaseRecord, TError extends HttpError = HttpError> = {
8
- queryResult: QueryObserverResult<GetOneResponse<TData>, TError>;
9
- showId?: BaseKey;
10
- setShowId: React.Dispatch<React.SetStateAction<BaseKey | undefined>>;
11
- } & UseLoadingOvertimeReturnType;
12
- export type useShowProps<TQueryFnData extends BaseRecord = BaseRecord, TError extends HttpError = HttpError, TData extends BaseRecord = TQueryFnData> = {
13
- /**
14
- * Resource name for API data interactions
15
- * @default Reads `:resource` from the URL
16
- */
17
- resource?: string;
18
- /**
19
- * Data item ID for API data interactions
20
- * @default Reads `:id` from the URL
21
- */
22
- id?: BaseKey;
23
- /**
24
- * react-query's [useQuery](https://tanstack.com/query/v4/docs/reference/useQuery) options
25
- */
26
- queryOptions?: UseQueryOptions<GetOneResponse<TQueryFnData>, TError, GetOneResponse<TData>>;
27
- /**
28
- * Additional meta data to pass to the data provider's `getOne`
29
- */
30
- meta?: MetaQuery;
31
- /**
32
- * Additional meta data to pass to the data provider's `getOne`
33
- * @deprecated `metaData` is deprecated with refine@4, refine will pass `meta` instead, however, we still support `metaData` for backward compatibility.
34
- */
35
- metaData?: MetaQuery;
36
- /**
37
- * Target data provider name for API call to be made
38
- * @default `"default"`
39
- */
40
- dataProviderName?: string;
41
- } & LiveModeProps & SuccessErrorNotification<GetOneResponse<TData>, TError, Prettify<{
42
- id?: BaseKey;
43
- } & MetaQuery>> & UseLoadingOvertimeOptionsProps;
44
- /**
45
- * `useShow` hook allows you to fetch the desired record.
46
- * It uses `getOne` method as query function from the dataProvider that is
47
- * passed to {@link https://refine.dev/docs/api-reference/core/components/refine-config/ `<Refine>`}.
48
- *
49
- * @see {@link https://refine.dev/docs/api-reference/core/hooks/show/useShow} for more details.
50
- *
51
- * @typeParam TQueryFnData - Result data returned by the query function. Extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#baserecord `BaseRecord`}
52
- * @typeParam TError - Custom error object that extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#httperror `HttpError`}
53
- * @typeParam TData - Result data returned by the `select` function. Extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#baserecord `BaseRecord`}. Defaults to `TQueryFnData`
54
- *
55
- */
56
- export declare const useShow: <TQueryFnData extends BaseRecord = BaseRecord, TError extends HttpError = HttpError, TData extends BaseRecord = TQueryFnData>({ resource: resourceFromProp, id, successNotification, errorNotification, meta, metaData, liveMode, onLiveEvent, dataProviderName, queryOptions, overtimeOptions, }?: useShowProps<TQueryFnData, TError, TData>) => useShowReturnType<TData, TError>;
57
- //# sourceMappingURL=useShow.d.ts.map
@@ -1,57 +0,0 @@
1
- import React from "react";
2
- import type { QueryObserverResult, UseQueryOptions } from "@tanstack/react-query";
3
- import type { BaseKey, BaseRecord, GetOneResponse, HttpError, MetaQuery, Prettify } from "../../contexts/data/types";
4
- import type { LiveModeProps } from "../../contexts/live/types";
5
- import type { SuccessErrorNotification } from "../../contexts/notification/types";
6
- import { type UseLoadingOvertimeOptionsProps, type UseLoadingOvertimeReturnType } from "../useLoadingOvertime";
7
- export type useShowReturnType<TData extends BaseRecord = BaseRecord, TError extends HttpError = HttpError> = {
8
- queryResult: QueryObserverResult<GetOneResponse<TData>, TError>;
9
- showId?: BaseKey;
10
- setShowId: React.Dispatch<React.SetStateAction<BaseKey | undefined>>;
11
- } & UseLoadingOvertimeReturnType;
12
- export type useShowProps<TQueryFnData extends BaseRecord = BaseRecord, TError extends HttpError = HttpError, TData extends BaseRecord = TQueryFnData> = {
13
- /**
14
- * Resource name for API data interactions
15
- * @default Reads `:resource` from the URL
16
- */
17
- resource?: string;
18
- /**
19
- * Data item ID for API data interactions
20
- * @default Reads `:id` from the URL
21
- */
22
- id?: BaseKey;
23
- /**
24
- * react-query's [useQuery](https://tanstack.com/query/v4/docs/reference/useQuery) options
25
- */
26
- queryOptions?: UseQueryOptions<GetOneResponse<TQueryFnData>, TError, GetOneResponse<TData>>;
27
- /**
28
- * Additional meta data to pass to the data provider's `getOne`
29
- */
30
- meta?: MetaQuery;
31
- /**
32
- * Additional meta data to pass to the data provider's `getOne`
33
- * @deprecated `metaData` is deprecated with refine@4, refine will pass `meta` instead, however, we still support `metaData` for backward compatibility.
34
- */
35
- metaData?: MetaQuery;
36
- /**
37
- * Target data provider name for API call to be made
38
- * @default `"default"`
39
- */
40
- dataProviderName?: string;
41
- } & LiveModeProps & SuccessErrorNotification<GetOneResponse<TData>, TError, Prettify<{
42
- id?: BaseKey;
43
- } & MetaQuery>> & UseLoadingOvertimeOptionsProps;
44
- /**
45
- * `useShow` hook allows you to fetch the desired record.
46
- * It uses `getOne` method as query function from the dataProvider that is
47
- * passed to {@link https://refine.dev/docs/api-reference/core/components/refine-config/ `<Refine>`}.
48
- *
49
- * @see {@link https://refine.dev/docs/api-reference/core/hooks/show/useShow} for more details.
50
- *
51
- * @typeParam TQueryFnData - Result data returned by the query function. Extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#baserecord `BaseRecord`}
52
- * @typeParam TError - Custom error object that extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#httperror `HttpError`}
53
- * @typeParam TData - Result data returned by the `select` function. Extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#baserecord `BaseRecord`}. Defaults to `TQueryFnData`
54
- *
55
- */
56
- export declare const useShow: <TQueryFnData extends BaseRecord = BaseRecord, TError extends HttpError = HttpError, TData extends BaseRecord = TQueryFnData>({ resource: resourceFromProp, id, successNotification, errorNotification, meta, metaData, liveMode, onLiveEvent, dataProviderName, queryOptions, overtimeOptions, }?: useShowProps<TQueryFnData, TError, TData>) => useShowReturnType<TData, TError>;
57
- //# sourceMappingURL=useShow.d.ts.map
@@ -1,57 +0,0 @@
1
- import React from "react";
2
- import type { QueryObserverResult, UseQueryOptions } from "@tanstack/react-query";
3
- import type { BaseKey, BaseRecord, GetOneResponse, HttpError, MetaQuery, Prettify } from "../../contexts/data/types";
4
- import type { LiveModeProps } from "../../contexts/live/types";
5
- import type { SuccessErrorNotification } from "../../contexts/notification/types";
6
- import { type UseLoadingOvertimeOptionsProps, type UseLoadingOvertimeReturnType } from "../useLoadingOvertime";
7
- export type useShowReturnType<TData extends BaseRecord = BaseRecord, TError extends HttpError = HttpError> = {
8
- queryResult: QueryObserverResult<GetOneResponse<TData>, TError>;
9
- showId?: BaseKey;
10
- setShowId: React.Dispatch<React.SetStateAction<BaseKey | undefined>>;
11
- } & UseLoadingOvertimeReturnType;
12
- export type useShowProps<TQueryFnData extends BaseRecord = BaseRecord, TError extends HttpError = HttpError, TData extends BaseRecord = TQueryFnData> = {
13
- /**
14
- * Resource name for API data interactions
15
- * @default Reads `:resource` from the URL
16
- */
17
- resource?: string;
18
- /**
19
- * Data item ID for API data interactions
20
- * @default Reads `:id` from the URL
21
- */
22
- id?: BaseKey;
23
- /**
24
- * react-query's [useQuery](https://tanstack.com/query/v4/docs/reference/useQuery) options
25
- */
26
- queryOptions?: UseQueryOptions<GetOneResponse<TQueryFnData>, TError, GetOneResponse<TData>>;
27
- /**
28
- * Additional meta data to pass to the data provider's `getOne`
29
- */
30
- meta?: MetaQuery;
31
- /**
32
- * Additional meta data to pass to the data provider's `getOne`
33
- * @deprecated `metaData` is deprecated with refine@4, refine will pass `meta` instead, however, we still support `metaData` for backward compatibility.
34
- */
35
- metaData?: MetaQuery;
36
- /**
37
- * Target data provider name for API call to be made
38
- * @default `"default"`
39
- */
40
- dataProviderName?: string;
41
- } & LiveModeProps & SuccessErrorNotification<GetOneResponse<TData>, TError, Prettify<{
42
- id?: BaseKey;
43
- } & MetaQuery>> & UseLoadingOvertimeOptionsProps;
44
- /**
45
- * `useShow` hook allows you to fetch the desired record.
46
- * It uses `getOne` method as query function from the dataProvider that is
47
- * passed to {@link https://refine.dev/docs/api-reference/core/components/refine-config/ `<Refine>`}.
48
- *
49
- * @see {@link https://refine.dev/docs/api-reference/core/hooks/show/useShow} for more details.
50
- *
51
- * @typeParam TQueryFnData - Result data returned by the query function. Extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#baserecord `BaseRecord`}
52
- * @typeParam TError - Custom error object that extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#httperror `HttpError`}
53
- * @typeParam TData - Result data returned by the `select` function. Extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#baserecord `BaseRecord`}. Defaults to `TQueryFnData`
54
- *
55
- */
56
- export declare const useShow: <TQueryFnData extends BaseRecord = BaseRecord, TError extends HttpError = HttpError, TData extends BaseRecord = TQueryFnData>({ resource: resourceFromProp, id, successNotification, errorNotification, meta, metaData, liveMode, onLiveEvent, dataProviderName, queryOptions, overtimeOptions, }?: useShowProps<TQueryFnData, TError, TData>) => useShowReturnType<TData, TError>;
57
- //# sourceMappingURL=useShow.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useShow.d.ts","source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;;OAGG;IACH,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,GAAG,aAAa,GACf,wBAAwB,CACtB,cAAc,CAAC,KAAK,CAAC,EACrB,MAAM,EACN,QAAQ,CAAC;IAAE,EAAE,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,SAAS,CAAC,CACvC,GACD,8BAA8B,CAAC;AAEjC;;;;;;;;;;;GAWG;AAEH,eAAO,MAAM,OAAO,sSAgBjB,aAAa,YAAY,EAAE,MAAM,EAAE,KAAK,CAAC,KAAQ,kBAClD,KAAK,EACL,MAAM,CAiEP,CAAC"}
@@ -1,179 +0,0 @@
1
- import React, { useState } from "react";
2
-
3
- import type {
4
- QueryObserverResult,
5
- UseQueryOptions,
6
- } from "@tanstack/react-query";
7
- import warnOnce from "warn-once";
8
-
9
- import { pickNotDeprecated } from "@definitions/helpers";
10
- import { useMeta, useOne } from "@hooks";
11
-
12
- import type {
13
- BaseKey,
14
- BaseRecord,
15
- GetOneResponse,
16
- HttpError,
17
- MetaQuery,
18
- Prettify,
19
- } from "../../contexts/data/types";
20
- import type { LiveModeProps } from "../../contexts/live/types";
21
- import type { SuccessErrorNotification } from "../../contexts/notification/types";
22
- import { useResource } from "../resource/useResource";
23
- import {
24
- type UseLoadingOvertimeOptionsProps,
25
- type UseLoadingOvertimeReturnType,
26
- useLoadingOvertime,
27
- } from "../useLoadingOvertime";
28
-
29
- export type useShowReturnType<
30
- TData extends BaseRecord = BaseRecord,
31
- TError extends HttpError = HttpError,
32
- > = {
33
- queryResult: QueryObserverResult<GetOneResponse<TData>, TError>;
34
- showId?: BaseKey;
35
- setShowId: React.Dispatch<React.SetStateAction<BaseKey | undefined>>;
36
- } & UseLoadingOvertimeReturnType;
37
-
38
- export type useShowProps<
39
- TQueryFnData extends BaseRecord = BaseRecord,
40
- TError extends HttpError = HttpError,
41
- TData extends BaseRecord = TQueryFnData,
42
- > = {
43
- /**
44
- * Resource name for API data interactions
45
- * @default Reads `:resource` from the URL
46
- */
47
- resource?: string;
48
- /**
49
- * Data item ID for API data interactions
50
- * @default Reads `:id` from the URL
51
- */
52
- id?: BaseKey;
53
- /**
54
- * react-query's [useQuery](https://tanstack.com/query/v4/docs/reference/useQuery) options
55
- */
56
- queryOptions?: UseQueryOptions<
57
- GetOneResponse<TQueryFnData>,
58
- TError,
59
- GetOneResponse<TData>
60
- >;
61
- /**
62
- * Additional meta data to pass to the data provider's `getOne`
63
- */
64
- meta?: MetaQuery;
65
- /**
66
- * Additional meta data to pass to the data provider's `getOne`
67
- * @deprecated `metaData` is deprecated with refine@4, refine will pass `meta` instead, however, we still support `metaData` for backward compatibility.
68
- */
69
- metaData?: MetaQuery;
70
- /**
71
- * Target data provider name for API call to be made
72
- * @default `"default"`
73
- */
74
- dataProviderName?: string;
75
- } & LiveModeProps &
76
- SuccessErrorNotification<
77
- GetOneResponse<TData>,
78
- TError,
79
- Prettify<{ id?: BaseKey } & MetaQuery>
80
- > &
81
- UseLoadingOvertimeOptionsProps;
82
-
83
- /**
84
- * `useShow` hook allows you to fetch the desired record.
85
- * It uses `getOne` method as query function from the dataProvider that is
86
- * passed to {@link https://refine.dev/docs/api-reference/core/components/refine-config/ `<Refine>`}.
87
- *
88
- * @see {@link https://refine.dev/docs/api-reference/core/hooks/show/useShow} for more details.
89
- *
90
- * @typeParam TQueryFnData - Result data returned by the query function. Extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#baserecord `BaseRecord`}
91
- * @typeParam TError - Custom error object that extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#httperror `HttpError`}
92
- * @typeParam TData - Result data returned by the `select` function. Extends {@link https://refine.dev/docs/api-reference/core/interfaceReferences#baserecord `BaseRecord`}. Defaults to `TQueryFnData`
93
- *
94
- */
95
-
96
- export const useShow = <
97
- TQueryFnData extends BaseRecord = BaseRecord,
98
- TError extends HttpError = HttpError,
99
- TData extends BaseRecord = TQueryFnData,
100
- >({
101
- resource: resourceFromProp,
102
- id,
103
- successNotification,
104
- errorNotification,
105
- meta,
106
- metaData,
107
- liveMode,
108
- onLiveEvent,
109
- dataProviderName,
110
- queryOptions,
111
- overtimeOptions,
112
- }: useShowProps<TQueryFnData, TError, TData> = {}): useShowReturnType<
113
- TData,
114
- TError
115
- > => {
116
- const {
117
- resource,
118
- id: idFromRoute,
119
- identifier,
120
- } = useResource(resourceFromProp);
121
- const { identifier: inferredIdentifier } = useResource();
122
- const getMeta = useMeta();
123
-
124
- const getDefaultId = () => {
125
- const idFromPropsOrRoute = id ?? idFromRoute;
126
-
127
- if (resourceFromProp && resourceFromProp !== inferredIdentifier) {
128
- return id;
129
- }
130
-
131
- return idFromPropsOrRoute;
132
- };
133
- const defaultId = getDefaultId();
134
-
135
- const [showId, setShowId] = useState<BaseKey | undefined>(defaultId);
136
-
137
- React.useEffect(() => {
138
- setShowId(defaultId);
139
- }, [defaultId]);
140
-
141
- const combinedMeta = getMeta({
142
- resource,
143
- meta: pickNotDeprecated(meta, metaData),
144
- });
145
-
146
- warnOnce(
147
- Boolean(resourceFromProp) && !id,
148
- `[useShow]: resource: "${identifier}", id: ${id} \n\nIf you don't use the \`setShowId\` method to set the \`showId\`, you should pass the \`id\` prop to \`useShow\`. Otherwise, \`useShow\` will not be able to infer the \`id\` from the current URL. \n\nSee https://refine.dev/docs/api-reference/core/hooks/show/useShow/#resource`,
149
- );
150
-
151
- const queryResult = useOne<TQueryFnData, TError, TData>({
152
- resource: identifier,
153
- id: showId ?? "",
154
- queryOptions: {
155
- enabled: showId !== undefined,
156
- ...queryOptions,
157
- },
158
- successNotification,
159
- errorNotification,
160
- meta: combinedMeta,
161
- metaData: combinedMeta,
162
- liveMode,
163
- onLiveEvent,
164
- dataProviderName,
165
- });
166
-
167
- const { elapsedTime } = useLoadingOvertime({
168
- isLoading: queryResult.isFetching,
169
- interval: overtimeOptions?.interval,
170
- onInterval: overtimeOptions?.onInterval,
171
- });
172
-
173
- return {
174
- queryResult,
175
- showId,
176
- setShowId,
177
- overtime: { elapsedTime },
178
- };
179
- };