1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-04 00:20:07 +00:00

optimization code

This commit is contained in:
zxj96
2019-06-18 21:35:39 +08:00
parent e357bf972b
commit 46aaf835e1
2 changed files with 9 additions and 14 deletions

View File

@@ -357,11 +357,10 @@ class DirentListItem extends React.Component {
} }
let { selectedDirentList } = this.props; let { selectedDirentList } = this.props;
let selectedList = [];
if (selectedDirentList.length > 0 && selectedDirentList.includes(this.props.dirent)) { // drag items and selectedDirentList include item if (selectedDirentList.length > 0 && selectedDirentList.includes(this.props.dirent)) { // drag items and selectedDirentList include item
selectedList = selectedDirentList.map(item => { let selectedList = selectedDirentList.map(item => {
let getDirentPath = this.getDirentPath(item); let nodeRootPath = this.getDirentPath(item);
let dragStartItemData = {nodeDirent: item, nodeParentPath: this.props.path, nodeRootPath: getDirentPath}; let dragStartItemData = {nodeDirent: item, nodeParentPath: this.props.path, nodeRootPath: nodeRootPath};
return dragStartItemData; return dragStartItemData;
}); });
selectedList = JSON.stringify(selectedList); selectedList = JSON.stringify(selectedList);
@@ -369,8 +368,8 @@ class DirentListItem extends React.Component {
return ; return ;
} }
let getDirentPath = this.getDirentPath(this.props.dirent); let nodeRootPath = this.getDirentPath(this.props.dirent);
let dragStartItemData = {nodeDirent: this.props.dirent, nodeParentPath: this.props.path, nodeRootPath: getDirentPath}; let dragStartItemData = {nodeDirent: this.props.dirent, nodeParentPath: this.props.path, nodeRootPath: nodeRootPath};
dragStartItemData = JSON.stringify(dragStartItemData); dragStartItemData = JSON.stringify(dragStartItemData);
e.dataTransfer.setData('applicaiton/drag-item-info', dragStartItemData); e.dataTransfer.setData('applicaiton/drag-item-info', dragStartItemData);
@@ -411,10 +410,8 @@ class DirentListItem extends React.Component {
let dragStartItemData = e.dataTransfer.getData('applicaiton/drag-item-info'); let dragStartItemData = e.dataTransfer.getData('applicaiton/drag-item-info');
dragStartItemData = JSON.parse(dragStartItemData); dragStartItemData = JSON.parse(dragStartItemData);
if (Array.isArray(dragStartItemData)) { //move items if (Array.isArray(dragStartItemData)) { //move items
let direntPaths = []; let direntPaths = dragStartItemData.map(draggedItem => {
dragStartItemData.forEach(draggedItem => { return draggedItem.nodeRootPath
let path = Utils.joinPath(this.props.path, draggedItem.nodeDirent.name);
direntPaths.push(path);
}); });
let selectedPath = Utils.joinPath(this.props.path, this.props.dirent.name); let selectedPath = Utils.joinPath(this.props.path, this.props.dirent.name);

View File

@@ -135,8 +135,7 @@ class TreeView extends React.Component {
if (dropNodeData.object.type === 'dir' && nodeDirent.type === 'dir') { if (dropNodeData.object.type === 'dir' && nodeDirent.type === 'dir') {
if (dropNodeData.parentNode.path !== nodeParentPath) { if (dropNodeData.parentNode.path !== nodeParentPath) {
let paths = Utils.getPaths(dropNodeData.path); let paths = Utils.getPaths(dropNodeData.path);
let isChildPath = paths.includes(nodeRootPath); if (paths.includes(nodeRootPath)) {
if (isChildPath) {
return; return;
} }
} }
@@ -169,8 +168,7 @@ class TreeView extends React.Component {
// move dirents to one of their child. eg: A/B, A/D -> A/B/C // move dirents to one of their child. eg: A/B, A/D -> A/B/C
let isChildPath = direntPaths.some(direntPath => { let isChildPath = direntPaths.some(direntPath => {
let flag = paths.includes(direntPath); return paths.includes(direntPath);
return flag;
}); });
if (isChildPath) { if (isChildPath) {
return; return;