You've already forked DataMate
refactor(KnowledgeManagement): 优化知识集详情页面文件记录渲染逻辑
- 将重复的条件判断提取为变量 isFileRecord - 使用立即执行函数简化 JSX 结构 - 统一文件类型记录的操作按钮渲染方式 - 提高代码可读性和维护性
This commit is contained in:
@@ -335,41 +335,54 @@ const KnowledgeSetDetail = () => {
|
|||||||
/>
|
/>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
)}
|
)}
|
||||||
{(record.contentType === KnowledgeContentType.FILE ||
|
{(() => {
|
||||||
record.sourceType === KnowledgeSourceType.FILE_UPLOAD) && (
|
const isFileRecord =
|
||||||
<Tooltip title="预览">
|
record.contentType === KnowledgeContentType.FILE ||
|
||||||
<Button
|
record.sourceType === KnowledgeSourceType.FILE_UPLOAD;
|
||||||
type="text"
|
return (
|
||||||
icon={<EyeOutlined />}
|
<>
|
||||||
onClick={() => handlePreviewItemFile(record)}
|
{isFileRecord && (
|
||||||
loading={previewLoadingItemId === record.id}
|
<Tooltip title="预览">
|
||||||
aria-label="预览"
|
<Button
|
||||||
/>
|
type="text"
|
||||||
</Tooltip>
|
icon={<EyeOutlined />}
|
||||||
)}
|
onClick={() => handlePreviewItemFile(record)}
|
||||||
{(record.contentType === KnowledgeContentType.FILE ||
|
loading={previewLoadingItemId === record.id}
|
||||||
record.sourceType === KnowledgeSourceType.FILE_UPLOAD) && (
|
aria-label="预览"
|
||||||
<Tooltip title="下载文件">
|
/>
|
||||||
<Button
|
</Tooltip>
|
||||||
type="text"
|
)}
|
||||||
icon={<DownloadOutlined />}
|
{isFileRecord && (
|
||||||
onClick={() => handleDownloadItem(record)}
|
<Tooltip title="下载文件">
|
||||||
aria-label="下载文件"
|
<Button
|
||||||
/>
|
type="text"
|
||||||
</Tooltip>
|
icon={<DownloadOutlined />}
|
||||||
)}
|
onClick={() => handleDownloadItem(record)}
|
||||||
<Button
|
aria-label="下载文件"
|
||||||
type="text"
|
/>
|
||||||
icon={<EditOutlined />}
|
</Tooltip>
|
||||||
onClick={() => {
|
)}
|
||||||
setCurrentItem({
|
{isFileRecord && (
|
||||||
...(record as unknown as KnowledgeItem),
|
<Button
|
||||||
status: record.rawStatus,
|
type="text"
|
||||||
});
|
icon={<EditOutlined />}
|
||||||
setItemEditorOpen(true);
|
onClick={() => {
|
||||||
}}
|
setCurrentItem({
|
||||||
disabled={isReadOnly || record.rawStatus === KnowledgeStatusType.ARCHIVED || record.rawStatus === KnowledgeStatusType.DEPRECATED}
|
...(record as unknown as KnowledgeItem),
|
||||||
/>
|
status: record.rawStatus,
|
||||||
|
});
|
||||||
|
setItemEditorOpen(true);
|
||||||
|
}}
|
||||||
|
disabled={
|
||||||
|
isReadOnly ||
|
||||||
|
record.rawStatus === KnowledgeStatusType.ARCHIVED ||
|
||||||
|
record.rawStatus === KnowledgeStatusType.DEPRECATED
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
})()}
|
||||||
<Button
|
<Button
|
||||||
type="text"
|
type="text"
|
||||||
danger
|
danger
|
||||||
|
|||||||
Reference in New Issue
Block a user