Skip to content

Commit

Permalink
[Optimization] Optimizing replication types for resource paths (DataL…
Browse files Browse the repository at this point in the history
…inkDC#3443)

Signed-off-by: Zzm0809 <[email protected]>
Co-authored-by: Zzm0809 <[email protected]>
  • Loading branch information
Zzm0809 and Zzm0809 authored Apr 30, 2024
1 parent 280ef09 commit 3695aaf
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 36 deletions.
7 changes: 6 additions & 1 deletion dinky-web/src/locales/en-US/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!!!',
Expand Down
7 changes: 6 additions & 1 deletion dinky-web/src/locales/zh-CN/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 配置] 中启用资源管理功能!!!',

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' }}>
{' '}
Expand Down Expand Up @@ -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))
Expand All @@ -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)
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -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} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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'),
Expand All @@ -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'),
Expand Down
48 changes: 42 additions & 6 deletions dinky-web/src/pages/RegCenter/Resource/components/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,39 +46,63 @@ 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
}
];
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
Expand Down

0 comments on commit 3695aaf

Please sign in to comment.