File size: 3,832 Bytes
b9fe2b4 |
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 |
import NewDocumentLink from '@/components/new-document-link';
import { useTranslate } from '@/hooks/common-hooks';
import { useDownloadFile } from '@/hooks/file-manager-hooks';
import { IFile } from '@/interfaces/database/file-manager';
import {
getExtension,
isSupportedPreviewDocumentType,
} from '@/utils/document-util';
import {
DownloadOutlined,
EditOutlined,
EyeOutlined,
LinkOutlined,
} from '@ant-design/icons';
import { Button, Space, Tooltip } from 'antd';
import { FolderInput, Trash2 } from 'lucide-react';
import { useHandleDeleteFile } from '../hooks';
interface IProps {
record: IFile;
setCurrentRecord: (record: any) => void;
showRenameModal: (record: IFile) => void;
showMoveFileModal: (ids: string[]) => void;
showConnectToKnowledgeModal: (record: IFile) => void;
setSelectedRowKeys(keys: string[]): void;
}
const ActionCell = ({
record,
setCurrentRecord,
showRenameModal,
showConnectToKnowledgeModal,
setSelectedRowKeys,
showMoveFileModal,
}: IProps) => {
const documentId = record.id;
const beingUsed = false;
const { t } = useTranslate('fileManager');
const { handleRemoveFile } = useHandleDeleteFile(
[documentId],
setSelectedRowKeys,
);
const { downloadFile, loading } = useDownloadFile();
const extension = getExtension(record.name);
const isKnowledgeBase = record.source_type === 'knowledgebase';
const onDownloadDocument = () => {
downloadFile({
id: documentId,
filename: record.name,
});
};
const setRecord = () => {
setCurrentRecord(record);
};
const onShowRenameModal = () => {
setRecord();
showRenameModal(record);
};
const onShowConnectToKnowledgeModal = () => {
showConnectToKnowledgeModal(record);
};
const onShowMoveFileModal = () => {
showMoveFileModal([documentId]);
};
return (
<Space size={0}>
{isKnowledgeBase || (
<Tooltip title={t('addToKnowledge')}>
<Button type="text" onClick={onShowConnectToKnowledgeModal}>
<LinkOutlined size={20} />
</Button>
</Tooltip>
)}
{isKnowledgeBase || (
<Tooltip title={t('rename', { keyPrefix: 'common' })}>
<Button type="text" disabled={beingUsed} onClick={onShowRenameModal}>
<EditOutlined size={20} />
</Button>
</Tooltip>
)}
{isKnowledgeBase || (
<Tooltip title={t('move', { keyPrefix: 'common' })}>
<Button
type="text"
disabled={beingUsed}
onClick={onShowMoveFileModal}
className="flex items-end"
>
<FolderInput className="size-4" />
</Button>
</Tooltip>
)}
{isKnowledgeBase || (
<Tooltip title={t('delete', { keyPrefix: 'common' })}>
<Button
type="text"
disabled={beingUsed}
onClick={handleRemoveFile}
className="flex items-end"
>
<Trash2 className="size-4" />
</Button>
</Tooltip>
)}
{record.type !== 'folder' && (
<Tooltip title={t('download', { keyPrefix: 'common' })}>
<Button
type="text"
disabled={beingUsed}
loading={loading}
onClick={onDownloadDocument}
>
<DownloadOutlined size={20} />
</Button>
</Tooltip>
)}
{isSupportedPreviewDocumentType(extension) && (
<NewDocumentLink
documentId={documentId}
documentName={record.name}
color="black"
>
<Tooltip title={t('preview')}>
<Button type="text">
<EyeOutlined size={20} />
</Button>
</Tooltip>
</NewDocumentLink>
)}
</Space>
);
};
export default ActionCell;
|