File size: 3,727 Bytes
ba91369 68ed806 c020852 4056097 ba91369 8c06509 8d2a400 9426215 8c06509 8d2a400 8c06509 ba91369 bd39551 8c06509 40a88fa bd39551 ba91369 40a88fa 8c06509 9426215 bd39551 c020852 8d2a400 15052fd 8c06509 c020852 8c06509 40a88fa bd39551 40a88fa ba91369 8c06509 15052fd 589b0da 15052fd 8c06509 15052fd 589b0da 15052fd ba91369 15052fd 589b0da 15052fd 9426215 c020852 9426215 bd39551 8d2a400 d3e0754 8d2a400 589b0da 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 136 137 |
import NewDocumentLink from '@/components/new-document-link';
import SvgIcon from '@/components/svg-icon';
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 {
DeleteOutlined,
DownloadOutlined,
EditOutlined,
EyeOutlined,
LinkOutlined,
} from '@ant-design/icons';
import { Button, Space, Tooltip } from 'antd';
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}
>
<SvgIcon name={`move`} width={16}></SvgIcon>
</Button>
</Tooltip>
)}
{isKnowledgeBase || (
<Tooltip title={t('delete', { keyPrefix: 'common' })}>
<Button type="text" disabled={beingUsed} onClick={handleRemoveFile}>
<DeleteOutlined size={20} />
</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;
|