diff --git a/packages/core/client/src/data-source/collection/Collection.ts b/packages/core/client/src/data-source/collection/Collection.ts index 8792430c69..a3f9263224 100644 --- a/packages/core/client/src/data-source/collection/Collection.ts +++ b/packages/core/client/src/data-source/collection/Collection.ts @@ -297,4 +297,12 @@ export class Collection { isTitleField(field: CollectionFieldOptions) { return this.app.dataSourceManager.collectionFieldInterfaceManager.getFieldInterface(field.interface)?.titleUsable; } + + /** + * is inherited from other collection + * @returns boolean + */ + isInherited() { + return this.inherits.length > 0; + } } diff --git a/packages/core/client/src/modules/blocks/BlockSchemaToolbar.tsx b/packages/core/client/src/modules/blocks/BlockSchemaToolbar.tsx index 216f52872e..30dfacee5a 100644 --- a/packages/core/client/src/modules/blocks/BlockSchemaToolbar.tsx +++ b/packages/core/client/src/modules/blocks/BlockSchemaToolbar.tsx @@ -20,7 +20,7 @@ export const BlockSchemaToolbar = (props) => { const cm = useCollectionManager(); let { name: currentCollectionName, title: currentCollectionTitle } = useCollection() || {}; const template = useSchemaTemplate(); - const { association } = useDataBlockProps() || {}; + const { association, collection } = useDataBlockProps() || {}; const compile = useCompile(); if (association) { @@ -31,7 +31,10 @@ export const BlockSchemaToolbar = (props) => { } const associationField = cm.getCollectionField(association); - const associationCollection = cm.getCollection(associationField?.target); + // If both the collection and association parameters exist at the same time, + // it means that the collection of the current block is a child collection of inheritance, + // and the title of the child collection needs to be displayed at this time + const associationCollection = cm.getCollection(collection || associationField?.target); const templateName = ['FormItem', 'ReadPrettyFormItem'].includes(template?.componentName) ? `${template?.name} ${t('(Fields only)')}` : template?.name; diff --git a/packages/core/client/src/modules/blocks/data-blocks/details-single/RecordReadPrettyFormBlockInitializer.tsx b/packages/core/client/src/modules/blocks/data-blocks/details-single/RecordReadPrettyFormBlockInitializer.tsx index e39ca6444d..fc35bfbd83 100644 --- a/packages/core/client/src/modules/blocks/data-blocks/details-single/RecordReadPrettyFormBlockInitializer.tsx +++ b/packages/core/client/src/modules/blocks/data-blocks/details-single/RecordReadPrettyFormBlockInitializer.tsx @@ -11,10 +11,10 @@ import { FormOutlined } from '@ant-design/icons'; import React, { useCallback } from 'react'; import { SchemaInitializerItem, useSchemaInitializer, useSchemaInitializerItem } from '../../../../application'; import { useCollection_deprecated } from '../../../../collection-manager'; +import { useAssociationName, useCollectionManager } from '../../../../data-source'; import { useRecordCollectionDataSourceItems } from '../../../../schema-initializer/utils'; import { useSchemaTemplateManager } from '../../../../schema-templates'; import { createDetailsUISchema } from './createDetailsUISchema'; -import { useAssociationName } from '../../../../data-source'; export const RecordReadPrettyFormBlockInitializer = () => { const itemConfig = useSchemaInitializerItem(); @@ -37,21 +37,26 @@ export function useCreateSingleDetailsSchema() { const { insert } = useSchemaInitializer(); const { getTemplateSchemaByMode } = useSchemaTemplateManager(); const association = useAssociationName(); + const cm = useCollectionManager(); const templateWrap = useCallback( (templateSchema, options) => { const { item } = options; if (item.template.componentName === 'ReadPrettyFormItem') { + const collectionName = item.collectionName || item.name; + const collection = cm.getCollection(collectionName); const blockSchema = createDetailsUISchema( association ? { association, + // see: https://applink.feishu.cn/client/message/link/open?token=AmP9n9dkwcABZrr3nBdAwAI%3D + collectionName: collection.isInherited() ? collectionName : undefined, dataSource: item.dataSource, templateSchema: templateSchema, isCurrent: true, } : { - collectionName: item.collectionName || item.name, + collectionName, dataSource: item.dataSource, templateSchema: templateSchema, }, @@ -64,7 +69,7 @@ export function useCreateSingleDetailsSchema() { return templateSchema; } }, - [association], + [association, cm], ); const createSingleDetailsSchema = useCallback( @@ -73,23 +78,27 @@ export function useCreateSingleDetailsSchema() { const template = await getTemplateSchemaByMode(item); insert(templateWrap(template, { item })); } else { + const collectionName = item.collectionName || item.name; + const collection = cm.getCollection(collectionName); insert( createDetailsUISchema( association ? { association, + // see: https://applink.feishu.cn/client/message/link/open?token=AmP9n9dkwcABZrr3nBdAwAI%3D + collectionName: collection.isInherited() ? collectionName : undefined, dataSource: item.dataSource, isCurrent: true, } : { - collectionName: item.collectionName || item.name, + collectionName, dataSource: item.dataSource, }, ), ); } }, - [association, getTemplateSchemaByMode, insert, templateWrap], + [association, cm, getTemplateSchemaByMode, insert, templateWrap], ); return { createSingleDetailsSchema, templateWrap }; diff --git a/packages/core/client/src/modules/blocks/data-blocks/form/RecordFormBlockInitializer.tsx b/packages/core/client/src/modules/blocks/data-blocks/form/RecordFormBlockInitializer.tsx index e4397d4152..b9fc36213f 100644 --- a/packages/core/client/src/modules/blocks/data-blocks/form/RecordFormBlockInitializer.tsx +++ b/packages/core/client/src/modules/blocks/data-blocks/form/RecordFormBlockInitializer.tsx @@ -10,8 +10,8 @@ import { FormOutlined } from '@ant-design/icons'; import React, { useCallback } from 'react'; import { SchemaInitializerItem, useSchemaInitializer, useSchemaInitializerItem } from '../../../../application'; -import { useAssociationName } from '../../../../data-source'; import { useCollection_deprecated } from '../../../../collection-manager'; +import { useAssociationName, useCollectionManager } from '../../../../data-source'; import { useRecordCollectionDataSourceItems } from '../../../../schema-initializer/utils'; import { useSchemaTemplateManager } from '../../../../schema-templates'; import { createEditFormBlockUISchema } from './createEditFormBlockUISchema'; @@ -49,40 +49,47 @@ export const RecordFormBlockInitializer = () => { export function useCreateEditFormBlock() { const { insert } = useSchemaInitializer(); const association = useAssociationName(); + const cm = useCollectionManager(); const createEditFormBlock = useCallback( ({ item }) => { + const collectionName = item.collectionName || item.name; + const collection = cm.getCollection(collectionName); insert( createEditFormBlockUISchema( association ? { association, + collectionName: collection.isInherited() ? collectionName : undefined, dataSource: item.dataSource, isCurrent: true, } : { - collectionName: item.collectionName || item.name, + collectionName, dataSource: item.dataSource, }, ), ); }, - [association, insert], + [association, cm, insert], ); const templateWrap = useCallback( (templateSchema, { item }) => { if (item.template.componentName === 'FormItem') { + const collectionName = item.collectionName || item.name; + const collection = cm.getCollection(collectionName); const blockSchema = createEditFormBlockUISchema( association ? { association, + collectionName: collection.isInherited() ? collectionName : undefined, dataSource: item.dataSource, templateSchema: templateSchema, isCurrent: true, } : { - collectionName: item.collectionName || item.name, + collectionName, dataSource: item.dataSource, templateSchema: templateSchema, }, @@ -95,7 +102,7 @@ export function useCreateEditFormBlock() { return templateSchema; } }, - [association], + [association, cm], ); return { createEditFormBlock, templateWrap }; diff --git a/packages/core/client/src/schema-initializer/buttons/RecordBlockInitializers.tsx b/packages/core/client/src/schema-initializer/buttons/RecordBlockInitializers.tsx index d62ed90f0f..2c7eca06c6 100644 --- a/packages/core/client/src/schema-initializer/buttons/RecordBlockInitializers.tsx +++ b/packages/core/client/src/schema-initializer/buttons/RecordBlockInitializers.tsx @@ -13,7 +13,6 @@ import { useActionAvailable, useCollection, useCollectionManager_deprecated, - useCollection_deprecated, useCreateAssociationDetailsBlock, useCreateAssociationDetailsWithoutPagination, useCreateAssociationFormBlock, @@ -46,7 +45,7 @@ export const canMakeAssociationBlock = (field) => { }; function useRecordBlocks() { - const collection = useCollection_deprecated(); + const collection = useCollection(); const { getChildrenCollections } = useCollectionManager_deprecated(); const collectionsWithView = getChildrenCollections(collection.name, true, collection.dataSource).filter( (v) => v?.filterTargetKey, @@ -60,7 +59,7 @@ function useRecordBlocks() { collectionName: collection.name, dataSource: collection.dataSource, useComponentProps() { - const currentCollection = useCollection_deprecated(); + const currentCollection = useCollection(); const { createSingleDetailsSchema, templateWrap } = useCreateSingleDetailsSchema(); const { createAssociationDetailsBlock } = useCreateAssociationDetailsBlock(); const { @@ -126,7 +125,7 @@ function useRecordBlocks() { collectionName: collection.name, dataSource: collection.dataSource, useComponentProps() { - const currentCollection = useCollection_deprecated(); + const currentCollection = useCollection(); const { createEditFormBlock, templateWrap: templateWrapEdit } = useCreateEditFormBlock(); const collectionsNeedToDisplay = [currentCollection, ...collectionsWithView]; diff --git a/packages/core/client/src/schema-initializer/items/RecordAssociationDetailsBlockInitializer.tsx b/packages/core/client/src/schema-initializer/items/RecordAssociationDetailsBlockInitializer.tsx index 99a4b8f0fc..64351b0a16 100644 --- a/packages/core/client/src/schema-initializer/items/RecordAssociationDetailsBlockInitializer.tsx +++ b/packages/core/client/src/schema-initializer/items/RecordAssociationDetailsBlockInitializer.tsx @@ -12,9 +12,9 @@ import React, { useCallback } from 'react'; import { SchemaInitializerItem, useSchemaInitializer, useSchemaInitializerItem } from '../../application'; import { useCollectionManager_deprecated } from '../../collection-manager'; +import { createDetailsWithPaginationUISchema } from '../../modules/blocks/data-blocks/details-multi/createDetailsWithPaginationUISchema'; import { useSchemaTemplateManager } from '../../schema-templates'; import { useRecordCollectionDataSourceItems } from '../utils'; -import { createDetailsWithPaginationUISchema } from '../../modules/blocks/data-blocks/details-multi/createDetailsWithPaginationUISchema'; export const RecordAssociationDetailsBlockInitializer = () => { const itemConfig = useSchemaInitializerItem();