chore: when using association field by picker mode,it's open size can be changed (#1926)

This commit is contained in:
black 2023-05-25 13:05:00 +08:00 committed by GitHub
parent e787890671
commit 948d39bab4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 3 deletions

View File

@ -20,6 +20,8 @@ export const ActionDrawer: ComposedActionDrawer = observer((props) => {
const { visible, setVisible, openSize = 'middle' } = useActionContext(); const { visible, setVisible, openSize = 'middle' } = useActionContext();
const schema = useFieldSchema(); const schema = useFieldSchema();
const field = useField(); const field = useField();
const openSizeFromParent = schema.parent?.['x-component-props']?.['openSize'];
const finalOpenSize = openSizeFromParent || openSize;
const footerSchema = schema.reduceProperties((buf, s) => { const footerSchema = schema.reduceProperties((buf, s) => {
if (s['x-component'] === footerNodeName) { if (s['x-component'] === footerNodeName) {
return s; return s;
@ -35,7 +37,7 @@ export const ActionDrawer: ComposedActionDrawer = observer((props) => {
}} }}
> >
<Drawer <Drawer
width={openSizeWidthMap.get(openSize)} width={openSizeWidthMap.get(finalOpenSize)}
title={field.title} title={field.title}
{...others} {...others}
destroyOnClose destroyOnClose

View File

@ -32,6 +32,7 @@ import { FilterDynamicComponent } from '../table-v2/FilterDynamicComponent';
import { isInvariable } from '../variable'; import { isInvariable } from '../variable';
import { FilterFormDesigner } from './FormItem.FilterFormDesigner'; import { FilterFormDesigner } from './FormItem.FilterFormDesigner';
import { useEnsureOperatorsValid } from './SchemaSettingOptions'; import { useEnsureOperatorsValid } from './SchemaSettingOptions';
import { Select } from 'antd';
const defaultInputStyle = css` const defaultInputStyle = css`
& > .nb-form-item { & > .nb-form-item {
@ -174,6 +175,10 @@ FormItem.Designer = function Designer() {
const fieldSchemaWithoutRequired = _.omit(fieldSchema, 'required'); const fieldSchemaWithoutRequired = _.omit(fieldSchema, 'required');
const isPickerMode = fieldSchema['x-component-props'].mode === 'Picker';
const showFieldMode = isAssociationField && fieldModeOptions && !isTableField;
const showModeSelect = showFieldMode && isPickerMode;
return ( return (
<GeneralSchemaDesigner> <GeneralSchemaDesigner>
<GeneralSchemaItems /> <GeneralSchemaItems />
@ -559,7 +564,7 @@ FormItem.Designer = function Designer() {
}} }}
/> />
)} )}
{isAssociationField && fieldModeOptions && !isTableField && ( {showFieldMode && (
<SchemaSettings.SelectItem <SchemaSettings.SelectItem
key="field-mode" key="field-mode"
title={t('Field mode')} title={t('Field mode')}
@ -585,7 +590,37 @@ FormItem.Designer = function Designer() {
}} }}
/> />
)} )}
{showModeSelect && (
<SchemaSettings.Item>
<div style={{ alignItems: 'center', display: 'flex', justifyContent: 'space-between' }}>
{t('Popup size')}
<Select
bordered={false}
options={[
{ label: t('Small'), value: 'small' },
{ label: t('Middle'), value: 'middle' },
{ label: t('Large'), value: 'large' },
]}
value={
fieldSchema?.['x-component-props']?.['openSize'] ??
(fieldSchema?.['x-component-props']?.['openMode'] == 'modal' ? 'large' : 'middle')
}
onChange={(value) => {
field.componentProps.openSize = value;
fieldSchema['x-component-props'] = field.componentProps;
dn.emit('patch', {
schema: {
'x-uid': fieldSchema['x-uid'],
'x-component-props': fieldSchema['x-component-props'],
},
});
dn.refresh();
}}
style={{ textAlign: 'right', minWidth: 100 }}
/>
</div>
</SchemaSettings.Item>
)}
{!field.readPretty && isAssociationField && ['Select', 'Picker'].includes(fieldMode) && ( {!field.readPretty && isAssociationField && ['Select', 'Picker'].includes(fieldMode) && (
<SchemaSettings.SwitchItem <SchemaSettings.SwitchItem
key="allowAddNew" key="allowAddNew"