fix(botForm): default value not set to adapter_config while creating bot

This commit is contained in:
Junyan Qin
2025-05-08 11:39:27 +08:00
parent 4604f70a57
commit 2893c30f5c
2 changed files with 13 additions and 2 deletions
@@ -3,6 +3,7 @@ import { IChooseAdapterEntity } from '@/app/home/bots/components/bot-form/Choose
import { import {
DynamicFormItemConfig, DynamicFormItemConfig,
IDynamicFormItemConfig, IDynamicFormItemConfig,
getDefaultValues,
parseDynamicFormItemType, parseDynamicFormItemType,
} from '@/app/home/components/dynamic-form/DynamicFormItemConfig'; } from '@/app/home/components/dynamic-form/DynamicFormItemConfig';
import { UUID } from 'uuidjs'; import { UUID } from 'uuidjs';
@@ -182,6 +183,9 @@ export default function BotForm({
console.log(dynamicFormConfigList); console.log(dynamicFormConfigList);
if (dynamicFormConfigList) { if (dynamicFormConfigList) {
setDynamicFormConfigList(dynamicFormConfigList); setDynamicFormConfigList(dynamicFormConfigList);
if (!initBotId) {
form.setValue('adapter_config', getDefaultValues(dynamicFormConfigList));
}
} }
setShowDynamicForm(true); setShowDynamicForm(true);
} else { } else {
@@ -209,7 +213,7 @@ export default function BotForm({
name: form.getValues().name, name: form.getValues().name,
description: form.getValues().description, description: form.getValues().description,
adapter: form.getValues().adapter, adapter: form.getValues().adapter,
adapter_config: value, adapter_config: form.getValues().adapter_config,
}; };
httpClient httpClient
.updateBot(initBotId, updateBot) .updateBot(initBotId, updateBot)
@@ -241,7 +245,7 @@ export default function BotForm({
name: form.getValues().name, name: form.getValues().name,
description: form.getValues().description, description: form.getValues().description,
adapter: form.getValues().adapter, adapter: form.getValues().adapter,
adapter_config: value, adapter_config: form.getValues().adapter_config,
}; };
httpClient httpClient
.createBot(newBot) .createBot(newBot)
@@ -54,3 +54,10 @@ export function isDynamicFormItemType(
export function parseDynamicFormItemType(value: string): DynamicFormItemType { export function parseDynamicFormItemType(value: string): DynamicFormItemType {
return isDynamicFormItemType(value) ? value : DynamicFormItemType.UNKNOWN; return isDynamicFormItemType(value) ? value : DynamicFormItemType.UNKNOWN;
} }
export function getDefaultValues(itemConfigList: IDynamicFormItemConfig[]): Record<string, any> {
return itemConfigList.reduce((acc, item) => {
acc[item.name] = item.default;
return acc;
}, {} as Record<string, any>);
}