mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 11:46:46 +00:00
feat: improve form block (#4099)
* feat: improve form block * fix: remove RenderChildrenWithAssociationFilter * fix: improve form block
This commit is contained in:
parent
3025c254e6
commit
cb91f7dbd4
@ -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();
|
||||||
|
@ -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>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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>
|
||||||
);
|
);
|
||||||
|
@ -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>
|
||||||
);
|
);
|
||||||
|
@ -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}>{props.children}</div>
|
||||||
<div ref={formBlockRef}>
|
|
||||||
<RecursionField schema={fieldSchema} onlyRenderProperties />
|
|
||||||
</div>
|
|
||||||
</Component>
|
|
||||||
</FormBlockContext.Provider>
|
</FormBlockContext.Provider>
|
||||||
</BlockRequestContext_deprecated.Provider>
|
</BlockRequestContext_deprecated.Provider>
|
||||||
</FormActiveFieldsProvider>
|
</FormActiveFieldsProvider>
|
||||||
|
Loading…
Reference in New Issue
Block a user