2024-02-02 09:35:21 +08:00
|
|
|
import { Breadcrumb } from 'antd';
|
|
|
|
import { useEffect, useMemo } from 'react';
|
|
|
|
import {
|
|
|
|
useDispatch,
|
|
|
|
useLocation,
|
|
|
|
useNavigate,
|
|
|
|
useParams,
|
|
|
|
useSelector,
|
|
|
|
} from 'umi';
|
2024-01-30 19:26:29 +08:00
|
|
|
import Chunk from './components/knowledge-chunk';
|
|
|
|
import File from './components/knowledge-file';
|
|
|
|
import Search from './components/knowledge-search';
|
|
|
|
import Setting from './components/knowledge-setting';
|
2024-02-02 09:35:21 +08:00
|
|
|
import Siderbar from './components/knowledge-sidebar';
|
|
|
|
import { KnowledgeRouteKey, routeMap } from './constant';
|
2024-01-30 19:26:29 +08:00
|
|
|
import styles from './index.less';
|
2024-01-17 09:37:01 +08:00
|
|
|
|
2024-01-30 19:26:29 +08:00
|
|
|
const KnowledgeAdding = () => {
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
const kAModel = useSelector((state: any) => state.kAModel);
|
2024-02-02 09:35:21 +08:00
|
|
|
const navigate = useNavigate();
|
|
|
|
const { id, doc_id } = kAModel;
|
2024-01-17 09:37:01 +08:00
|
|
|
|
2024-01-30 19:26:29 +08:00
|
|
|
const location = useLocation();
|
2024-02-02 09:35:21 +08:00
|
|
|
const params = useParams();
|
|
|
|
const activeKey: KnowledgeRouteKey =
|
|
|
|
(params.module as KnowledgeRouteKey) || KnowledgeRouteKey.Dataset;
|
2024-01-17 09:37:01 +08:00
|
|
|
|
2024-02-02 09:35:21 +08:00
|
|
|
const gotoList = () => {
|
|
|
|
navigate('/knowledge');
|
|
|
|
};
|
|
|
|
|
|
|
|
const breadcrumbItems = useMemo(() => {
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
title: <a onClick={gotoList}>Knowledge Base</a>,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: routeMap[activeKey],
|
|
|
|
},
|
|
|
|
];
|
|
|
|
}, [activeKey]);
|
2024-01-18 18:27:38 +08:00
|
|
|
|
2024-01-30 19:26:29 +08:00
|
|
|
useEffect(() => {
|
|
|
|
const search: string = location.search.slice(1);
|
|
|
|
const map = search.split('&').reduce<Record<string, string>>((obj, cur) => {
|
|
|
|
const [key, value] = cur.split('=');
|
|
|
|
obj[key] = value;
|
|
|
|
return obj;
|
|
|
|
}, {});
|
2024-01-17 09:37:01 +08:00
|
|
|
|
2024-01-30 19:26:29 +08:00
|
|
|
dispatch({
|
|
|
|
type: 'kAModel/updateState',
|
|
|
|
payload: {
|
|
|
|
doc_id: undefined,
|
|
|
|
...map,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}, [location]);
|
2024-01-19 18:35:24 +08:00
|
|
|
|
2024-01-30 19:26:29 +08:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className={styles.container}>
|
2024-02-02 09:35:21 +08:00
|
|
|
<Siderbar></Siderbar>
|
|
|
|
<div className={styles.contentWrapper}>
|
|
|
|
<Breadcrumb items={breadcrumbItems} />
|
|
|
|
<div className={styles.content}>
|
|
|
|
{activeKey === KnowledgeRouteKey.Dataset && !doc_id && (
|
|
|
|
<File kb_id={id} />
|
|
|
|
)}
|
|
|
|
{activeKey === KnowledgeRouteKey.Configration && (
|
|
|
|
<Setting kb_id={id} />
|
|
|
|
)}
|
|
|
|
{activeKey === KnowledgeRouteKey.Testing && <Search kb_id={id} />}
|
|
|
|
{activeKey === KnowledgeRouteKey.Dataset && !!doc_id && (
|
|
|
|
<Chunk doc_id={doc_id} />
|
|
|
|
)}
|
|
|
|
</div>
|
2024-01-30 19:26:29 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
2024-01-17 09:37:01 +08:00
|
|
|
};
|
|
|
|
|
2024-01-30 19:26:29 +08:00
|
|
|
export default KnowledgeAdding;
|