refactor(schema-template): Inherit collection using blockTemplate (#2418)
* refactor: blockTemplate * refactor: code imrove
This commit is contained in:
parent
5edcaaea4b
commit
9881d69def
@ -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 (
|
||||
<SchemaInitializer.Item
|
||||
@ -48,7 +49,7 @@ export const RecordFormBlockInitializer = (props) => {
|
||||
);
|
||||
}
|
||||
}}
|
||||
items={useRecordCollectionDataSourceItems('FormItem')}
|
||||
items={useRecordCollectionDataSourceItems('FormItem', null, collection?.name)}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
@ -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)}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
@ -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<any>({});
|
||||
@ -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<any> {
|
||||
|
Loading…
Reference in New Issue
Block a user