fix: reset form after switch model

This commit is contained in:
jialin
2025-07-07 17:40:09 +08:00
parent 69cceb4fc7
commit 642ac3ebc4
5 changed files with 15 additions and 22 deletions
@@ -186,14 +186,7 @@ const AdvanceConfig: React.FC<AdvanceConfigProps> = (props) => {
}
};
const handleBeforeGpuSelectorChange = (gpuIds: any[]) => {
// if (backend !== backendOptionsMap.ascendMindie || !gpuIds?.length) {
// return;
// }
// const lastGroupName = gpuIds[gpuIds.length - 1][0];
// const lastGroupItems = gpuIds.filter((item) => item[0] === lastGroupName);
// form.setFieldValue(['gpu_selector', 'gpu_ids'], lastGroupItems);
};
const handleBeforeGpuSelectorChange = (gpuIds: any[]) => {};
const handleGpuSelectorChange = (value: any[]) => {
handleBeforeGpuSelectorChange(value);
@@ -548,4 +541,4 @@ const AdvanceConfig: React.FC<AdvanceConfigProps> = (props) => {
);
};
export default React.memo(AdvanceConfig);
export default AdvanceConfig;
+11 -11
View File
@@ -37,6 +37,7 @@ import TitleWrapper from './title-wrapper';
const resetFieldsByModel = ['backend_version', 'backend_parameters', 'env'];
const pickFieldsFromSpec = ['backend_version', 'backend_parameters', 'env'];
const dropFieldsFromForm = ['name', 'file_name', 'repo_id', 'backend'];
const resetFields = ['worker_selector', 'env'];
const resetFieldsByFile = [
'cpu_offloading',
@@ -309,14 +310,11 @@ const AddModal: FC<AddModalProps> = (props) => {
updateSelectedModel(item);
// TODO
form.current?.form?.setFieldsValue(defaultFormValues);
form.current?.resetFields(resetFields);
const modelInfo = onSelectModel(item, props.source);
form.current?.setFieldsValue?.({
...defaultFormValues,
...modelInfo,
..._.omit(form.current?.form?.getFieldsValue?.(), [
...dropFieldsFromForm,
...pickFieldsFromSpec
]),
categories: getCategory(item)
});
@@ -343,7 +341,7 @@ const AddModal: FC<AddModalProps> = (props) => {
}
if (manual) {
form.current?.form?.setFieldsValue(defaultFormValues);
form.current?.resetFields(resetFields);
}
// If the item is empty
setIsGGUF(item.isGGUF);
@@ -360,20 +358,22 @@ const AddModal: FC<AddModalProps> = (props) => {
item.evaluated
) {
handleShowCompatibleAlert(item.evaluateResult);
const newFormValues = {
...(manual
? { ...defaultFormValues }
: _.omit(form.current?.form?.getFieldsValue?.(), [
...dropFieldsFromForm
])),
...getDefaultSpec(item),
...modelInfo,
..._.omit(form.current?.form?.getFieldsValue?.(), [
...dropFieldsFromForm,
...pickFieldsFromSpec
]),
name: generateNameValue(item, modelInfo.name, manual),
categories: getCategory(item)
};
console.log('newFormValues:', newFormValues);
form.current?.setFieldsValue?.(newFormValues);
form.current?.form?.setFieldsValue?.(newFormValues);
handleOnValuesChangeBefore({
changedValues: {},