@refinedev/antd 5.21.0 → 5.23.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@refinedev/antd",
3
- "version": "5.21.0",
3
+ "version": "5.23.0",
4
4
  "description": "refine is a React-based framework for building internal tools, rapidly. It ships with Ant Design System, an enterprise-level UI toolkit.",
5
5
  "private": false,
6
6
  "main": "dist/index.js",
@@ -23,9 +23,9 @@
23
23
  "react-dom": "^17.0.0 || ^18.0.0"
24
24
  },
25
25
  "devDependencies": {
26
- "@refinedev/cli": "^2.5.3",
27
- "@refinedev/ui-tests": "^1.5.0",
28
- "@refinedev/core": "^4.17.0",
26
+ "@refinedev/cli": "^2.6.0",
27
+ "@refinedev/ui-tests": "^1.6.0",
28
+ "@refinedev/core": "^4.21.0",
29
29
  "@esbuild-plugins/node-resolve": "^0.1.4",
30
30
  "@testing-library/jest-dom": "^5.16.4",
31
31
  "@testing-library/react": "^13.1.1",
@@ -41,9 +41,9 @@
41
41
  "jest": "^29.3.1",
42
42
  "jest-environment-jsdom": "^29.3.1",
43
43
  "postcss": "^8.1.4",
44
- "react-router-dom": "^6.8.1",
44
+ "react-router-dom": "6.11.2",
45
45
  "ts-jest": "^29.0.3",
46
- "tsup": "^5.11.13",
46
+ "tsup": "^6.7.0",
47
47
  "typescript": "^4.7.4"
48
48
  },
49
49
  "dependencies": {
@@ -1,4 +1,4 @@
1
- import React from "react";
1
+ import React, { useContext } from "react";
2
2
  import { Button } from "antd";
3
3
  import { PlusSquareOutlined } from "@ant-design/icons";
4
4
  import {
@@ -9,6 +9,7 @@ import {
9
9
  useRouterContext,
10
10
  useRouterType,
11
11
  useLink,
12
+ AccessControlContext,
12
13
  } from "@refinedev/core";
13
14
  import {
14
15
  RefineButtonTestIds,
@@ -35,8 +36,16 @@ export const CloneButton: React.FC<CloneButtonProps> = ({
35
36
  onClick,
36
37
  ...rest
37
38
  }) => {
38
- const accessControlEnabled = accessControl?.enabled ?? true;
39
- const hideIfUnauthorized = accessControl?.hideIfUnauthorized ?? false;
39
+ const accessControlContext = useContext(AccessControlContext);
40
+
41
+ const accessControlEnabled =
42
+ accessControl?.enabled ??
43
+ accessControlContext.options.buttons.enableAccessControl;
44
+
45
+ const hideIfUnauthorized =
46
+ accessControl?.hideIfUnauthorized ??
47
+ accessControlContext.options.buttons.hideIfUnauthorized;
48
+
40
49
  const { cloneUrl: generateCloneUrl } = useNavigation();
41
50
  const routerType = useRouterType();
42
51
  const Link = useLink();
@@ -1,4 +1,4 @@
1
- import React from "react";
1
+ import React, { useContext } from "react";
2
2
  import { Button } from "antd";
3
3
  import { PlusSquareOutlined } from "@ant-design/icons";
4
4
  import {
@@ -9,6 +9,7 @@ import {
9
9
  useRouterContext,
10
10
  useRouterType,
11
11
  useLink,
12
+ AccessControlContext,
12
13
  } from "@refinedev/core";
13
14
  import {
14
15
  RefineButtonClassNames,
@@ -34,8 +35,16 @@ export const CreateButton: React.FC<CreateButtonProps> = ({
34
35
  onClick,
35
36
  ...rest
36
37
  }) => {
37
- const accessControlEnabled = accessControl?.enabled ?? true;
38
- const hideIfUnauthorized = accessControl?.hideIfUnauthorized ?? false;
38
+ const accessControlContext = useContext(AccessControlContext);
39
+
40
+ const accessControlEnabled =
41
+ accessControl?.enabled ??
42
+ accessControlContext.options.buttons.enableAccessControl;
43
+
44
+ const hideIfUnauthorized =
45
+ accessControl?.hideIfUnauthorized ??
46
+ accessControlContext.options.buttons.hideIfUnauthorized;
47
+
39
48
  const translate = useTranslate();
40
49
  const routerType = useRouterType();
41
50
  const Link = useLink();
@@ -1,4 +1,4 @@
1
- import React from "react";
1
+ import React, { useContext } from "react";
2
2
  import { Button, Popconfirm } from "antd";
3
3
  import { DeleteOutlined } from "@ant-design/icons";
4
4
  import {
@@ -9,6 +9,7 @@ import {
9
9
  useResource,
10
10
  pickNotDeprecated,
11
11
  useWarnAboutChange,
12
+ AccessControlContext,
12
13
  } from "@refinedev/core";
13
14
  import {
14
15
  RefineButtonClassNames,
@@ -43,8 +44,16 @@ export const DeleteButton: React.FC<DeleteButtonProps> = ({
43
44
  invalidates,
44
45
  ...rest
45
46
  }) => {
46
- const accessControlEnabled = accessControl?.enabled ?? true;
47
- const hideIfUnauthorized = accessControl?.hideIfUnauthorized ?? false;
47
+ const accessControlContext = useContext(AccessControlContext);
48
+
49
+ const accessControlEnabled =
50
+ accessControl?.enabled ??
51
+ accessControlContext.options.buttons.enableAccessControl;
52
+
53
+ const hideIfUnauthorized =
54
+ accessControl?.hideIfUnauthorized ??
55
+ accessControlContext.options.buttons.hideIfUnauthorized;
56
+
48
57
  const translate = useTranslate();
49
58
 
50
59
  const { id, resource } = useResource(
@@ -66,6 +75,16 @@ export const DeleteButton: React.FC<DeleteButtonProps> = ({
66
75
  },
67
76
  });
68
77
 
78
+ const disabledTitle = () => {
79
+ if (data?.can) return "";
80
+ else if (data?.reason) return data.reason;
81
+ else
82
+ return translate(
83
+ "buttons.notAccessTitle",
84
+ "You don't have permission to access",
85
+ );
86
+ };
87
+
69
88
  const { setWarnWhen } = useWarnAboutChange();
70
89
 
71
90
  if (accessControlEnabled && hideIfUnauthorized && !data?.can) {
@@ -117,6 +136,7 @@ export const DeleteButton: React.FC<DeleteButtonProps> = ({
117
136
  danger
118
137
  loading={(recordItemId ?? id) === variables?.id && isLoading}
119
138
  icon={<DeleteOutlined />}
139
+ title={disabledTitle()}
120
140
  disabled={data?.can === false}
121
141
  data-testid={RefineButtonTestIds.DeleteButton}
122
142
  className={RefineButtonClassNames.DeleteButton}
@@ -1,4 +1,4 @@
1
- import React from "react";
1
+ import React, { useContext } from "react";
2
2
  import { Button } from "antd";
3
3
  import { EditOutlined } from "@ant-design/icons";
4
4
  import {
@@ -9,6 +9,7 @@ import {
9
9
  useRouterContext,
10
10
  useRouterType,
11
11
  useLink,
12
+ AccessControlContext,
12
13
  } from "@refinedev/core";
13
14
  import {
14
15
  RefineButtonClassNames,
@@ -35,8 +36,16 @@ export const EditButton: React.FC<EditButtonProps> = ({
35
36
  onClick,
36
37
  ...rest
37
38
  }) => {
38
- const accessControlEnabled = accessControl?.enabled ?? true;
39
- const hideIfUnauthorized = accessControl?.hideIfUnauthorized ?? false;
39
+ const accessControlContext = useContext(AccessControlContext);
40
+
41
+ const accessControlEnabled =
42
+ accessControl?.enabled ??
43
+ accessControlContext.options.buttons.enableAccessControl;
44
+
45
+ const hideIfUnauthorized =
46
+ accessControl?.hideIfUnauthorized ??
47
+ accessControlContext.options.buttons.hideIfUnauthorized;
48
+
40
49
  const translate = useTranslate();
41
50
 
42
51
  const routerType = useRouterType();
@@ -1,4 +1,4 @@
1
- import React from "react";
1
+ import React, { useContext } from "react";
2
2
  import { Button } from "antd";
3
3
  import { BarsOutlined } from "@ant-design/icons";
4
4
  import {
@@ -11,6 +11,7 @@ import {
11
11
  useRouterType,
12
12
  useLink,
13
13
  pickNotDeprecated,
14
+ AccessControlContext,
14
15
  } from "@refinedev/core";
15
16
  import {
16
17
  RefineButtonClassNames,
@@ -36,8 +37,16 @@ export const ListButton: React.FC<ListButtonProps> = ({
36
37
  onClick,
37
38
  ...rest
38
39
  }) => {
39
- const accessControlEnabled = accessControl?.enabled ?? true;
40
- const hideIfUnauthorized = accessControl?.hideIfUnauthorized ?? false;
40
+ const accessControlContext = useContext(AccessControlContext);
41
+
42
+ const accessControlEnabled =
43
+ accessControl?.enabled ??
44
+ accessControlContext.options.buttons.enableAccessControl;
45
+
46
+ const hideIfUnauthorized =
47
+ accessControl?.hideIfUnauthorized ??
48
+ accessControlContext.options.buttons.hideIfUnauthorized;
49
+
41
50
  const { listUrl: generateListUrl } = useNavigation();
42
51
  const routerType = useRouterType();
43
52
  const Link = useLink();
@@ -1,4 +1,4 @@
1
- import React from "react";
1
+ import React, { useContext } from "react";
2
2
  import { Button } from "antd";
3
3
  import { EyeOutlined } from "@ant-design/icons";
4
4
  import {
@@ -9,6 +9,7 @@ import {
9
9
  useRouterContext,
10
10
  useRouterType,
11
11
  useLink,
12
+ AccessControlContext,
12
13
  } from "@refinedev/core";
13
14
  import {
14
15
  RefineButtonClassNames,
@@ -35,8 +36,16 @@ export const ShowButton: React.FC<ShowButtonProps> = ({
35
36
  onClick,
36
37
  ...rest
37
38
  }) => {
38
- const accessControlEnabled = accessControl?.enabled ?? true;
39
- const hideIfUnauthorized = accessControl?.hideIfUnauthorized ?? false;
39
+ const accessControlContext = useContext(AccessControlContext);
40
+
41
+ const accessControlEnabled =
42
+ accessControl?.enabled ??
43
+ accessControlContext.options.buttons.enableAccessControl;
44
+
45
+ const hideIfUnauthorized =
46
+ accessControl?.hideIfUnauthorized ??
47
+ accessControlContext.options.buttons.hideIfUnauthorized;
48
+
40
49
  const { showUrl: generateShowUrl } = useNavigation();
41
50
  const routerType = useRouterType();
42
51
  const Link = useLink();