2024-04-24 11:07:22 +08:00
|
|
|
import { useTranslate } from '@/hooks/commonHooks';
|
|
|
|
|
import { IFile } from '@/interfaces/database/file-manager';
|
2024-04-23 17:46:56 +08:00
|
|
|
import { api_host } from '@/utils/api';
|
|
|
|
|
import { downloadFile } from '@/utils/fileUtil';
|
|
|
|
|
import {
|
|
|
|
|
DeleteOutlined,
|
|
|
|
|
DownloadOutlined,
|
|
|
|
|
EditOutlined,
|
2024-04-26 18:55:37 +08:00
|
|
|
LinkOutlined,
|
2024-04-23 17:46:56 +08:00
|
|
|
} from '@ant-design/icons';
|
|
|
|
|
import { Button, Space, Tooltip } from 'antd';
|
2024-05-08 10:30:18 +08:00
|
|
|
import { useHandleDeleteFile, useNavigateToDocument } from '../hooks';
|
2024-04-23 17:46:56 +08:00
|
|
|
|
|
|
|
|
import styles from './index.less';
|
|
|
|
|
|
|
|
|
|
interface IProps {
|
|
|
|
|
record: IFile;
|
|
|
|
|
setCurrentRecord: (record: any) => void;
|
|
|
|
|
showRenameModal: (record: IFile) => void;
|
2024-04-25 19:06:24 +08:00
|
|
|
showConnectToKnowledgeModal: (record: IFile) => void;
|
|
|
|
|
setSelectedRowKeys(keys: string[]): void;
|
2024-04-23 17:46:56 +08:00
|
|
|
}
|
|
|
|
|
|
2024-04-25 08:46:18 +08:00
|
|
|
const ActionCell = ({
|
|
|
|
|
record,
|
|
|
|
|
setCurrentRecord,
|
|
|
|
|
showRenameModal,
|
|
|
|
|
showConnectToKnowledgeModal,
|
2024-04-25 19:06:24 +08:00
|
|
|
setSelectedRowKeys,
|
2024-04-25 08:46:18 +08:00
|
|
|
}: IProps) => {
|
2024-04-23 17:46:56 +08:00
|
|
|
const documentId = record.id;
|
|
|
|
|
const beingUsed = false;
|
2024-04-26 18:55:37 +08:00
|
|
|
const { t } = useTranslate('fileManager');
|
2024-04-25 19:06:24 +08:00
|
|
|
const { handleRemoveFile } = useHandleDeleteFile(
|
|
|
|
|
[documentId],
|
|
|
|
|
setSelectedRowKeys,
|
|
|
|
|
);
|
2024-05-08 10:30:18 +08:00
|
|
|
const navigateToDocument = useNavigateToDocument(record.id, record.name);
|
2024-04-23 17:46:56 +08:00
|
|
|
|
|
|
|
|
const onDownloadDocument = () => {
|
|
|
|
|
downloadFile({
|
2024-04-26 17:22:23 +08:00
|
|
|
url: `${api_host}/file/get/${documentId}`,
|
2024-04-23 17:46:56 +08:00
|
|
|
filename: record.name,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const setRecord = () => {
|
|
|
|
|
setCurrentRecord(record);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onShowRenameModal = () => {
|
|
|
|
|
setRecord();
|
|
|
|
|
showRenameModal(record);
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-25 08:46:18 +08:00
|
|
|
const onShowConnectToKnowledgeModal = () => {
|
2024-04-25 19:06:24 +08:00
|
|
|
showConnectToKnowledgeModal(record);
|
2024-04-25 08:46:18 +08:00
|
|
|
};
|
|
|
|
|
|
2024-04-23 17:46:56 +08:00
|
|
|
return (
|
|
|
|
|
<Space size={0}>
|
2024-05-08 10:30:18 +08:00
|
|
|
{/* <Tooltip title={t('addToKnowledge')}>
|
|
|
|
|
<Button
|
|
|
|
|
type="text"
|
|
|
|
|
className={styles.iconButton}
|
|
|
|
|
onClick={navigateToDocument}
|
|
|
|
|
>
|
|
|
|
|
<EyeOutlined size={20} />
|
|
|
|
|
</Button>
|
|
|
|
|
</Tooltip> */}
|
2024-04-26 18:55:37 +08:00
|
|
|
<Tooltip title={t('addToKnowledge')}>
|
|
|
|
|
<Button
|
|
|
|
|
type="text"
|
|
|
|
|
className={styles.iconButton}
|
|
|
|
|
onClick={onShowConnectToKnowledgeModal}
|
|
|
|
|
>
|
|
|
|
|
<LinkOutlined size={20} />
|
|
|
|
|
</Button>
|
|
|
|
|
</Tooltip>
|
2024-04-23 17:46:56 +08:00
|
|
|
|
|
|
|
|
<Tooltip title={t('rename', { keyPrefix: 'common' })}>
|
|
|
|
|
<Button
|
|
|
|
|
type="text"
|
|
|
|
|
disabled={beingUsed}
|
|
|
|
|
onClick={onShowRenameModal}
|
|
|
|
|
className={styles.iconButton}
|
|
|
|
|
>
|
|
|
|
|
<EditOutlined size={20} />
|
|
|
|
|
</Button>
|
|
|
|
|
</Tooltip>
|
2024-04-26 18:55:37 +08:00
|
|
|
<Tooltip title={t('delete', { keyPrefix: 'common' })}>
|
2024-04-25 19:06:24 +08:00
|
|
|
<Button
|
|
|
|
|
type="text"
|
|
|
|
|
disabled={beingUsed}
|
2024-04-26 18:55:37 +08:00
|
|
|
onClick={handleRemoveFile}
|
2024-04-25 19:06:24 +08:00
|
|
|
className={styles.iconButton}
|
|
|
|
|
>
|
2024-04-26 18:55:37 +08:00
|
|
|
<DeleteOutlined size={20} />
|
2024-04-25 19:06:24 +08:00
|
|
|
</Button>
|
2024-04-26 18:55:37 +08:00
|
|
|
</Tooltip>
|
|
|
|
|
{record.type !== 'folder' && (
|
|
|
|
|
<Tooltip title={t('download', { keyPrefix: 'common' })}>
|
|
|
|
|
<Button
|
|
|
|
|
type="text"
|
|
|
|
|
disabled={beingUsed}
|
|
|
|
|
onClick={onDownloadDocument}
|
|
|
|
|
className={styles.iconButton}
|
|
|
|
|
>
|
|
|
|
|
<DownloadOutlined size={20} />
|
|
|
|
|
</Button>
|
|
|
|
|
</Tooltip>
|
2024-04-25 19:06:24 +08:00
|
|
|
)}
|
2024-04-23 17:46:56 +08:00
|
|
|
</Space>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default ActionCell;
|