fix(client): fix constant input lose focus in variable (#1689)

This commit is contained in:
Junyi 2023-04-11 10:14:37 +07:00 committed by GitHub
parent 0126a48cfa
commit 59865248f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -98,14 +98,14 @@ const ConstantTypes = {
function getTypedConstantOption(type) { function getTypedConstantOption(type, props) {
const { t } = useTranslation(); const { t } = useTranslation();
return { return {
value: '', value: '',
label: t('Constant'), label: t('Constant'),
children: Object.values(ConstantTypes), children: Object.values(ConstantTypes),
component: ConstantTypes[type]?.component content: ConstantTypes[type]?.component({ value: props.value, onChange: props.onChange })
}; };
} }
@ -122,18 +122,18 @@ export function Input(props) {
const type = isConstant ? parsed : ''; const type = isConstant ? parsed : '';
const variable = isConstant ? null : parsed; const variable = isConstant ? null : parsed;
const compile = useCompile(); const compile = useCompile();
const { component: ConstantComponent, ...constantOption }: VariableOptions & { component: React.FC<any> } = children const { content, ...constantOption }: VariableOptions & { content: React.ReactNode } = children
? { ? {
value: '', value: '',
label: '{{t("Constant")}}', label: '{{t("Constant")}}',
component: () => children content: children
} }
: (useTypedConstant : (useTypedConstant
? getTypedConstantOption(type) ? getTypedConstantOption(type, props)
: { : {
value: '', value: '',
label: '{{t("Null")}}', label: '{{t("Null")}}',
component: ConstantTypes.null.component content: ConstantTypes.null.component()
} }
); );
const options: VariableOptions[] = compile([ const options: VariableOptions[] = compile([
@ -247,9 +247,7 @@ export function Input(props) {
</span> </span>
) : null} ) : null}
</div> </div>
) : ( ) : content}
<ConstantComponent value={value} onChange={onChange} />
)}
{options.length > 1 ? ( {options.length > 1 ? (
<Cascader <Cascader
options={options} options={options}