mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 11:36:42 +00:00
fix: allow collection provider to be null
This commit is contained in:
parent
5dae47d5f1
commit
01134f8253
@ -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>;
|
||||||
|
@ -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 }}>
|
||||||
|
Loading…
Reference in New Issue
Block a user