Unverified Commit ded5ae68 authored by ZackYoung's avatar ZackYoung Committed by GitHub

[Fix][Web]Fix resources manage (#2500)

* fix_resources_manage * fix_resources_manage * fix_resources_manage
parent 9b76c75d
...@@ -88,7 +88,7 @@ public class UDFController { ...@@ -88,7 +88,7 @@ public class UDFController {
* @return Result * @return Result
*/ */
@PostMapping("/addOrUpdateByResourceId") @PostMapping("/addOrUpdateByResourceId")
public Result<Void> saveOrUpdate(@RequestBody CommonDTO<List<Integer>> dto) { public Result<Void> addOrUpdateByResourceId(@RequestBody CommonDTO<List<Integer>> dto) {
udfService.addOrUpdateByResourceId(dto.getData()); udfService.addOrUpdateByResourceId(dto.getData());
return Result.succeed(); return Result.succeed();
} }
......
/* /*
* *
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with * (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* *
*/ */
import RightContextMenu from '@/components/RightContextMenu'; import RightContextMenu from '@/components/RightContextMenu';
import { AuthorizedObject, useAccess } from '@/hooks/useAccess'; import {AuthorizedObject, useAccess} from '@/hooks/useAccess';
import { import {
RIGHT_CONTEXT_FILE_MENU, RIGHT_CONTEXT_FILE_MENU,
RIGHT_CONTEXT_FOLDER_MENU RIGHT_CONTEXT_FOLDER_MENU
} from '@/pages/RegCenter/Resource/components/constants'; } from '@/pages/RegCenter/Resource/components/constants';
import FileShow from '@/pages/RegCenter/Resource/components/FileShow'; import FileShow from '@/pages/RegCenter/Resource/components/FileShow';
import FileTree from '@/pages/RegCenter/Resource/components/FileTree'; import FileTree from '@/pages/RegCenter/Resource/components/FileTree';
import ResourceModal from '@/pages/RegCenter/Resource/components/ResourceModal'; import ResourceModal from '@/pages/RegCenter/Resource/components/ResourceModal';
import ResourcesUploadModal from '@/pages/RegCenter/Resource/components/ResourcesUploadModal'; import ResourcesUploadModal from '@/pages/RegCenter/Resource/components/ResourcesUploadModal';
import { handleOption, handleRemoveById, queryDataByParams } from '@/services/BusinessCrud'; import {handleOption, handleRemoveById, queryDataByParams} from '@/services/BusinessCrud';
import { API_CONSTANTS } from '@/services/endpoints'; import {API_CONSTANTS} from '@/services/endpoints';
import { ResourceInfo } from '@/types/RegCenter/data'; import {ResourceInfo} from '@/types/RegCenter/data';
import { InitResourceState } from '@/types/RegCenter/init.d'; import {InitResourceState} from '@/types/RegCenter/init.d';
import { ResourceState } from '@/types/RegCenter/state.d'; import {ResourceState} from '@/types/RegCenter/state.d';
import { l } from '@/utils/intl'; import {l} from '@/utils/intl';
import { ProCard } from '@ant-design/pro-components'; import {ProCard} from '@ant-design/pro-components';
import { MenuInfo } from 'rc-menu/es/interface'; import {MenuInfo} from 'rc-menu/es/interface';
import { Resizable } from 're-resizable'; import {Resizable} from 're-resizable';
import React, { useCallback, useEffect, useState } from 'react'; import React, {useCallback, useState} from 'react';
import {useAsyncEffect} from "ahooks";
import {unSupportView} from "@/utils/function";
const ResourceOverView: React.FC = () => { const ResourceOverView: React.FC = () => {
const [resourceState, setResourceState] = useState<ResourceState>(InitResourceState); const [resourceState, setResourceState] = useState<ResourceState>(InitResourceState);
const [editModal, setEditModal] = useState<string>(''); const [editModal, setEditModal] = useState<string>('');
const [uploadValue] = useState({ const [uploadValue] = useState({
url: API_CONSTANTS.RESOURCE_UPLOAD, url: API_CONSTANTS.RESOURCE_UPLOAD,
pid: '', pid: '',
description: '' description: ''
}); });
const refreshTree = async () => { const refreshTree = async () => {
await queryDataByParams<ResourceInfo[]>(API_CONSTANTS.RESOURCE_SHOW_TREE).then((res) => await queryDataByParams<ResourceInfo[]>(API_CONSTANTS.RESOURCE_SHOW_TREE).then((res) =>
setResourceState((prevState) => ({ ...prevState, treeData: res ?? [] })) setResourceState((prevState) => ({...prevState, treeData: res ?? []}))
); );
}; };
useAsyncEffect(async () => {
await refreshTree();
}, [])
useEffect(() => { /**
refreshTree(); * query content by id
}, [resourceState]); * @type {(id: number) => Promise<void>}
*/
const queryContent: (id: number) => Promise<void> = useCallback(
async (id: number) => {
await queryDataByParams<string>(API_CONSTANTS.RESOURCE_GET_CONTENT_BY_ID, {
id
}).then((res) => setResourceState((prevState) => ({...prevState, content: res ?? ''})));
},
[]
);
/** /**
* query content by id * the node click event
* @type {(id: number) => Promise<void>} * @param info
*/ * @returns {Promise<void>}
const queryContent = useCallback( */
async (id: number) => { const handleNodeClick = async (info: any): Promise<void> => {
await queryDataByParams<string>(API_CONSTANTS.RESOURCE_GET_CONTENT_BY_ID, { const {
id node: {id, isLeaf, key, name},
}).then((res) => setResourceState((prevState) => ({ ...prevState, content: res ?? '' }))); node
}, } = info;
[resourceState.clickedNode] setResourceState((prevState) => ({...prevState, selectedKeys: [key], clickedNode: node}));
); if (isLeaf && !unSupportView(name)) {
await queryContent(id);
} else {
setResourceState((prevState) => ({...prevState, content: ''}));
}
};
/** /**
* the node click event * the node right click event OF upload,
* @param info */
* @returns {Promise<void>} const handleCreateFolder = () => {
*/ if (resourceState.rightClickedNode) {
const handleNodeClick = async (info: any): Promise<void> => { setEditModal('createFolder');
const { const {id} = resourceState.rightClickedNode;
node: { id, isLeaf, key }, setResourceState((prevState) => ({
node ...prevState,
} = info; editOpen: true,
setResourceState((prevState) => ({ ...prevState, selectedKeys: [key], clickedNode: node })); value: {id, fileName: '', description: ''},
if (isLeaf) { contextMenuOpen: false
await queryContent(id); }));
} else { }
setResourceState((prevState) => ({ ...prevState, content: '' })); };
} const handleUpload = () => {
}; if (resourceState.rightClickedNode) {
uploadValue.pid = resourceState.rightClickedNode.id;
// todo: upload
setResourceState((prevState) => ({...prevState, uploadOpen: true, contextMenuOpen: false}));
}
};
/** /**
* the node right click event OF upload, * the node right click event OF delete,
*/ */
const handleCreateFolder = () => { const handleDelete = async () => {
if (resourceState.rightClickedNode) { if (resourceState.rightClickedNode) {
setEditModal('createFolder'); setResourceState((prevState) => ({...prevState, contextMenuOpen: false}));
const { id } = resourceState.rightClickedNode; await handleRemoveById(API_CONSTANTS.RESOURCE_REMOVE, resourceState.rightClickedNode.id);
setResourceState((prevState) => ({ await refreshTree();
...prevState, }
editOpen: true, };
value: { id, fileName: '', description: '' },
contextMenuOpen: false
}));
}
};
const handleUpload = () => {
if (resourceState.rightClickedNode) {
uploadValue.pid = resourceState.rightClickedNode.id;
// todo: upload
setResourceState((prevState) => ({ ...prevState, uploadOpen: true, contextMenuOpen: false }));
}
};
/** /**
* the node right click event OF delete, * the node right click event OF rename,
*/ */
const handleDelete = async () => { const handleRename = () => {
if (resourceState.rightClickedNode) { if (resourceState.rightClickedNode) {
setResourceState((prevState) => ({ ...prevState, contextMenuOpen: false })); setEditModal('rename');
await handleRemoveById(API_CONSTANTS.RESOURCE_REMOVE, resourceState.rightClickedNode.id); const {id, name, desc} = resourceState.rightClickedNode;
await refreshTree(); setResourceState((prevState) => ({
} ...prevState,
}; editOpen: true,
value: {id, fileName: name, description: desc},
contextMenuOpen: false
}));
}
};
/** const handleMenuClick = async (node: MenuInfo) => {
* the node right click event OF rename, switch (node.key) {
*/ case 'createFolder':
const handleRename = () => { handleCreateFolder();
if (resourceState.rightClickedNode) { break;
setEditModal('rename'); case 'upload':
const { id, name, desc } = resourceState.rightClickedNode; handleUpload();
setResourceState((prevState) => ({ break;
...prevState, case 'delete':
editOpen: true, await handleDelete();
value: { id, fileName: name, description: desc }, break;
contextMenuOpen: false case 'rename':
})); handleRename();
} break;
}; default:
break;
}
};
const handleMenuClick = (node: MenuInfo) => { /**
switch (node.key) { * the right click event
case 'createFolder': * @param info
handleCreateFolder(); */
break; const handleRightClick = (info: any) => {
case 'upload': // 获取右键点击的节点信息
handleUpload(); const {node, event} = info;
break; console.log('node', node);
case 'delete': setResourceState((prevState) => ({
handleDelete(); ...prevState,
break; selectedKeys: [node.key],
case 'rename': rightClickedNode: node,
handleRename(); contextMenuOpen: true,
break; contextMenuPosition: {
default: ...prevState.contextMenuPosition,
break; left: event.clientX + 20,
} top: event.clientY + 20
}; }
}));
};
/** /**
* the right click event * the rename cancel
* @param info */
*/ const handleModalCancel = async () => {
const handleRightClick = (info: any) => { setResourceState((prevState) => ({...prevState, editOpen: false}));
// 获取右键点击的节点信息 await refreshTree();
const { node, event } = info; };
console.log('node', node);
setResourceState((prevState) => ({
...prevState,
selectedKeys: [node.key],
rightClickedNode: node,
contextMenuOpen: true,
contextMenuPosition: {
...prevState.contextMenuPosition,
left: event.clientX + 20,
top: event.clientY + 20
}
}));
};
/** /**
* the rename cancel * the rename ok
*/ */
const handleModalCancel = () => { const handleModalSubmit = async (value: Partial<ResourceInfo>) => {
setResourceState((prevState) => ({ ...prevState, editOpen: false })); const {id: pid} = resourceState.rightClickedNode;
refreshTree(); if (editModal === 'createFolder') {
}; await handleOption(API_CONSTANTS.RESOURCE_CREATE_FOLDER, l('right.menu.createFolder'), {
...value,
pid
});
setResourceState((prevState) => ({...prevState, editOpen: false}));
} else if (editModal === 'rename') {
await handleOption(API_CONSTANTS.RESOURCE_RENAME, l('right.menu.rename'), {...value, pid});
}
};
const handleUploadCancel = async () => {
setResourceState((prevState) => ({...prevState, uploadOpen: false}));
await refreshTree();
};
/** /**
* the rename ok * the content change
*/ * @param value
const handleModalSubmit = async (value: Partial<ResourceInfo>) => { */
const { id: pid } = resourceState.rightClickedNode; const handleContentChange = (value: any) => {
if (editModal === 'createFolder') { setResourceState((prevState) => ({...prevState, content: value}));
await handleOption(API_CONSTANTS.RESOURCE_CREATE_FOLDER, l('right.menu.createFolder'), { // todo: save content
...value, };
pid
});
setResourceState((prevState) => ({ ...prevState, editOpen: false }));
} else if (editModal === 'rename') {
await handleOption(API_CONSTANTS.RESOURCE_RENAME, l('right.menu.rename'), { ...value, pid });
}
};
const handleUploadCancel = async () => {
setResourceState((prevState) => ({ ...prevState, uploadOpen: false }));
await refreshTree();
};
/** const access = useAccess();
* the content change
* @param value
*/
const handleContentChange = (value: any) => {
setResourceState((prevState) => ({ ...prevState, content: value }));
// todo: save content
};
const access = useAccess(); const renderRightMenu = () => {
if (!resourceState.rightClickedNode.isLeaf) {
return RIGHT_CONTEXT_FOLDER_MENU.filter(
(menu) => !menu.path || !!AuthorizedObject({path: menu.path, children: menu, access})
);
}
return RIGHT_CONTEXT_FILE_MENU.filter(
(menu) => !menu.path || !!AuthorizedObject({path: menu.path, children: menu, access})
);
};
const renderRightMenu = () => { /**
if (!resourceState.rightClickedNode.isLeaf) { * render
return RIGHT_CONTEXT_FOLDER_MENU.filter( */
(menu) => !!!menu.path || !!AuthorizedObject({ path: menu.path, children: menu, access }) return (
); <>
} <ProCard size={'small'}>
return RIGHT_CONTEXT_FILE_MENU.filter( <Resizable
(menu) => !!!menu.path || !!AuthorizedObject({ path: menu.path, children: menu, access }) defaultSize={{
width: 500,
height: '100%'
}}
minWidth={200}
maxWidth={1200}
>
<ProCard ghost hoverable colSpan={'18%'} className={'siderTree schemaTree'}>
<FileTree
selectedKeys={resourceState.selectedKeys}
treeData={resourceState.treeData}
onRightClick={handleRightClick}
onNodeClick={(info: any) => handleNodeClick(info)}
/>
<RightContextMenu
contextMenuPosition={resourceState.contextMenuPosition}
open={resourceState.contextMenuOpen}
openChange={() =>
setResourceState((prevState) => ({...prevState, contextMenuOpen: false}))
}
items={renderRightMenu()}
onClick={handleMenuClick}
/>
</ProCard>
</Resizable>
<ProCard.Divider type={'vertical'}/>
<ProCard ghost hoverable className={'schemaTree'} bodyStyle={{height: '100%'}}>
<FileShow
onChange={handleContentChange}
code={resourceState.content}
item={resourceState.clickedNode}
/>
</ProCard>
</ProCard>
{resourceState.editOpen && (
<ResourceModal
title={
editModal === 'createFolder'
? l('right.menu.createFolder')
: editModal === 'rename'
? l('right.menu.rename')
: ''
}
formValues={resourceState.value}
onOk={handleModalSubmit}
onClose={handleModalCancel}
visible={resourceState.editOpen}
/>
)}
{resourceState.uploadOpen && (
<ResourcesUploadModal
onUpload={uploadValue}
visible={resourceState.uploadOpen}
onOk={handleUploadCancel}
onClose={handleUploadCancel}
/>
)}
</>
); );
};
/**
* render
*/
return (
<>
<ProCard size={'small'}>
<Resizable
defaultSize={{
width: 500,
height: '100%'
}}
minWidth={200}
maxWidth={1200}
>
<ProCard ghost hoverable colSpan={'18%'} className={'siderTree schemaTree'}>
<FileTree
selectedKeys={resourceState.selectedKeys}
treeData={resourceState.treeData}
onRightClick={handleRightClick}
onNodeClick={(info: any) => handleNodeClick(info)}
/>
<RightContextMenu
contextMenuPosition={resourceState.contextMenuPosition}
open={resourceState.contextMenuOpen}
openChange={() =>
setResourceState((prevState) => ({ ...prevState, contextMenuOpen: false }))
}
items={renderRightMenu()}
onClick={handleMenuClick}
/>
</ProCard>
</Resizable>
<ProCard.Divider type={'vertical'} />
<ProCard ghost hoverable className={'schemaTree'} bodyStyle={{ height: '100%' }}>
<FileShow
onChange={handleContentChange}
code={resourceState.content}
item={resourceState.clickedNode}
/>
</ProCard>
</ProCard>
{resourceState.editOpen && (
<ResourceModal
title={
editModal === 'createFolder'
? l('right.menu.createFolder')
: editModal === 'rename'
? l('right.menu.rename')
: ''
}
formValues={resourceState.value}
onOk={handleModalSubmit}
onClose={handleModalCancel}
visible={resourceState.editOpen}
/>
)}
{resourceState.uploadOpen && (
<ResourcesUploadModal
onUpload={uploadValue}
visible={resourceState.uploadOpen}
onOk={handleUploadCancel}
onClose={handleUploadCancel}
/>
)}
</>
);
}; };
export default ResourceOverView; export default ResourceOverView;
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