1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-01 15:09:14 +00:00

Repair move copy bug 2 (#4511)

* optimize code

* optimize code

* add copy tip
This commit is contained in:
杨顺强
2020-04-02 15:45:33 +08:00
committed by GitHub
parent 07e9013c26
commit 11a0d0fc3c

View File

@@ -599,6 +599,15 @@ class LibContentView extends React.Component {
}
if (data.successful) {
if (asyncOperationType === 'move') {
if (this.state.currentMode === 'column') {
let direntPaths = this.getSelectedDirentPaths();
this.deleteTreeNodes(direntPaths);
}
let direntNames = this.getSelectedDirentNames();
this.moveDirents(direntNames);
}
this.setState({isCopyMoveProgressDialogShow: false});
let message = gettext('Successfully moved files to another library.');
if (asyncOperationType === 'copy') {
@@ -607,10 +616,11 @@ class LibContentView extends React.Component {
toaster.success(message);
return;
}
// init state: total is 0
let asyncOperationProgress = !data.total ? 0 : parseInt((data.done/data.total * 100).toFixed(2));
let asyncOperationProgress = parseInt((data.done/data.total * 100).toFixed(2));
this.setState({asyncOperationProgress: asyncOperationProgress});
this.getAsyncCopyMoveProgress();
this.setState({asyncOperationProgress: asyncOperationProgress});
} catch (error) {
this.setState({
asyncOperationProgress: 0,
@@ -626,7 +636,7 @@ class LibContentView extends React.Component {
onMoveProgressDialogToggle = () => {
let { asyncOperationProgress } = this.state;
if (asyncOperationProgress && asyncOperationProgress !== 100) {
if (asyncOperationProgress !== 100) {
this.cancelCopyMoveDirent();
}
@@ -656,33 +666,37 @@ class LibContentView extends React.Component {
this.setState({
asyncCopyMoveTaskId: res.data.task_id,
}, () => {
// After moving successfully, delete related files
this.getAsyncCopyMoveProgress();
});
}
direntPaths.forEach((direntPath, index) => {
if (this.state.currentMode === 'column') {
this.deleteTreeNode(direntPath);
}
this.moveDirent(direntPath);
});
// 1. move to current repo
// 2. tow columns mode need update left tree
if (repoID === destRepo.repo_id && this.state.currentMode === 'column') {
this.updateMoveCopyTreeNode(destDirentPath);
}
// show tip message if move to current repo
if (repoID === destRepo.repo_id) {
if (this.state.currentMode === 'column') {
this.deleteTreeNodes(direntPaths);
}
this.moveDirents(dirNames);
// 2. tow columns mode need update left tree
if (this.state.currentMode === 'column') {
this.updateMoveCopyTreeNode(destDirentPath);
}
// show tip message if move to current repo
let message = Utils.getMoveSuccessMessage(dirNames);
toaster.success(message);
}
}).catch((error) => {
let errMessage = Utils.getErrorMsg(error);
if (errMessage === gettext('Error')) {
errMessage = Utils.getMoveFailedMessage(dirNames);
}
this.setState({
asyncOperationProgress: 0,
isCopyMoveProgressDialogShow: false,
});
toaster.danger(errMessage);
});
}
@@ -710,12 +724,18 @@ class LibContentView extends React.Component {
});
}
if (repoID === destRepo.repo_id && this.state.currentMode === 'column') {
this.updateMoveCopyTreeNode(destDirentPath);
}
if (repoID === destRepo.repo_id) {
if (this.state.currentMode === 'column') {
this.updateMoveCopyTreeNode(destDirentPath);
}
if (destDirentPath === this.state.path) {
this.loadDirentList(this.state.path);
if (destDirentPath === this.state.path) {
this.loadDirentList(this.state.path);
}
// show tip message if copy to current repo
let message = Utils.getCopySuccessfulMessage(dirNames);
toaster.success(message);
}
}).catch((error) => {
let errMessage = Utils.getErrorMsg(error);
@@ -733,12 +753,12 @@ class LibContentView extends React.Component {
this.setState({updateDetail: !this.state.updateDetail});
seafileAPI.deleteMutipleDirents(repoID, this.state.path, dirNames).then(res => {
direntPaths.forEach(direntPath => {
if (this.state.currentMode === 'column') {
this.deleteTreeNode(direntPath);
}
this.deleteDirent(direntPath);
});
if (this.state.currentMode === 'column') {
this.deleteTreeNodes(direntPaths);
}
this.deleteDirents(dirNames);
let msg = '';
if (direntPaths.length > 1) {
msg = gettext('Successfully deleted {name} and other {n} items.');
@@ -1348,6 +1368,19 @@ class LibContentView extends React.Component {
// else do nothing
}
// only one scence: The deleted items are inside current path
deleteDirents = (direntNames) => {
let direntList = this.state.direntList.filter(item => {
return direntNames.indexOf(item.name) === -1;
});
// Recalculate the state of the selection
this.recaculateSelectedStateAfterDirentDeleted(name, direntList);
this.setState({direntList: direntList});
this.updateReadmeMarkdown(direntList);
}
moveDirent = (direntPath, moveToDirentPath = null) => {
let name = Utils.getFileName(direntPath);
if (moveToDirentPath === this.state.path) {
@@ -1365,6 +1398,19 @@ class LibContentView extends React.Component {
this.updateReadmeMarkdown(direntList);
}
// only one scence: The moved items are inside current path
moveDirents = (direntNames) => {
let direntList = this.state.direntList.filter(item => {
return direntNames.indexOf(item.name) === -1;
});
// Recalculate the state of the selection
this.recaculateSelectedStateAfterDirentDeleted(name, direntList);
this.setState({direntList: direntList});
this.updateReadmeMarkdown(direntList);
}
updateDirent = (dirent, paramKey, paramValue) => {
let newDirentList = this.state.direntList.map(item => {
if (item.name === dirent.name) {
@@ -1541,6 +1587,11 @@ class LibContentView extends React.Component {
this.setState({treeData: tree});
}
deleteTreeNodes = (paths) => {
let tree = treeHelper.deleteNodeListByPaths(this.state.treeData, paths);
this.setState({treeData: tree});
}
moveTreeNode = (nodePath, moveToPath, moveToRepo, nodeName) => {
let repoID = this.props.repoID;
if (repoID !== moveToRepo.repo_id) {