@refinedev/core 4.54.1 → 4.56.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 +165 -0
- package/dist/components/index.d.cts +1 -0
- package/dist/components/index.d.cts.map +1 -1
- package/dist/components/index.d.mts +1 -0
- package/dist/components/index.d.mts.map +1 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/link/index.d.cts +20 -0
- package/dist/components/link/index.d.cts.map +1 -0
- package/dist/components/link/index.d.mts +20 -0
- package/dist/components/link/index.d.mts.map +20 -0
- package/dist/components/link/index.d.ts +20 -0
- package/dist/components/link/index.d.ts.map +1 -0
- package/dist/components/pages/auth/components/forgotPassword/index.d.cts.map +1 -1
- package/dist/components/pages/auth/components/forgotPassword/index.d.ts.map +1 -1
- package/dist/components/pages/auth/components/login/index.d.cts.map +1 -1
- package/dist/components/pages/auth/components/login/index.d.ts.map +1 -1
- package/dist/components/pages/auth/components/register/index.d.cts.map +1 -1
- package/dist/components/pages/auth/components/register/index.d.ts.map +1 -1
- package/dist/components/pages/auth/components/updatePassword/index.d.cts.map +1 -1
- package/dist/components/pages/auth/components/updatePassword/index.d.ts.map +1 -1
- package/dist/components/pages/auth/types.d.cts +8 -0
- package/dist/components/pages/auth/types.d.cts.map +1 -1
- package/dist/components/pages/auth/types.d.mts +8 -0
- package/dist/components/pages/auth/types.d.mts.map +8 -0
- package/dist/components/pages/auth/types.d.ts +8 -0
- package/dist/components/pages/auth/types.d.ts.map +1 -1
- package/dist/contexts/metaContext/index.d.cts +18 -0
- package/dist/contexts/metaContext/index.d.cts.map +1 -0
- package/dist/contexts/metaContext/index.d.mts +18 -0
- package/dist/contexts/metaContext/index.d.mts.map +18 -0
- package/dist/contexts/metaContext/index.d.ts +18 -0
- package/dist/contexts/metaContext/index.d.ts.map +1 -0
- package/dist/contexts/notification/types.d.cts +2 -2
- package/dist/contexts/notification/types.d.cts.map +1 -1
- package/dist/contexts/notification/types.d.mts +2 -2
- package/dist/contexts/notification/types.d.mts.map +2 -2
- package/dist/contexts/notification/types.d.ts +2 -2
- package/dist/contexts/notification/types.d.ts.map +1 -1
- package/dist/hooks/auth/index.d.cts +1 -0
- package/dist/hooks/auth/index.d.cts.map +1 -1
- package/dist/hooks/auth/index.d.mts +1 -0
- package/dist/hooks/auth/index.d.mts.map +1 -0
- package/dist/hooks/auth/index.d.ts +1 -0
- package/dist/hooks/auth/index.d.ts.map +1 -1
- package/dist/hooks/menu/useMenu.d.cts +1 -1
- package/dist/hooks/menu/useMenu.d.cts.map +1 -1
- package/dist/hooks/menu/useMenu.d.mts +1 -1
- package/dist/hooks/menu/useMenu.d.mts.map +1 -1
- package/dist/hooks/menu/useMenu.d.ts +1 -1
- package/dist/hooks/menu/useMenu.d.ts.map +1 -1
- package/dist/hooks/navigation/index.d.cts +1 -1
- package/dist/hooks/navigation/index.d.mts +1 -1
- package/dist/hooks/navigation/index.d.mts.map +1 -1
- package/dist/hooks/navigation/index.d.ts +1 -1
- package/dist/hooks/router/use-link/index.d.cts +4 -5
- package/dist/hooks/router/use-link/index.d.cts.map +1 -1
- package/dist/hooks/router/use-link/index.d.mts +4 -5
- package/dist/hooks/router/use-link/index.d.mts.map +4 -5
- package/dist/hooks/router/use-link/index.d.ts +4 -5
- package/dist/hooks/router/use-link/index.d.ts.map +1 -1
- package/dist/hooks/useMeta/index.d.cts +2 -12
- package/dist/hooks/useMeta/index.d.cts.map +1 -1
- package/dist/hooks/useMeta/index.d.mts +2 -12
- package/dist/hooks/useMeta/index.d.mts.map +2 -12
- package/dist/hooks/useMeta/index.d.ts +2 -12
- package/dist/hooks/useMeta/index.d.ts.map +1 -1
- package/dist/hooks/useTable/index.d.cts.map +1 -1
- package/dist/hooks/useTable/index.d.ts.map +1 -1
- package/dist/index.cjs +18 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +18 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/index.ts +1 -0
- package/src/components/link/index.tsx +72 -0
- package/src/components/pages/auth/components/forgotPassword/index.tsx +2 -1
- package/src/components/pages/auth/components/login/index.tsx +3 -1
- package/src/components/pages/auth/components/register/index.tsx +3 -1
- package/src/components/pages/auth/components/updatePassword/index.tsx +2 -0
- package/src/components/pages/auth/types.tsx +8 -0
- package/src/contexts/metaContext/index.tsx +45 -0
- package/src/contexts/notification/types.ts +2 -2
- package/src/hooks/auth/index.ts +1 -0
- package/src/hooks/menu/useMenu.tsx +11 -7
- package/src/hooks/navigation/index.ts +1 -1
- package/src/hooks/router/use-link/index.tsx +2 -14
- package/src/hooks/useMeta/index.ts +16 -2
- package/src/hooks/useTable/index.ts +47 -31
- package/src/index.tsx +5 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@refinedev/core",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.56.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "refine is a React-based framework for building internal tools, rapidly. It ships with Ant Design System, an enterprise-level UI toolkit.",
|
|
6
6
|
"repository": {
|
package/src/components/index.ts
CHANGED
|
@@ -8,3 +8,4 @@ export { RouteChangeHandler } from "./routeChangeHandler";
|
|
|
8
8
|
export { CanAccess, CanAccessProps } from "./canAccess";
|
|
9
9
|
export { GitHubBanner } from "./gh-banner";
|
|
10
10
|
export { AutoSaveIndicator, AutoSaveIndicatorProps } from "./autoSaveIndicator";
|
|
11
|
+
export { Link, LinkProps } from "./link";
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import React, { type Ref, forwardRef, useContext } from "react";
|
|
2
|
+
import { useGo } from "@hooks/router";
|
|
3
|
+
import { RouterContext } from "@contexts/router";
|
|
4
|
+
import type { GoConfigWithResource } from "../../hooks/router/use-go";
|
|
5
|
+
import warnOnce from "warn-once";
|
|
6
|
+
|
|
7
|
+
type LinkPropsWithGo = {
|
|
8
|
+
go: Omit<GoConfigWithResource, "type">;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
type LinkPropsWithTo = {
|
|
12
|
+
to: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type LinkProps<TProps = {}> = React.PropsWithChildren<
|
|
16
|
+
(LinkPropsWithGo | LinkPropsWithTo) & TProps
|
|
17
|
+
>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param to The path to navigate to.
|
|
21
|
+
* @param go The useGo.go params to navigate to. If `to` provided, this will be ignored.
|
|
22
|
+
* @returns routerProvider.Link if it is provided, otherwise an anchor tag.
|
|
23
|
+
*/
|
|
24
|
+
const LinkComponent = <TProps = {}>(
|
|
25
|
+
props: LinkProps<TProps>,
|
|
26
|
+
ref: Ref<Element>,
|
|
27
|
+
) => {
|
|
28
|
+
const routerContext = useContext(RouterContext);
|
|
29
|
+
const LinkFromContext = routerContext?.Link;
|
|
30
|
+
|
|
31
|
+
const goFunction = useGo();
|
|
32
|
+
|
|
33
|
+
let resolvedTo = "";
|
|
34
|
+
if ("go" in props) {
|
|
35
|
+
if (!routerContext?.go) {
|
|
36
|
+
warnOnce(
|
|
37
|
+
true,
|
|
38
|
+
"[Link]: `routerProvider` is not found. To use `go`, Please make sure that you have provided the `routerProvider` for `<Refine />` https://refine.dev/docs/routing/router-provider/ \n",
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
resolvedTo = goFunction({ ...props.go, type: "path" }) as string;
|
|
42
|
+
}
|
|
43
|
+
if ("to" in props) {
|
|
44
|
+
resolvedTo = props.to;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (LinkFromContext) {
|
|
48
|
+
return (
|
|
49
|
+
<LinkFromContext
|
|
50
|
+
ref={ref}
|
|
51
|
+
{...props}
|
|
52
|
+
to={resolvedTo}
|
|
53
|
+
// This is a workaround to avoid passing `go` to the Link component.
|
|
54
|
+
go={undefined}
|
|
55
|
+
/>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
return (
|
|
59
|
+
<a
|
|
60
|
+
ref={ref}
|
|
61
|
+
href={resolvedTo}
|
|
62
|
+
{...props}
|
|
63
|
+
// This is a workaround to avoid passing `go` and `to` to the anchor tag.
|
|
64
|
+
to={undefined}
|
|
65
|
+
go={undefined}
|
|
66
|
+
/>
|
|
67
|
+
);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export const Link = forwardRef(LinkComponent) as <T = {}>(
|
|
71
|
+
props: LinkProps<T> & { ref?: Ref<Element> },
|
|
72
|
+
) => ReturnType<typeof LinkComponent>;
|
|
@@ -27,6 +27,7 @@ export const ForgotPasswordPage: React.FC<ForgotPasswordProps> = ({
|
|
|
27
27
|
renderContent,
|
|
28
28
|
formProps,
|
|
29
29
|
title = undefined,
|
|
30
|
+
mutationVariables,
|
|
30
31
|
}) => {
|
|
31
32
|
const translate = useTranslate();
|
|
32
33
|
const routerType = useRouterType();
|
|
@@ -53,7 +54,7 @@ export const ForgotPasswordPage: React.FC<ForgotPasswordProps> = ({
|
|
|
53
54
|
<form
|
|
54
55
|
onSubmit={(e) => {
|
|
55
56
|
e.preventDefault();
|
|
56
|
-
forgotPassword({ email });
|
|
57
|
+
forgotPassword({ ...mutationVariables, email });
|
|
57
58
|
}}
|
|
58
59
|
{...formProps}
|
|
59
60
|
>
|
|
@@ -25,6 +25,7 @@ export const LoginPage: React.FC<LoginProps> = ({
|
|
|
25
25
|
formProps,
|
|
26
26
|
title = undefined,
|
|
27
27
|
hideForm,
|
|
28
|
+
mutationVariables,
|
|
28
29
|
}) => {
|
|
29
30
|
const routerType = useRouterType();
|
|
30
31
|
const Link = useLink();
|
|
@@ -62,6 +63,7 @@ export const LoginPage: React.FC<LoginProps> = ({
|
|
|
62
63
|
<button
|
|
63
64
|
onClick={() =>
|
|
64
65
|
login({
|
|
66
|
+
...mutationVariables,
|
|
65
67
|
providerName: provider.name,
|
|
66
68
|
})
|
|
67
69
|
}
|
|
@@ -91,7 +93,7 @@ export const LoginPage: React.FC<LoginProps> = ({
|
|
|
91
93
|
<form
|
|
92
94
|
onSubmit={(e) => {
|
|
93
95
|
e.preventDefault();
|
|
94
|
-
login({ email, password, remember });
|
|
96
|
+
login({ ...mutationVariables, email, password, remember });
|
|
95
97
|
}}
|
|
96
98
|
{...formProps}
|
|
97
99
|
>
|
|
@@ -28,6 +28,7 @@ export const RegisterPage: React.FC<RegisterProps> = ({
|
|
|
28
28
|
formProps,
|
|
29
29
|
title = undefined,
|
|
30
30
|
hideForm,
|
|
31
|
+
mutationVariables,
|
|
31
32
|
}) => {
|
|
32
33
|
const routerType = useRouterType();
|
|
33
34
|
const Link = useLink();
|
|
@@ -64,6 +65,7 @@ export const RegisterPage: React.FC<RegisterProps> = ({
|
|
|
64
65
|
<button
|
|
65
66
|
onClick={() =>
|
|
66
67
|
register({
|
|
68
|
+
...mutationVariables,
|
|
67
69
|
providerName: provider.name,
|
|
68
70
|
})
|
|
69
71
|
}
|
|
@@ -93,7 +95,7 @@ export const RegisterPage: React.FC<RegisterProps> = ({
|
|
|
93
95
|
<form
|
|
94
96
|
onSubmit={(e) => {
|
|
95
97
|
e.preventDefault();
|
|
96
|
-
register({ email, password });
|
|
98
|
+
register({ ...mutationVariables, email, password });
|
|
97
99
|
}}
|
|
98
100
|
{...formProps}
|
|
99
101
|
>
|
|
@@ -21,6 +21,7 @@ export const UpdatePasswordPage: React.FC<UpdatePasswordProps> = ({
|
|
|
21
21
|
renderContent,
|
|
22
22
|
formProps,
|
|
23
23
|
title = undefined,
|
|
24
|
+
mutationVariables,
|
|
24
25
|
}) => {
|
|
25
26
|
const translate = useTranslate();
|
|
26
27
|
|
|
@@ -43,6 +44,7 @@ export const UpdatePasswordPage: React.FC<UpdatePasswordProps> = ({
|
|
|
43
44
|
onSubmit={(e) => {
|
|
44
45
|
e.preventDefault();
|
|
45
46
|
updatePassword({
|
|
47
|
+
...mutationVariables,
|
|
46
48
|
password: newPassword,
|
|
47
49
|
confirmPassword,
|
|
48
50
|
});
|
|
@@ -144,6 +144,10 @@ export type AuthPageProps<
|
|
|
144
144
|
* @optional
|
|
145
145
|
* */
|
|
146
146
|
title?: React.ReactNode;
|
|
147
|
+
/**
|
|
148
|
+
* @description Can be used to pass additional variables to the mutation. This is useful when you need to pass other variables to the authProvider.
|
|
149
|
+
*/
|
|
150
|
+
mutationVariables?: Record<string, any>;
|
|
147
151
|
};
|
|
148
152
|
|
|
149
153
|
/**
|
|
@@ -167,6 +171,7 @@ export type LoginPageProps<
|
|
|
167
171
|
formProps?: TFormProps;
|
|
168
172
|
title?: React.ReactNode;
|
|
169
173
|
hideForm?: boolean;
|
|
174
|
+
mutationVariables?: Record<string, unknown>;
|
|
170
175
|
}>;
|
|
171
176
|
|
|
172
177
|
/**
|
|
@@ -188,6 +193,7 @@ export type RegisterPageProps<
|
|
|
188
193
|
formProps?: TFormProps;
|
|
189
194
|
title?: React.ReactNode;
|
|
190
195
|
hideForm?: boolean;
|
|
196
|
+
mutationVariables?: Record<string, unknown>;
|
|
191
197
|
}>;
|
|
192
198
|
|
|
193
199
|
/**
|
|
@@ -207,6 +213,7 @@ export type ForgotPasswordPageProps<
|
|
|
207
213
|
contentProps?: TContentProps;
|
|
208
214
|
formProps?: TFormProps;
|
|
209
215
|
title?: React.ReactNode;
|
|
216
|
+
mutationVariables?: Record<string, unknown>;
|
|
210
217
|
}>;
|
|
211
218
|
|
|
212
219
|
/**
|
|
@@ -225,4 +232,5 @@ export type UpdatePasswordPageProps<
|
|
|
225
232
|
contentProps?: TContentProps;
|
|
226
233
|
formProps?: TFormProps;
|
|
227
234
|
title?: React.ReactNode;
|
|
235
|
+
mutationVariables?: Record<string, unknown>;
|
|
228
236
|
}>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
type ReactNode,
|
|
3
|
+
createContext,
|
|
4
|
+
useContext,
|
|
5
|
+
useMemo,
|
|
6
|
+
} from "react";
|
|
7
|
+
|
|
8
|
+
type MetaContextValue = Record<string, any>;
|
|
9
|
+
|
|
10
|
+
export const MetaContext = createContext<MetaContextValue>({});
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Is used to provide meta data to the children components.
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export const MetaContextProvider = ({
|
|
17
|
+
children,
|
|
18
|
+
value,
|
|
19
|
+
}: { children: ReactNode; value: MetaContextValue }) => {
|
|
20
|
+
const currentValue = useMetaContext();
|
|
21
|
+
|
|
22
|
+
const metaContext = useMemo(() => {
|
|
23
|
+
return {
|
|
24
|
+
...currentValue,
|
|
25
|
+
...value,
|
|
26
|
+
};
|
|
27
|
+
}, [currentValue, value]);
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<MetaContext.Provider value={metaContext}>{children}</MetaContext.Provider>
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @internal
|
|
36
|
+
* @returns The MetaContext value.
|
|
37
|
+
*/
|
|
38
|
+
export const useMetaContext = () => {
|
|
39
|
+
const context = useContext(MetaContext);
|
|
40
|
+
if (!context) {
|
|
41
|
+
throw new Error("useMetaContext must be used within a MetaContextProvider");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return useContext(MetaContext);
|
|
45
|
+
};
|
|
@@ -15,7 +15,7 @@ export type SuccessErrorNotification<
|
|
|
15
15
|
data?: TData,
|
|
16
16
|
values?: TVariables,
|
|
17
17
|
resource?: string,
|
|
18
|
-
) => OpenNotificationParams | false);
|
|
18
|
+
) => OpenNotificationParams | false | undefined);
|
|
19
19
|
/**
|
|
20
20
|
* Error notification configuration to be displayed when the mutation fails.
|
|
21
21
|
* @default '"There was an error creating resource (status code: `statusCode`)" or "Error when updating resource (status code: statusCode)"'
|
|
@@ -27,7 +27,7 @@ export type SuccessErrorNotification<
|
|
|
27
27
|
error?: TError,
|
|
28
28
|
values?: TVariables,
|
|
29
29
|
resource?: string,
|
|
30
|
-
) => OpenNotificationParams | false);
|
|
30
|
+
) => OpenNotificationParams | false | undefined);
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
export type OpenNotificationParams = {
|
package/src/hooks/auth/index.ts
CHANGED
|
@@ -8,3 +8,4 @@ export { useUpdatePassword } from "./useUpdatePassword";
|
|
|
8
8
|
export { useAuthenticated, useIsAuthenticated } from "./useIsAuthenticated";
|
|
9
9
|
export { useCheckError, useOnError } from "./useOnError";
|
|
10
10
|
export { useIsExistAuthentication } from "./useIsExistAuthentication";
|
|
11
|
+
export { useInvalidateAuthStore } from "./useInvalidateAuthStore";
|
|
@@ -23,12 +23,14 @@ export type UseMenuProps = {
|
|
|
23
23
|
hideOnMissingParameter?: boolean;
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
export type TreeMenuItem =
|
|
27
|
-
route
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
export type TreeMenuItem =
|
|
27
|
+
// Omitted because `label` and `route` are deprecated in `resource` but not in `menuItems`. These are populated in `prepareItem` for ease of use.
|
|
28
|
+
Omit<FlatTreeItem, "label" | "route" | "children"> & {
|
|
29
|
+
route?: string;
|
|
30
|
+
icon?: React.ReactNode;
|
|
31
|
+
label?: string;
|
|
32
|
+
children: TreeMenuItem[];
|
|
33
|
+
};
|
|
32
34
|
|
|
33
35
|
const getCleanPath = (pathname: string) => {
|
|
34
36
|
return pathname
|
|
@@ -86,7 +88,9 @@ export const useMenu = (
|
|
|
86
88
|
|
|
87
89
|
const prepareItem = React.useCallback(
|
|
88
90
|
(item: FlatTreeItem): TreeMenuItem | undefined => {
|
|
89
|
-
if (item?.meta?.hide
|
|
91
|
+
if (pickNotDeprecated(item?.meta?.hide, item?.options?.hide)) {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
90
94
|
if (!item?.list && item.children.length === 0) return undefined;
|
|
91
95
|
|
|
92
96
|
const composed = item.list
|
|
@@ -13,7 +13,7 @@ import type { IResourceItem } from "../../contexts/resource/types";
|
|
|
13
13
|
export type HistoryType = "push" | "replace";
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* `refine` uses {@link https://reactrouter.com/en/hooks/use-navigate `React Router`} and comes with all redirects out of the box.
|
|
16
|
+
* `refine` uses {@link https://reactrouter.com/en/main/hooks/use-navigate#usenavigate `React Router`} and comes with all redirects out of the box.
|
|
17
17
|
* It allows you to manage your routing operations in refine.
|
|
18
18
|
* Using this hook, you can manage all the routing operations of your application very easily.
|
|
19
19
|
*
|
|
@@ -1,17 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import React, { useContext } from "react";
|
|
1
|
+
import { Link } from "../../../components/link";
|
|
3
2
|
|
|
4
3
|
export const useLink = () => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
if (routerContext?.Link) {
|
|
8
|
-
return routerContext.Link;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const FallbackLink: Required<typeof routerContext>["Link"] = ({
|
|
12
|
-
to,
|
|
13
|
-
...rest
|
|
14
|
-
}) => <a href={to} {...rest} />;
|
|
15
|
-
|
|
16
|
-
return FallbackLink;
|
|
4
|
+
return Link;
|
|
17
5
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useMetaContext } from "@contexts/metaContext";
|
|
1
2
|
import { sanitizeResource } from "@definitions/helpers/sanitize-resource";
|
|
2
3
|
import { useParsed } from "@hooks/router";
|
|
3
4
|
|
|
@@ -6,12 +7,14 @@ import type { IResourceItem } from "../../contexts/resource/types";
|
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Hook that returns a function to get meta.
|
|
9
|
-
* The meta is a combination of the resource meta, hook meta and
|
|
10
|
+
* The meta is a combination of the resource meta, hook meta, query params and metaContext value.
|
|
10
11
|
* @internal
|
|
11
12
|
*/
|
|
12
13
|
export const useMeta = () => {
|
|
13
14
|
const { params } = useParsed();
|
|
14
15
|
|
|
16
|
+
const metaContext = useMetaContext();
|
|
17
|
+
|
|
15
18
|
const getMetaFn = ({
|
|
16
19
|
resource,
|
|
17
20
|
meta: metaFromProp,
|
|
@@ -30,7 +33,18 @@ export const useMeta = () => {
|
|
|
30
33
|
...additionalParams
|
|
31
34
|
} = params ?? {};
|
|
32
35
|
|
|
33
|
-
|
|
36
|
+
const result: Record<string, unknown> = {
|
|
37
|
+
...meta,
|
|
38
|
+
...additionalParams,
|
|
39
|
+
...metaFromProp,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// when MultiTenancyProvider from "@refinedev-ee/multi-tenancy" is provided, we need to add tenantId to the meta
|
|
43
|
+
if (metaContext?.tenantId) {
|
|
44
|
+
result["tenantId"] = metaContext.tenantId;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return result;
|
|
34
48
|
};
|
|
35
49
|
|
|
36
50
|
return getMetaFn;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useState, useEffect } from "react";
|
|
1
|
+
import React, { useState, useEffect, useCallback } from "react";
|
|
2
2
|
|
|
3
3
|
import type {
|
|
4
4
|
QueryObserverResult,
|
|
@@ -520,40 +520,56 @@ export function useTable<
|
|
|
520
520
|
dataProviderName,
|
|
521
521
|
});
|
|
522
522
|
|
|
523
|
-
const setFiltersAsMerge = (
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
523
|
+
const setFiltersAsMerge = useCallback(
|
|
524
|
+
(newFilters: CrudFilter[]) => {
|
|
525
|
+
setFilters((prevFilters) =>
|
|
526
|
+
unionFilters(preferredPermanentFilters, newFilters, prevFilters),
|
|
527
|
+
);
|
|
528
|
+
},
|
|
529
|
+
[preferredPermanentFilters],
|
|
530
|
+
);
|
|
528
531
|
|
|
529
|
-
const setFiltersAsReplace = (
|
|
530
|
-
|
|
531
|
-
|
|
532
|
+
const setFiltersAsReplace = useCallback(
|
|
533
|
+
(newFilters: CrudFilter[]) => {
|
|
534
|
+
setFilters(unionFilters(preferredPermanentFilters, newFilters));
|
|
535
|
+
},
|
|
536
|
+
[preferredPermanentFilters],
|
|
537
|
+
);
|
|
532
538
|
|
|
533
|
-
const setFiltersWithSetter = (
|
|
534
|
-
setter: (prevFilters: CrudFilter[]) => CrudFilter[]
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
539
|
+
const setFiltersWithSetter = useCallback(
|
|
540
|
+
(setter: (prevFilters: CrudFilter[]) => CrudFilter[]) => {
|
|
541
|
+
setFilters((prev) =>
|
|
542
|
+
unionFilters(preferredPermanentFilters, setter(prev)),
|
|
543
|
+
);
|
|
544
|
+
},
|
|
545
|
+
[preferredPermanentFilters],
|
|
546
|
+
);
|
|
538
547
|
|
|
539
|
-
const setFiltersFn: useTableReturnType<TQueryFnData>["setFilters"] =
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
548
|
+
const setFiltersFn: useTableReturnType<TQueryFnData>["setFilters"] =
|
|
549
|
+
useCallback(
|
|
550
|
+
(
|
|
551
|
+
setterOrFilters,
|
|
552
|
+
behavior: SetFilterBehavior = prefferedFilterBehavior,
|
|
553
|
+
) => {
|
|
554
|
+
if (typeof setterOrFilters === "function") {
|
|
555
|
+
setFiltersWithSetter(setterOrFilters);
|
|
556
|
+
} else {
|
|
557
|
+
if (behavior === "replace") {
|
|
558
|
+
setFiltersAsReplace(setterOrFilters);
|
|
559
|
+
} else {
|
|
560
|
+
setFiltersAsMerge(setterOrFilters);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
},
|
|
564
|
+
[setFiltersWithSetter, setFiltersAsReplace, setFiltersAsMerge],
|
|
565
|
+
);
|
|
553
566
|
|
|
554
|
-
const setSortWithUnion = (
|
|
555
|
-
|
|
556
|
-
|
|
567
|
+
const setSortWithUnion = useCallback(
|
|
568
|
+
(newSorter: CrudSort[]) => {
|
|
569
|
+
setSorters(() => unionSorters(preferredPermanentSorters, newSorter));
|
|
570
|
+
},
|
|
571
|
+
[preferredPermanentSorters],
|
|
572
|
+
);
|
|
557
573
|
|
|
558
574
|
const { elapsedTime } = useLoadingOvertime({
|
|
559
575
|
isLoading: queryResult.isFetching,
|
package/src/index.tsx
CHANGED