feat: improve form block (#4099)

* feat: improve form block

* fix: remove RenderChildrenWithAssociationFilter

* fix: improve form block
This commit is contained in:
chenos 2024-04-19 16:15:03 +08:00 committed by GitHub
parent 3025c254e6
commit cb91f7dbd4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 16 additions and 25 deletions

View File

@ -132,9 +132,8 @@ export const useBlockRequestContext = () => {
}; };
/** /**
* @internal * @deprecated
* @param props * 使
* @returns
*/ */
export const RenderChildrenWithAssociationFilter: React.FC<any> = (props) => { export const RenderChildrenWithAssociationFilter: React.FC<any> = (props) => {
const fieldSchema = useFieldSchema(); const fieldSchema = useFieldSchema();

View File

@ -1,5 +1,5 @@
import { createForm } from '@formily/core'; import { createForm } from '@formily/core';
import { RecursionField, Schema, useField, useFieldSchema } from '@formily/react'; import { Schema, useField } from '@formily/react';
import { Spin } from 'antd'; import { Spin } from 'antd';
import React, { createContext, useContext, useEffect, useMemo, useRef } from 'react'; import React, { createContext, useContext, useEffect, useMemo, useRef } from 'react';
import { withDynamicSchemaProps } from '../application/hoc/withDynamicSchemaProps'; import { withDynamicSchemaProps } from '../application/hoc/withDynamicSchemaProps';
@ -88,7 +88,7 @@ const InternalFormBlockProvider = (props) => {
<FormBlockContext.Provider value={formBlockValue}> <FormBlockContext.Provider value={formBlockValue}>
<RecordProvider isNew={record?.isNew} parent={record?.parentRecord?.data} record={record?.data}> <RecordProvider isNew={record?.isNew} parent={record?.parentRecord?.data} record={record?.data}>
<div ref={formBlockRef}> <div ref={formBlockRef}>
<RenderChildrenWithDataTemplates form={form} /> <RenderChildrenWithDataTemplates form={form}>{props.children}</RenderChildrenWithDataTemplates>
</div> </div>
</RecordProvider> </RecordProvider>
</FormBlockContext.Provider> </FormBlockContext.Provider>
@ -189,16 +189,12 @@ export const useFormBlockProps = () => {
}; };
}; };
const RenderChildrenWithDataTemplates = ({ form }) => { const RenderChildrenWithDataTemplates = ({ form, children }) => {
const FieldSchema = useFieldSchema();
const { findComponent } = useDesignable();
const field = useField();
const Component = findComponent(field.component?.[0]) || React.Fragment;
return ( return (
<Component {...field.componentProps}> <>
<DataTemplateSelect style={{ marginBottom: 18 }} form={form} /> <DataTemplateSelect style={{ marginBottom: 18 }} form={form} />
<RecursionField schema={FieldSchema} onlyRenderProperties /> {children}
</Component> </>
); );
}; };

View File

@ -5,7 +5,7 @@ import { withDynamicSchemaProps } from '../application/hoc/withDynamicSchemaProp
import { useCollectionManager_deprecated } from '../collection-manager'; import { useCollectionManager_deprecated } from '../collection-manager';
import { useTableBlockParams } from '../modules/blocks/data-blocks/table'; import { useTableBlockParams } from '../modules/blocks/data-blocks/table';
import { FixedBlockWrapper, SchemaComponentOptions } from '../schema-component'; import { FixedBlockWrapper, SchemaComponentOptions } from '../schema-component';
import { BlockProvider, RenderChildrenWithAssociationFilter, useBlockRequestContext } from './BlockProvider'; import { BlockProvider, useBlockRequestContext } from './BlockProvider';
/** /**
* @internal * @internal
@ -39,6 +39,7 @@ interface Props {
* Table collection name * Table collection name
*/ */
collection?: string; collection?: string;
children?: any;
} }
const InternalTableBlockProvider = (props: Props) => { const InternalTableBlockProvider = (props: Props) => {
@ -81,7 +82,7 @@ const InternalTableBlockProvider = (props: Props) => {
setExpandFlag: setExpandFlagValue, setExpandFlag: setExpandFlagValue,
}} }}
> >
<RenderChildrenWithAssociationFilter {...props} /> {props.children}
</TableBlockContext.Provider> </TableBlockContext.Provider>
</FixedBlockWrapper> </FixedBlockWrapper>
); );

View File

@ -10,7 +10,7 @@ import { isInFilterFormBlock } from '../filter-provider';
import { mergeFilter } from '../filter-provider/utils'; import { mergeFilter } from '../filter-provider/utils';
import { RecordProvider, useRecord } from '../record-provider'; import { RecordProvider, useRecord } from '../record-provider';
import { SchemaComponentOptions } from '../schema-component'; import { SchemaComponentOptions } from '../schema-component';
import { BlockProvider, RenderChildrenWithAssociationFilter, useBlockRequestContext } from './BlockProvider'; import { BlockProvider, useBlockRequestContext } from './BlockProvider';
import { useParsedFilter } from './hooks'; import { useParsedFilter } from './hooks';
type Params = { type Params = {
@ -76,7 +76,7 @@ const InternalTableSelectorProvider = (props) => {
}, },
}} }}
> >
<RenderChildrenWithAssociationFilter {...props} /> {props.children}
</TableSelectorContext.Provider> </TableSelectorContext.Provider>
</RecordProvider> </RecordProvider>
); );

View File

@ -1,5 +1,5 @@
import { createForm } from '@formily/core'; import { createForm } from '@formily/core';
import { RecursionField, useField, useFieldSchema } from '@formily/react'; import { useField, useFieldSchema } from '@formily/react';
import { import {
BlockRequestContext_deprecated, BlockRequestContext_deprecated,
CollectionManagerProvider, CollectionManagerProvider,
@ -31,7 +31,6 @@ export function FormBlockProvider(props) {
const values = userJob?.result?.[formKey]; const values = userJob?.result?.[formKey];
const { findComponent } = useDesignable(); const { findComponent } = useDesignable();
const Component = findComponent(field.component?.[0]) || React.Fragment;
const form = useMemo( const form = useMemo(
() => () =>
@ -81,12 +80,8 @@ export function FormBlockProvider(props) {
value={{ block: 'form', props, field, service, resource, __parent }} value={{ block: 'form', props, field, service, resource, __parent }}
> >
<FormBlockContext.Provider value={formBlockValue}> <FormBlockContext.Provider value={formBlockValue}>
<Component {...field.componentProps}>
<FormV2.Templates style={{ marginBottom: 18 }} form={form} /> <FormV2.Templates style={{ marginBottom: 18 }} form={form} />
<div ref={formBlockRef}> <div ref={formBlockRef}>{props.children}</div>
<RecursionField schema={fieldSchema} onlyRenderProperties />
</div>
</Component>
</FormBlockContext.Provider> </FormBlockContext.Provider>
</BlockRequestContext_deprecated.Provider> </BlockRequestContext_deprecated.Provider>
</FormActiveFieldsProvider> </FormActiveFieldsProvider>