File size: 3,544 Bytes
68ed806 4056097 8c06509 e08f767 8c06509 8d2a400 9426215 8c06509 8d2a400 8c06509 8d2a400 d3e0754 e08f767 8c06509 bd39551 8c06509 40a88fa bd39551 40a88fa 8c06509 9426215 bd39551 8d2a400 15052fd 8c06509 7c6cf75 8c06509 40a88fa bd39551 40a88fa 8c06509 15052fd 8c06509 15052fd 9426215 bd39551 8d2a400 d3e0754 8d2a400 8c06509 |
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 |
import { useTranslate } from '@/hooks/common-hooks';
import { IFile } from '@/interfaces/database/file-manager';
import { api_host } from '@/utils/api';
import { downloadFile } from '@/utils/file-util';
import {
DeleteOutlined,
DownloadOutlined,
EditOutlined,
EyeOutlined,
LinkOutlined,
} from '@ant-design/icons';
import { Button, Space, Tooltip } from 'antd';
import { useHandleDeleteFile } from '../hooks';
import NewDocumentLink from '@/components/new-document-link';
import {
getExtension,
isSupportedPreviewDocumentType,
} from '@/utils/document-util';
import styles from './index.less';
interface IProps {
record: IFile;
setCurrentRecord: (record: any) => void;
showRenameModal: (record: IFile) => void;
showConnectToKnowledgeModal: (record: IFile) => void;
setSelectedRowKeys(keys: string[]): void;
}
const ActionCell = ({
record,
setCurrentRecord,
showRenameModal,
showConnectToKnowledgeModal,
setSelectedRowKeys,
}: IProps) => {
const documentId = record.id;
const beingUsed = false;
const { t } = useTranslate('fileManager');
const { handleRemoveFile } = useHandleDeleteFile(
[documentId],
setSelectedRowKeys,
);
const extension = getExtension(record.name);
const isKnowledgeBase = record.source_type === 'knowledgebase';
const onDownloadDocument = () => {
downloadFile({
url: `${api_host}/file/get/${documentId}`,
filename: record.name,
});
};
const setRecord = () => {
setCurrentRecord(record);
};
const onShowRenameModal = () => {
setRecord();
showRenameModal(record);
};
const onShowConnectToKnowledgeModal = () => {
showConnectToKnowledgeModal(record);
};
return (
<Space size={0}>
{isKnowledgeBase || (
<Tooltip title={t('addToKnowledge')}>
<Button
type="text"
className={styles.iconButton}
onClick={onShowConnectToKnowledgeModal}
>
<LinkOutlined size={20} />
</Button>
</Tooltip>
)}
{isKnowledgeBase || (
<Tooltip title={t('rename', { keyPrefix: 'common' })}>
<Button
type="text"
disabled={beingUsed}
onClick={onShowRenameModal}
className={styles.iconButton}
>
<EditOutlined size={20} />
</Button>
</Tooltip>
)}
{isKnowledgeBase || (
<Tooltip title={t('delete', { keyPrefix: 'common' })}>
<Button
type="text"
disabled={beingUsed}
onClick={handleRemoveFile}
className={styles.iconButton}
>
<DeleteOutlined size={20} />
</Button>
</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>
)}
{isSupportedPreviewDocumentType(extension) && (
<NewDocumentLink
documentId={documentId}
documentName={record.name}
color="black"
>
<Tooltip title={t('preview')}>
<Button type="text" className={styles.iconButton}>
<EyeOutlined size={20} />
</Button>
</Tooltip>
</NewDocumentLink>
)}
</Space>
);
};
export default ActionCell;
|