diff --git a/packages/core/client/src/collection-manager/Configuration/CollectionFields.tsx b/packages/core/client/src/collection-manager/Configuration/CollectionFields.tsx index 45516e1b9..30d035486 100644 --- a/packages/core/client/src/collection-manager/Configuration/CollectionFields.tsx +++ b/packages/core/client/src/collection-manager/Configuration/CollectionFields.tsx @@ -53,12 +53,6 @@ const tableContainer = css` const titlePrompt = 'Default title for each record'; -// 是否可以作为标题字段 -export const isTitleField = (field) => { - const { getInterface } = useCollectionManager(); - return !field.isForeignKey && getInterface(field.interface)?.titleUsable; -}; - const CurrentFields = (props) => { const compile = useCompile(); const { getInterface } = useCollectionManager(); @@ -67,7 +61,7 @@ const CurrentFields = (props) => { const { resource, targetKey } = props.collectionResource || {}; const { [targetKey]: filterByTk, titleField } = useRecord(); const [loadingRecord, setLoadingRecord] = React.useState(null); - const { refreshCM } = useCollectionManager(); + const { refreshCM, isTitleField } = useCollectionManager(); const columns: TableColumnProps[] = [ { @@ -173,7 +167,7 @@ const InheritFields = (props) => { const { [targetKey]: filterByTk, titleField, name } = useRecord(); const [loadingRecord, setLoadingRecord] = React.useState(null); const { t } = useTranslation(); - const { refreshCM } = useCollectionManager(); + const { refreshCM, isTitleField } = useCollectionManager(); const columns: TableColumnProps[] = [ { diff --git a/packages/core/client/src/collection-manager/hooks/useCollectionManager.ts b/packages/core/client/src/collection-manager/hooks/useCollectionManager.ts index 1397f4319..7015663ba 100644 --- a/packages/core/client/src/collection-manager/hooks/useCollectionManager.ts +++ b/packages/core/client/src/collection-manager/hooks/useCollectionManager.ts @@ -264,6 +264,15 @@ export const useCollectionManager = () => { return getInheritChain(collectionName); }; + const getInterface = (name: string) => { + return interfaces[name] ? clone(interfaces[name]) : null; + }; + + // 是否可以作为标题字段 + const isTitleField = (field) => { + return !field.isForeignKey && getInterface(field.interface)?.titleUsable; + }; + return { service, interfaces, @@ -302,9 +311,7 @@ export const useCollectionManager = () => { } return collectionField; }, - getInterface(name: string) { - return interfaces[name] ? clone(interfaces[name]) : null; - }, + getInterface, getTemplate(name = 'general') { return templates[name] ? clone(templates[name] || templates['general']) : null; }, @@ -328,5 +335,6 @@ export const useCollectionManager = () => { }, getAllCollectionsInheritChain, getInheritCollectionsChain, + isTitleField, }; }; diff --git a/packages/core/client/src/schema-component/antd/association-select/AssociationSelect.tsx b/packages/core/client/src/schema-component/antd/association-select/AssociationSelect.tsx index c0a08c30a..85c7fa458 100644 --- a/packages/core/client/src/schema-component/antd/association-select/AssociationSelect.tsx +++ b/packages/core/client/src/schema-component/antd/association-select/AssociationSelect.tsx @@ -13,7 +13,6 @@ import { useCollectionManager, useSortFields, } from '../../../collection-manager'; -import { isTitleField } from '../../../collection-manager/Configuration/CollectionFields'; import { GeneralSchemaItems } from '../../../schema-items'; import { GeneralSchemaDesigner, SchemaSettings, isPatternDisabled, isShowDefaultValue } from '../../../schema-settings'; import { useIsShowMultipleSwitch } from '../../../schema-settings/hooks/useIsShowMultipleSwitch'; @@ -95,7 +94,8 @@ interface AssociationSelectInterface { export const AssociationSelect = InternalAssociationSelect as unknown as AssociationSelectInterface; AssociationSelect.Designer = function Designer() { - const { getCollectionFields, getInterface, getCollectionJoinField, getCollection } = useCollectionManager(); + const { getCollectionFields, getInterface, getCollectionJoinField, getCollection, isTitleField } = + useCollectionManager(); const { getField } = useCollection(); const { form } = useFormBlockContext(); const field = useField(); diff --git a/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx b/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx index 2230cfb4d..75fac30cb 100644 --- a/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx +++ b/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx @@ -17,7 +17,6 @@ import { useCollectionFilterOptions, useCollectionManager, } from '../../../collection-manager'; -import { isTitleField } from '../../../collection-manager/Configuration/CollectionFields'; import { GeneralSchemaItems } from '../../../schema-items/GeneralSchemaItems'; import { GeneralSchemaDesigner, SchemaSettings, isPatternDisabled, isShowDefaultValue } from '../../../schema-settings'; import { useIsShowMultipleSwitch } from '../../../schema-settings/hooks/useIsShowMultipleSwitch'; @@ -159,7 +158,8 @@ export const FormItem: any = observer( FormItem.Designer = function Designer() { let targetField; - const { getCollectionFields, getInterface, getCollectionJoinField, getCollection } = useCollectionManager(); + const { getCollectionFields, getInterface, getCollectionJoinField, getCollection, isTitleField } = + useCollectionManager(); const { getField } = useCollection(); const { form } = useFormBlockContext(); const ctx = useBlockRequestContext(); diff --git a/packages/core/client/src/schema-settings/DataTemplates/components/Designer.tsx b/packages/core/client/src/schema-settings/DataTemplates/components/Designer.tsx index d1a60c3f8..45c68cb4b 100644 --- a/packages/core/client/src/schema-settings/DataTemplates/components/Designer.tsx +++ b/packages/core/client/src/schema-settings/DataTemplates/components/Designer.tsx @@ -8,14 +8,13 @@ import { useTranslation } from 'react-i18next'; import { GeneralSchemaDesigner, SchemaSettings } from '../..'; import { mergeFilter } from '../../../block-provider'; import { useCollectionFilterOptions, useCollectionManager } from '../../../collection-manager'; -import { isTitleField } from '../../../collection-manager/Configuration/CollectionFields'; import { removeNullCondition, useCompile, useDesignable } from '../../../schema-component'; import { ITemplate } from '../../../schema-component/antd/form-v2/Templates'; import { FilterDynamicComponent } from '../../../schema-component/antd/table-v2/FilterDynamicComponent'; export const Designer = observer( () => { - const { getCollectionFields, getCollectionField, getCollection } = useCollectionManager(); + const { getCollectionFields, getCollectionField, getCollection, isTitleField } = useCollectionManager(); const field = useField(); const fieldSchema = useFieldSchema(); const { t } = useTranslation();