From 68976e0ebe164cadf3dc9afa35b1c6561d5f822c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=A2=AB=E9=9B=A8=E6=B0=B4=E8=BF=87=E6=BB=A4=E7=9A=84?=
=?UTF-8?q?=E7=A9=BA=E6=B0=94-Rain?= <958414905@qq.com>
Date: Mon, 24 Jul 2023 16:24:15 +0800
Subject: [PATCH] fix(default-value): fix tag in RemoteSelect (#2306)
---
.../antd/form-item/FormItem.tsx | 100 +++++++-----------
.../antd/remote-select/RemoteSelect.tsx | 10 +-
.../schema-component/antd/select/Select.tsx | 22 +++-
3 files changed, 61 insertions(+), 71 deletions(-)
diff --git a/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx b/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx
index 2aad77835..3e781f987 100644
--- a/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx
+++ b/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx
@@ -353,73 +353,47 @@ FormItem.Designer = function Designer() {
type: 'object',
title: t('Set default value'),
properties: {
- default:
- // isInvariable(interfaceConfig)
- // ? {
- // ...(fieldSchemaWithoutRequired || {}),
- // 'x-decorator': 'FormItem',
- // 'x-component-props': {
- // ...fieldSchema['x-component-props'],
- // targetField,
- // component:
- // collectionField?.target && collectionField?.interface !== 'chinaRegion'
- // ? 'AssociationSelect'
- // : undefined,
- // service: {
- // resource: collectionField?.target,
- // },
- // style: {
- // width: '100%',
- // verticalAlign: 'top',
- // },
- // },
- // name: 'default',
- // title: t('Default value'),
- // default: getFieldDefaultValue(fieldSchema, collectionField),
- // 'x-read-pretty': false,
- // 'x-disabled': false,
- // }
- // :
- {
- ...(fieldSchemaWithoutRequired || {}),
- 'x-decorator': 'FormItem',
- 'x-component': 'VariableInput',
- 'x-component-props': {
- ...(fieldSchema?.['x-component-props'] || {}),
- collectionField,
- targetField,
- collectionName: collectionField?.collectionName,
- schema: collectionField?.uiSchema,
- className: defaultInputStyle,
- renderSchemaComponent: function Com(props) {
- const s = _.cloneDeep(fieldSchemaWithoutRequired) || ({} as Schema);
- s.title = '';
- s['x-read-pretty'] = false;
- s['x-disabled'] = false;
+ default: {
+ ...(fieldSchemaWithoutRequired || {}),
+ 'x-decorator': 'FormItem',
+ 'x-component': 'VariableInput',
+ 'x-component-props': {
+ ...(fieldSchema?.['x-component-props'] || {}),
+ collectionField,
+ targetField,
+ collectionName: collectionField?.collectionName,
+ schema: collectionField?.uiSchema,
+ className: defaultInputStyle,
+ renderSchemaComponent: function Com(props) {
+ const s = _.cloneDeep(fieldSchemaWithoutRequired) || ({} as Schema);
- return (
-
- );
- },
+ },
+ }}
+ />
+ );
},
- name: 'default',
- title: t('Default value'),
- default: getFieldDefaultValue(fieldSchema, collectionField),
},
+ name: 'default',
+ title: t('Default value'),
+ default: getFieldDefaultValue(fieldSchema, collectionField),
+ },
},
} as ISchema
}
diff --git a/packages/core/client/src/schema-component/antd/remote-select/RemoteSelect.tsx b/packages/core/client/src/schema-component/antd/remote-select/RemoteSelect.tsx
index b32e96506..84257c122 100644
--- a/packages/core/client/src/schema-component/antd/remote-select/RemoteSelect.tsx
+++ b/packages/core/client/src/schema-component/antd/remote-select/RemoteSelect.tsx
@@ -35,6 +35,7 @@ const InternalRemoteSelect = connect(
service = {},
wait = 300,
value,
+ defaultValue,
objectValue,
manual = true,
mapOptions,
@@ -249,12 +250,13 @@ const InternalRemoteSelect = connect(
};
const options = useMemo(() => {
+ const v = value || defaultValue;
if (!data?.data?.length) {
- return value != null ? (Array.isArray(value) ? value : [value]) : [];
+ return v != null ? (Array.isArray(v) ? v : [v]) : [];
}
- const valueOptions = (value != null && (Array.isArray(value) ? value : [value])) || [];
+ const valueOptions = (v != null && (Array.isArray(v) ? v : [v])) || [];
return uniqBy(data?.data?.concat(valueOptions) || [], fieldNames.value);
- }, [data?.data, value]);
+ }, [value, defaultValue, data?.data, fieldNames.value]);
const onDropdownVisibleChange = (visible) => {
setOpen(visible);
@@ -264,6 +266,7 @@ const InternalRemoteSelect = connect(
}
firstRun.current = true;
};
+
return (