fix: allow collection provider to be null

This commit is contained in:
chenos 2022-04-22 11:13:06 +08:00
parent 5dae47d5f1
commit 01134f8253
2 changed files with 4 additions and 4 deletions

View File

@ -3,11 +3,11 @@ import { CollectionContext } from './context';
import { useCollectionManager } from './hooks';
import { CollectionOptions } from './types';
export const CollectionProvider: React.FC<{ name?: string; collection?: CollectionOptions }> = (props) => {
const { name, collection, children } = props;
export const CollectionProvider: React.FC<{ allowNull?: boolean; name?: string; collection?: CollectionOptions }> = (props) => {
const { allowNull, name, collection, children } = props;
const { getCollection } = useCollectionManager();
const value = getCollection(collection || name);
if (!value) {
if (!value && !allowNull) {
return null;
}
return <CollectionContext.Provider value={value}>{children}</CollectionContext.Provider>;

View File

@ -97,7 +97,7 @@ export const InputRecordPicker: React.FC<any> = (props) => {
open={false}
/>
<RecordPickerContext.Provider value={{ multiple, onChange, selectedRows, setSelectedRows }}>
<CollectionProvider name={collectionField?.target}>
<CollectionProvider allowNull name={collectionField?.target}>
<ActionContext.Provider value={{ openMode: 'drawer', visible, setVisible }}>
<FormProvider>
<SchemaComponentOptions scope={{ useTableSelectorProps, usePickActionProps }}>