@refinedev/core 4.54.0 → 4.55.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 +98 -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/contexts/data/types.d.cts +71 -0
- package/dist/contexts/data/types.d.cts.map +1 -1
- package/dist/contexts/data/types.d.mts +71 -0
- package/dist/contexts/data/types.d.mts.map +71 -0
- package/dist/contexts/data/types.d.ts +71 -0
- package/dist/contexts/data/types.d.ts.map +1 -1
- 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/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 +3 -0
- package/dist/hooks/useMeta/index.d.cts.map +1 -1
- package/dist/hooks/useMeta/index.d.mts +3 -0
- package/dist/hooks/useMeta/index.d.mts.map +3 -0
- package/dist/hooks/useMeta/index.d.ts +3 -0
- 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 +10 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +10 -10
- 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 +74 -0
- package/src/contexts/data/types.ts +72 -0
- package/src/contexts/notification/types.ts +2 -2
- 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/use-resource-params/index.ts +1 -1
- package/src/hooks/useTable/index.ts +47 -31
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@refinedev/core",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.55.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,74 @@
|
|
|
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) &
|
|
17
|
+
React.AnchorHTMLAttributes<HTMLAnchorElement> &
|
|
18
|
+
TProps
|
|
19
|
+
>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param to The path to navigate to.
|
|
23
|
+
* @param go The useGo.go params to navigate to. If `to` provided, this will be ignored.
|
|
24
|
+
* @returns routerProvider.Link if it is provided, otherwise an anchor tag.
|
|
25
|
+
*/
|
|
26
|
+
const LinkComponent = <TProps = {}>(
|
|
27
|
+
props: LinkProps<TProps>,
|
|
28
|
+
ref: Ref<HTMLAnchorElement>,
|
|
29
|
+
) => {
|
|
30
|
+
const routerContext = useContext(RouterContext);
|
|
31
|
+
const LinkFromContext = routerContext?.Link;
|
|
32
|
+
|
|
33
|
+
const goFunction = useGo();
|
|
34
|
+
|
|
35
|
+
let resolvedTo = "";
|
|
36
|
+
if ("to" in props) {
|
|
37
|
+
resolvedTo = props.to;
|
|
38
|
+
}
|
|
39
|
+
if ("go" in props) {
|
|
40
|
+
if (!routerContext?.go) {
|
|
41
|
+
warnOnce(
|
|
42
|
+
true,
|
|
43
|
+
"[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",
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
resolvedTo = goFunction({ ...props.go, type: "path" }) as string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (LinkFromContext) {
|
|
50
|
+
return (
|
|
51
|
+
<LinkFromContext
|
|
52
|
+
ref={ref}
|
|
53
|
+
{...props}
|
|
54
|
+
to={resolvedTo}
|
|
55
|
+
// This is a workaround to avoid passing `go` to the Link component.
|
|
56
|
+
go={undefined}
|
|
57
|
+
/>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
return (
|
|
61
|
+
<a
|
|
62
|
+
ref={ref}
|
|
63
|
+
href={resolvedTo}
|
|
64
|
+
{...props}
|
|
65
|
+
// This is a workaround to avoid passing `go` and `to` to the anchor tag.
|
|
66
|
+
to={undefined}
|
|
67
|
+
go={undefined}
|
|
68
|
+
/>
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const Link = forwardRef(LinkComponent) as <T = {}>(
|
|
73
|
+
props: LinkProps<T> & { ref?: Ref<HTMLAnchorElement> },
|
|
74
|
+
) => ReturnType<typeof LinkComponent>;
|
|
@@ -96,6 +96,78 @@ export type GraphQLQueryOptions = {
|
|
|
96
96
|
* ```
|
|
97
97
|
*/
|
|
98
98
|
gqlMutation?: DocumentNode;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* @description GraphQL Variables to be used for more advanced query filters by data providers. If filters correspond to table columns,
|
|
102
|
+
* these variables will not be presented in the initial filters selected and will not be reset or set by table column filtering.
|
|
103
|
+
* @optional
|
|
104
|
+
* @example
|
|
105
|
+
* ```tsx
|
|
106
|
+
* import gql from "graphql-tag";
|
|
107
|
+
* import { useTable } from "@refinedev/antd";
|
|
108
|
+
* import type { GetFieldsFromList } from "@refinedev/hasura";
|
|
109
|
+
* import type { GetPostsQuery } from "graphql/types";
|
|
110
|
+
*
|
|
111
|
+
* const POSTS_QUERY = gql`
|
|
112
|
+
* query GetPosts(
|
|
113
|
+
* $offset: Int!
|
|
114
|
+
* $limit: Int!
|
|
115
|
+
* $order_by: [posts_order_by!]
|
|
116
|
+
* $where: posts_bool_exp
|
|
117
|
+
* ) {
|
|
118
|
+
* posts(
|
|
119
|
+
* offset: $offset
|
|
120
|
+
* limit: $limit
|
|
121
|
+
* order_by: $order_by
|
|
122
|
+
* where: $where
|
|
123
|
+
* ) {
|
|
124
|
+
* id
|
|
125
|
+
* title
|
|
126
|
+
* category {
|
|
127
|
+
* id
|
|
128
|
+
* title
|
|
129
|
+
* }
|
|
130
|
+
* }
|
|
131
|
+
* posts_aggregate(where: $where) {
|
|
132
|
+
* aggregate {
|
|
133
|
+
* count
|
|
134
|
+
* }
|
|
135
|
+
* }
|
|
136
|
+
* } `;
|
|
137
|
+
*
|
|
138
|
+
*
|
|
139
|
+
* export const PostList = () => {
|
|
140
|
+
* const { tableProps } = useTable<
|
|
141
|
+
* GetFieldsFromList<GetPostsQuery>
|
|
142
|
+
* >({
|
|
143
|
+
* meta: {
|
|
144
|
+
* gqlQuery: POSTS_QUERY,
|
|
145
|
+
* gqlVariables: {
|
|
146
|
+
* where: {
|
|
147
|
+
* _and: [
|
|
148
|
+
* {
|
|
149
|
+
* title: {
|
|
150
|
+
* _ilike: "%Updated%",
|
|
151
|
+
* },
|
|
152
|
+
* },
|
|
153
|
+
* {
|
|
154
|
+
* created_at: {
|
|
155
|
+
* _gte: "2023-08-04T08:26:26.489116+00:00"
|
|
156
|
+
* }
|
|
157
|
+
* }
|
|
158
|
+
* ],
|
|
159
|
+
* },
|
|
160
|
+
* },
|
|
161
|
+
* }
|
|
162
|
+
* });
|
|
163
|
+
* return ( <Table {...tableProps}/>);
|
|
164
|
+
* }
|
|
165
|
+
*
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
gqlVariables?: {
|
|
169
|
+
[key: string]: any;
|
|
170
|
+
};
|
|
99
171
|
};
|
|
100
172
|
|
|
101
173
|
export type MetaQuery = {
|
|
@@ -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 = {
|
|
@@ -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
|
};
|
|
@@ -64,7 +64,7 @@ export function useResourceParams(props?: Props): ResourceParams {
|
|
|
64
64
|
|
|
65
65
|
const [id, setId] = React.useState<BaseKey | undefined>(defaultId);
|
|
66
66
|
|
|
67
|
-
React.
|
|
67
|
+
React.useMemo(() => setId(defaultId), [defaultId]);
|
|
68
68
|
|
|
69
69
|
const formAction = React.useMemo(() => {
|
|
70
70
|
if (!isSameResource && !props?.action) {
|
|
@@ -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,
|