fix: rename collectionFieldInterfaceInstance to fieldInterfaceInstance

This commit is contained in:
dream2023 2024-01-11 17:19:52 +08:00
parent b492f4999c
commit f934cb9bbe
18 changed files with 57 additions and 65 deletions

View File

@ -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]);

View File

@ -37,10 +37,10 @@ class CollectionManagerV2 {
removeCollection(path: string, options?: GetCollectionOptions): void;
getCollectionField(path: string, options?: GetCollectionOptions): Promise<CollectionFieldOptions | undefined>;
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
```

View File

@ -59,7 +59,7 @@ export interface ApplicationOptions {
designable?: boolean;
loadRemotePlugins?: boolean;
devDynamicImport?: DevDynamicImport;
collectionManager?: CollectionManagerV2 | CollectionManagerOptionsV2;
collectionManager?: CollectionManagerOptionsV2;
}
export class Application {

View File

@ -60,10 +60,8 @@ export interface CollectionManagerOptionsV2 {
export class CollectionManagerV2<Mixins = {}> {
public app: Application;
protected collections: Record<string, Record<string, CollectionV2>> = {};
// protected collectionTemplateClasses: typeof CollectionTemplateV2[] = [];
protected collectionTemplateInstances: Record<string, CollectionTemplateV2> = {};
// protected collectionFieldInterfaceClasses: typeof CollectionFieldInterfaceV2[] = [];
protected collectionFieldInterfaceInstances: Record<string, CollectionFieldInterfaceV2> = {};
protected fieldInterfaceInstances: Record<string, CollectionFieldInterfaceV2> = {};
protected collectionMixins: CollectionMixinConstructor[] = [];
protected collectionNamespaces: Record<string, string> = {
[DEFAULT_COLLECTION_NAMESPACE_NAME]: DEFAULT_COLLECTION_NAMESPACE_TITLE,
@ -86,7 +84,7 @@ export class CollectionManagerV2<Mixins = {}> {
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<Mixins = {}> {
| (CollectionTemplateV2Options | typeof CollectionTemplateV2)[]
| Record<string, CollectionTemplateV2Options>,
) {
// this.collectionTemplateClasses = [...this.collectionTemplateClasses, ...templateClasses];
const newCollectionTemplateInstances =
typeof templateClasses === 'object' && !Array.isArray(templateClasses)
? templateClasses
@ -269,10 +266,9 @@ export class CollectionManagerV2<Mixins = {}> {
}
// field interface
addCollectionFieldInterfaces(interfaces: (IField | typeof CollectionFieldInterfaceV2)[] | Record<string, IField>) {
// this.collectionFieldInterfaceClasses = [...this.collectionFieldInterfaceClasses, ...interfaces];
addFieldInterfaces(interfaces: (IField | typeof CollectionFieldInterfaceV2)[] | Record<string, IField>) {
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<Mixins = {}> {
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<any>, namespace: string = DEFAULT_COLLECTION_NAMESPACE_NAME) {
@ -302,6 +298,7 @@ export class CollectionManagerV2<Mixins = {}> {
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<Mixins = {}> {
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,

View File

@ -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;
};

View File

@ -12,7 +12,7 @@ import { interfaces as defaultInterfaces } from './Configuration/interfaces';
import { collectionTemplates } from './Configuration/templates';
export const CollectionManagerProvider: React.FC<CollectionManagerOptions> = (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<CollectionManagerOptions> = (pr
);
return ctx.inherit({
collections: collections as any,
collectionFieldInterfaces: interfaces,
collectionTemplates: templates,
reloadCallback,
});
}, [cm]);

View File

@ -75,17 +75,18 @@ export const useFieldInterfaceOptions = () => {
const cm = useCollectionManagerV2();
return useMemo(() => {
const collectionFieldInterfaceInstances = cm.getCollectionFieldInterfaces();
const groups = Object.values(collectionFieldInterfaceInstances).reduce<
Record<string, CollectionFieldInterfaceV2[]>
>((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<Record<string, CollectionFieldInterfaceV2[]>>(
(memo, fieldInterface) => {
const group = fieldInterface.group || 'basic';
if (!memo[group]) {
memo[group] = [];
}
memo[group].push(fieldInterface);
return memo;
},
{},
);
return getOptions(groups);
}, [cm]);
};

View File

@ -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,

View File

@ -10,7 +10,7 @@ import { uid } from '@formily/shared';
export const useCollectionManager = () => {
const cm = useCollectionManagerV2<InheritanceCollectionMixin>();
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],
);

View File

@ -67,9 +67,7 @@ export interface CollectionOptions {
export interface CollectionManagerOptions {
service?: any;
interfaces?: any;
collections?: CollectionOptions[];
templates?: any;
// refreshCM?: () => Promise<void>;
reloadCallback?: (collection: CollectionV2[]) => void;
cm?: CollectionManagerV2;

View File

@ -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]);
}
}

View File

@ -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);

View File

@ -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]);
}
}

View File

@ -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');

View File

@ -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]);
}
}

View File

@ -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]);
}
}

View File

@ -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]);
}
}

View File

@ -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,
});