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

View File

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