chore: allow space in backend parameters

This commit is contained in:
jialin
2025-12-01 10:06:00 +08:00
parent 769cc09906
commit 14f0afec08
5 changed files with 32 additions and 12 deletions
+5 -7
View File
@@ -8,13 +8,14 @@ interface HintInputProps {
onChange: (value: string) => void; onChange: (value: string) => void;
onBlur?: (e: any) => void; onBlur?: (e: any) => void;
placeholder?: string; placeholder?: string;
trim?: boolean;
sourceOptions?: Global.HintOptions[]; sourceOptions?: Global.HintOptions[];
} }
const matchReg = /[^=]+=[^=]*$/; const matchReg = /[^=]+=[^=]*$/;
const HintInput: React.FC<HintInputProps> = (props) => { const HintInput: React.FC<HintInputProps> = (props) => {
const { value, label, onChange, onBlur, sourceOptions } = props; const { value, label, onChange, onBlur, sourceOptions, trim = true } = props;
const cursorPosRef = React.useRef(0); const cursorPosRef = React.useRef(0);
const contextBeforeCursorRef = React.useRef(''); const contextBeforeCursorRef = React.useRef('');
const [options, setOptions] = React.useState< const [options, setOptions] = React.useState<
@@ -70,11 +71,7 @@ const HintInput: React.FC<HintInputProps> = (props) => {
const handleInput = (e: any) => { const handleInput = (e: any) => {
getContextBeforeCursor(e); getContextBeforeCursor(e);
onChange(e.target.value?.trim()); onChange(e.target.value);
};
const handleOnChange = (value: string) => {
onChange(value?.trim());
}; };
const handleOnSelect = (value: string) => { const handleOnSelect = (value: string) => {
@@ -93,9 +90,10 @@ const HintInput: React.FC<HintInputProps> = (props) => {
onBlur={onBlur} onBlur={onBlur}
label={label} label={label}
options={options} options={options}
trim={trim}
style={{ width: '100%' }} style={{ width: '100%' }}
/> />
); );
}; };
export default React.memo(HintInput); export default HintInput;
+4 -3
View File
@@ -1,4 +1,3 @@
import { useIntl } from '@umijs/max';
import _ from 'lodash'; import _ from 'lodash';
import React from 'react'; import React from 'react';
import Wrapper from '../label-selector/wrapper'; import Wrapper from '../label-selector/wrapper';
@@ -12,13 +11,13 @@ interface ListInputProps {
options?: Global.HintOptions[]; options?: Global.HintOptions[];
placeholder?: string; placeholder?: string;
labelExtra?: React.ReactNode; labelExtra?: React.ReactNode;
trim?: boolean;
onChange: (data: string[]) => void; onChange: (data: string[]) => void;
onBlur?: (e: any, index: number) => void; onBlur?: (e: any, index: number) => void;
onDelete?: (index: number) => void; onDelete?: (index: number) => void;
} }
const ListInput: React.FC<ListInputProps> = (props) => { const ListInput: React.FC<ListInputProps> = (props) => {
const intl = useIntl();
const { const {
dataList, dataList,
label, label,
@@ -28,7 +27,8 @@ const ListInput: React.FC<ListInputProps> = (props) => {
onDelete, onDelete,
btnText, btnText,
options, options,
labelExtra labelExtra,
trim = true
} = props; } = props;
const [list, setList] = React.useState<{ value: string; uid: number }[]>([]); const [list, setList] = React.useState<{ value: string; uid: number }[]>([]);
const countRef = React.useRef(0); const countRef = React.useRef(0);
@@ -97,6 +97,7 @@ const ListInput: React.FC<ListInputProps> = (props) => {
onBlur={(e) => onBlur?.(e, index)} onBlur={(e) => onBlur?.(e, index)}
onRemove={() => handleOnRemove(index)} onRemove={() => handleOnRemove(index)}
onChange={(val) => handleOnChange(val, index)} onChange={(val) => handleOnChange(val, index)}
trim={trim}
/> />
); );
})} })}
+12 -2
View File
@@ -13,10 +13,19 @@ interface LabelItemProps {
label?: string; label?: string;
placeholder?: string; placeholder?: string;
options?: Global.HintOptions[]; options?: Global.HintOptions[];
trim?: boolean;
} }
const ListItem: React.FC<LabelItemProps> = (props) => { const ListItem: React.FC<LabelItemProps> = (props) => {
const { onRemove, onChange, onBlur, label, value, options } = props; const {
onRemove,
onChange,
onBlur,
label,
value,
options,
trim = true
} = props;
const handleOnChange = (value: any) => { const handleOnChange = (value: any) => {
onChange(value); onChange(value);
@@ -30,6 +39,7 @@ const ListItem: React.FC<LabelItemProps> = (props) => {
onBlur={onBlur} onBlur={onBlur}
label={label} label={label}
sourceOptions={options} sourceOptions={options}
trim={trim}
placeholder={props.placeholder} placeholder={props.placeholder}
/> />
<Button <Button
@@ -44,4 +54,4 @@ const ListItem: React.FC<LabelItemProps> = (props) => {
); );
}; };
export default React.memo(ListItem); export default ListItem;
@@ -90,6 +90,14 @@ const SealAutoComplete: React.FC<
const handleOnSelect = (value: any, option: any) => { const handleOnSelect = (value: any, option: any) => {
onSelect?.(value, option); onSelect?.(value, option);
}; };
const handleOnInput = (e: any) => {
if (trim) {
e.target.value = e.target.value?.trim();
}
props.onInput?.(e);
};
const renderAfter = () => { const renderAfter = () => {
if (loading) { if (loading) {
return ( return (
@@ -123,6 +131,7 @@ const SealAutoComplete: React.FC<
> >
<AutoComplete <AutoComplete
{...rest} {...rest}
trim={trim}
ref={inputRef} ref={inputRef}
placeholder={ placeholder={
isFocus || !label ? ( isFocus || !label ? (
@@ -141,6 +150,7 @@ const SealAutoComplete: React.FC<
onSearch={handleSearch} onSearch={handleSearch}
onChange={handleChange} onChange={handleChange}
popupRender={popupRender} popupRender={popupRender}
onInput={handleOnInput}
></AutoComplete> ></AutoComplete>
</Wrapper> </Wrapper>
</SelectWrapper> </SelectWrapper>
@@ -39,6 +39,7 @@ const BackendParametersList: React.FC = () => {
return ( return (
<Form.Item<FormData> name="backend_parameters"> <Form.Item<FormData> name="backend_parameters">
<ListInput <ListInput
trim={false}
placeholder={ placeholder={
backendParamsHolderTips[backend] backendParamsHolderTips[backend]
? intl.formatMessage({ ? intl.formatMessage({