fix: async bugs in BotForm

This commit is contained in:
Junyan Qin
2025-05-08 12:23:24 +08:00
parent 436b45c05c
commit ef6be4dfd9
@@ -100,7 +100,7 @@ export default function BotForm({
const [isLoading, setIsLoading] = useState<boolean>(false); const [isLoading, setIsLoading] = useState<boolean>(false);
useEffect(() => { useEffect(() => {
initBotFormComponent(); initBotFormComponent().then(() => {
// 拉取初始化表单信息 // 拉取初始化表单信息
if (initBotId) { if (initBotId) {
@@ -115,18 +115,31 @@ export default function BotForm({
handleAdapterSelect(val.adapter); handleAdapterSelect(val.adapter);
// dynamicForm.setFieldsValue(val.adapter_config); // dynamicForm.setFieldsValue(val.adapter_config);
}); });
} else { } else {
form.reset(); form.reset();
} }
})
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, []); }, []);
async function initBotFormComponent() { 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 // 拉取adapter
const rawAdapterList = await httpClient.getAdapters(); const adaptersRes = await httpClient.getAdapters();
// 初始化适配器选择列表 console.log('rawAdapterList', adaptersRes);
setAdapterNameList( setAdapterNameList(
rawAdapterList.adapters.map((item) => { adaptersRes.adapters.map((item) => {
return { return {
label: item.label.zh_CN, label: item.label.zh_CN,
value: item.name, value: item.name,
@@ -136,7 +149,7 @@ export default function BotForm({
// 初始化适配器图标列表 // 初始化适配器图标列表
setAdapterIconList( setAdapterIconList(
rawAdapterList.adapters.reduce((acc, item) => { adaptersRes.adapters.reduce((acc, item) => {
acc[item.name] = httpClient.getAdapterIconURL(item.name); acc[item.name] = httpClient.getAdapterIconURL(item.name);
return acc; return acc;
}, {} as Record<string, string>), }, {} as Record<string, string>),
@@ -144,27 +157,14 @@ export default function BotForm({
// 初始化适配器描述列表 // 初始化适配器描述列表
setAdapterDescriptionList( setAdapterDescriptionList(
rawAdapterList.adapters.reduce((acc, item) => { adaptersRes.adapters.reduce((acc, item) => {
acc[item.name] = item.description.zh_CN; acc[item.name] = item.description.zh_CN;
return acc; return acc;
}, {} as Record<string, string>), }, {} as Record<string, string>),
); );
if (initBotId) {
// 初始化流水线列表
const rawPipelineList = await httpClient.getPipelines();
setPipelineNameList(
rawPipelineList.pipelines.map((item) => {
return {
label: item.name,
value: item.uuid,
};
}),
);
}
// 初始化适配器表单map // 初始化适配器表单map
rawAdapterList.adapters.forEach((rawAdapter) => { adaptersRes.adapters.forEach((rawAdapter) => {
adapterNameToDynamicConfigMap.set( adapterNameToDynamicConfigMap.set(
rawAdapter.name, rawAdapter.name,
rawAdapter.spec.config.map( rawAdapter.spec.config.map(
@@ -198,7 +198,7 @@ export default function BotForm({
name: bot.name, name: bot.name,
adapter_config: bot.adapter_config, adapter_config: bot.adapter_config,
enable: bot.enable ?? true, enable: bot.enable ?? true,
use_pipeline_uuid: bot.use_pipeline_uuid, use_pipeline_uuid: bot.use_pipeline_uuid ?? '',
}; };
} }