fix: deep level association field adding error (#2700)

This commit is contained in:
katherinehhh 2023-09-22 10:34:35 +08:00 committed by GitHub
parent 60aeba4a12
commit b0069ca64a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);
}
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<any> = (props) => {
};
export const BlockProvider = (props) => {
console.log(props);
const { collection, association } = props;
const resource = useResource(props);
const params = { ...props.params };