File size: 8,476 Bytes
503735c f305776 7b71fb2 362ec6c 7b71fb2 6b8fc2c 7b71fb2 6b8fc2c f305776 362ec6c 7b71fb2 362ec6c 6b8fc2c 7b71fb2 362ec6c f305776 7b71fb2 f305776 7b71fb2 362ec6c 6b8fc2c f305776 362ec6c 7b71fb2 362ec6c f305776 362ec6c 6b8fc2c f305776 362ec6c 7b71fb2 362ec6c f305776 6b8fc2c f305776 7b71fb2 6b8fc2c 362ec6c f305776 362ec6c f305776 362ec6c 7b71fb2 362ec6c f305776 362ec6c 6b8fc2c 362ec6c 7b71fb2 362ec6c 7b71fb2 362ec6c 6b8fc2c 7b71fb2 362ec6c 7b71fb2 362ec6c 503735c 7b71fb2 503735c 362ec6c 7b71fb2 362ec6c 7b71fb2 362ec6c 7b71fb2 362ec6c 7b71fb2 362ec6c 7b71fb2 362ec6c 7b71fb2 362ec6c 7b71fb2 362ec6c 7b71fb2 362ec6c 7b71fb2 362ec6c 7b71fb2 362ec6c 7b71fb2 f305776 7b71fb2 362ec6c 7b71fb2 f305776 362ec6c 7b71fb2 362ec6c 7b71fb2 362ec6c 7b71fb2 362ec6c 7b71fb2 362ec6c 7b71fb2 362ec6c f305776 7b71fb2 362ec6c 7b71fb2 362ec6c 7b71fb2 362ec6c 6b8fc2c 362ec6c |
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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
import { KnowledgeRouteKey } from '@/constants/knowledge';
import {
useDeleteDocumentById,
useKnowledgeBaseId,
} from '@/hooks/knowledgeHook';
import { Pagination } from '@/interfaces/common';
import { IKnowledgeFile } from '@/interfaces/database/knowledge';
import { getOneNamespaceEffectsLoading } from '@/utils/stroreUtil';
import { PlusOutlined, SearchOutlined } from '@ant-design/icons';
import type { MenuProps } from 'antd';
import {
Button,
Divider,
Dropdown,
Input,
Space,
Switch,
Table,
Tag,
} from 'antd';
import type { ColumnsType } from 'antd/es/table';
import { PaginationProps } from 'antd/lib';
import React, { useEffect, useMemo, useState } from 'react';
import { useDispatch, useNavigate, useSelector } from 'umi';
import CreateEPModal from './createEFileModal';
import styles from './index.less';
import ParsingActionCell from './parsing-action-cell';
import ParsingStatusCell from './parsing-status-cell';
import RenameModal from './rename-modal';
import SegmentSetModal from './segmentSetModal';
import UploadFile from './upload';
const KnowledgeFile = () => {
const dispatch = useDispatch();
const kFModel = useSelector((state: any) => state.kFModel);
const effects = useSelector((state: any) => state.loading.effects);
const { data, total } = kFModel;
const knowledgeBaseId = useKnowledgeBaseId();
const { removeDocument } = useDeleteDocumentById();
const loading = getOneNamespaceEffectsLoading('kFModel', effects, [
'getKfList',
'updateDocumentStatus',
]);
const [doc_id, setDocId] = useState('0');
const [parser_id, setParserId] = useState('0');
let navigate = useNavigate();
const getKfList = () => {
const payload = {
kb_id: knowledgeBaseId,
};
dispatch({
type: 'kFModel/getKfList',
payload,
});
};
const throttledGetDocumentList = () => {
dispatch({
type: 'kFModel/throttledGetDocumentList',
payload: knowledgeBaseId,
});
};
const setPagination = (pageNumber = 1, pageSize?: number) => {
const pagination: Pagination = {
current: pageNumber,
} as Pagination;
if (pageSize) {
pagination.pageSize = pageSize;
}
dispatch({
type: 'kFModel/setPagination',
payload: pagination,
});
};
const onPageChange: PaginationProps['onChange'] = (pageNumber, pageSize) => {
setPagination(pageNumber, pageSize);
getKfList();
};
const pagination: PaginationProps = useMemo(() => {
return {
showQuickJumper: true,
total,
showSizeChanger: true,
current: kFModel.pagination.currentPage,
pageSize: kFModel.pagination.pageSize,
pageSizeOptions: [1, 2, 10, 20, 50, 100],
onChange: onPageChange,
};
}, [total, kFModel.pagination]);
useEffect(() => {
if (knowledgeBaseId) {
getKfList();
dispatch({
type: 'kFModel/pollGetDocumentList-start',
payload: knowledgeBaseId,
});
}
return () => {
dispatch({
type: 'kFModel/pollGetDocumentList-stop',
});
};
}, [knowledgeBaseId]);
const handleInputChange = (
e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,
) => {
const value = e.target.value;
dispatch({ type: 'kFModel/setSearchString', payload: value });
setPagination();
throttledGetDocumentList();
};
const onChangeStatus = (e: boolean, doc_id: string) => {
dispatch({
type: 'kFModel/updateDocumentStatus',
payload: {
doc_id,
status: Number(e),
kb_id: knowledgeBaseId,
},
});
};
const onRmDocument = () => {
removeDocument(doc_id);
};
const showCEFModal = () => {
dispatch({
type: 'kFModel/updateState',
payload: {
isShowCEFwModal: true,
},
});
};
const showSegmentSetModal = () => {
dispatch({
type: 'kFModel/updateState',
payload: {
isShowSegmentSetModal: true,
},
});
};
const actionItems: MenuProps['items'] = useMemo(() => {
return [
{
key: '1',
label: (
<div>
<UploadFile kb_id={knowledgeBaseId} getKfList={getKfList} />
</div>
),
},
{
key: '2',
label: (
<div>
<Button type="link" onClick={showCEFModal}>
{' '}
导入虚拟文件
</Button>
</div>
),
// disabled: true,
},
];
}, [knowledgeBaseId]);
const chunkItems: MenuProps['items'] = [
{
key: '1',
label: (
<div>
<Button type="link" onClick={showSegmentSetModal}>
{' '}
分段设置
</Button>
</div>
),
},
{
key: '2',
label: (
<div>
<Button type="link" onClick={onRmDocument}>
{' '}
删除
</Button>
</div>
),
// disabled: true,
},
];
const toChunk = (id: string) => {
navigate(
`/knowledge/${KnowledgeRouteKey.Dataset}/chunk?id=${knowledgeBaseId}&doc_id=${id}`,
);
};
const setDocumentAndParserId = (record: IKnowledgeFile) => () => {
setDocId(record.id);
setParserId(record.parser_id);
};
const columns: ColumnsType<IKnowledgeFile> = [
{
title: 'Name',
dataIndex: 'name',
key: 'name',
render: (text: any, { id }) => (
<div className={styles.tochunks} onClick={() => toChunk(id)}>
<img
className={styles.img}
src="https://gw.alipayobjects.com/zos/antfincdn/efFD%24IOql2/weixintupian_20170331104822.jpg"
alt=""
/>
{text}
</div>
),
},
{
title: 'Chunk Number',
dataIndex: 'chunk_num',
key: 'chunk_num',
},
{
title: 'Upload Date',
dataIndex: 'create_date',
key: 'create_date',
},
{
title: 'Parsing Status',
dataIndex: 'run',
key: 'run',
render: (text, record) => {
return <ParsingStatusCell record={record}></ParsingStatusCell>;
},
},
{
title: 'Enabled',
key: 'status',
dataIndex: 'status',
render: (_, { status, id }) => (
<>
<Switch
defaultChecked={status === '1'}
onChange={(e) => {
onChangeStatus(e, id);
}}
/>
</>
),
},
{
title: 'Action',
key: 'action',
render: (_, record) => (
<ParsingActionCell
knowledgeBaseId={knowledgeBaseId}
setDocumentAndParserId={setDocumentAndParserId(record)}
record={record}
></ParsingActionCell>
),
},
];
const finalColumns = columns.map((x) => ({
...x,
className: `${styles.column}`,
}));
return (
<div className={styles.datasetWrapper}>
<h3>Dataset</h3>
<p>Hey, don't forget to adjust the chunk after adding the dataset! 😉</p>
<Divider></Divider>
<div className={styles.filter}>
<Space>
<h3>Total</h3>
<Tag color="purple">{total} files</Tag>
</Space>
<Space>
<Input
placeholder="Seach your files"
value={kFModel.searchString}
style={{ width: 220 }}
allowClear
onChange={handleInputChange}
prefix={<SearchOutlined />}
/>
<Dropdown menu={{ items: actionItems }} trigger={['click']}>
<Button type="primary" icon={<PlusOutlined />}>
Add file
</Button>
</Dropdown>
</Space>
</div>
<Table
rowKey="id"
columns={finalColumns}
dataSource={data}
loading={loading}
pagination={pagination}
scroll={{ scrollToFirstRowOnChange: true, x: true, y: 'fill' }}
/>
<CreateEPModal getKfList={getKfList} kb_id={knowledgeBaseId} />
<SegmentSetModal
getKfList={getKfList}
parser_id={parser_id}
doc_id={doc_id}
/>
<RenameModal></RenameModal>
</div>
);
};
export default KnowledgeFile;
|