mirror of
https://github.com/nocobase/nocobase
synced 2024-11-16 09:42:34 +00:00
feat: add ParentCollectionContext
This commit is contained in:
parent
e9e6d4a817
commit
c8ebcbcbb3
@ -1,8 +1,9 @@
|
||||
import React, { FC, ReactNode } from 'react';
|
||||
import { useCollectionManagerV2 } from './CollectionManagerProvider';
|
||||
import { CollectionDeletedPlaceholder } from '../components/CollectionDeletedPlaceholder';
|
||||
import { CollectionProviderV2 } from './CollectionProvider';
|
||||
import React, { FC, ReactNode, createContext, useContext } from 'react';
|
||||
import { CollectionFieldProviderV2 } from '../collection-field';
|
||||
import { CollectionDeletedPlaceholder } from '../components/CollectionDeletedPlaceholder';
|
||||
import { CollectionV2 } from './Collection';
|
||||
import { useCollectionManagerV2 } from './CollectionManagerProvider';
|
||||
import { CollectionProviderV2, useCollectionV2 } from './CollectionProvider';
|
||||
|
||||
export interface AssociationProviderPropsV2 {
|
||||
dataSource?: string;
|
||||
@ -10,6 +11,17 @@ export interface AssociationProviderPropsV2 {
|
||||
children?: ReactNode;
|
||||
}
|
||||
|
||||
const ParentCollectionContext = createContext<CollectionV2>(null);
|
||||
|
||||
const ParentCollectionProvider = (props) => {
|
||||
const collection = useCollectionV2();
|
||||
return <ParentCollectionContext.Provider value={collection}>{props.children}</ParentCollectionContext.Provider>;
|
||||
};
|
||||
|
||||
export const useParentCollection = () => {
|
||||
return useContext(ParentCollectionContext);
|
||||
};
|
||||
|
||||
export const AssociationProviderV2: FC<AssociationProviderPropsV2> = (props) => {
|
||||
const { name, children } = props;
|
||||
|
||||
@ -20,9 +32,11 @@ export const AssociationProviderV2: FC<AssociationProviderPropsV2> = (props) =>
|
||||
|
||||
return (
|
||||
<CollectionProviderV2 name={String(name).split('.')[0]}>
|
||||
<CollectionFieldProviderV2 name={name}>
|
||||
<CollectionProviderV2 name={collectionName}>{children}</CollectionProviderV2>
|
||||
</CollectionFieldProviderV2>
|
||||
<ParentCollectionProvider>
|
||||
<CollectionFieldProviderV2 name={name}>
|
||||
<CollectionProviderV2 name={collectionName}>{children}</CollectionProviderV2>
|
||||
</CollectionFieldProviderV2>
|
||||
</ParentCollectionProvider>
|
||||
</CollectionProviderV2>
|
||||
);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user