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:
chenos 2024-04-19 17:19:07 +08:00 committed by GitHub
parent d24c30a7f8
commit 0af40dfa3e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 26 additions and 7 deletions

View File

@ -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();

View File

@ -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';

View File

@ -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);

View File

@ -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]);

View File

@ -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';