feat: add hooks for document table and refactor document-related modal (#141)

* feat: add hooks for document table

* refactor: refactor document-related modal
This commit is contained in:
balibabu
2024-03-22 11:35:25 +08:00
committed by GitHub
parent 6c6b144de2
commit 73c2f4d418
12 changed files with 625 additions and 401 deletions

View File

@ -1,5 +1,8 @@
import showDeleteConfirm from '@/components/deleting-confirm';
import { useRemoveDocument } from '@/hooks/documentHooks';
import { IKnowledgeFile } from '@/interfaces/database/knowledge';
import { api_host } from '@/utils/api';
import { downloadFile } from '@/utils/fileUtil';
import {
DeleteOutlined,
DownloadOutlined,
@ -7,37 +10,27 @@ import {
ToolOutlined,
} from '@ant-design/icons';
import { Button, Dropdown, MenuProps, Space, Tooltip } from 'antd';
import { useDispatch } from 'umi';
import { isParserRunning } from '../utils';
import { api_host } from '@/utils/api';
import { downloadFile } from '@/utils/fileUtil';
import styles from './index.less';
interface IProps {
knowledgeBaseId: string;
record: IKnowledgeFile;
setDocumentAndParserId: () => void;
showRenameModal: () => void;
showChangeParserModal: () => void;
}
const ParsingActionCell = ({
knowledgeBaseId,
record,
setDocumentAndParserId,
showRenameModal,
showChangeParserModal,
}: IProps) => {
const dispatch = useDispatch();
const documentId = record.id;
const isRunning = isParserRunning(record.run);
const removeDocument = () => {
dispatch({
type: 'kFModel/document_rm',
payload: {
doc_id: documentId,
kb_id: knowledgeBaseId,
},
});
};
const removeDocument = useRemoveDocument(documentId);
const onRmDocument = () => {
if (!isRunning) {
@ -52,39 +45,13 @@ const ParsingActionCell = ({
});
};
const setCurrentRecord = () => {
dispatch({
type: 'kFModel/setCurrentRecord',
payload: record,
});
};
const showSegmentSetModal = () => {
dispatch({
type: 'kFModel/updateState',
payload: {
isShowSegmentSetModal: true,
},
});
};
const showRenameModal = () => {
if (!isRunning) {
setCurrentRecord();
dispatch({
type: 'kFModel/setIsShowRenameModal',
payload: true,
});
}
};
const chunkItems: MenuProps['items'] = [
{
key: '1',
label: (
<div>
<Button type="link" onClick={showSegmentSetModal}>
Category
<Button type="link" onClick={showChangeParserModal}>
Chunk Method
</Button>
</div>
),