File size: 3,989 Bytes
f3d0ebd 503735c 51db3f9 242ee03 503735c 0a903c7 badd5fe 242ee03 badd5fe 8ef29dd 51db3f9 503735c 7b71fb2 242ee03 503735c badd5fe 8ef29dd 503735c 242ee03 503735c 51db3f9 503735c 0a903c7 badd5fe 0a903c7 badd5fe 0a903c7 badd5fe 0a903c7 503735c 51db3f9 503735c badd5fe 503735c badd5fe 503735c badd5fe 7b71fb2 f3d0ebd 0a903c7 503735c 51db3f9 99634df 51db3f9 503735c f3d0ebd 503735c f3d0ebd 503735c f305776 503735c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
import { ReactComponent as ConfigurationIcon } 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 {
useFetchKnowledgeBaseConfiguration,
useFetchKnowledgeGraph,
} from '@/hooks/knowledge-hooks';
import {
useGetKnowledgeSearchParams,
useSecondPathName,
} from '@/hooks/route-hook';
import { getWidth } from '@/utils';
import { Avatar, Menu, MenuProps, Space } from 'antd';
import classNames from 'classnames';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'umi';
import { KnowledgeRouteKey } from '../../constant';
import { isEmpty } from 'lodash';
import { GitGraph } from 'lucide-react';
import styles from './index.less';
const KnowledgeSidebar = () => {
let navigate = useNavigate();
const activeKey = useSecondPathName();
const { knowledgeId } = useGetKnowledgeSearchParams();
const [windowWidth, setWindowWidth] = useState(getWidth());
const [collapsed, setCollapsed] = useState(false);
const { t } = useTranslation();
const { data: knowledgeDetails } = useFetchKnowledgeBaseConfiguration();
const handleSelect: MenuProps['onSelect'] = (e) => {
navigate(`/knowledge/${e.key}?id=${knowledgeId}`);
};
const { data } = useFetchKnowledgeGraph();
type MenuItem = Required<MenuProps>['items'][number];
const getItem = useCallback(
(
label: string,
key: React.Key,
icon?: React.ReactNode,
disabled?: boolean,
children?: MenuItem[],
type?: 'group',
): MenuItem => {
return {
key,
icon,
children,
label: t(`knowledgeDetails.${label}`),
type,
disabled,
} as MenuItem;
},
[t],
);
const items: MenuItem[] = useMemo(() => {
const list = [
getItem(
KnowledgeRouteKey.Dataset, // TODO: Change icon color when selected
KnowledgeRouteKey.Dataset,
<DatasetIcon />,
),
getItem(
KnowledgeRouteKey.Testing,
KnowledgeRouteKey.Testing,
<TestingIcon />,
),
getItem(
KnowledgeRouteKey.Configuration,
KnowledgeRouteKey.Configuration,
<ConfigurationIcon />,
),
];
if (!isEmpty(data?.graph)) {
list.push(
getItem(
KnowledgeRouteKey.KnowledgeGraph,
KnowledgeRouteKey.KnowledgeGraph,
<GitGraph />,
),
);
}
return list;
}, [data, getItem]);
useEffect(() => {
if (windowWidth.width > 957) {
setCollapsed(false);
} else {
setCollapsed(true);
}
}, [windowWidth.width]);
useEffect(() => {
const widthSize = () => {
const width = getWidth();
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} src={knowledgeDetails.avatar} />
<div className={styles.knowledgeTitle}>{knowledgeDetails.name}</div>
</Space>
<p className={styles.knowledgeDescription}>
{knowledgeDetails.description}
</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;
|