@refinedev/core 5.0.5 → 5.0.7
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 +20 -0
- package/dist/components/containers/refine/index.d.cts.map +1 -1
- package/dist/components/containers/refine/index.d.ts.map +1 -1
- package/dist/contexts/refine/index.d.cts.map +1 -1
- package/dist/contexts/refine/index.d.ts.map +1 -1
- package/dist/contexts/refine/types.d.cts +2 -0
- package/dist/contexts/refine/types.d.cts.map +1 -1
- package/dist/contexts/refine/types.d.mts +2 -0
- package/dist/contexts/refine/types.d.mts.map +2 -0
- package/dist/contexts/refine/types.d.ts +2 -0
- package/dist/contexts/refine/types.d.ts.map +1 -1
- package/dist/definitions/helpers/handleRefineOptions/index.d.cts +2 -1
- package/dist/definitions/helpers/handleRefineOptions/index.d.cts.map +1 -1
- package/dist/definitions/helpers/handleRefineOptions/index.d.mts +2 -1
- package/dist/definitions/helpers/handleRefineOptions/index.d.mts.map +2 -1
- package/dist/definitions/helpers/handleRefineOptions/index.d.ts +2 -1
- package/dist/definitions/helpers/handleRefineOptions/index.d.ts.map +1 -1
- package/dist/hooks/data/useList.d.cts.map +1 -1
- package/dist/hooks/data/useList.d.ts.map +1 -1
- package/dist/hooks/form/index.d.cts.map +1 -1
- package/dist/hooks/form/index.d.ts.map +1 -1
- package/dist/index.cjs +483 -456
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +63 -36
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/containers/refine/index.tsx +6 -1
- package/src/contexts/refine/index.tsx +1 -0
- package/src/contexts/refine/types.ts +2 -0
- package/src/definitions/helpers/handleRefineOptions/index.ts +6 -0
- package/src/hooks/data/useList.ts +34 -22
- package/src/hooks/form/index.ts +20 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@refinedev/core",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.7",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Refine is a React meta-framework for building enterprise-level, data-intensive applications rapidly with support for modern UI libraries and headless integrations.",
|
|
6
6
|
"repository": {
|
|
@@ -57,6 +57,9 @@ export const Refine: React.FC<RefineProps> = ({
|
|
|
57
57
|
options,
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
+
const disableRouteChangeHandler =
|
|
61
|
+
optionsWithDefaults.disableRouteChangeHandler;
|
|
62
|
+
|
|
60
63
|
const queryClient = useDeepMemo(() => {
|
|
61
64
|
if (reactQueryWithDefaults.clientConfig instanceof QueryClient) {
|
|
62
65
|
return reactQueryWithDefaults.clientConfig;
|
|
@@ -127,7 +130,9 @@ export const Refine: React.FC<RefineProps> = ({
|
|
|
127
130
|
<React.Fragment>
|
|
128
131
|
{children}
|
|
129
132
|
{!disableTelemetryWithDefault && <Telemetry />}
|
|
130
|
-
|
|
133
|
+
{!disableRouteChangeHandler && (
|
|
134
|
+
<RouteChangeHandler />
|
|
135
|
+
)}
|
|
131
136
|
</React.Fragment>
|
|
132
137
|
</UnsavedWarnContextProvider>
|
|
133
138
|
</RefineContextProvider>
|
|
@@ -73,6 +73,7 @@ export interface IRefineOptions {
|
|
|
73
73
|
undoableTimeout?: number;
|
|
74
74
|
liveMode?: LiveModeProps["liveMode"];
|
|
75
75
|
disableTelemetry?: boolean;
|
|
76
|
+
disableRouteChangeHandler?: boolean;
|
|
76
77
|
redirect?: {
|
|
77
78
|
afterCreate?: RedirectAction;
|
|
78
79
|
afterClone?: RedirectAction;
|
|
@@ -118,6 +119,7 @@ export interface IRefineContextOptions {
|
|
|
118
119
|
overtime: UseLoadingOvertimeRefineContext;
|
|
119
120
|
textTransformers: Required<TextTransformers>;
|
|
120
121
|
disableServerSideValidation: boolean;
|
|
122
|
+
disableRouteChangeHandler: boolean;
|
|
121
123
|
projectId?: string;
|
|
122
124
|
title: {
|
|
123
125
|
icon?: React.ReactNode;
|
|
@@ -17,6 +17,7 @@ type HandleRefineOptionsProps = {
|
|
|
17
17
|
undoableTimeout?: number;
|
|
18
18
|
liveMode?: LiveModeProps["liveMode"];
|
|
19
19
|
disableTelemetry?: boolean;
|
|
20
|
+
disableRouteChangeHandler?: boolean;
|
|
20
21
|
reactQueryClientConfig?: QueryClientConfig;
|
|
21
22
|
reactQueryDevtoolConfig?: any | false;
|
|
22
23
|
};
|
|
@@ -39,6 +40,7 @@ export const handleRefineOptions = ({
|
|
|
39
40
|
syncWithLocation,
|
|
40
41
|
undoableTimeout,
|
|
41
42
|
warnWhenUnsavedChanges,
|
|
43
|
+
disableRouteChangeHandler,
|
|
42
44
|
}: HandleRefineOptionsProps = {}): HandleRefineOptionsReturnValues => {
|
|
43
45
|
const optionsWithDefaults: IRefineContextOptions = {
|
|
44
46
|
breadcrumb: options?.breadcrumb,
|
|
@@ -95,6 +97,10 @@ export const handleRefineOptions = ({
|
|
|
95
97
|
? defaultRefineOptions.title.text
|
|
96
98
|
: options?.title?.text,
|
|
97
99
|
},
|
|
100
|
+
disableRouteChangeHandler:
|
|
101
|
+
options?.disableRouteChangeHandler ??
|
|
102
|
+
disableRouteChangeHandler ??
|
|
103
|
+
defaultRefineOptions.disableRouteChangeHandler,
|
|
98
104
|
};
|
|
99
105
|
|
|
100
106
|
const disableTelemetryWithDefault =
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useEffect } from "react";
|
|
2
2
|
|
|
3
3
|
import { getXRay } from "@refinedev/devtools-internal";
|
|
4
|
+
import { useMemo } from "react";
|
|
4
5
|
import {
|
|
5
6
|
type QueryObserverResult,
|
|
6
7
|
type UseQueryOptions,
|
|
@@ -200,6 +201,38 @@ export const useList = <
|
|
|
200
201
|
},
|
|
201
202
|
});
|
|
202
203
|
|
|
204
|
+
// Memoize the select function to prevent it from running multiple times
|
|
205
|
+
// Note: If queryOptions.select is not memoized by the user, this will still
|
|
206
|
+
// re-run on every render. Users should wrap their select function in useCallback.
|
|
207
|
+
const memoizedSelect = useMemo(() => {
|
|
208
|
+
return (rawData: GetListResponse<TQueryFnData>): GetListResponse<TData> => {
|
|
209
|
+
let data = rawData;
|
|
210
|
+
|
|
211
|
+
if (prefferedPagination.mode === "client") {
|
|
212
|
+
data = {
|
|
213
|
+
...data,
|
|
214
|
+
data: data.data.slice(
|
|
215
|
+
(prefferedPagination.currentPage - 1) *
|
|
216
|
+
prefferedPagination.pageSize,
|
|
217
|
+
prefferedPagination.currentPage * prefferedPagination.pageSize,
|
|
218
|
+
),
|
|
219
|
+
total: data.total,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (queryOptions?.select) {
|
|
224
|
+
return queryOptions?.select?.(data);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return data as unknown as GetListResponse<TData>;
|
|
228
|
+
};
|
|
229
|
+
}, [
|
|
230
|
+
prefferedPagination.currentPage,
|
|
231
|
+
prefferedPagination.pageSize,
|
|
232
|
+
prefferedPagination.mode,
|
|
233
|
+
queryOptions?.select,
|
|
234
|
+
]);
|
|
235
|
+
|
|
203
236
|
const queryResponse = useQuery<
|
|
204
237
|
GetListResponse<TQueryFnData>,
|
|
205
238
|
TError,
|
|
@@ -238,28 +271,7 @@ export const useList = <
|
|
|
238
271
|
typeof queryOptions?.enabled !== "undefined"
|
|
239
272
|
? queryOptions?.enabled
|
|
240
273
|
: !!resource?.name,
|
|
241
|
-
select:
|
|
242
|
-
let data = rawData;
|
|
243
|
-
|
|
244
|
-
const { currentPage, mode, pageSize } = prefferedPagination;
|
|
245
|
-
|
|
246
|
-
if (mode === "client") {
|
|
247
|
-
data = {
|
|
248
|
-
...data,
|
|
249
|
-
data: data.data.slice(
|
|
250
|
-
(currentPage - 1) * pageSize,
|
|
251
|
-
currentPage * pageSize,
|
|
252
|
-
),
|
|
253
|
-
total: data.total,
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
if (queryOptions?.select) {
|
|
258
|
-
return queryOptions?.select?.(data);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
return data as unknown as GetListResponse<TData>;
|
|
262
|
-
},
|
|
274
|
+
select: memoizedSelect,
|
|
263
275
|
meta: {
|
|
264
276
|
...queryOptions?.meta,
|
|
265
277
|
...getXRay("useList", resource?.name),
|
package/src/hooks/form/index.ts
CHANGED
|
@@ -302,12 +302,28 @@ export const useForm = <
|
|
|
302
302
|
return submissionPromise;
|
|
303
303
|
};
|
|
304
304
|
|
|
305
|
-
const
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
305
|
+
const onFinishRef = React.useRef(onFinish);
|
|
306
|
+
React.useEffect(() => {
|
|
307
|
+
onFinishRef.current = onFinish;
|
|
308
|
+
}, [onFinish]);
|
|
309
|
+
|
|
310
|
+
const onFinishAutoSave = React.useMemo(
|
|
311
|
+
() =>
|
|
312
|
+
asyncDebounce(
|
|
313
|
+
(values: TVariables) =>
|
|
314
|
+
onFinishRef.current(values, { isAutosave: true }),
|
|
315
|
+
props.autoSave?.debounce ?? 1000,
|
|
316
|
+
"Cancelled by debounce",
|
|
317
|
+
),
|
|
318
|
+
[props.autoSave?.debounce],
|
|
309
319
|
);
|
|
310
320
|
|
|
321
|
+
React.useEffect(() => {
|
|
322
|
+
return () => {
|
|
323
|
+
onFinishAutoSave.cancel();
|
|
324
|
+
};
|
|
325
|
+
}, [onFinishAutoSave]);
|
|
326
|
+
|
|
311
327
|
const overtime = {
|
|
312
328
|
elapsedTime,
|
|
313
329
|
};
|