From f934cb9bbe7efa5a01834ca32cdf3b46106649dd Mon Sep 17 00:00:00 2001 From: dream2023 <1098626505@qq.com> Date: Thu, 11 Jan 2024 17:19:52 +0800 Subject: [PATCH] fix: rename collectionFieldInterfaceInstance to fieldInterfaceInstance --- .../collection/collection-field-interface.md | 8 +++--- .../core/collection/collection-manager.md | 26 +++++++++--------- .../client/src/application/Application.tsx | 2 +- .../collection/CollectionManager.tsx | 27 ++++++++----------- .../src/application/collection/utils.ts | 2 +- .../CollectionManagerProvider.tsx | 4 +-- .../Configuration/interfaces.tsx | 23 ++++++++-------- .../collection-manager/collectionPlugin.ts | 8 +++--- .../hooks/useCollectionManager.ts | 4 +-- .../client/src/collection-manager/types.ts | 2 -- .../src/client/index.tsx | 2 +- .../plugin-file-manager/src/client/index.tsx | 2 +- .../plugin-formula-field/src/client/index.tsx | 2 +- .../@nocobase/plugin-map/src/client/index.tsx | 2 +- .../src/client/index.tsx | 2 +- .../src/client/index.tsx | 2 +- .../src/client/index.tsx | 2 +- .../src/client/index.ts | 2 +- 18 files changed, 57 insertions(+), 65 deletions(-) diff --git a/packages/core/client/docs/zh-CN/core/collection/collection-field-interface.md b/packages/core/client/docs/zh-CN/core/collection/collection-field-interface.md index ec2831dba3..144d6d7896 100644 --- a/packages/core/client/docs/zh-CN/core/collection/collection-field-interface.md +++ b/packages/core/client/docs/zh-CN/core/collection/collection-field-interface.md @@ -39,7 +39,7 @@ const email = new CollectionFieldInterfaceV2({ class MyPlugin extends Plugin { load() { - this.app.addCollectionFieldInterfaces([ email ]); + this.app.addFieldInterfaces([ email ]); } } ``` @@ -119,7 +119,7 @@ import { useCollectionManagerV2 } from '@nocobase/client'; const Demo = () => { const collectionManager = useCollectionManagerV2(); const options = useMemo(() => { - const email = collectionManager.getCollectionFieldInterface('email'); + const email = collectionManager.getFieldInterface('email'); const options = email.getOptions(); }, [collectionManager]); @@ -147,7 +147,7 @@ import { Plugin } from '@nocobase/client'; class MyPlugin extends Plugin { load() { const collectionManager = this.app.collectionManager.getCollectionManager(); - const email = collectionManager.getCollectionFieldInterface('email'); + const email = collectionManager.getFieldInterface('email'); // deep merge email.setOptions({ @@ -175,7 +175,7 @@ const Demo = () => { const collectionManager = useCollectionManagerV2(); const compile = useCompile(); const title = useMemo(() => { - const email = collectionManager.getCollectionFieldInterface('email'); + const email = collectionManager.getFieldInterface('email'); const title = email.getOption('title'); }, [collectionManager]); diff --git a/packages/core/client/docs/zh-CN/core/collection/collection-manager.md b/packages/core/client/docs/zh-CN/core/collection/collection-manager.md index ec712325c6..4cee63fdc4 100644 --- a/packages/core/client/docs/zh-CN/core/collection/collection-manager.md +++ b/packages/core/client/docs/zh-CN/core/collection/collection-manager.md @@ -37,10 +37,10 @@ class CollectionManagerV2 { removeCollection(path: string, options?: GetCollectionOptions): void; getCollectionField(path: string, options?: GetCollectionOptions): Promise; - addCollectionFieldInterfaces(interfaces:CollectionFieldInterfaceV2[] | CollectionFieldInterfaceOptions[]): void; - getCollectionFieldInterfaces(): CollectionFieldInterfaceV2[] + addFieldInterfaces(interfaces:CollectionFieldInterfaceV2[] | CollectionFieldInterfaceOptions[]): void; + getFieldInterfaces(): CollectionFieldInterfaceV2[] getCollectionFieldInterfaceGroups(): { name: string; children: CollectionFieldInterfaceV2[] }[] - getCollectionFieldInterface(name: string): CollectionFieldInterfaceV2 + getFieldInterface(name: string): CollectionFieldInterfaceV2 } ``` @@ -179,7 +179,7 @@ class MyPlugin extends Plugin { }); this.app.collectionManager.addCollectionTemplates([ treeCollectionTemplate, sqlCollectionTemplate ]); - this.app.collectionManager.addCollectionFieldInterfaces([checkboxCollectionFieldInterface]); + this.app.collectionManager.addFieldInterfaces([checkboxCollectionFieldInterface]); const collections = await this.app.apiClient.request({ url: 'collections:list' }) .then((res) => res.data.data); @@ -491,7 +491,7 @@ collectionManager.getCollectionField('users.username'); // { name: 'username', t collectionManager.getCollectionField('users.roles.name'); // 获取 roles 关联字段对应的 roles 表中的 name 字段 ``` -### cm.addCollectionFieldInterfaces(interfaces) +### cm.addFieldInterfaces(interfaces) 添加数据表字段接口。 @@ -499,7 +499,7 @@ collectionManager.getCollectionField('users.roles.name'); // 获取 roles 关联 ```tsx | pure class CollectionManagerV2 { - addCollectionFieldInterfaces(interfaces:CollectionFieldInterfaceV2[] | CollectionFieldInterfaceOptions[]): void; + addFieldInterfaces(interfaces:CollectionFieldInterfaceV2[] | CollectionFieldInterfaceOptions[]): void; } ``` @@ -515,12 +515,12 @@ const checkboxCollectionFieldInterface = new CollectionFieldInterface({ class MyPlugin extends Plugin { async load() { - this.app.collectionManager.addCollectionFieldInterfaces([checkboxCollectionFieldInterface]); + this.app.collectionManager.addFieldInterfaces([checkboxCollectionFieldInterface]); } } ``` -### cm.getCollectionFieldInterfaces() +### cm.getFieldInterfaces() 获取数据表字段接口。 @@ -528,14 +528,14 @@ class MyPlugin extends Plugin { ```tsx | pure class CollectionManagerV2 { - getCollectionFieldInterfaces(): CollectionFieldInterfaceV2[] + getFieldInterfaces(): CollectionFieldInterfaceV2[] } ``` - 示例 ```tsx | pure -collectionManager.getCollectionFieldInterfaces(); // [ checkboxCollectionFieldInterface ] +collectionManager.getFieldInterfaces(); // [ checkboxCollectionFieldInterface ] ``` ### cm.getCollectionFieldInterfaceGroups() @@ -556,7 +556,7 @@ class CollectionManagerV2 { collectionManager.getCollectionFieldInterfaceGroups(); // [ { name: '基础', children: [ checkboxCollectionFieldInterface ] } ] ``` -### cm.getCollectionFieldInterface(name) +### cm.getFieldInterface(name) 获取数据表字段接口。 @@ -564,12 +564,12 @@ collectionManager.getCollectionFieldInterfaceGroups(); // [ { name: '基础', ch ```tsx | pure class CollectionManagerV2 { - getCollectionFieldInterface(name: string): CollectionFieldInterfaceV2 + getFieldInterface(name: string): CollectionFieldInterfaceV2 } ``` - 示例 ```tsx | pure -collectionManager.getCollectionFieldInterface('checkbox'); // checkboxCollectionFieldInterface +collectionManager.getFieldInterface('checkbox'); // checkboxCollectionFieldInterface ``` diff --git a/packages/core/client/src/application/Application.tsx b/packages/core/client/src/application/Application.tsx index fa3cc43fc1..838a8b7d4e 100644 --- a/packages/core/client/src/application/Application.tsx +++ b/packages/core/client/src/application/Application.tsx @@ -59,7 +59,7 @@ export interface ApplicationOptions { designable?: boolean; loadRemotePlugins?: boolean; devDynamicImport?: DevDynamicImport; - collectionManager?: CollectionManagerV2 | CollectionManagerOptionsV2; + collectionManager?: CollectionManagerOptionsV2; } export class Application { diff --git a/packages/core/client/src/application/collection/CollectionManager.tsx b/packages/core/client/src/application/collection/CollectionManager.tsx index b0c4ddf608..ee2410699d 100644 --- a/packages/core/client/src/application/collection/CollectionManager.tsx +++ b/packages/core/client/src/application/collection/CollectionManager.tsx @@ -60,10 +60,8 @@ export interface CollectionManagerOptionsV2 { export class CollectionManagerV2 { public app: Application; protected collections: Record> = {}; - // protected collectionTemplateClasses: typeof CollectionTemplateV2[] = []; protected collectionTemplateInstances: Record = {}; - // protected collectionFieldInterfaceClasses: typeof CollectionFieldInterfaceV2[] = []; - protected collectionFieldInterfaceInstances: Record = {}; + protected fieldInterfaceInstances: Record = {}; protected collectionMixins: CollectionMixinConstructor[] = []; protected collectionNamespaces: Record = { [DEFAULT_COLLECTION_NAMESPACE_NAME]: DEFAULT_COLLECTION_NAMESPACE_TITLE, @@ -86,7 +84,7 @@ export class CollectionManagerV2 { init(options: CollectionManagerOptionsV2) { this.collectionMixins.push(...(options.collectionMixins || [])); this.addCollectionTemplates(options.collectionTemplates || []); - this.addCollectionFieldInterfaces(options.collectionFieldInterfaces || []); + this.addFieldInterfaces(options.collectionFieldInterfaces || []); this.addCollectionNamespaces(options.collectionNamespaces || {}); if (Array.isArray(options.collections)) { this.addCollections(options.collections); @@ -235,7 +233,6 @@ export class CollectionManagerV2 { | (CollectionTemplateV2Options | typeof CollectionTemplateV2)[] | Record, ) { - // this.collectionTemplateClasses = [...this.collectionTemplateClasses, ...templateClasses]; const newCollectionTemplateInstances = typeof templateClasses === 'object' && !Array.isArray(templateClasses) ? templateClasses @@ -269,10 +266,9 @@ export class CollectionManagerV2 { } // field interface - addCollectionFieldInterfaces(interfaces: (IField | typeof CollectionFieldInterfaceV2)[] | Record) { - // this.collectionFieldInterfaceClasses = [...this.collectionFieldInterfaceClasses, ...interfaces]; + addFieldInterfaces(interfaces: (IField | typeof CollectionFieldInterfaceV2)[] | Record) { if (typeof interfaces === 'object' && !Array.isArray(interfaces)) { - Object.assign(this.collectionFieldInterfaceInstances, interfaces); + Object.assign(this.fieldInterfaceInstances, interfaces); return; } const newCollectionFieldInterfaces = interfaces.reduce((acc, Interface) => { @@ -281,13 +277,13 @@ export class CollectionManagerV2 { return acc; }, {}); - Object.assign(this.collectionFieldInterfaceInstances, newCollectionFieldInterfaces); + Object.assign(this.fieldInterfaceInstances, newCollectionFieldInterfaces); } - getCollectionFieldInterfaces() { - return this.collectionFieldInterfaceInstances; + getFieldInterfaces() { + return this.fieldInterfaceInstances; } - getCollectionFieldInterface(name: string) { - return this.collectionFieldInterfaceInstances[name]; + getFieldInterface(name: string) { + return this.fieldInterfaceInstances[name]; } setReloadFn(fn: (...args: any[]) => Promise, namespace: string = DEFAULT_COLLECTION_NAMESPACE_NAME) { @@ -302,6 +298,7 @@ export class CollectionManagerV2 { const collections = await this.reloadFns[namespace](); this.setCollections(collections); callback && callback(collections); + this.reloadCallbacks[namespace]?.forEach((cb) => cb(collections)); } } @@ -316,10 +313,8 @@ export class CollectionManagerV2 { private getInheritData() { return { collections: this.collections, - // collectionTemplateClasses: this.collectionTemplateClasses, collectionTemplateInstances: this.collectionTemplateInstances, - // collectionFieldInterfaceClasses: this.collectionFieldInterfaceClasses, - collectionFieldInterfaceInstances: this.collectionFieldInterfaceInstances, + fieldInterfaceInstances: this.fieldInterfaceInstances, collectionMixins: this.collectionMixins, collectionNamespaces: this.collectionNamespaces, reloadFns: this.reloadFns, diff --git a/packages/core/client/src/application/collection/utils.ts b/packages/core/client/src/application/collection/utils.ts index 84f3d1d029..14f5e546dc 100644 --- a/packages/core/client/src/application/collection/utils.ts +++ b/packages/core/client/src/application/collection/utils.ts @@ -104,5 +104,5 @@ export function getCollectionFieldsOptions( } export const isTitleField = (cm: CollectionManagerV2, field: CollectionFieldOptionsV2) => { - return !field.isForeignKey && cm.getCollectionFieldInterface(field.interface)?.titleUsable; + return !field.isForeignKey && cm.getFieldInterface(field.interface)?.titleUsable; }; diff --git a/packages/core/client/src/collection-manager/CollectionManagerProvider.tsx b/packages/core/client/src/collection-manager/CollectionManagerProvider.tsx index 2578a06c36..9e9866bd2a 100644 --- a/packages/core/client/src/collection-manager/CollectionManagerProvider.tsx +++ b/packages/core/client/src/collection-manager/CollectionManagerProvider.tsx @@ -12,7 +12,7 @@ import { interfaces as defaultInterfaces } from './Configuration/interfaces'; import { collectionTemplates } from './Configuration/templates'; export const CollectionManagerProvider: React.FC = (props) => { - const { interfaces, reloadCallback, cm, collections = [], templates } = props; + const { reloadCallback, cm, collections = [] } = props; const cmContext = useCollectionManagerV2(); const app = useApp(); const newCm = useMemo(() => { @@ -28,8 +28,6 @@ export const CollectionManagerProvider: React.FC = (pr ); return ctx.inherit({ collections: collections as any, - collectionFieldInterfaces: interfaces, - collectionTemplates: templates, reloadCallback, }); }, [cm]); diff --git a/packages/core/client/src/collection-manager/Configuration/interfaces.tsx b/packages/core/client/src/collection-manager/Configuration/interfaces.tsx index a82fd32dd6..6f2dad72a9 100644 --- a/packages/core/client/src/collection-manager/Configuration/interfaces.tsx +++ b/packages/core/client/src/collection-manager/Configuration/interfaces.tsx @@ -75,17 +75,18 @@ export const useFieldInterfaceOptions = () => { const cm = useCollectionManagerV2(); return useMemo(() => { - const collectionFieldInterfaceInstances = cm.getCollectionFieldInterfaces(); - const groups = Object.values(collectionFieldInterfaceInstances).reduce< - Record - >((memo, fieldInterface) => { - const group = fieldInterface.group || 'basic'; - if (!memo[group]) { - memo[group] = []; - } - memo[group].push(fieldInterface); - return memo; - }, {}); + const fieldInterfaceInstances = cm.getFieldInterfaces(); + const groups = Object.values(fieldInterfaceInstances).reduce>( + (memo, fieldInterface) => { + const group = fieldInterface.group || 'basic'; + if (!memo[group]) { + memo[group] = []; + } + memo[group].push(fieldInterface); + return memo; + }, + {}, + ); return getOptions(groups); }, [cm]); }; diff --git a/packages/core/client/src/collection-manager/collectionPlugin.ts b/packages/core/client/src/collection-manager/collectionPlugin.ts index a6a2273a68..6884e256c8 100644 --- a/packages/core/client/src/collection-manager/collectionPlugin.ts +++ b/packages/core/client/src/collection-manager/collectionPlugin.ts @@ -46,16 +46,16 @@ import { collection } from './Configuration/schemas/collections'; export class CollectionPlugin extends Plugin { async load() { this.collectionManager.addCollectionMixins([InheritanceCollectionMixin]); - this.addCollectionFieldInterfaces(); + this.addFieldInterfaces(); this.addCollectionTemplates(); this.collectionManager.setReloadFn(this.reloadCollections.bind(this)); // await this.collectionManager.reload(); } - addCollectionFieldInterfaces() { - this.app.collectionManager.addCollectionFieldInterfaces([...interfaces.values()]); - // this.app.collectionManager.addCollectionFieldInterfaces([ + addFieldInterfaces() { + this.app.collectionManager.addFieldInterfaces([...interfaces.values()]); + // this.app.collectionManager.addFieldInterfaces([ // checkbox, // checkboxGroup, // chinaRegion, diff --git a/packages/core/client/src/collection-manager/hooks/useCollectionManager.ts b/packages/core/client/src/collection-manager/hooks/useCollectionManager.ts index 6473a6d7e5..eebf20a052 100644 --- a/packages/core/client/src/collection-manager/hooks/useCollectionManager.ts +++ b/packages/core/client/src/collection-manager/hooks/useCollectionManager.ts @@ -10,7 +10,7 @@ import { uid } from '@formily/shared'; export const useCollectionManager = () => { const cm = useCollectionManagerV2(); const [random, setRandom] = useState(uid()); - const interfaces = useMemo(() => cm?.getCollectionFieldInterfaces(), [cm, random]); + const interfaces = useMemo(() => cm?.getFieldInterfaces(), [cm, random]); const templates = useMemo(() => cm?.getCollectionTemplates(), [cm, random]); const collections = useMemo( () => @@ -208,7 +208,7 @@ export const useCollectionManager = () => { const getInterface = useCallback( (name: string) => { - return cm?.getCollectionFieldInterface(name); + return cm?.getFieldInterface(name); }, [cm], ); diff --git a/packages/core/client/src/collection-manager/types.ts b/packages/core/client/src/collection-manager/types.ts index 5ed534e01c..416e93ebae 100644 --- a/packages/core/client/src/collection-manager/types.ts +++ b/packages/core/client/src/collection-manager/types.ts @@ -67,9 +67,7 @@ export interface CollectionOptions { export interface CollectionManagerOptions { service?: any; - interfaces?: any; collections?: CollectionOptions[]; - templates?: any; // refreshCM?: () => Promise; reloadCallback?: (collection: CollectionV2[]) => void; cm?: CollectionManagerV2; diff --git a/packages/plugins/@nocobase/plugin-excel-formula-field/src/client/index.tsx b/packages/plugins/@nocobase/plugin-excel-formula-field/src/client/index.tsx index ec815d6f65..d81a0bde07 100644 --- a/packages/plugins/@nocobase/plugin-excel-formula-field/src/client/index.tsx +++ b/packages/plugins/@nocobase/plugin-excel-formula-field/src/client/index.tsx @@ -5,7 +5,7 @@ import { excelFormula } from './excel-formula'; export class ExcelFormulaFieldPlugin extends Plugin { async load() { this.app.use(ExcelFormulaFieldProvider); - this.app.collectionManager.addCollectionFieldInterfaces([excelFormula]); + this.app.collectionManager.addFieldInterfaces([excelFormula]); } } diff --git a/packages/plugins/@nocobase/plugin-file-manager/src/client/index.tsx b/packages/plugins/@nocobase/plugin-file-manager/src/client/index.tsx index 6a9a46f612..f0f84bd812 100644 --- a/packages/plugins/@nocobase/plugin-file-manager/src/client/index.tsx +++ b/packages/plugins/@nocobase/plugin-file-manager/src/client/index.tsx @@ -10,7 +10,7 @@ export class FileManagerPlugin extends Plugin { storageTypes = new Map(); async load() { - this.app.collectionManager.addCollectionFieldInterfaces([attachment]); + this.app.collectionManager.addFieldInterfaces([attachment]); this.app.collectionManager.addCollectionTemplates([fileCollectionTemplate]); this.app.use(FileManagerProvider); diff --git a/packages/plugins/@nocobase/plugin-formula-field/src/client/index.tsx b/packages/plugins/@nocobase/plugin-formula-field/src/client/index.tsx index d262cdea43..7060710829 100644 --- a/packages/plugins/@nocobase/plugin-formula-field/src/client/index.tsx +++ b/packages/plugins/@nocobase/plugin-formula-field/src/client/index.tsx @@ -5,7 +5,7 @@ import formulaField from './interfaces/formula'; export class FormulaFieldPlugin extends Plugin { async load() { this.app.use(FormulaFieldProvider); - this.app.collectionManager.addCollectionFieldInterfaces([formulaField]); + this.app.collectionManager.addFieldInterfaces([formulaField]); } } diff --git a/packages/plugins/@nocobase/plugin-map/src/client/index.tsx b/packages/plugins/@nocobase/plugin-map/src/client/index.tsx index e227beb4ce..5a38a822ef 100644 --- a/packages/plugins/@nocobase/plugin-map/src/client/index.tsx +++ b/packages/plugins/@nocobase/plugin-map/src/client/index.tsx @@ -25,7 +25,7 @@ export class MapPlugin extends Plugin { async load() { this.app.use(MapProvider); - this.app.collectionManager.addCollectionFieldInterfaces(fields); + this.app.collectionManager.addFieldInterfaces(fields); this.app.schemaInitializerManager.add(mapActionInitializers); const blockInitializers = this.app.schemaInitializerManager.get('BlockInitializers'); diff --git a/packages/plugins/@nocobase/plugin-math-formula-field/src/client/index.tsx b/packages/plugins/@nocobase/plugin-math-formula-field/src/client/index.tsx index 5e0b0824de..04baf0d5d5 100644 --- a/packages/plugins/@nocobase/plugin-math-formula-field/src/client/index.tsx +++ b/packages/plugins/@nocobase/plugin-math-formula-field/src/client/index.tsx @@ -5,7 +5,7 @@ import { mathFormula } from './math-formula'; export class MathFormulaFieldPlugin extends Plugin { async load() { this.app.use(MathFormulaFieldProvider); - this.app.collectionManager.addCollectionFieldInterfaces([mathFormula]); + this.app.collectionManager.addFieldInterfaces([mathFormula]); } } diff --git a/packages/plugins/@nocobase/plugin-sequence-field/src/client/index.tsx b/packages/plugins/@nocobase/plugin-sequence-field/src/client/index.tsx index 52eb8401fd..1af205a9e1 100644 --- a/packages/plugins/@nocobase/plugin-sequence-field/src/client/index.tsx +++ b/packages/plugins/@nocobase/plugin-sequence-field/src/client/index.tsx @@ -5,7 +5,7 @@ import { sequence } from './sequence'; export class SequenceFieldPlugin extends Plugin { async load() { this.app.use(SequenceFieldProvider); - this.app.collectionManager.addCollectionFieldInterfaces([sequence]); + this.app.collectionManager.addFieldInterfaces([sequence]); } } diff --git a/packages/plugins/@nocobase/plugin-snapshot-field/src/client/index.tsx b/packages/plugins/@nocobase/plugin-snapshot-field/src/client/index.tsx index 31a6c0ad88..ce30bdda2b 100644 --- a/packages/plugins/@nocobase/plugin-snapshot-field/src/client/index.tsx +++ b/packages/plugins/@nocobase/plugin-snapshot-field/src/client/index.tsx @@ -7,7 +7,7 @@ export class SnapshotFieldPlugin extends Plugin { async load() { this.app.use(SnapshotFieldProvider); this.app.schemaInitializerManager.add(snapshotBlockInitializers); - this.app.collectionManager.addCollectionFieldInterfaces([snapshot]); + this.app.collectionManager.addFieldInterfaces([snapshot]); } } diff --git a/packages/plugins/@nocobase/plugin-workflow-dynamic-calculation/src/client/index.ts b/packages/plugins/@nocobase/plugin-workflow-dynamic-calculation/src/client/index.ts index 79315a1adf..9112489a58 100644 --- a/packages/plugins/@nocobase/plugin-workflow-dynamic-calculation/src/client/index.ts +++ b/packages/plugins/@nocobase/plugin-workflow-dynamic-calculation/src/client/index.ts @@ -14,7 +14,7 @@ export default class extends Plugin { // You can get and modify the app instance here async load() { - this.app.collectionManager.addCollectionFieldInterfaces([expression]); + this.app.collectionManager.addFieldInterfaces([expression]); this.app.addComponents({ DynamicExpression, });