diff --git a/frontend/src/components/dialog/copy-dirent-dialog.js b/frontend/src/components/dialog/copy-dirent-dialog.js index 58f7831f41..d22978f382 100644 --- a/frontend/src/components/dialog/copy-dirent-dialog.js +++ b/frontend/src/components/dialog/copy-dirent-dialog.js @@ -111,7 +111,8 @@ class CopyDirent extends React.Component { return; } - // copy the dirent to it's child. eg: A/B -> A/B/C + // 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 48304b2c2a..a12dea8064 100644 --- a/frontend/src/components/tree-view/tree-view.js +++ b/frontend/src/components/tree-view/tree-view.js @@ -100,10 +100,10 @@ class TreeView extends React.Component { } this.props.onItemsMove(this.props.currentRepoInfo, '/'); this.setState({isTreeViewDropTipShow: false}); - return ; + return; } this.onMoveItems(dragStartNodeData, dropNodeData, this.props.currentRepoInfo, node.path); - return ; + return; } if (!dropNodeData) { @@ -134,9 +134,23 @@ class TreeView extends React.Component { // copy the dirent to it's child. eg: A/B -> A/B/C if (dropNodeData.object.type === 'dir' && nodeDirent.type === 'dir') { if (dropNodeData.parentNode.path !== nodeParentPath) { - if (dropNodeData.path.indexOf(nodeRootPath) !== -1) { + 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; + } + } + if (isFather.length === 0) { return; } + // if (dropNodeData.path.indexOf(nodeRootPath) !== -1) { + // return; + // } } } @@ -145,6 +159,7 @@ class TreeView extends React.Component { onMoveItems = (dragStartNodeData, dropNodeData, destRepo, destDirentPath) => { let direntPaths = []; + let destDirentPathArr = destDirentPath.split('/') dragStartNodeData.forEach(dirent => { let path = dirent.nodeRootPath; direntPaths.push(path); @@ -161,21 +176,31 @@ class TreeView extends React.Component { // move dirents to one of their child. eg: A/B, A/D -> A/B/C let isChildPath = direntPaths.some(direntPath => { - let flag = destDirentPath.length > direntPath.length && destDirentPath.indexOf(direntPath) > -1; + let direntPathArr = direntPath.split('/'); + + let flag = this.compareArray(direntPathArr, destDirentPathArr); return flag; }); if (isChildPath) { return; } - if (!dropNodeData) { //selectPath === '/' - this.setState({isTreeViewDropTipShow: false}); - return; - } - this.props.onItemsMove(destRepo, destDirentPath); } + compareArray = (direntPathArr, destDirentPathArr) => { + if (destDirentPathArr.length < direntPathArr.length) { // 往上移 + return false; + } else { + for (let i = 0; i < direntPathArr.length; i++) { //往下移 + if (direntPathArr[i] !== destDirentPathArr[i]) { + return false; + } + } + } + return true; + } + freezeItem = () => { this.setState({isItemFreezed: true}); }