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

View File

@@ -3,6 +3,7 @@ import { IChooseAdapterEntity } from '@/app/home/bots/components/bot-form/Choose
import {
DynamicFormItemConfig,
IDynamicFormItemConfig,
getDefaultValues,
parseDynamicFormItemType,
} from '@/app/home/components/dynamic-form/DynamicFormItemConfig';
import { UUID } from 'uuidjs';
@@ -182,6 +183,9 @@ export default function BotForm({
console.log(dynamicFormConfigList);
if (dynamicFormConfigList) {
setDynamicFormConfigList(dynamicFormConfigList);
if (!initBotId) {
form.setValue('adapter_config', getDefaultValues(dynamicFormConfigList));
}
}
setShowDynamicForm(true);
} else {
@@ -209,7 +213,7 @@ export default function BotForm({
name: form.getValues().name,
description: form.getValues().description,
adapter: form.getValues().adapter,
adapter_config: value,
adapter_config: form.getValues().adapter_config,
};
httpClient
.updateBot(initBotId, updateBot)
@@ -241,7 +245,7 @@ export default function BotForm({
name: form.getValues().name,
description: form.getValues().description,
adapter: form.getValues().adapter,
adapter_config: value,
adapter_config: form.getValues().adapter_config,
};
httpClient
.createBot(newBot)

View File

@@ -54,3 +54,10 @@ export function isDynamicFormItemType(
export function parseDynamicFormItemType(value: string): DynamicFormItemType {
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>);
}