mirror of
https://github.com/nocobase/nocobase
synced 2024-11-16 13:37:39 +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 React, { FC, ReactNode, createContext, useContext } from 'react';
|
||||||
import { useCollectionManagerV2 } from './CollectionManagerProvider';
|
|
||||||
import { CollectionDeletedPlaceholder } from '../components/CollectionDeletedPlaceholder';
|
|
||||||
import { CollectionProviderV2 } from './CollectionProvider';
|
|
||||||
import { CollectionFieldProviderV2 } from '../collection-field';
|
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 {
|
export interface AssociationProviderPropsV2 {
|
||||||
dataSource?: string;
|
dataSource?: string;
|
||||||
@ -10,6 +11,17 @@ export interface AssociationProviderPropsV2 {
|
|||||||
children?: ReactNode;
|
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) => {
|
export const AssociationProviderV2: FC<AssociationProviderPropsV2> = (props) => {
|
||||||
const { name, children } = props;
|
const { name, children } = props;
|
||||||
|
|
||||||
@ -20,9 +32,11 @@ export const AssociationProviderV2: FC<AssociationProviderPropsV2> = (props) =>
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<CollectionProviderV2 name={String(name).split('.')[0]}>
|
<CollectionProviderV2 name={String(name).split('.')[0]}>
|
||||||
<CollectionFieldProviderV2 name={name}>
|
<ParentCollectionProvider>
|
||||||
<CollectionProviderV2 name={collectionName}>{children}</CollectionProviderV2>
|
<CollectionFieldProviderV2 name={name}>
|
||||||
</CollectionFieldProviderV2>
|
<CollectionProviderV2 name={collectionName}>{children}</CollectionProviderV2>
|
||||||
|
</CollectionFieldProviderV2>
|
||||||
|
</ParentCollectionProvider>
|
||||||
</CollectionProviderV2>
|
</CollectionProviderV2>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user