diff --git a/packages/core/client/src/schema-initializer/items/RecordFormBlockInitializer.tsx b/packages/core/client/src/schema-initializer/items/RecordFormBlockInitializer.tsx index e4933f9d03..ec58f4795c 100644 --- a/packages/core/client/src/schema-initializer/items/RecordFormBlockInitializer.tsx +++ b/packages/core/client/src/schema-initializer/items/RecordFormBlockInitializer.tsx @@ -9,7 +9,8 @@ import { createFormBlockSchema, useRecordCollectionDataSourceItems } from '../ut export const RecordFormBlockInitializer = (props) => { const { onCreateBlockSchema, componentType, createBlockSchema, insert, targetCollection, ...others } = props; const { getTemplateSchemaByMode } = useSchemaTemplateManager(); - const collection = targetCollection || useCollection(); + const currentCollection = useCollection(); + const collection = targetCollection || currentCollection; const association = useBlockAssociationContext(); return ( { ); } }} - items={useRecordCollectionDataSourceItems('FormItem')} + items={useRecordCollectionDataSourceItems('FormItem', null, collection?.name)} /> ); }; diff --git a/packages/core/client/src/schema-initializer/items/RecordReadPrettyFormBlockInitializer.tsx b/packages/core/client/src/schema-initializer/items/RecordReadPrettyFormBlockInitializer.tsx index 5643ea0277..761a597591 100644 --- a/packages/core/client/src/schema-initializer/items/RecordReadPrettyFormBlockInitializer.tsx +++ b/packages/core/client/src/schema-initializer/items/RecordReadPrettyFormBlockInitializer.tsx @@ -17,7 +17,8 @@ export const RecordReadPrettyFormBlockInitializer = (props) => { ...others } = props; const { getTemplateSchemaByMode } = useSchemaTemplateManager(); - const collection = targetCollection || useCollection(); + const currentCollection = useCollection(); + const collection = targetCollection || currentCollection; const association = useBlockAssociationContext(); const { block } = useBlockRequestContext(); const actionInitializers = @@ -61,7 +62,7 @@ export const RecordReadPrettyFormBlockInitializer = (props) => { ); } }} - items={useRecordCollectionDataSourceItems('ReadPrettyFormItem')} + items={useRecordCollectionDataSourceItems('ReadPrettyFormItem', null, collection?.name)} /> ); }; diff --git a/packages/core/client/src/schema-templates/SchemaTemplateManagerProvider.tsx b/packages/core/client/src/schema-templates/SchemaTemplateManagerProvider.tsx index c89380445d..cf09dc19cf 100644 --- a/packages/core/client/src/schema-templates/SchemaTemplateManagerProvider.tsx +++ b/packages/core/client/src/schema-templates/SchemaTemplateManagerProvider.tsx @@ -5,6 +5,7 @@ import { cloneDeep } from 'lodash'; import React, { createContext, ReactNode, useContext, useMemo } from 'react'; import { useAPIClient, useRequest } from '../api-client'; import { Plugin } from '../application/Plugin'; +import { useCollectionManager } from '../collection-manager'; import { BlockTemplate } from './BlockTemplate'; export const SchemaTemplateManagerContext = createContext({}); @@ -35,6 +36,7 @@ export const useSchemaTemplate = () => { }; export const useSchemaTemplateManager = () => { + const { getInheritCollections } = useCollectionManager(); const { refresh, templates = [] } = useContext(SchemaTemplateManagerContext); const api = useAPIClient(); return { @@ -100,7 +102,9 @@ export const useSchemaTemplateManager = () => { return templates?.find((template) => template.key === key); }, getTemplatesByCollection(collectionName: string, resourceName: string = null) { - const items = templates?.filter?.((template) => template.collectionName === collectionName); + const parentCollections = getInheritCollections(collectionName); + const totalCollections = parentCollections.concat([collectionName]); + const items = templates?.filter?.((template) => totalCollections.includes(template.collectionName)); return items || []; }, getTemplatesByComponentName(componentName: string): Array {