diff --git a/packages/core/client/src/collection-manager/Configuration/CollectionFields.tsx b/packages/core/client/src/collection-manager/Configuration/CollectionFields.tsx index edd2252b9..4711f9132 100644 --- a/packages/core/client/src/collection-manager/Configuration/CollectionFields.tsx +++ b/packages/core/client/src/collection-manager/Configuration/CollectionFields.tsx @@ -361,9 +361,9 @@ export const CollectionFields = (props) => { const collection = getCollection(key); return { key, - title: `${t('Inherited fields')} - ` + compile(collection.title), + title: `${t('Inherited fields')} - ` + compile(collection?.title), inherit: true, - fields: collection.fields, + fields: collection?.fields || [], }; }), ); diff --git a/packages/core/client/src/schema-initializer/utils.ts b/packages/core/client/src/schema-initializer/utils.ts index 945e5c265..46a3ec372 100644 --- a/packages/core/client/src/schema-initializer/utils.ts +++ b/packages/core/client/src/schema-initializer/utils.ts @@ -448,18 +448,18 @@ export const useFilterAssociatedFormItemInitializerFields = () => { }; export const useInheritsFormItemInitializerFields = (options?) => { - const { name, template } = useCollection(); + const { name } = useCollection(); const { getInterface, getInheritCollections, getCollection, getParentCollectionFields } = useCollectionManager(); const inherits = getInheritCollections(name); const { snapshot } = useActionContext(); + const form = useForm(); return inherits?.map((v) => { const fields = getParentCollectionFields(v, name); - const form = useForm(); const { readPretty = form.readPretty, block = 'Form' } = options || {}; const targetCollection = getCollection(v); return { - [targetCollection.title]: fields + [targetCollection?.title]: fields ?.filter((field) => field?.interface && !field?.isForeignKey) ?.map((field) => { const interfaceConfig = getInterface(field.interface); diff --git a/packages/core/client/src/schema-settings/DataTemplates/FormDataTemplates.tsx b/packages/core/client/src/schema-settings/DataTemplates/FormDataTemplates.tsx index 5b449d084..1065922db 100644 --- a/packages/core/client/src/schema-settings/DataTemplates/FormDataTemplates.tsx +++ b/packages/core/client/src/schema-settings/DataTemplates/FormDataTemplates.tsx @@ -87,12 +87,13 @@ export const FormDataTemplates = observer((props: any) => { targetField: field, mapOptions(option) { try { - const label = collection?.titleField || 'id'; + const label = getLabel(collection); option[label] = ( <> #{option.id} {option[label]} ); + return option; } catch (error) { console.error(error); @@ -100,7 +101,7 @@ export const FormDataTemplates = observer((props: any) => { } }, fieldNames: { - label: collection?.titleField || 'id', + label: getLabel(collection), value: 'id', }, }, @@ -190,3 +191,7 @@ export const FormDataTemplates = observer((props: any) => { /> ); }); + +function getLabel(collection: any) { + return !collection?.titleField || collection.titleField === 'id' ? 'label' : collection?.titleField; +} diff --git a/packages/core/client/src/schema-settings/DataTemplates/hooks/useCollectionState.ts b/packages/core/client/src/schema-settings/DataTemplates/hooks/useCollectionState.ts index fa4688b8a..6c4be3307 100644 --- a/packages/core/client/src/schema-settings/DataTemplates/hooks/useCollectionState.ts +++ b/packages/core/client/src/schema-settings/DataTemplates/hooks/useCollectionState.ts @@ -11,7 +11,7 @@ export const useCollectionState = (currentCollectionName: string) => { function getCollectionList() { const collections = getAllCollectionsInheritChain(currentCollectionName); - return collections.map((name) => ({ label: getCollection(name).title, value: name })); + return collections.map((name) => ({ label: getCollection(name)?.title, value: name })); } const getEnableFieldTree = (collectionName: string) => {