mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-14 14:31:00 +00:00
refactor: delete empty components
This commit is contained in:
@@ -9,7 +9,7 @@ import BotForm from '@/app/home/bots/components/bot-form/BotForm';
|
|||||||
import BotCard from '@/app/home/bots/components/bot-card/BotCard';
|
import BotCard from '@/app/home/bots/components/bot-card/BotCard';
|
||||||
import CreateCardComponent from '@/app/infra/basic-component/create-card-component/CreateCardComponent';
|
import CreateCardComponent from '@/app/infra/basic-component/create-card-component/CreateCardComponent';
|
||||||
import { httpClient } from '@/app/infra/http/HttpClient';
|
import { httpClient } from '@/app/infra/http/HttpClient';
|
||||||
import { Bot, Adapter } from '@/app/infra/api/api-types';
|
import { Bot, Adapter } from '@/app/infra/entities/api';
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
@@ -20,27 +20,14 @@ import {
|
|||||||
} from "@/components/ui/dialog"
|
} from "@/components/ui/dialog"
|
||||||
|
|
||||||
export default function BotConfigPage() {
|
export default function BotConfigPage() {
|
||||||
const router = useRouter();
|
|
||||||
const [pageShowRule, setPageShowRule] = useState<BotConfigPageShowRule>(
|
|
||||||
BotConfigPageShowRule.NO_BOT,
|
|
||||||
);
|
|
||||||
const [modalOpen, setModalOpen] = useState<boolean>(false);
|
const [modalOpen, setModalOpen] = useState<boolean>(false);
|
||||||
const [botList, setBotList] = useState<BotCardVO[]>([]);
|
const [botList, setBotList] = useState<BotCardVO[]>([]);
|
||||||
const [isEditForm, setIsEditForm] = useState(false);
|
const [isEditForm, setIsEditForm] = useState(false);
|
||||||
const [nowSelectedBotCard, setNowSelectedBotCard] = useState<BotCardVO>();
|
const [nowSelectedBotCard, setNowSelectedBotCard] = useState<BotCardVO>();
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// TODO:补齐加载转圈逻辑
|
// TODO:补齐加载转圈逻辑
|
||||||
setIsLoading(true);
|
|
||||||
checkHasLLM().then((hasLLM) => {
|
|
||||||
if (hasLLM) {
|
|
||||||
getBotList();
|
|
||||||
} else {
|
|
||||||
setPageShowRule(BotConfigPageShowRule.NO_LLM);
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
async function checkHasLLM(): Promise<boolean> {
|
async function checkHasLLM(): Promise<boolean> {
|
||||||
@@ -49,7 +36,6 @@ export default function BotConfigPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getBotList() {
|
async function getBotList() {
|
||||||
setIsLoading(true);
|
|
||||||
|
|
||||||
const adapterListResp = await httpClient.getAdapters();
|
const adapterListResp = await httpClient.getAdapters();
|
||||||
const adapterList = adapterListResp.adapters.map((adapter: Adapter) => {
|
const adapterList = adapterListResp.adapters.map((adapter: Adapter) => {
|
||||||
@@ -72,11 +58,6 @@ export default function BotConfigPage() {
|
|||||||
usePipelineName: bot.use_pipeline_name || '',
|
usePipelineName: bot.use_pipeline_name || '',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
if (botList.length === 0) {
|
|
||||||
setPageShowRule(BotConfigPageShowRule.NO_BOT);
|
|
||||||
} else {
|
|
||||||
setPageShowRule(BotConfigPageShowRule.HAVE_BOT);
|
|
||||||
}
|
|
||||||
setBotList(botList);
|
setBotList(botList);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -89,7 +70,7 @@ export default function BotConfigPage() {
|
|||||||
// });
|
// });
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
setIsLoading(false);
|
// setIsLoading(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,7 +117,6 @@ export default function BotConfigPage() {
|
|||||||
</Dialog>
|
</Dialog>
|
||||||
|
|
||||||
{/* 注意:其余的返回内容需要保持在Spin组件外部 */}
|
{/* 注意:其余的返回内容需要保持在Spin组件外部 */}
|
||||||
{pageShowRule === BotConfigPageShowRule.HAVE_BOT && (
|
|
||||||
<div className={`${styles.botListContainer}`}>
|
<div className={`${styles.botListContainer}`}>
|
||||||
|
|
||||||
<CreateCardComponent
|
<CreateCardComponent
|
||||||
@@ -158,13 +138,6 @@ export default function BotConfigPage() {
|
|||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum BotConfigPageShowRule {
|
|
||||||
NO_LLM,
|
|
||||||
NO_BOT,
|
|
||||||
HAVE_BOT,
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -98,43 +98,27 @@ export default function LLMConfigPage() {
|
|||||||
/>
|
/>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
<div className={`${styles.modelListContainer}`}>
|
||||||
|
|
||||||
{cardList.length > 0 && (
|
<CreateCardComponent
|
||||||
<div className={`${styles.modelListContainer}`}>
|
width={'24rem'}
|
||||||
|
height={'10rem'}
|
||||||
<CreateCardComponent
|
plusSize={'90px'}
|
||||||
width={'24rem'}
|
onClick={handleCreateModelClick}
|
||||||
height={'10rem'}
|
/>
|
||||||
plusSize={'90px'}
|
{cardList.map((cardVO) => {
|
||||||
onClick={handleCreateModelClick}
|
return (
|
||||||
/>
|
<div
|
||||||
{cardList.map((cardVO) => {
|
key={cardVO.id}
|
||||||
return (
|
onClick={() => {
|
||||||
<div
|
selectLLM(cardVO);
|
||||||
key={cardVO.id}
|
}}
|
||||||
onClick={() => {
|
>
|
||||||
selectLLM(cardVO);
|
<LLMCard cardVO={cardVO}></LLMCard>
|
||||||
}}
|
</div>
|
||||||
>
|
);
|
||||||
<LLMCard cardVO={cardVO}></LLMCard>
|
})}
|
||||||
</div>
|
</div>
|
||||||
);
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{cardList.length === 0 && (
|
|
||||||
<div className={`${styles.emptyContainer}`}>
|
|
||||||
<EmptyAndCreateComponent
|
|
||||||
title={'模型列表空空如也~'}
|
|
||||||
subTitle={'快去创建一个吧!'}
|
|
||||||
buttonText={'创建模型 +'}
|
|
||||||
onButtonClick={() => {
|
|
||||||
handleCreateModelClick();
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,9 +43,9 @@ export default function PluginConfigPage() {
|
|||||||
let currentTime = new Date();
|
let currentTime = new Date();
|
||||||
const pipelineList = value.pipelines.map((pipeline) => {
|
const pipelineList = value.pipelines.map((pipeline) => {
|
||||||
let lastUpdatedTimeAgo = Math.floor((currentTime.getTime() - new Date(pipeline.updated_at ?? currentTime.getTime()).getTime()) / 1000 / 60 / 60 / 24);
|
let lastUpdatedTimeAgo = Math.floor((currentTime.getTime() - new Date(pipeline.updated_at ?? currentTime.getTime()).getTime()) / 1000 / 60 / 60 / 24);
|
||||||
|
|
||||||
let lastUpdatedTimeAgoText = lastUpdatedTimeAgo > 0 ? ` ${lastUpdatedTimeAgo} 天前` : '今天';
|
let lastUpdatedTimeAgoText = lastUpdatedTimeAgo > 0 ? ` ${lastUpdatedTimeAgo} 天前` : '今天';
|
||||||
|
|
||||||
return new PipelineCardVO({
|
return new PipelineCardVO({
|
||||||
lastUpdatedTimeAgo: lastUpdatedTimeAgoText,
|
lastUpdatedTimeAgo: lastUpdatedTimeAgoText,
|
||||||
description: pipeline.description,
|
description: pipeline.description,
|
||||||
@@ -82,7 +82,7 @@ export default function PluginConfigPage() {
|
|||||||
<div className={styles.configPageContainer}>
|
<div className={styles.configPageContainer}>
|
||||||
|
|
||||||
<Dialog open={modalOpen} onOpenChange={setModalOpen}>
|
<Dialog open={modalOpen} onOpenChange={setModalOpen}>
|
||||||
<DialogContent className="w-[700px] max-h-[80vh] p-0 flex flex-col">
|
<DialogContent className="w-[700px] max-h-[80vh] p-0 flex flex-col">
|
||||||
<DialogHeader className="px-6 pt-6 pb-4">
|
<DialogHeader className="px-6 pt-6 pb-4">
|
||||||
<DialogTitle>
|
<DialogTitle>
|
||||||
{isEditForm ? '编辑流水线' : '创建流水线'}
|
{isEditForm ? '编辑流水线' : '创建流水线'}
|
||||||
@@ -109,38 +109,35 @@ export default function PluginConfigPage() {
|
|||||||
</div>
|
</div>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|
||||||
|
|
||||||
{pipelineList.length > 0 && (
|
<div className={styles.pipelineListContainer}>
|
||||||
<div className={styles.pipelineListContainer}>
|
<CreateCardComponent
|
||||||
<CreateCardComponent
|
width={'24rem'}
|
||||||
width={'24rem'}
|
height={'10rem'}
|
||||||
height={'10rem'}
|
plusSize={'90px'}
|
||||||
plusSize={'90px'}
|
onClick={() => {
|
||||||
onClick={() => {
|
setIsEditForm(false);
|
||||||
setIsEditForm(false);
|
setModalOpen(true);
|
||||||
setModalOpen(true);
|
}}
|
||||||
}}
|
/>
|
||||||
/>
|
|
||||||
|
|
||||||
{pipelineList.map((pipeline) => {
|
{pipelineList.map((pipeline) => {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={pipeline.id}
|
key={pipeline.id}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setDisableForm(true);
|
setDisableForm(true);
|
||||||
setIsEditForm(true);
|
setIsEditForm(true);
|
||||||
setModalOpen(true);
|
setModalOpen(true);
|
||||||
setSelectedPipelineId(pipeline.id);
|
setSelectedPipelineId(pipeline.id);
|
||||||
getSelectedPipelineForm(pipeline.id);
|
getSelectedPipelineForm(pipeline.id);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<PipelineCard cardVO={pipeline} />
|
<PipelineCard cardVO={pipeline} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user