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 collectionName = getCollectionName(name || collection);
const cm = useCollectionManagerV2(); const cm = useCollectionManagerV2();
const hasCollection = cm.getCollection(collectionName); const hasCollection = cm.getCollection(collectionName);
if (hasCollection || allowNull) if (hasCollection || (allowNull && !collection))
return ( return (
<CollectionProviderV2 allowNull={allowNull} name={collectionName}> <CollectionProviderV2 allowNull={allowNull} name={collectionName}>
{children} {children}
</CollectionProviderV2> </CollectionProviderV2>
); );
if (typeof collection === 'object') if (typeof collection === 'object') {
return ( return (
<CollectionManagerProvider collections={[collection]}> <CollectionManagerProvider collections={[collection]}>
<CollectionProviderV2 name={collection.name}>{children}</CollectionProviderV2> <CollectionProviderV2 name={collection.name}>{children}</CollectionProviderV2>
</CollectionManagerProvider> </CollectionManagerProvider>
); );
}
return <DeletedPlaceholder type="Collection" name={name} />; return <DeletedPlaceholder type="Collection" name={name} />;
}; };

View File

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

View File

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