From a3dc6d67e0674e07d82c22edfa4e4d392aa13534 Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Thu, 6 Jul 2023 16:50:10 +0800 Subject: [PATCH] fix: optional fields of the child collection cannot be displayed correctly in the parent collection (#2194) --- .../src/collection-manager/CollectionFieldProvider.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/core/client/src/collection-manager/CollectionFieldProvider.tsx b/packages/core/client/src/collection-manager/CollectionFieldProvider.tsx index aec1f6496..b0275af3a 100644 --- a/packages/core/client/src/collection-manager/CollectionFieldProvider.tsx +++ b/packages/core/client/src/collection-manager/CollectionFieldProvider.tsx @@ -1,5 +1,6 @@ import { SchemaKey, useFieldSchema } from '@formily/react'; import React from 'react'; +import { useRecord } from '../record-provider'; import { CollectionFieldContext } from './context'; import { useCollection, useCollectionManager } from './hooks'; import { CollectionFieldOptions } from './types'; @@ -12,8 +13,11 @@ export const CollectionFieldProvider: React.FC<{ const { name, field, children, fallback = null } = props; const fieldSchema = useFieldSchema(); const { getField } = useCollection(); + const { __collection } = useRecord(); const { getCollectionJoinField } = useCollectionManager(); - const value = field || getField(field?.name || name) || getCollectionJoinField(fieldSchema?.['x-collection-field']); + const value = __collection + ? getCollectionJoinField(`${__collection}.${name}`) + : field || getField(field?.name || name) || getCollectionJoinField(fieldSchema?.['x-collection-field']); if (!value) { return fallback; }