fix: modal will automatically close when configing fields to association field details in sub-table (#2371)

This commit is contained in:
katherinehhh 2023-08-01 21:20:34 +08:00 committed by GitHub
parent 4e4c4eae27
commit cfa252bfb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,9 +1,9 @@
import { css } from '@emotion/css'; import { css } from '@emotion/css';
import { FormItem, FormLayout } from '@formily/antd-v5'; import { FormItem, FormLayout } from '@formily/antd-v5';
import { RecursionField, observer, useField, useFieldSchema } from '@formily/react'; import { RecursionField, observer, useField, useFieldSchema, SchemaOptionsContext } from '@formily/react';
import React, { useEffect } from 'react'; import React, { useEffect } from 'react';
import { CollectionProvider } from '../../../collection-manager'; import { CollectionProvider } from '../../../collection-manager';
import { SchemaComponentOptions } from '../../../schema-component'; import { useSchemaOptionsContext } from '../../../schema-component';
import Select from '../select/Select'; import Select from '../select/Select';
import { useAssociationFieldContext, useInsertSchema } from './hooks'; import { useAssociationFieldContext, useInsertSchema } from './hooks';
import schema from './schema'; import schema from './schema';
@ -18,6 +18,14 @@ export const InternalSubTable = observer(
insert(schema.SubTable); insert(schema.SubTable);
field.required = fieldSchema['required']; field.required = fieldSchema['required'];
}, []); }, []);
const option = useSchemaOptionsContext();
const components = {
...option.components,
FormItem: (props) => <FormItem {...props} />,
'Radio.Group': Select,
'Checkbox.Group': (props) => <Select multiple={true} mode="multiple" {...props} />,
};
return ( return (
<CollectionProvider name={options.target}> <CollectionProvider name={options.target}>
<FormLayout <FormLayout
@ -39,11 +47,10 @@ export const InternalSubTable = observer(
layout={'vertical'} layout={'vertical'}
bordered={false} bordered={false}
> >
<SchemaComponentOptions <SchemaOptionsContext.Provider
components={{ value={{
FormItem: (props) => <FormItem {...props} />, scope: option.scope,
'Radio.Group': Select, components,
'Checkbox.Group': (props) => <Select multiple={true} mode="multiple" {...props} />,
}} }}
> >
<RecursionField <RecursionField
@ -54,7 +61,7 @@ export const InternalSubTable = observer(
return s['x-component'] === 'AssociationField.SubTable'; return s['x-component'] === 'AssociationField.SubTable';
}} }}
/> />
</SchemaComponentOptions> </SchemaOptionsContext.Provider>
</FormLayout> </FormLayout>
</CollectionProvider> </CollectionProvider>
); );