mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-23 10:37:13 +00:00
fix: async bugs in BotForm
This commit is contained in:
@@ -100,7 +100,7 @@ export default function BotForm({
|
||||
const [isLoading, setIsLoading] = useState<boolean>(false);
|
||||
|
||||
useEffect(() => {
|
||||
initBotFormComponent();
|
||||
initBotFormComponent().then(() => {
|
||||
|
||||
// 拉取初始化表单信息
|
||||
if (initBotId) {
|
||||
@@ -115,18 +115,31 @@ export default function BotForm({
|
||||
handleAdapterSelect(val.adapter);
|
||||
// dynamicForm.setFieldsValue(val.adapter_config);
|
||||
});
|
||||
|
||||
} else {
|
||||
form.reset();
|
||||
}
|
||||
})
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
async function initBotFormComponent() {
|
||||
// 初始化流水线列表
|
||||
const pipelinesRes = await httpClient.getPipelines();
|
||||
console.log('rawPipelineList', pipelinesRes);
|
||||
setPipelineNameList(
|
||||
pipelinesRes.pipelines.map((item) => {
|
||||
return {
|
||||
label: item.name,
|
||||
value: item.uuid,
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
||||
// 拉取adapter
|
||||
const rawAdapterList = await httpClient.getAdapters();
|
||||
// 初始化适配器选择列表
|
||||
const adaptersRes = await httpClient.getAdapters();
|
||||
console.log('rawAdapterList', adaptersRes);
|
||||
setAdapterNameList(
|
||||
rawAdapterList.adapters.map((item) => {
|
||||
adaptersRes.adapters.map((item) => {
|
||||
return {
|
||||
label: item.label.zh_CN,
|
||||
value: item.name,
|
||||
@@ -136,7 +149,7 @@ export default function BotForm({
|
||||
|
||||
// 初始化适配器图标列表
|
||||
setAdapterIconList(
|
||||
rawAdapterList.adapters.reduce((acc, item) => {
|
||||
adaptersRes.adapters.reduce((acc, item) => {
|
||||
acc[item.name] = httpClient.getAdapterIconURL(item.name);
|
||||
return acc;
|
||||
}, {} as Record<string, string>),
|
||||
@@ -144,27 +157,14 @@ export default function BotForm({
|
||||
|
||||
// 初始化适配器描述列表
|
||||
setAdapterDescriptionList(
|
||||
rawAdapterList.adapters.reduce((acc, item) => {
|
||||
adaptersRes.adapters.reduce((acc, item) => {
|
||||
acc[item.name] = item.description.zh_CN;
|
||||
return acc;
|
||||
}, {} as Record<string, string>),
|
||||
);
|
||||
|
||||
if (initBotId) {
|
||||
// 初始化流水线列表
|
||||
const rawPipelineList = await httpClient.getPipelines();
|
||||
setPipelineNameList(
|
||||
rawPipelineList.pipelines.map((item) => {
|
||||
return {
|
||||
label: item.name,
|
||||
value: item.uuid,
|
||||
};
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
// 初始化适配器表单map
|
||||
rawAdapterList.adapters.forEach((rawAdapter) => {
|
||||
adaptersRes.adapters.forEach((rawAdapter) => {
|
||||
adapterNameToDynamicConfigMap.set(
|
||||
rawAdapter.name,
|
||||
rawAdapter.spec.config.map(
|
||||
@@ -198,7 +198,7 @@ export default function BotForm({
|
||||
name: bot.name,
|
||||
adapter_config: bot.adapter_config,
|
||||
enable: bot.enable ?? true,
|
||||
use_pipeline_uuid: bot.use_pipeline_uuid,
|
||||
use_pipeline_uuid: bot.use_pipeline_uuid ?? '',
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user