From c8ebcbcbb30a48feed75c1457451cdfd0e4cbae5 Mon Sep 17 00:00:00 2001 From: chenos Date: Thu, 8 Feb 2024 10:43:21 +0800 Subject: [PATCH] feat: add ParentCollectionContext --- .../collection/AssociationProvider.tsx | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/packages/core/client/src/data-source/collection/AssociationProvider.tsx b/packages/core/client/src/data-source/collection/AssociationProvider.tsx index 749a8d9f55..e3c2ae183c 100644 --- a/packages/core/client/src/data-source/collection/AssociationProvider.tsx +++ b/packages/core/client/src/data-source/collection/AssociationProvider.tsx @@ -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(null); + +const ParentCollectionProvider = (props) => { + const collection = useCollectionV2(); + return {props.children}; +}; + +export const useParentCollection = () => { + return useContext(ParentCollectionContext); +}; + export const AssociationProviderV2: FC = (props) => { const { name, children } = props; @@ -20,9 +32,11 @@ export const AssociationProviderV2: FC = (props) => return ( - - {children} - + + + {children} + + ); };