From 666189a970597d78b66217a8d47a1a2f4a52cc9b Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Sun, 30 Jul 2023 13:24:22 +0200 Subject: [PATCH] UI: Rollback moving folders after failure Signed-off-by: Marcel Klehr --- src/components/Folder.vue | 9 ++++++--- src/components/MoveDialog.vue | 7 +++++-- src/store/actions.js | 8 +++++++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/components/Folder.vue b/src/components/Folder.vue index 5cddac1f..0de70cad 100644 --- a/src/components/Folder.vue +++ b/src/components/Folder.vue @@ -130,7 +130,7 @@ export default { return this.$store.state.sharedFoldersById[this.folder.id] !== undefined }, isEditable() { - return this.isOwner || (!this.isOwner && (this.isDirectShare || this.permissions.canWrite)) + return this.isOwner || this.isDirectShare || this.permissions.canWrite }, shares() { return this.$store.getters.getSharesOfFolder(this.folder.id) @@ -210,8 +210,11 @@ export default { }, async onDrop(e) { e.preventDefault() - await this.$store.dispatch(actions.MOVE_SELECTION, this.folder.id) - this.$store.commit(mutations.RESET_SELECTION) + try { + await this.$store.dispatch(actions.MOVE_SELECTION, this.folder.id) + } finally { + this.$store.commit(mutations.RESET_SELECTION) + } }, }, } diff --git a/src/components/MoveDialog.vue b/src/components/MoveDialog.vue index 45bce273..0fea712f 100644 --- a/src/components/MoveDialog.vue +++ b/src/components/MoveDialog.vue @@ -56,8 +56,11 @@ export default { methods: { async onSubmit(folderId) { this.$store.commit(mutations.DISPLAY_MOVE_DIALOG, false) - await this.$store.dispatch(actions.MOVE_SELECTION, folderId) - this.$store.commit(mutations.RESET_SELECTION) + try { + await this.$store.dispatch(actions.MOVE_SELECTION, folderId) + } finally { + this.$store.commit(mutations.RESET_SELECTION) + } }, onClose() { this.$store.commit(mutations.DISPLAY_MOVE_DIALOG, false) diff --git a/src/store/actions.js b/src/store/actions.js index 54fd6a17..f9e7a1e9 100644 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -785,7 +785,13 @@ export default { commit(mutations.MOVE_FOLDER, { folder: folder.id, target: folderId }) const oldParent = folder.parent_folder folder.parent_folder = folderId - await dispatch(actions.SAVE_FOLDER, folder.id) // reloads children order for new parent + try { + await dispatch(actions.SAVE_FOLDER, folder.id) // reloads children order for new parent + } catch (err) { + commit(mutations.MOVE_FOLDER, { folder: folder.id, target: oldParent }) + folder.parent_folder = oldParent + throw err + } dispatch( actions.LOAD_FOLDER_CHILDREN_ORDER, oldParent