Unverified Commit 3695aaf9 authored by Zzm0809's avatar Zzm0809 Committed by GitHub

[Optimization] Optimizing replication types for resource paths (#3443)

parent 280ef090
......@@ -985,7 +985,12 @@ export default {
'Support for a single or bulk upload. Strictly prohibited from uploading company data or\n other banned files.',
'rc.resource.filelist': 'File list',
'rc.resource.sync': 'Sync remote files',
'rc.resource.copy': 'Copy as: {fillValue}',
'rc.resource.copy_to_add_custom_jar': 'Copy as ADD CUSTOMJAR syntax',
'rc.resource.copy_to_add_jar': 'Copy as ADD JAR syntax',
'rc.resource.copy_to_add_file': 'Copy as ADD FILE syntax',
'rc.resource.copy_to_add_rs_path': 'Copy RS protocol resource path',
'rc.resource.copy_success':
'Copy successfully, The value is: [{fillValue}] has been copied to the clipboard. Please paste it to the desired location for use',
'rc.resource.enable': 'Resource management function is not enabled',
'rc.resource.enable.tips':
'Please go to [Setting Center -> Global Settings -> Resource Configuration] to enable the resource management function!!!',
......
......@@ -943,7 +943,12 @@ export default {
'rc.resource.upload.tip2': '支持单个或批量上传。严禁上传公司数据或其他禁止上传的文件。',
'rc.resource.filelist': '文件列表',
'rc.resource.sync': '同步目录结构',
'rc.resource.copy': '复制为: {fillValue}',
'rc.resource.copy_to_add_custom_jar': '复制为 ADD CUSTOMJAR 语法',
'rc.resource.copy_to_add_jar': '复制为 ADD JAR 语法',
'rc.resource.copy_to_add_file': '复制为 ADD FILE 语法',
'rc.resource.copy_to_add_rs_path': '复制 RS 协议资源路径',
'rc.resource.copy_success':
'复制成功,值为:[{fillValue}] 已复制到剪贴板。请粘贴到需要的地方进行使用',
'rc.resource.enable': '未启用资源管理功能',
'rc.resource.enable.tips': '请前往 [配置中心 -> 全局配置 -> Resource 配置] 中启用资源管理功能!!!',
......
......@@ -21,22 +21,11 @@ import { TagAlignCenter } from '@/components/StyledComponents';
import { ResourceInfo } from '@/types/RegCenter/data';
import { parseByteStr, renderIcon } from '@/utils/function';
import { l } from '@/utils/intl';
import { Typography } from 'antd';
const buildTitleLabel = (showCopy = false, item: ResourceInfo) => {
const fillValue = `ADD FILE 'rs:${item.fullName}';`;
const buildTitleLabel = (item: ResourceInfo) => {
return (
<>
{!item.isDirectory && showCopy ? (
<Typography.Text
copyable={{ text: fillValue, tooltips: l('rc.resource.copy', '', { fillValue }) }}
>
{item.fileName}
</Typography.Text>
) : (
item.fileName
)}
{item.fileName}
{!item.isDirectory && (
<span style={{ color: 'gray' }}>
{' '}
......@@ -92,8 +81,7 @@ function filterEmpty(
export const buildResourceTreeData = (
data: ResourceInfo[] = [],
isFilterEmptyChildren = false,
filterSuffixList: string[] = [],
showCopy: boolean = false
filterSuffixList: string[] = []
): any =>
data
.filter((item: ResourceInfo) => filterEmpty(isFilterEmptyChildren, item, filterSuffixList))
......@@ -105,12 +93,12 @@ export const buildResourceTreeData = (
label: item.fileName,
icon: <TagAlignCenter>{renderIcon(item.fileName, '.', item.isDirectory)}</TagAlignCenter>,
path: item.fullName,
title: buildTitleLabel(showCopy, item),
title: buildTitleLabel(item),
fullInfo: item,
key: item.id,
id: item.id,
children:
item.children &&
buildResourceTreeData(item.children, isFilterEmptyChildren, filterSuffixList, showCopy)
buildResourceTreeData(item.children, isFilterEmptyChildren, filterSuffixList)
};
});
......@@ -50,7 +50,7 @@ const FileTree: React.FC<FileTreeProps> = (props) => {
selectedKeys={selectedKeys}
onSelect={(_, info) => onNodeClick(info)}
onRightClick={(info) => onRightClick(info)}
treeData={buildResourceTreeData(treeData, false, [], true)}
treeData={buildResourceTreeData(treeData, false, [])}
/>
) : (
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
......
......@@ -20,6 +20,7 @@
import RightContextMenu from '@/components/RightContextMenu';
import { AuthorizedObject, useAccess } from '@/hooks/useAccess';
import {
ResourceRightMenuKey,
RIGHT_CONTEXT_FILE_MENU,
RIGHT_CONTEXT_FOLDER_MENU
} from '@/pages/RegCenter/Resource/components/constants';
......@@ -41,6 +42,7 @@ import { InitResourceState } from '@/types/RegCenter/init.d';
import { ResourceState } from '@/types/RegCenter/state.d';
import { unSupportView } from '@/utils/function';
import { l } from '@/utils/intl';
import { SuccessMessage } from '@/utils/messages';
import { SplitPane } from '@andrewray/react-multi-split-pane';
import { Pane } from '@andrewray/react-multi-split-pane/dist/lib/Pane';
import { WarningOutlined } from '@ant-design/icons';
......@@ -119,7 +121,7 @@ const ResourceOverView: React.FC<connect> = (props) => {
*/
const handleCreateFolder = () => {
if (resourceState.rightClickedNode) {
setEditModal('createFolder');
setEditModal(ResourceRightMenuKey.CREATE_FOLDER);
const { id } = resourceState.rightClickedNode;
setResourceState((prevState) => ({
...prevState,
......@@ -153,7 +155,7 @@ const ResourceOverView: React.FC<connect> = (props) => {
*/
const handleRename = () => {
if (resourceState.rightClickedNode) {
setEditModal('rename');
setEditModal(ResourceRightMenuKey.RENAME);
const { id, name, desc } = resourceState.rightClickedNode;
setResourceState((prevState) => ({
...prevState,
......@@ -164,20 +166,50 @@ const ResourceOverView: React.FC<connect> = (props) => {
}
};
async function handleCopyTo(fillValue: string) {
await navigator.clipboard.writeText(fillValue);
await SuccessMessage(l('rc.resource.copy_success', '', { fillValue }));
}
const handleMenuClick = async (node: MenuInfo) => {
const { fullInfo } = resourceState.rightClickedNode;
switch (node.key) {
case 'createFolder':
case ResourceRightMenuKey.CREATE_FOLDER:
handleCreateFolder();
break;
case 'upload':
case ResourceRightMenuKey.UPLOAD:
handleUpload();
break;
case 'delete':
case ResourceRightMenuKey.DELETE:
await handleDelete();
break;
case 'rename':
case ResourceRightMenuKey.RENAME:
handleRename();
break;
case ResourceRightMenuKey.COPY_TO_ADD_CUSTOM_JAR:
if (fullInfo) {
const fillValue = `ADD CUSTOMJAR 'rs:${fullInfo.fullName}';`;
await handleCopyTo(fillValue);
}
break;
case ResourceRightMenuKey.COPY_TO_ADD_JAR:
if (fullInfo) {
const fillValue = `ADD JAR 'rs:${fullInfo.fullName}';`;
await handleCopyTo(fillValue);
}
break;
case ResourceRightMenuKey.COPY_TO_ADD_FILE:
if (fullInfo) {
const fillValue = `ADD FILE 'rs:${fullInfo.fullName}';`;
await handleCopyTo(fillValue);
}
break;
case ResourceRightMenuKey.COPY_TO_ADD_RS_PATH:
if (fullInfo) {
const fillValue = `rs:${fullInfo.fullName}`;
await handleCopyTo(fillValue);
}
break;
default:
break;
}
......@@ -188,10 +220,10 @@ const ResourceOverView: React.FC<connect> = (props) => {
* @param info
*/
const handleRightClick = (info: any) => {
// 获取右键点击的节点信息
// Obtain the node information for right-click
const { node, event } = info;
// 判断右键的位置是否超出屏幕 , 如果超出屏幕则设置为屏幕的最大值 往上偏移 75 (需要根据具体的右键菜单数量合理设置)
// Determine if the position of the right button exceeds the screen. If it exceeds the screen, set it to the maximum value of the screen offset upwards by 75 (it needs to be reasonably set according to the specific number of right button menus)
if (event.clientY + 150 > window.innerHeight) {
event.clientY = window.innerHeight - 75;
}
......@@ -229,7 +261,7 @@ const ResourceOverView: React.FC<connect> = (props) => {
*/
const handleModalSubmit = async (value: Partial<ResourceInfo>) => {
const { id: pid } = resourceState.rightClickedNode;
if (editModal === 'createFolder') {
if (editModal === ResourceRightMenuKey.CREATE_FOLDER) {
await handleOption(
API_CONSTANTS.RESOURCE_CREATE_FOLDER,
l('right.menu.createFolder'),
......@@ -239,7 +271,7 @@ const ResourceOverView: React.FC<connect> = (props) => {
},
() => handleModalCancel()
);
} else if (editModal === 'rename') {
} else if (editModal === ResourceRightMenuKey.RENAME) {
await handleOption(
API_CONSTANTS.RESOURCE_RENAME,
l('right.menu.rename'),
......
......@@ -20,12 +20,24 @@
import { PermissionConstants } from '@/types/Public/constants';
import { l } from '@/utils/intl';
import {
CopyOutlined,
DeleteOutlined,
EditOutlined,
PlusCircleOutlined,
UploadOutlined
} from '@ant-design/icons';
export enum ResourceRightMenuKey {
COPY_TO_ADD_CUSTOM_JAR = 'copy_to_add_custom_jar',
COPY_TO_ADD_JAR = 'copy_to_add_jar',
COPY_TO_ADD_FILE = 'copy_to_add_file',
COPY_TO_ADD_RS_PATH = 'copy_to_add_rs_path',
DELETE = 'delete',
RENAME = 'rename',
CREATE_FOLDER = 'createFolder',
UPLOAD = 'upload'
}
/**
* the right context menu
* @param {boolean} isDisabled - is disabled or not , if disabled , the menu will be disabled too
......@@ -34,13 +46,37 @@ import {
*/
export const RIGHT_CONTEXT_FILE_MENU = [
{
key: 'delete',
key: ResourceRightMenuKey.COPY_TO_ADD_CUSTOM_JAR,
icon: <CopyOutlined />,
label: l('rc.resource.copy_to_add_custom_jar'),
path: PermissionConstants.REGISTRATION_RESOURCE_DELETE
},
{
key: ResourceRightMenuKey.COPY_TO_ADD_JAR,
icon: <CopyOutlined />,
label: l('rc.resource.copy_to_add_jar'),
path: PermissionConstants.REGISTRATION_RESOURCE_DELETE
},
{
key: ResourceRightMenuKey.COPY_TO_ADD_FILE,
icon: <CopyOutlined />,
label: l('rc.resource.copy_to_add_file'),
path: PermissionConstants.REGISTRATION_RESOURCE_DELETE
},
{
key: ResourceRightMenuKey.COPY_TO_ADD_RS_PATH,
icon: <CopyOutlined />,
label: l('rc.resource.copy_to_add_rs_path'),
path: PermissionConstants.REGISTRATION_RESOURCE_DELETE
},
{
key: ResourceRightMenuKey.DELETE,
icon: <DeleteOutlined />,
label: l('right.menu.delete'),
path: PermissionConstants.REGISTRATION_RESOURCE_DELETE
},
{
key: 'rename',
key: ResourceRightMenuKey.RENAME,
icon: <EditOutlined />,
label: l('right.menu.rename'),
path: PermissionConstants.REGISTRATION_RESOURCE_RENAME
......@@ -48,25 +84,25 @@ export const RIGHT_CONTEXT_FILE_MENU = [
];
export const RIGHT_CONTEXT_FOLDER_MENU = [
{
key: 'createFolder',
key: ResourceRightMenuKey.CREATE_FOLDER,
icon: <PlusCircleOutlined />,
label: l('right.menu.createFolder'),
path: PermissionConstants.REGISTRATION_RESOURCE_ADD_FOLDER
},
{
key: 'upload',
key: ResourceRightMenuKey.UPLOAD,
icon: <UploadOutlined />,
label: l('button.upload'),
path: PermissionConstants.REGISTRATION_RESOURCE_UPLOAD
},
{
key: 'delete',
key: ResourceRightMenuKey.DELETE,
icon: <DeleteOutlined />,
label: l('right.menu.delete'),
path: PermissionConstants.REGISTRATION_RESOURCE_DELETE
},
{
key: 'rename',
key: ResourceRightMenuKey.RENAME,
icon: <EditOutlined />,
label: l('right.menu.rename'),
path: PermissionConstants.REGISTRATION_RESOURCE_RENAME
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment