@refinedev/core 4.26.2 → 4.26.4

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/core",
3
- "version": "4.26.2",
3
+ "version": "4.26.4",
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",
@@ -1,10 +1,39 @@
1
- import { useContext } from "react";
1
+ import React from "react";
2
2
 
3
3
  import { AccessControlContext } from "@contexts/accessControl";
4
+ import { sanitizeResource } from "@definitions/helpers/sanitize-resource";
4
5
  import { IAccessControlContext } from "../../interfaces";
5
6
 
6
7
  export const useCanWithoutCache = (): IAccessControlContext => {
7
- const { can } = useContext(AccessControlContext);
8
+ const { can: canFromContext } = React.useContext(AccessControlContext);
9
+
10
+ const can = React.useMemo(() => {
11
+ if (!canFromContext) {
12
+ return undefined;
13
+ }
14
+
15
+ const canWithSanitizedResource: NonNullable<
16
+ typeof canFromContext
17
+ > = async ({ params, ...rest }) => {
18
+ const sanitizedResource = params?.resource
19
+ ? sanitizeResource(params.resource)
20
+ : undefined;
21
+
22
+ return canFromContext({
23
+ ...rest,
24
+ ...(params
25
+ ? {
26
+ params: {
27
+ ...params,
28
+ resource: sanitizedResource,
29
+ },
30
+ }
31
+ : {}),
32
+ });
33
+ };
34
+
35
+ return canWithSanitizedResource;
36
+ }, [canFromContext]);
8
37
 
9
38
  return { can };
10
39
  };
@@ -257,7 +257,7 @@ export const useDelete = <
257
257
  const previousQueries: PreviousQuery<TData>[] =
258
258
  queryClient.getQueriesData(queryKey.resourceAll);
259
259
 
260
- if (!(mutationModePropOrContext === "pessimistic")) {
260
+ if (mutationModePropOrContext !== "pessimistic") {
261
261
  // Set the previous queries to the new ones:
262
262
  queryClient.setQueriesData(
263
263
  queryKey.list(),
@@ -263,7 +263,7 @@ export const useDeleteMany = <
263
263
  const previousQueries: PreviousQuery<TData>[] =
264
264
  queryClient.getQueriesData(queryKey.resourceAll);
265
265
 
266
- if (!(mutationModePropOrContext === "pessimistic")) {
266
+ if (mutationModePropOrContext !== "pessimistic") {
267
267
  // Set the previous queries to the new ones:
268
268
  queryClient.setQueriesData(
269
269
  queryKey.list(),
@@ -59,7 +59,7 @@ export type UpdateParams<TData, TError, TVariables> = {
59
59
  */
60
60
  mutationMode?: MutationMode;
61
61
  /**
62
- * Duration to wait before executing the mutation when `mutationMode = "undoable"`
62
+ * Duration in ms to wait before executing the mutation when `mutationMode = "undoable"`
63
63
  */
64
64
  undoableTimeout?: number;
65
65
  /**
@@ -288,7 +288,7 @@ export const useUpdate = <
288
288
  },
289
289
  );
290
290
 
291
- if (!(mutationModePropOrContext === "pessimistic")) {
291
+ if (mutationModePropOrContext !== "pessimistic") {
292
292
  // Set the previous queries to the new ones:
293
293
  queryClient.setQueriesData(
294
294
  queryKey.list(),
@@ -271,7 +271,7 @@ export const useUpdateMany = <
271
271
  QueryResponse<TData>
272
272
  >(queryKey.resourceAll);
273
273
 
274
- if (!(mutationModePropOrContext === "pessimistic")) {
274
+ if (mutationModePropOrContext !== "pessimistic") {
275
275
  // Set the previous queries to the new ones:
276
276
  queryClient.setQueriesData(
277
277
  queryKey.list(),