feat: enhance input field configurations with blur listeners and update translations for display name

pull/21398/head
twwu 11 months ago
parent 5193fa2118
commit 4a249c40b1

@ -50,6 +50,7 @@ const InputField = ({
return ( return (
<form.AppField <form.AppField
name={variable} name={variable}
listeners={listeners}
children={field => ( children={field => (
<field.TextField <field.TextField
label={label} label={label}

@ -64,11 +64,12 @@ export const useHiddenFieldNames = (type: PipelineInputVarType) => {
} }
export const useConfigurations = (props: { export const useConfigurations = (props: {
getFieldValue: (fieldName: DeepKeys<FormData>) => any,
setFieldValue: (fieldName: DeepKeys<FormData>, value: any) => void, setFieldValue: (fieldName: DeepKeys<FormData>, value: any) => void,
supportFile: boolean supportFile: boolean
}) => { }) => {
const { t } = useTranslation() const { t } = useTranslation()
const { setFieldValue, supportFile } = props const { getFieldValue, setFieldValue, supportFile } = props
const handleTypeChange = useCallback((type: PipelineInputVarType) => { const handleTypeChange = useCallback((type: PipelineInputVarType) => {
if ([PipelineInputVarType.singleFile, PipelineInputVarType.multiFiles].includes(type)) { if ([PipelineInputVarType.singleFile, PipelineInputVarType.multiFiles].includes(type)) {
@ -84,6 +85,17 @@ export const useConfigurations = (props: {
setFieldValue('maxLength', DEFAULT_VALUE_MAX_LEN) setFieldValue('maxLength', DEFAULT_VALUE_MAX_LEN)
}, [setFieldValue]) }, [setFieldValue])
const handleVariableNameBlur = useCallback((value: string) => {
if (!value)
return
setFieldValue('label', value)
}, [setFieldValue])
const handleDisplayNameBlur = useCallback((value: string) => {
if (!value)
setFieldValue('label', getFieldValue('variable'))
}, [getFieldValue, setFieldValue])
const initialConfigurations = useMemo((): InputFieldConfiguration[] => { const initialConfigurations = useMemo((): InputFieldConfiguration[] => {
return [{ return [{
type: InputFieldType.inputTypeSelect, type: InputFieldType.inputTypeSelect,
@ -101,13 +113,19 @@ export const useConfigurations = (props: {
variable: 'variable', variable: 'variable',
placeholder: t('appDebug.variableConfig.inputPlaceholder'), placeholder: t('appDebug.variableConfig.inputPlaceholder'),
required: true, required: true,
listeners: {
onBlur: ({ value }) => handleVariableNameBlur(value),
},
showConditions: [], showConditions: [],
}, { }, {
type: InputFieldType.textInput, type: InputFieldType.textInput,
label: t('appDebug.variableConfig.labelName'), label: t('appDebug.variableConfig.displayName'),
variable: 'label', variable: 'label',
placeholder: t('appDebug.variableConfig.inputPlaceholder'), placeholder: t('appDebug.variableConfig.inputPlaceholder'),
required: true, required: false,
listeners: {
onBlur: ({ value }) => handleDisplayNameBlur(value),
},
showConditions: [], showConditions: [],
}, { }, {
type: InputFieldType.numberInput, type: InputFieldType.numberInput,
@ -155,7 +173,7 @@ export const useConfigurations = (props: {
required: true, required: true,
showConditions: [], showConditions: [],
}] }]
}, [handleTypeChange, supportFile, t]) }, [t, supportFile, handleTypeChange, handleVariableNameBlur, handleDisplayNameBlur])
return initialConfigurations return initialConfigurations
} }

@ -16,11 +16,16 @@ const InitialFields = ({
render: function Render({ render: function Render({
form, form,
}) { }) {
const getFieldValue = useCallback((fieldName: string) => {
return form.getFieldValue(fieldName)
}, [form])
const setFieldValue = useCallback((fieldName: string, value: any) => { const setFieldValue = useCallback((fieldName: string, value: any) => {
form.setFieldValue(fieldName, value) form.setFieldValue(fieldName, value)
}, [form]) }, [form])
const initialConfigurations = useConfigurations({ const initialConfigurations = useConfigurations({
getFieldValue,
setFieldValue, setFieldValue,
supportFile, supportFile,
}) })

@ -69,7 +69,7 @@ const CrawledResult = ({
onChange={handleCheckedAll} label={isCheckAll ? t(`${I18N_PREFIX}.resetAll`) : t(`${I18N_PREFIX}.selectAll`)} onChange={handleCheckedAll} label={isCheckAll ? t(`${I18N_PREFIX}.resetAll`) : t(`${I18N_PREFIX}.selectAll`)}
/> />
</div> </div>
<div className='flex flex-col gap-y-px border-t border-divider-subtle bg-background-default-subtle p-2'> <div className='flex flex-col gap-y-px overflow-hidden border-t border-divider-subtle bg-background-default-subtle p-2'>
{list.map((item, index) => ( {list.map((item, index) => (
<CrawledResultItem <CrawledResultItem
key={item.source_url} key={item.source_url}

@ -90,6 +90,7 @@ const Options = ({
<Button <Button
variant='primary' variant='primary'
onClick={form.handleSubmit} onClick={form.handleSubmit}
disabled={isRunning}
loading={isRunning} loading={isRunning}
className='shrink-0 gap-x-0.5' className='shrink-0 gap-x-0.5'
spinnerClassName='!ml-0' spinnerClassName='!ml-0'

@ -365,6 +365,7 @@ const translation = {
'apiBasedVar': 'API-based Variable', 'apiBasedVar': 'API-based Variable',
'varName': 'Variable Name', 'varName': 'Variable Name',
'labelName': 'Label Name', 'labelName': 'Label Name',
'displayName': 'Display Name',
'inputPlaceholder': 'Please input', 'inputPlaceholder': 'Please input',
'content': 'Content', 'content': 'Content',
'required': 'Required', 'required': 'Required',

@ -360,6 +360,7 @@ const translation = {
'varName': '变量名称', 'varName': '变量名称',
'inputPlaceholder': '请输入', 'inputPlaceholder': '请输入',
'labelName': '显示名称', 'labelName': '显示名称',
'displayName': '显示名称',
'required': '必填', 'required': '必填',
'hide': '隐藏', 'hide': '隐藏',
'placeholder': '占位符', 'placeholder': '占位符',

Loading…
Cancel
Save