mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-07-20 19:36:08 +00:00
fix(botForm): default value not set to adapter_config while creating bot
This commit is contained in:
@@ -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>);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user