mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
### What problem does this PR solve? fix: Change document status with @tanstack/react-query #13306 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) - [ ] New Feature (non-breaking change which adds functionality) - [ ] Documentation Update - [ ] Refactoring - [ ] Performance Improvement - [ ] Other (please describe):
121 lines
3.0 KiB
TypeScript
121 lines
3.0 KiB
TypeScript
import { useShowDeleteConfirm, useTranslate } from '@/hooks/common-hooks';
|
|
import { useRemoveNextDocument } from '@/hooks/document-hooks';
|
|
import { IDocumentInfo } from '@/interfaces/database/document';
|
|
import { api_host } from '@/utils/api';
|
|
import { downloadFile } from '@/utils/file-util';
|
|
import {
|
|
DeleteOutlined,
|
|
DownloadOutlined,
|
|
EditOutlined,
|
|
ToolOutlined,
|
|
} from '@ant-design/icons';
|
|
import { Button, Dropdown, MenuProps, Space, Tooltip } from 'antd';
|
|
import { isParserRunning } from '../utils';
|
|
|
|
import styles from './index.less';
|
|
|
|
interface IProps {
|
|
record: IDocumentInfo;
|
|
setCurrentRecord: (record: IDocumentInfo) => void;
|
|
showRenameModal: () => void;
|
|
showChangeParserModal: () => void;
|
|
}
|
|
|
|
const ParsingActionCell = ({
|
|
record,
|
|
setCurrentRecord,
|
|
showRenameModal,
|
|
showChangeParserModal,
|
|
}: IProps) => {
|
|
const documentId = record.id;
|
|
const isRunning = isParserRunning(record.run);
|
|
const { t } = useTranslate('knowledgeDetails');
|
|
const { removeDocument } = useRemoveNextDocument();
|
|
const showDeleteConfirm = useShowDeleteConfirm();
|
|
|
|
const onRmDocument = () => {
|
|
if (!isRunning) {
|
|
showDeleteConfirm({ onOk: () => removeDocument([documentId]) });
|
|
}
|
|
};
|
|
|
|
const onDownloadDocument = () => {
|
|
downloadFile({
|
|
url: `${api_host}/document/get/${documentId}`,
|
|
filename: record.name,
|
|
});
|
|
};
|
|
|
|
const setRecord = () => {
|
|
setCurrentRecord(record);
|
|
};
|
|
|
|
const onShowRenameModal = () => {
|
|
setRecord();
|
|
showRenameModal();
|
|
};
|
|
const onShowChangeParserModal = () => {
|
|
setRecord();
|
|
showChangeParserModal();
|
|
};
|
|
|
|
const chunkItems: MenuProps['items'] = [
|
|
{
|
|
key: '1',
|
|
label: (
|
|
<div>
|
|
<Button type="link" onClick={onShowChangeParserModal}>
|
|
{t('chunkMethod')}
|
|
</Button>
|
|
</div>
|
|
),
|
|
},
|
|
];
|
|
|
|
return (
|
|
<Space size={0}>
|
|
<Dropdown
|
|
menu={{ items: chunkItems }}
|
|
trigger={['click']}
|
|
disabled={isRunning}
|
|
>
|
|
<Button type="text" className={styles.iconButton}>
|
|
<ToolOutlined size={20} />
|
|
</Button>
|
|
</Dropdown>
|
|
<Tooltip title={t('rename', { keyPrefix: 'common' })}>
|
|
<Button
|
|
type="text"
|
|
disabled={isRunning}
|
|
onClick={onShowRenameModal}
|
|
className={styles.iconButton}
|
|
>
|
|
<EditOutlined size={20} />
|
|
</Button>
|
|
</Tooltip>
|
|
<Tooltip title={t('delete', { keyPrefix: 'common' })}>
|
|
<Button
|
|
type="text"
|
|
disabled={isRunning}
|
|
onClick={onRmDocument}
|
|
className={styles.iconButton}
|
|
>
|
|
<DeleteOutlined size={20} />
|
|
</Button>
|
|
</Tooltip>
|
|
<Tooltip title={t('download', { keyPrefix: 'common' })}>
|
|
<Button
|
|
type="text"
|
|
disabled={isRunning}
|
|
onClick={onDownloadDocument}
|
|
className={styles.iconButton}
|
|
>
|
|
<DownloadOutlined size={20} />
|
|
</Button>
|
|
</Tooltip>
|
|
</Space>
|
|
);
|
|
};
|
|
|
|
export default ParsingActionCell;
|