From a3a91965c7436ce43348fd15027a25e39160846d Mon Sep 17 00:00:00 2001 From: Junyi Date: Tue, 18 Apr 2023 20:44:53 +0700 Subject: [PATCH] fix(client): fix error on clear value in variable input (#1723) --- .../schema-component/antd/variable/Input.tsx | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/packages/core/client/src/schema-component/antd/variable/Input.tsx b/packages/core/client/src/schema-component/antd/variable/Input.tsx index 59e54925a..fb5f9059a 100644 --- a/packages/core/client/src/schema-component/antd/variable/Input.tsx +++ b/packages/core/client/src/schema-component/antd/variable/Input.tsx @@ -98,14 +98,12 @@ const ConstantTypes = { -function getTypedConstantOption(type, props) { - const { t } = useTranslation(); - +function getTypedConstantOption(type) { return { value: '', - label: t('Constant'), + label: '{{t("Constant")}}', children: Object.values(ConstantTypes), - content: ConstantTypes[type]?.component({ value: props.value, onChange: props.onChange }) + component: ConstantTypes[type]?.component }; } @@ -116,33 +114,34 @@ type VariableOptions = { }; export function Input(props) { + const compile = useCompile(); + const form = useForm(); + const { value = '', scope, onChange, children, button, useTypedConstant } = props; const parsed = parseValue(value); const isConstant = typeof parsed === 'string'; const type = isConstant ? parsed : ''; const variable = isConstant ? null : parsed; - const compile = useCompile(); - const { content, ...constantOption }: VariableOptions & { content: React.ReactNode } = children + const varialbeOptions = typeof scope === 'function' ? scope() : scope ?? []; + + const { component: ConstantComponent, ...constantOption }: VariableOptions & { component?: React.FC } = children ? { value: '', - label: '{{t("Constant")}}', - content: children + label: '{{t("Constant")}}' } : (useTypedConstant - ? getTypedConstantOption(type, props) + ? getTypedConstantOption(type) : { value: '', label: '{{t("Null")}}', - content: ConstantTypes.null.component() + component: ConstantTypes.null.component } ); const options: VariableOptions[] = compile([ constantOption, - ...(typeof scope === 'function' ? scope() : scope ?? []), + ...varialbeOptions, ]); - const form = useForm(); - function onSwitch(next) { if (next[0] === '') { if (next[1]) { @@ -247,7 +246,7 @@ export function Input(props) { ) : null} - ) : content} + ) : children ?? } {options.length > 1 ? (