This commit is contained in:
dream2023 2024-01-09 10:47:37 +08:00
parent 08ccdb2964
commit 6ac6f050c2
3 changed files with 7 additions and 5 deletions

View File

@ -20,17 +20,18 @@ export const CollectionProvider: FC<{
const collectionName = getCollectionName(name || collection);
const cm = useCollectionManagerV2();
const hasCollection = cm.getCollection(collectionName);
if (hasCollection || allowNull)
if (hasCollection || (allowNull && !collection))
return (
<CollectionProviderV2 allowNull={allowNull} name={collectionName}>
{children}
</CollectionProviderV2>
);
if (typeof collection === 'object')
if (typeof collection === 'object') {
return (
<CollectionManagerProvider collections={[collection]}>
<CollectionProviderV2 name={collection.name}>{children}</CollectionProviderV2>
</CollectionManagerProvider>
);
}
return <DeletedPlaceholder type="Collection" name={name} />;
};

View File

@ -4,15 +4,15 @@ import { message } from 'antd';
import { useTranslation } from 'react-i18next';
import { useAPIClient } from '../../../api-client';
import { i18n } from '../../../i18n';
import { CollectionOptions } from '../../types';
import { CollectionCategory } from '../components/CollectionCategory';
import { CollectionTemplate } from '../components/CollectionTemplate';
import { CollectionOptionsV2 } from '../../../application';
const compile = (source) => {
return Schema.compile(source, { t: i18n.t });
};
export const collection: CollectionOptions = {
export const collection: CollectionOptionsV2 = {
name: 'collections',
filterTargetKey: 'name',
targetKey: 'name',

View File

@ -41,6 +41,7 @@ import { InheritanceCollectionMixin } from './mixins/InheritanceCollectionMixin'
// import { general, expression, sql, tree, view } from './templates';
import { interfaces } from './Configuration/interfaces';
import { collectionTemplates } from './Configuration/templates';
import { collection } from './Configuration/schemas/collections';
export class CollectionPlugin extends Plugin {
async load() {
@ -114,6 +115,6 @@ export class CollectionPlugin extends Plugin {
},
});
return service?.data?.data || [];
return [...(service?.data?.data || []), collection];
}
}