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[]) => { 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 handleGpuSelectorChange = (value: any[]) => { const handleGpuSelectorChange = (value: any[]) => {
handleBeforeGpuSelectorChange(value); 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 resetFieldsByModel = ['backend_version', 'backend_parameters', 'env'];
const pickFieldsFromSpec = ['backend_version', 'backend_parameters', 'env']; const pickFieldsFromSpec = ['backend_version', 'backend_parameters', 'env'];
const dropFieldsFromForm = ['name', 'file_name', 'repo_id', 'backend']; const dropFieldsFromForm = ['name', 'file_name', 'repo_id', 'backend'];
const resetFields = ['worker_selector', 'env'];
const resetFieldsByFile = [ const resetFieldsByFile = [
'cpu_offloading', 'cpu_offloading',
@@ -309,14 +310,11 @@ const AddModal: FC<AddModalProps> = (props) => {
updateSelectedModel(item); updateSelectedModel(item);
// TODO // TODO
form.current?.form?.setFieldsValue(defaultFormValues); form.current?.resetFields(resetFields);
const modelInfo = onSelectModel(item, props.source); const modelInfo = onSelectModel(item, props.source);
form.current?.setFieldsValue?.({ form.current?.setFieldsValue?.({
...defaultFormValues,
...modelInfo, ...modelInfo,
..._.omit(form.current?.form?.getFieldsValue?.(), [
...dropFieldsFromForm,
...pickFieldsFromSpec
]),
categories: getCategory(item) categories: getCategory(item)
}); });
@@ -343,7 +341,7 @@ const AddModal: FC<AddModalProps> = (props) => {
} }
if (manual) { if (manual) {
form.current?.form?.setFieldsValue(defaultFormValues); form.current?.resetFields(resetFields);
} }
// If the item is empty // If the item is empty
setIsGGUF(item.isGGUF); setIsGGUF(item.isGGUF);
@@ -360,20 +358,22 @@ const AddModal: FC<AddModalProps> = (props) => {
item.evaluated item.evaluated
) { ) {
handleShowCompatibleAlert(item.evaluateResult); handleShowCompatibleAlert(item.evaluateResult);
const newFormValues = { const newFormValues = {
...(manual
? { ...defaultFormValues }
: _.omit(form.current?.form?.getFieldsValue?.(), [
...dropFieldsFromForm
])),
...getDefaultSpec(item), ...getDefaultSpec(item),
...modelInfo, ...modelInfo,
..._.omit(form.current?.form?.getFieldsValue?.(), [
...dropFieldsFromForm,
...pickFieldsFromSpec
]),
name: generateNameValue(item, modelInfo.name, manual), name: generateNameValue(item, modelInfo.name, manual),
categories: getCategory(item) categories: getCategory(item)
}; };
console.log('newFormValues:', newFormValues); console.log('newFormValues:', newFormValues);
form.current?.setFieldsValue?.(newFormValues); form.current?.form?.setFieldsValue?.(newFormValues);
handleOnValuesChangeBefore({ handleOnValuesChangeBefore({
changedValues: {}, changedValues: {},
-1
View File
@@ -429,7 +429,6 @@ export const excludeFields = [
'repo_id', 'repo_id',
'file_name', 'file_name',
'replicas', 'replicas',
'categories',
'name', 'name',
'description', 'description',
'env', 'env',
+1
View File
@@ -634,6 +634,7 @@ export const useSelectModel = (data: { gpuOptions: any[] }) => {
repo_id: selectModel.name, repo_id: selectModel.name,
file_name: '', file_name: '',
name: name, name: name,
source: source,
backend: backend backend: backend
}; };
}; };
+1 -1
View File
@@ -37,7 +37,7 @@ export const rerankerSamples: Record<
} }
> = { > = {
'zh-CN': { 'zh-CN': {
query: '', query: '如何提高睡眠质量?',
documents: [ documents: [
'保持规律的作息时间,晚上避免使用电子产品。', '保持规律的作息时间,晚上避免使用电子产品。',
'参加更多社交活动有助于提高情绪。', '参加更多社交活动有助于提高情绪。',