fix: check the image and run_command valid when select custom backend

This commit is contained in:
jialin
2025-11-23 18:51:01 +08:00
parent 2ecf83ddae
commit 782e81568d
4 changed files with 48 additions and 38 deletions
+12 -30
View File
@@ -1,12 +1,6 @@
import { Form, Input } from 'antd'; import { Form, Input } from 'antd';
import type { TextAreaProps } from 'antd/es/input/TextArea'; import type { TextAreaProps } from 'antd/es/input/TextArea';
import React, { import React, { useEffect, useMemo, useRef, useState } from 'react';
useCallback,
useEffect,
useMemo,
useRef,
useState
} from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import { SealFormItemProps } from './types'; import { SealFormItemProps } from './types';
import Wrapper from './wrapper'; import Wrapper from './wrapper';
@@ -73,46 +67,34 @@ const SealTextArea: React.FC<InputTextareaProps & SealFormItemProps> = (
return focusRows; return focusRows;
}, [props.autoSize, isFocus, scaleSize]); }, [props.autoSize, isFocus, scaleSize]);
const handleClickWrapper = useCallback(() => { const handleClickWrapper = () => {
if (!props.disabled && !isFocus) { if (!props.disabled && !isFocus) {
inputRef.current?.focus?.({ inputRef.current?.focus?.({
cursor: 'all' cursor: 'all'
}); });
setIsFocus(true); setIsFocus(true);
} }
}, [props.disabled, isFocus]); };
const handleChange = useCallback( const handleChange = (e: any) => {
(e: any) => {
onChange?.(e); onChange?.(e);
}, };
[onChange]
);
const handleOnFocus = useCallback( const handleOnFocus = (e: any) => {
(e: any) => {
setIsFocus(true); setIsFocus(true);
onFocus?.(e); onFocus?.(e);
}, };
[onFocus]
);
const handleOnBlur = useCallback( const handleOnBlur = (e: any) => {
(e: any) => {
if (!inputRef.current?.resizableTextArea?.textArea?.value) { if (!inputRef.current?.resizableTextArea?.textArea?.value) {
setIsFocus(false); setIsFocus(false);
onBlur?.(e);
} }
}, onBlur?.(e);
[onBlur, scaleSize] };
);
const handleInput = useCallback( const handleInput = (e: any) => {
(e: any) => {
onInput?.(e); onInput?.(e);
}, };
[onInput]
);
console.log('style=========', style, rest); console.log('style=========', style, rest);
@@ -17,7 +17,6 @@ export const backendOptionsMap = {
}; };
export const BuiltInBackendOptions = [ export const BuiltInBackendOptions = [
backendOptionsMap.vllm,
backendOptionsMap.ascendMindie, backendOptionsMap.ascendMindie,
backendOptionsMap.SGLang, backendOptionsMap.SGLang,
backendOptionsMap.voxBox backendOptionsMap.voxBox
@@ -5,6 +5,7 @@ import { useIntl } from '@umijs/max';
import { Form } from 'antd'; import { Form } from 'antd';
import React from 'react'; import React from 'react';
import { backendOptionsMap } from '../config/backend-parameters'; import { backendOptionsMap } from '../config/backend-parameters';
import { useFormContext } from '../config/form-context';
import { FormData } from '../config/types'; import { FormData } from '../config/types';
const CustomBackend: React.FC = () => { const CustomBackend: React.FC = () => {
@@ -12,6 +13,23 @@ const CustomBackend: React.FC = () => {
const { getRuleMessage } = useAppUtils(); const { getRuleMessage } = useAppUtils();
const form = Form.useFormInstance(); const form = Form.useFormInstance();
const backend = Form.useWatch('backend', form); const backend = Form.useWatch('backend', form);
const { onValuesChange } = useFormContext();
const handleImageNameOnBlur = (e: React.FocusEvent<HTMLInputElement>) => {
const value = e.target.value;
const runCommand = form.getFieldValue('run_command');
if (value && runCommand) {
onValuesChange?.({ image_name: value }, form.getFieldsValue());
}
};
const handleRunCommandOnBlur = (e: React.FocusEvent<HTMLTextAreaElement>) => {
const value = e.target.value;
const imageName = form.getFieldValue('image_name');
if (value && imageName) {
onValuesChange?.({ run_command: value }, form.getFieldsValue());
}
};
return ( return (
<> <>
@@ -29,6 +47,7 @@ const CustomBackend: React.FC = () => {
<SealInput.Input <SealInput.Input
required required
allowClear allowClear
onBlur={handleImageNameOnBlur}
label={intl.formatMessage({ id: 'backend.imageName' })} label={intl.formatMessage({ id: 'backend.imageName' })}
></SealInput.Input> ></SealInput.Input>
</Form.Item> </Form.Item>
@@ -46,6 +65,7 @@ const CustomBackend: React.FC = () => {
required required
scaleSize={false} scaleSize={false}
alwaysFocus={true} alwaysFocus={true}
onBlur={handleRunCommandOnBlur}
autoSize={{ minRows: 2, maxRows: 4 }} autoSize={{ minRows: 2, maxRows: 4 }}
label={intl.formatMessage({ id: 'backend.runCommand' })} label={intl.formatMessage({ id: 'backend.runCommand' })}
description={intl.formatMessage({ description={intl.formatMessage({
+9
View File
@@ -240,6 +240,15 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
...updateKVCacheConfig(val, option), ...updateKVCacheConfig(val, option),
...updateGPUSelector(val) ...updateGPUSelector(val)
}); });
const imageName = form.getFieldValue('image_name');
const runCommand = form.getFieldValue('run_command');
// if the image_name or run_command is empty, set them to default value of the backend
if (val === backendOptionsMap.custom && !imageName && !runCommand) {
return;
}
onBackendChange?.(val); onBackendChange?.(val);
}; };