From f2ba1f3d77f2bd2d1a081e81c90fe40e23f373ed Mon Sep 17 00:00:00 2001 From: zxj96 <519213124@qq.com> Date: Tue, 18 Jun 2019 10:39:52 +0800 Subject: [PATCH] optimization code --- .../components/dialog/copy-dirent-dialog.js | 1 - .../src/components/tree-view/tree-view.js | 23 +++++-------------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/frontend/src/components/dialog/copy-dirent-dialog.js b/frontend/src/components/dialog/copy-dirent-dialog.js index d22978f382..0fd0b53693 100644 --- a/frontend/src/components/dialog/copy-dirent-dialog.js +++ b/frontend/src/components/dialog/copy-dirent-dialog.js @@ -112,7 +112,6 @@ class CopyDirent extends React.Component { } // copy the dirent to it's child. eg: A/B -> A/B/C - //find problem eg ABC can't move AB/ABC and A can't move B/AB if ( selectedPath && selectedPath.length > direntPath.length && selectedPath.indexOf(direntPath) > -1) { message = gettext('Can not copy directory %(src)s to its subdirectory %(des)s'); message = message.replace('%(src)s', direntPath); diff --git a/frontend/src/components/tree-view/tree-view.js b/frontend/src/components/tree-view/tree-view.js index a12dea8064..bdc3403b95 100644 --- a/frontend/src/components/tree-view/tree-view.js +++ b/frontend/src/components/tree-view/tree-view.js @@ -136,21 +136,10 @@ class TreeView extends React.Component { if (dropNodeData.parentNode.path !== nodeParentPath) { let dropNodeDataArr = dropNodeData.path.split('/'); let nodeRootPathArr = nodeRootPath.split('/'); - let isFather = ''; - - let smallArr = dropNodeDataArr.length > nodeRootPathArr.length ? nodeRootPathArr : dropNodeDataArr; - for (let i = 0; i< smallArr.length; i++) { - if (dropNodeDataArr[i] !== nodeRootPathArr[i]) { - isFather = smallArr[i]; - break; - } + let flag = this.compareArray(nodeRootPathArr, dropNodeDataArr); + if (flag) { + return ; } - if (isFather.length === 0) { - return; - } - // if (dropNodeData.path.indexOf(nodeRootPath) !== -1) { - // return; - // } } } @@ -159,7 +148,7 @@ class TreeView extends React.Component { onMoveItems = (dragStartNodeData, dropNodeData, destRepo, destDirentPath) => { let direntPaths = []; - let destDirentPathArr = destDirentPath.split('/') + let destDirentPathArr = destDirentPath.split('/'); dragStartNodeData.forEach(dirent => { let path = dirent.nodeRootPath; direntPaths.push(path); @@ -189,10 +178,10 @@ class TreeView extends React.Component { } compareArray = (direntPathArr, destDirentPathArr) => { - if (destDirentPathArr.length < direntPathArr.length) { // 往上移 + if (destDirentPathArr.length < direntPathArr.length) { return false; } else { - for (let i = 0; i < direntPathArr.length; i++) { //往下移 + for (let i = 0; i < direntPathArr.length; i++) { if (direntPathArr[i] !== destDirentPathArr[i]) { return false; }