feat: Modify the color of the svg icon in the header according to the selected state and feat: extract routing information from the knowledge base into constants (#51)

* feat: Modify the color of the svg icon in the header according to the selected state

* feat: add translation icon to header

* feat: shorten the route length of the knowledge base

* feat: extract routing information from the knowledge base into constants
This commit is contained in:
balibabu
2024-02-02 09:35:21 +08:00
committed by GitHub
parent e6acaf6738
commit 503735cd1d
26 changed files with 439 additions and 130 deletions

View File

@ -1,3 +1,4 @@
import { KnowledgeRouteKey } from '@/constants/knowledge';
import { getOneNamespaceEffectsLoading } from '@/utils/stroreUtil';
import { DownOutlined } from '@ant-design/icons';
import type { MenuProps } from 'antd';
@ -158,8 +159,9 @@ const KnowledgeFile: React.FC<KFProps> = ({ kb_id }) => {
},
];
const toChunk = (id: string) => {
console.log(id);
navigate(`/knowledge/add/setting?activeKey=file&id=${kb_id}&doc_id=${id}`);
navigate(
`/knowledge/${KnowledgeRouteKey.Dataset}?id=${kb_id}&doc_id=${id}`,
);
};
const columns: ColumnsType<DataType> = [
{

View File

@ -1,7 +1,9 @@
import { KnowledgeRouteKey } from '@/constants/knowledge';
import { Button, Form, Input, Radio, Select, Space, Tag } from 'antd';
import React, { useCallback, useEffect, useState } from 'react';
import { useDispatch, useNavigate, useSelector } from 'umi';
import styles from './index.less';
const { CheckableTag } = Tag;
const layout = {
labelCol: { span: 8 },
@ -67,7 +69,7 @@ const KnowledgeSetting: React.FC<kSProps> = ({ kb_id }) => {
},
});
retcode === 0 &&
navigate(`/knowledge/add/setting?activeKey=file&id=${kb_id}`);
navigate(`/knowledge/${KnowledgeRouteKey.Dataset}?id=${kb_id}`);
}
} catch (error) {
console.warn(error);

View File

@ -0,0 +1,63 @@
.sidebarWrapper {
max-width: 288px;
padding: 32px 24px 24px 24px;
flex-direction: column;
.sidebarTop {
text-align: center;
.knowledgeLogo {
}
.knowledgeTitle {
font-family: 'Nunito Sans';
font-size: 16px;
line-height: 24px;
font-weight: @fontWeight700;
color: @gray2;
margin-bottom: 6px;
}
.knowledgeDescription {
font-family: 'Nunito Sans';
font-size: 12px;
font-weight: @fontWeight600;
color: @gray8;
margin: 0;
}
padding-bottom: 20px;
}
.divider {
height: 2px;
background-image: linear-gradient(
to right,
@gray11 0%,
@gray11 50%,
transparent 50%
);
background-size: 10px 2px;
background-repeat: repeat-x;
}
.menuWrapper {
padding-top: 10px;
.menu {
border: none;
font-size: @fontSize14;
font-weight: @fontWeight600;
}
.defaultWidth {
width: 240px;
}
.minWidth {
width: 50px;
}
.menuText {
color: @gray3;
font-family: @fontFamilyNunitoSans;
font-size: @fontSize14;
font-weight: @fontWeight700;
}
}
}

View File

@ -0,0 +1,118 @@
import { ReactComponent as ConfigrationIcon } from '@/assets/svg/knowledge-configration.svg';
import { ReactComponent as DatasetIcon } from '@/assets/svg/knowledge-dataset.svg';
import { ReactComponent as TestingIcon } from '@/assets/svg/knowledge-testing.svg';
import { getWidth } from '@/utils';
import { AntDesignOutlined } from '@ant-design/icons';
import { Avatar, Menu, MenuProps, Space } from 'antd';
import classNames from 'classnames';
import { useEffect, useMemo, useState } from 'react';
import { useNavigate, useParams, useSelector } from 'umi';
import { KnowledgeRouteKey, routeMap } from '../../constant';
import styles from './index.less';
const KnowledgeSidebar = () => {
const kAModel = useSelector((state: any) => state.kAModel);
const { id } = kAModel;
let navigate = useNavigate();
const params = useParams();
const activeKey = params.module || KnowledgeRouteKey.Dataset;
const [windowWidth, setWindowWidth] = useState(getWidth());
const [collapsed, setCollapsed] = useState(false);
const handleSelect: MenuProps['onSelect'] = (e) => {
navigate(`/knowledge/${e.key}?id=${id}`);
};
type MenuItem = Required<MenuProps>['items'][number];
function getItem(
label: React.ReactNode,
key: React.Key,
icon?: React.ReactNode,
disabled?: boolean,
children?: MenuItem[],
type?: 'group',
): MenuItem {
return {
key,
icon,
children,
label,
type,
disabled,
} as MenuItem;
}
const items: MenuItem[] = useMemo(() => {
return [
getItem(
routeMap[KnowledgeRouteKey.Dataset], // TODO: Change icon color when selected
KnowledgeRouteKey.Dataset,
<DatasetIcon />,
),
getItem(
routeMap[KnowledgeRouteKey.Testing],
KnowledgeRouteKey.Testing,
<TestingIcon />,
),
getItem(
routeMap[KnowledgeRouteKey.Configration],
KnowledgeRouteKey.Configration,
<ConfigrationIcon />,
),
];
}, [id]);
useEffect(() => {
if (windowWidth.width > 957) {
setCollapsed(false);
} else {
setCollapsed(true);
}
}, [windowWidth.width]);
// 标记一下
useEffect(() => {
const widthSize = () => {
const width = getWidth();
console.log(width);
setWindowWidth(width);
};
window.addEventListener('resize', widthSize);
return () => {
window.removeEventListener('resize', widthSize);
};
}, []);
return (
<div className={styles.sidebarWrapper}>
<div className={styles.sidebarTop}>
<Space size={8} direction="vertical">
<Avatar size={64} icon={<AntDesignOutlined />} />
<div className={styles.knowledgeTitle}>Cloud Computing</div>
</Space>
<p className={styles.knowledgeDescription}>
A scalable, secure cloud-based database optimized for high-performance
computing and data storage.
</p>
</div>
<div className={styles.divider}></div>
<div className={styles.menuWrapper}>
<Menu
selectedKeys={[activeKey]}
// mode="inline"
className={classNames(styles.menu, {
[styles.defaultWidth]: windowWidth.width > 957,
[styles.minWidth]: windowWidth.width <= 957,
})}
inlineCollapsed={collapsed}
items={items}
onSelect={handleSelect}
/>
</div>
</div>
);
};
export default KnowledgeSidebar;

View File

@ -0,0 +1,9 @@
import { KnowledgeRouteKey } from '@/constants/knowledge';
export const routeMap = {
[KnowledgeRouteKey.Dataset]: 'Dataset',
[KnowledgeRouteKey.Testing]: 'Retrieval testing',
[KnowledgeRouteKey.Configration]: 'Configuration',
};
export * from '@/constants/knowledge';

View File

@ -1,19 +1,15 @@
.container {
display: flex;
.menu {
.defaultWidth {
width: 256px;
}
.minWidth {
width: 50px
}
}
.content {
flex: 1;
overflow-x: auto;
height: 100%;
}
}
display: flex;
height: 100%;
.contentWrapper {
flex: 1;
overflow-x: auto;
height: 100%;
background-color: rgba(247, 248, 250, 1);
padding: 16px 20px 28px 40px;
}
.content {
background-color: white;
margin-top: 16px;
}
}

