mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 09:47:10 +00:00
fix: add SanitizedCollectionProvider (#4100)
* fix: add SanitizedCollectionProvider * fix: client unit test * chore: add comment [skip ci] --------- Co-authored-by: dream2023 <1098626505@qq.com> Co-authored-by: Zeke Zhang <958414905@qq.com>
This commit is contained in:
parent
d24c30a7f8
commit
0af40dfa3e
@ -2,7 +2,7 @@ import { Field } from '@formily/core';
|
||||
import { useField, useFieldSchema } from '@formily/react';
|
||||
import { useIsFileField } from '../schema-component/antd/form-item/FormItem.Settings';
|
||||
import { useColumnSchema } from '../schema-component/antd/table-v2/Table.Column.Decorator';
|
||||
import { useCollectionField } from '../data-source';
|
||||
import { useCollectionField } from '../data-source/collection-field/CollectionFieldProvider';
|
||||
|
||||
export function useFieldComponentName(): string {
|
||||
const { fieldSchema: tableColumnSchema, collectionField: tableColumnField } = useColumnSchema();
|
||||
|
@ -1,5 +1,5 @@
|
||||
import React, { FC, ReactNode, createContext, useContext } from 'react';
|
||||
import { CollectionFieldProvider, useCollectionField } from '../collection-field';
|
||||
import { CollectionFieldProvider, useCollectionField } from '../collection-field/CollectionFieldProvider';
|
||||
import { CollectionDeletedPlaceholder } from '../components/CollectionDeletedPlaceholder';
|
||||
import { Collection } from './Collection';
|
||||
import { useCollectionManager } from './CollectionManagerProvider';
|
||||
|
@ -1,8 +1,9 @@
|
||||
import React, { FC, ReactNode, createContext, useContext, useMemo } from 'react';
|
||||
|
||||
import { useCollectionManager } from './CollectionManagerProvider';
|
||||
import { CollectionFieldContext } from '../collection-field/CollectionFieldProvider';
|
||||
import { CollectionDeletedPlaceholder } from '../components/CollectionDeletedPlaceholder';
|
||||
import type { CollectionOptions, Collection, GetCollectionFieldPredicate } from './Collection';
|
||||
import type { Collection, CollectionOptions, GetCollectionFieldPredicate } from './Collection';
|
||||
import { useCollectionManager } from './CollectionManagerProvider';
|
||||
|
||||
export const CollectionContext = createContext<Collection>(null);
|
||||
CollectionContext.displayName = 'CollectionContext';
|
||||
@ -22,6 +23,19 @@ export const CollectionProvider: FC<CollectionProviderProps> = (props) => {
|
||||
return <CollectionContext.Provider value={collection}>{children}</CollectionContext.Provider>;
|
||||
};
|
||||
|
||||
/**
|
||||
* 用来消除普通区块(非关系区块)中可能存在的 CollectionField 上下文,因为普通区块就是一个区块,不应该和任何字段有关联
|
||||
* @param props
|
||||
* @returns
|
||||
*/
|
||||
export const SanitizedCollectionProvider: FC<CollectionProviderProps> = (props) => {
|
||||
return (
|
||||
<CollectionFieldContext.Provider value={null}>
|
||||
<CollectionProvider {...props} />
|
||||
</CollectionFieldContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export function useCollection<Mixins = {}>(): (Mixins & Collection) | undefined {
|
||||
const context = useContext(CollectionContext);
|
||||
|
||||
|
@ -4,7 +4,12 @@ import { ACLCollectionProvider } from '../../acl/ACLProvider';
|
||||
import { UseRequestOptions, UseRequestService } from '../../api-client';
|
||||
import { withDynamicSchemaProps } from '../../application/hoc';
|
||||
import { Designable, useDesignable } from '../../schema-component';
|
||||
import { AssociationProvider, CollectionManagerProvider, CollectionOptions, CollectionProvider } from '../collection';
|
||||
import {
|
||||
AssociationProvider,
|
||||
CollectionManagerProvider,
|
||||
CollectionOptions,
|
||||
SanitizedCollectionProvider,
|
||||
} from '../collection';
|
||||
import { CollectionRecord } from '../collection-record';
|
||||
import { BlockRequestProvider } from './DataBlockRequestProvider';
|
||||
import { DataBlockResourceProvider } from './DataBlockResourceProvider';
|
||||
@ -121,7 +126,7 @@ export const AssociationOrCollectionProvider = (props: {
|
||||
};
|
||||
}
|
||||
return {
|
||||
Component: CollectionProvider,
|
||||
Component: SanitizedCollectionProvider,
|
||||
name: collection,
|
||||
};
|
||||
}, [collection, association]);
|
||||
|
@ -16,7 +16,7 @@ import { FilterFormDesigner } from './FormItem.FilterFormDesigner';
|
||||
import { useEnsureOperatorsValid } from './SchemaSettingOptions';
|
||||
import useLazyLoadDisplayAssociationFieldsOfForm from './hooks/useLazyLoadDisplayAssociationFieldsOfForm';
|
||||
import useParseDefaultValue from './hooks/useParseDefaultValue';
|
||||
import { CollectionFieldProvider } from '../../../data-source';
|
||||
import { CollectionFieldProvider } from '../../../data-source/collection-field/CollectionFieldProvider';
|
||||
|
||||
Item.displayName = 'FormilyFormItem';
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user