1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-31 14:42:10 +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 selectedList = [];
if (selectedDirentList.length > 0 && selectedDirentList.includes(this.props.dirent)) { // drag items and selectedDirentList include item
selectedList = selectedDirentList.map(item => {
let getDirentPath = this.getDirentPath(item);
let dragStartItemData = {nodeDirent: item, nodeParentPath: this.props.path, nodeRootPath: getDirentPath};
let selectedList = selectedDirentList.map(item => {
let nodeRootPath = this.getDirentPath(item);
let dragStartItemData = {nodeDirent: item, nodeParentPath: this.props.path, nodeRootPath: nodeRootPath};
return dragStartItemData;
});
selectedList = JSON.stringify(selectedList);
@@ -369,8 +368,8 @@ class DirentListItem extends React.Component {
return ;
}
let getDirentPath = this.getDirentPath(this.props.dirent);
let dragStartItemData = {nodeDirent: this.props.dirent, nodeParentPath: this.props.path, nodeRootPath: getDirentPath};
let nodeRootPath = this.getDirentPath(this.props.dirent);
let dragStartItemData = {nodeDirent: this.props.dirent, nodeParentPath: this.props.path, nodeRootPath: nodeRootPath};
dragStartItemData = JSON.stringify(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');
dragStartItemData = JSON.parse(dragStartItemData);
if (Array.isArray(dragStartItemData)) { //move items
let direntPaths = [];
dragStartItemData.forEach(draggedItem => {
let path = Utils.joinPath(this.props.path, draggedItem.nodeDirent.name);
direntPaths.push(path);
let direntPaths = dragStartItemData.map(draggedItem => {
return draggedItem.nodeRootPath
});
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.parentNode.path !== nodeParentPath) {
let paths = Utils.getPaths(dropNodeData.path);
let isChildPath = paths.includes(nodeRootPath);
if (isChildPath) {
if (paths.includes(nodeRootPath)) {
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
let isChildPath = direntPaths.some(direntPath => {
let flag = paths.includes(direntPath);
return flag;
return paths.includes(direntPath);
});
if (isChildPath) {
return;