View File

@ -1,39 +1,46 @@
import { getWidth } from '@/utils';
import { BarsOutlined, SearchOutlined, ToolOutlined } from '@ant-design/icons';
import type { MenuProps } from 'antd';
import { Menu } from 'antd';
import React, { useEffect, useMemo, useState } from 'react';
import { useDispatch, useLocation, useNavigate, useSelector } from 'umi';
import { Breadcrumb } from 'antd';
import { useEffect, useMemo } from 'react';
import {
useDispatch,
useLocation,
useNavigate,
useParams,
useSelector,
} from 'umi';
import Chunk from './components/knowledge-chunk';
import File from './components/knowledge-file';
import Search from './components/knowledge-search';
import Setting from './components/knowledge-setting';
import Siderbar from './components/knowledge-sidebar';
import { KnowledgeRouteKey, routeMap } from './constant';
import styles from './index.less';
const KnowledgeAdding = () => {
const dispatch = useDispatch();
const kAModel = useSelector((state: any) => state.kAModel);
const { id, activeKey, doc_id } = kAModel;
const navigate = useNavigate();
const { id, doc_id } = kAModel;
const [collapsed, setCollapsed] = useState(false);
const [windowWidth, setWindowWidth] = useState(getWidth());
let navigate = useNavigate();
const location = useLocation();
const params = useParams();
const activeKey: KnowledgeRouteKey =
(params.module as KnowledgeRouteKey) || KnowledgeRouteKey.Dataset;
// 标记一下
console.log(doc_id, '>>>>>>>>>>>>>doc_id');
useEffect(() => {
const widthSize = () => {
const width = getWidth();
console.log(width);
const gotoList = () => {
navigate('/knowledge');
};
const breadcrumbItems = useMemo(() => {
return [
{
title: <a onClick={gotoList}>Knowledge Base</a>,
},
{
title: routeMap[activeKey],
},
];
}, [activeKey]);
setWindowWidth(width);
};
window.addEventListener('resize', widthSize);
return () => {
window.removeEventListener('resize', widthSize);
};
}, []);
useEffect(() => {
const search: string = location.search.slice(1);
const map = search.split('&').reduce<Record<string, string>>((obj, cur) => {
@ -51,66 +58,24 @@ const KnowledgeAdding = () => {
});
}, [location]);
useEffect(() => {
if (windowWidth.width > 957) {
setCollapsed(false);
} else {
setCollapsed(true);
}
}, [windowWidth.width]);
type MenuItem = Required<MenuProps>['items'][number];
function getItem(
label: React.ReactNode,
key: React.Key,
icon?: React.ReactNode,
disabled?: boolean,
children?: MenuItem[],
type?: 'group',
): MenuItem {
return {
key,
icon,
children,
label,
type,
disabled,
} as MenuItem;
}
const items: MenuItem[] = useMemo(() => {
const disabled = !id;
return [
getItem('配置', 'setting', <ToolOutlined />),
getItem('知识库', 'file', <BarsOutlined />, disabled),
getItem('搜索测试', 'search', <SearchOutlined />, disabled),
];
}, [id]);
const handleSelect: MenuProps['onSelect'] = (e) => {
navigate(`/knowledge/add/setting?activeKey=${e.key}&id=${id}`);
};
return (
<>
<div className={styles.container}>
<div className={styles.menu}>
<Menu
selectedKeys={[activeKey]}
mode="inline"
className={
windowWidth.width > 957 ? styles.defaultWidth : styles.minWidth
}
inlineCollapsed={collapsed}
items={items}
onSelect={handleSelect}
/>
</div>
<div className={styles.content}>
{activeKey === 'file' && !doc_id && <File kb_id={id} />}
{activeKey === 'setting' && <Setting kb_id={id} />}
{activeKey === 'search' && <Search kb_id={id} />}
{activeKey === 'file' && !!doc_id && <Chunk doc_id={doc_id} />}
<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>
</div>
</div>
</>

View File

@ -3,7 +3,6 @@ export interface kAModelState {
isShowPSwModal: boolean;
isShowTntModal: boolean;
tenantIfo: any;
activeKey: string;
id: string;
doc_id: string;
}
@ -14,7 +13,6 @@ const model: DvaModel<kAModelState> = {
isShowPSwModal: false,
isShowTntModal: false,
tenantIfo: {},
activeKey: 'setting',
id: '',
doc_id: '',
},

View File

@ -20,7 +20,7 @@ const Knowledge = () => {
}, []);
const handleAddKnowledge = () => {
navigate(`add/setting?activeKey=setting`);
navigate(`add/setting`);
};
useEffect(() => {

View File

@ -1,13 +1,13 @@
import { ReactComponent as MoreIcon } from '@/assets/svg/more.svg';
import { KnowledgeRouteKey } from '@/constants/knowledge';
import { formatDate } from '@/utils/date';
import {
AntDesignOutlined,
CalendarOutlined,
DeleteOutlined,
FileTextOutlined,
UserOutlined,
} from '@ant-design/icons';
import { Avatar, Card, Dropdown, MenuProps, Space, Tooltip } from 'antd';
import { Avatar, Card, Dropdown, MenuProps, Space } from 'antd';
import { MouseEvent } from 'react';
import { useDispatch, useNavigate } from 'umi';
@ -47,7 +47,7 @@ const KnowledgeCard = ({ item }: IProps) => {
};
const handleCardClick = () => {
navigate(`add/setting?activeKey=file&id=${item.id}`);
navigate(`/knowledge/${KnowledgeRouteKey.Dataset}?id=${item.id}`);
};
const onConfirmDelete = (e?: MouseEvent<HTMLElement>) => {
@ -97,7 +97,7 @@ const KnowledgeCard = ({ item }: IProps) => {
{formatDate(item.update_date)}
</span>
</div>
<Avatar.Group size={25}>
{/* <Avatar.Group size={25}>
<Avatar src="https://api.dicebear.com/7.x/miniavs/svg?seed=1" />
<a href="https://ant.design">
<Avatar style={{ backgroundColor: '#f56a00' }}>K</Avatar>
@ -112,7 +112,7 @@ const KnowledgeCard = ({ item }: IProps) => {
style={{ backgroundColor: '#1677ff' }}
icon={<AntDesignOutlined />}
/>
</Avatar.Group>
</Avatar.Group> */}
</div>
</div>
</div>