From f2a3cef3cf46fe3ff43c53600ff2ef8cbd589055 Mon Sep 17 00:00:00 2001 From: chenos Date: Thu, 21 Apr 2022 18:08:18 +0800 Subject: [PATCH] fix: hide collections & fields if not exist --- .../collection-manager/CollectionFieldProvider.tsx | 11 +++++++---- .../src/collection-manager/CollectionProvider.tsx | 6 +++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/core/client/src/collection-manager/CollectionFieldProvider.tsx b/packages/core/client/src/collection-manager/CollectionFieldProvider.tsx index 441b5ef4b..b9f551ee7 100644 --- a/packages/core/client/src/collection-manager/CollectionFieldProvider.tsx +++ b/packages/core/client/src/collection-manager/CollectionFieldProvider.tsx @@ -1,15 +1,18 @@ +import { SchemaKey } from '@formily/react'; import React from 'react'; -import { merge } from '@formily/shared'; +import { CollectionFieldContext } from './context'; import { useCollection } from './hooks'; import { CollectionFieldOptions } from './types'; -import { CollectionFieldContext } from './context'; -import { SchemaKey } from '@formily/react'; export const CollectionFieldProvider: React.FC<{ name?: SchemaKey; field?: CollectionFieldOptions }> = (props) => { const { name, field, children } = props; const { getField } = useCollection(); + const value = field || getField(field?.name || name); + if (!value) { + return null; + } return ( - + {children} ); diff --git a/packages/core/client/src/collection-manager/CollectionProvider.tsx b/packages/core/client/src/collection-manager/CollectionProvider.tsx index 7dce442ca..8b9e8271e 100644 --- a/packages/core/client/src/collection-manager/CollectionProvider.tsx +++ b/packages/core/client/src/collection-manager/CollectionProvider.tsx @@ -6,5 +6,9 @@ import { CollectionOptions } from './types'; export const CollectionProvider: React.FC<{ name?: string; collection?: CollectionOptions }> = (props) => { const { name, collection, children } = props; const { getCollection } = useCollectionManager(); - return {children}; + const value = getCollection(collection || name); + if (!value) { + return null; + } + return {children}; };