From b0069ca64afb9ff00ceca2ef5e8cbdae0b25f6cf Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Fri, 22 Sep 2023 10:34:35 +0800 Subject: [PATCH] fix: deep level association field adding error (#2700) --- .../core/client/src/block-provider/BlockProvider.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/core/client/src/block-provider/BlockProvider.tsx b/packages/core/client/src/block-provider/BlockProvider.tsx index 2ee77cb3e..accdc3e0c 100644 --- a/packages/core/client/src/block-provider/BlockProvider.tsx +++ b/packages/core/client/src/block-provider/BlockProvider.tsx @@ -34,6 +34,7 @@ interface UseResourceProps { resource: any; association?: any; useSourceId?: any; + collection?: any; block?: any; } @@ -48,7 +49,7 @@ export const useAssociation = (props) => { }; const useResource = (props: UseResourceProps) => { - const { block, resource, useSourceId } = props; + const { block, collection, resource, useSourceId } = props; const record = useRecord(); const api = useAPIClient(); const { fieldSchema } = useActionContext(); @@ -83,8 +84,10 @@ const useResource = (props: UseResourceProps) => { if (sourceId) { return api.resource(resource, sourceId); } - - return api.resource(resource, record[association?.sourceKey || 'id']); + if (record[association?.sourceKey || 'id']) { + return api.resource(resource, record[association?.sourceKey || 'id']); + } + return api.resource(collection); }; const useActionParams = (props) => { @@ -271,6 +274,7 @@ export const RenderChildrenWithAssociationFilter: React.FC = (props) => { }; export const BlockProvider = (props) => { + console.log(props); const { collection, association } = props; const resource = useResource(props); const params = { ...props.params };