diff --git a/packages/core/client/src/acl/ACLProvider.tsx b/packages/core/client/src/acl/ACLProvider.tsx index 093ae75e71..61a00f7e2b 100644 --- a/packages/core/client/src/acl/ACLProvider.tsx +++ b/packages/core/client/src/acl/ACLProvider.tsx @@ -14,11 +14,15 @@ import React, { createContext, useCallback, useContext, useEffect, useMemo } fro import { Navigate } from 'react-router-dom'; import { useAPIClient, useRequest } from '../api-client'; import { useAppSpin } from '../application/hooks/useAppSpin'; -import { useBlockRequestContext } from '../block-provider/BlockProvider'; import { useResourceActionContext } from '../collection-manager/ResourceActionProvider'; -import { CollectionNotAllowViewPlaceholder, useCollection, useCollectionManager } from '../data-source'; +import { + CollectionNotAllowViewPlaceholder, + useCollection, + useCollectionManager, + useCollectionRecordData, + useDataBlockProps, +} from '../data-source'; import { useDataSourceKey } from '../data-source/data-source/DataSourceProvider'; -import { useRecord } from '../record-provider'; import { SchemaComponentOptions, useDesignable } from '../schema-component'; import { useApp } from '../application'; @@ -177,12 +181,12 @@ const useAllowedActions = () => { const useResourceName = () => { const service = useResourceActionContext(); - const result = useBlockRequestContext() || { service }; + const dataBlockProps = useDataBlockProps(); return ( - result?.props?.resource || - result?.props?.association || - result?.props?.collection || - result?.service?.defaultRequest?.resource + dataBlockProps?.resource || + dataBlockProps?.association || + dataBlockProps?.collection || + service?.defaultRequest?.resource ); }; @@ -282,14 +286,14 @@ export const useACLActionParamsContext = () => { export const useRecordPkValue = () => { const collection = useCollection(); - const record = useRecord(); + const recordData = useCollectionRecordData(); if (!collection) { return; } const primaryKey = collection.getPrimaryKey(); - return record?.[primaryKey]; + return recordData?.[primaryKey]; }; export const ACLActionProvider = (props) => { diff --git a/packages/core/client/src/collection-manager/ResourceActionProvider.tsx b/packages/core/client/src/collection-manager/ResourceActionProvider.tsx index 77cee09cb5..bb2d0a22c8 100644 --- a/packages/core/client/src/collection-manager/ResourceActionProvider.tsx +++ b/packages/core/client/src/collection-manager/ResourceActionProvider.tsx @@ -9,7 +9,7 @@ import { useField } from '@formily/react'; import { Result } from 'ahooks/es/useRequest/src/types'; -import React, { createContext, useContext, useEffect } from 'react'; +import React, { createContext, useContext, useEffect, useMemo } from 'react'; import { useCollectionManager_deprecated } from '.'; import { CollectionProvider_deprecated, useRecord } from '..'; import { useAPIClient, useRequest } from '../api-client'; @@ -58,9 +58,15 @@ const CollectionResourceActionProvider = (props) => { { uid }, ); const resource = api.resource(request.resource); + const resourceActionValue = useMemo( + () => ({ ...service, defaultRequest: request, dragSort }), + [dragSort, request, service], + ); + const resourceContextValue = useMemo(() => ({ type: 'collection', resource, collection }), [collection, resource]); + return ( - - + + {props.children} @@ -88,9 +94,18 @@ const AssociationResourceActionProvider = (props) => { { uid }, ); const resource = api.resource(request.resource, resourceOf); + const resourceContextValue = useMemo( + () => ({ type: 'association', resource, association, collection }), + [association, collection, resource], + ); + const resourceActionContextValue = useMemo( + () => ({ ...service, defaultRequest: request, dragSort }), + [dragSort, request, service], + ); + return ( - - + + {props.children}