From 4f86fb57950ee27e311e025bbc005719e547b9b5 Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Wed, 27 Jul 2022 13:53:54 +0200 Subject: [PATCH 1/2] Fix batch deleting multiple files --- .../bugfix-batch-delete-multiple-files | 6 ++++++ packages/web-app-files/src/store/actions.js | 21 ++++++++++--------- packages/web-app-files/src/store/mutations.js | 10 +++++++++ 3 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 changelog/unreleased/bugfix-batch-delete-multiple-files diff --git a/changelog/unreleased/bugfix-batch-delete-multiple-files b/changelog/unreleased/bugfix-batch-delete-multiple-files new file mode 100644 index 00000000000..fbb2dbb2a9e --- /dev/null +++ b/changelog/unreleased/bugfix-batch-delete-multiple-files @@ -0,0 +1,6 @@ +Bugfix: Batch deleting multiple files + +We've fixed a bug where deleting many files in a batch action would fail. + +https://github.com/owncloud/web/pull/7357 +https://github.com/owncloud/web/issues/7329 diff --git a/packages/web-app-files/src/store/actions.js b/packages/web-app-files/src/store/actions.js index eda3619b9d5..daa1b5508fa 100644 --- a/packages/web-app-files/src/store/actions.js +++ b/packages/web-app-files/src/store/actions.js @@ -152,6 +152,7 @@ export default { }, deleteFiles(context, { files, client, isPublicLinkContext, firstRun = true }) { const promises = [] + const removedFiles = [] for (const file of files) { let p = null if (isPublicLinkContext) { @@ -165,10 +166,7 @@ export default { } const promise = p .then(() => { - context.dispatch('sidebar/close') - context.commit('REMOVE_FILE', file) - context.commit('REMOVE_FILE_SELECTION', file) - context.commit('REMOVE_FILE_FROM_SEARCHED', file) + removedFiles.push(file) }) .catch((error) => { let translated = $gettext('Failed to delete "%{file}"') @@ -196,7 +194,12 @@ export default { }) promises.push(promise) } - return Promise.all(promises) + return Promise.all(promises).then(() => { + context.dispatch('sidebar/close') + context.commit('REMOVE_FILES', removedFiles) + context.commit('REMOVE_FILES_FROM_SEARCHED', removedFiles) + context.commit('RESET_SELECTION') + }) }, async clearTrashBin(context) { await context.dispatch('sidebar/close') @@ -206,11 +209,9 @@ export default { }, async removeFilesFromTrashbin(context, files) { await context.dispatch('sidebar/close') - for (const file of files) { - context.commit('REMOVE_FILE', file) - context.commit('REMOVE_FILE_SELECTION', file) - context.commit('REMOVE_FILE_FROM_SEARCHED', file) - } + context.commit('REMOVE_FILES', files) + context.commit('REMOVE_FILES_FROM_SEARCHED', files) + context.commit('RESET_SELECTION') }, renameFile(context, { file, newValue, client, isPublicLinkContext, isSameResource }) { if (file !== undefined && newValue !== undefined && newValue !== file.name) { diff --git a/packages/web-app-files/src/store/mutations.js b/packages/web-app-files/src/store/mutations.js index 26c7b567cdc..0c637b17fc5 100644 --- a/packages/web-app-files/src/store/mutations.js +++ b/packages/web-app-files/src/store/mutations.js @@ -76,6 +76,13 @@ export default { state.filesSearched = state.filesSearched.filter((i) => file.id !== i.id) }, + REMOVE_FILES_FROM_SEARCHED(state, files) { + if (!state.filesSearched) { + return + } + + state.filesSearched = state.filesSearched.filter((i) => !files.find((f) => f.id === i.id)) + }, CLEAR_FILES_SEARCHED(state) { state.filesSearched = null }, @@ -126,6 +133,9 @@ export default { REMOVE_FILE(state, removedFile) { state.files = [...state.files].filter((file) => file.id !== removedFile.id) }, + REMOVE_FILES(state, removedFiles) { + state.files = [...state.files].filter((file) => !removedFiles.find((r) => r.id === file.id)) + }, RENAME_FILE(state, { file, newValue, newPath }) { const resources = [...state.files] const fileIndex = resources.findIndex((f) => { From 7175dd91431a91ae9bef3d215290fd9817c4c300 Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Thu, 28 Jul 2022 09:05:40 +0200 Subject: [PATCH 2/2] Remove REMOVE_FILE and REMOVE_FILE_FROM_SEARCHED mutations --- .../web-app-files/src/mixins/spaces/actions/delete.js | 4 ++-- packages/web-app-files/src/store/mutations.js | 10 ---------- packages/web-app-files/src/views/Personal.vue | 10 +++++++--- packages/web-app-files/src/views/PublicFiles.vue | 8 ++++---- .../web-app-files/src/views/shares/SharedResource.vue | 10 +++++++--- packages/web-app-files/src/views/spaces/Project.vue | 8 ++++---- .../tests/unit/components/components.setup.js | 4 ++-- packages/web-app-files/tests/unit/views/views.setup.js | 4 ++-- 8 files changed, 28 insertions(+), 30 deletions(-) diff --git a/packages/web-app-files/src/mixins/spaces/actions/delete.js b/packages/web-app-files/src/mixins/spaces/actions/delete.js index 1d26b000e5a..ceccf642ca6 100644 --- a/packages/web-app-files/src/mixins/spaces/actions/delete.js +++ b/packages/web-app-files/src/mixins/spaces/actions/delete.js @@ -37,7 +37,7 @@ export default { 'showMessage', 'toggleModalConfirmButton' ]), - ...mapMutations('Files', ['REMOVE_FILE', 'REMOVE_SPACE']), + ...mapMutations('Files', ['REMOVE_FILES', 'REMOVE_SPACE']), $_delete_trigger({ resources }) { if (resources.length !== 1) { @@ -72,7 +72,7 @@ export default { }) .then(() => { this.hideModal() - this.REMOVE_FILE({ id }) + this.REMOVE_FILES([{ id }]) this.REMOVE_SPACE({ id }) this.showMessage({ title: this.$gettext('Space was deleted successfully') diff --git a/packages/web-app-files/src/store/mutations.js b/packages/web-app-files/src/store/mutations.js index 0c637b17fc5..8c75652905b 100644 --- a/packages/web-app-files/src/store/mutations.js +++ b/packages/web-app-files/src/store/mutations.js @@ -69,13 +69,6 @@ export default { LOAD_FILES_SEARCHED(state, files) { state.filesSearched = files }, - REMOVE_FILE_FROM_SEARCHED(state, file) { - if (!state.filesSearched) { - return - } - - state.filesSearched = state.filesSearched.filter((i) => file.id !== i.id) - }, REMOVE_FILES_FROM_SEARCHED(state, files) { if (!state.filesSearched) { return @@ -130,9 +123,6 @@ export default { RESET_SELECTION(state) { state.selectedIds = [] }, - REMOVE_FILE(state, removedFile) { - state.files = [...state.files].filter((file) => file.id !== removedFile.id) - }, REMOVE_FILES(state, removedFiles) { state.files = [...state.files].filter((file) => !removedFiles.find((r) => r.id === file.id)) }, diff --git a/packages/web-app-files/src/views/Personal.vue b/packages/web-app-files/src/views/Personal.vue index 6061c2896af..9f385c9dd9a 100644 --- a/packages/web-app-files/src/views/Personal.vue +++ b/packages/web-app-files/src/views/Personal.vue @@ -248,7 +248,11 @@ export default defineComponent({ methods: { ...mapActions('Files', ['loadPreview']), ...mapActions(['showMessage', 'createModal', 'hideModal']), - ...mapMutations('Files', ['REMOVE_FILE', 'REMOVE_FILE_FROM_SEARCHED', 'REMOVE_FILE_SELECTION']), + ...mapMutations('Files', [ + 'REMOVE_FILES', + 'REMOVE_FILES_FROM_SEARCHED', + 'REMOVE_FILE_SELECTION' + ]), async fileDropped(fileIdTarget) { const selected = [...this.selectedResources] @@ -269,8 +273,8 @@ export default defineComponent({ this.$route.name ) for (const resource of movedResources) { - this.REMOVE_FILE(resource) - this.REMOVE_FILE_FROM_SEARCHED(resource) + this.REMOVE_FILES([resource]) + this.REMOVE_FILES_FROM_SEARCHED([resource]) this.REMOVE_FILE_SELECTION(resource) } }, diff --git a/packages/web-app-files/src/views/PublicFiles.vue b/packages/web-app-files/src/views/PublicFiles.vue index 149c9083d40..d5f09e2b151 100644 --- a/packages/web-app-files/src/views/PublicFiles.vue +++ b/packages/web-app-files/src/views/PublicFiles.vue @@ -186,8 +186,8 @@ export default defineComponent({ 'SET_CURRENT_FOLDER', 'LOAD_FILES', 'CLEAR_CURRENT_FILES_LIST', - 'REMOVE_FILE', - 'REMOVE_FILE_FROM_SEARCHED', + 'REMOVE_FILES', + 'REMOVE_FILES_FROM_SEARCHED', 'REMOVE_FILE_SELECTION' ]), @@ -211,8 +211,8 @@ export default defineComponent({ this.publicLinkPassword ) for (const resource of movedResources) { - this.REMOVE_FILE(resource) - this.REMOVE_FILE_FROM_SEARCHED(resource) + this.REMOVE_FILES([resource]) + this.REMOVE_FILES_FROM_SEARCHED([resource]) this.REMOVE_FILE_SELECTION(resource) } }, diff --git a/packages/web-app-files/src/views/shares/SharedResource.vue b/packages/web-app-files/src/views/shares/SharedResource.vue index d0ecc8b84d2..3ff3b2e631b 100644 --- a/packages/web-app-files/src/views/shares/SharedResource.vue +++ b/packages/web-app-files/src/views/shares/SharedResource.vue @@ -216,7 +216,11 @@ export default defineComponent({ methods: { ...mapActions('Files', ['loadPreview']), ...mapActions(['showMessage']), - ...mapMutations('Files', ['REMOVE_FILE', 'REMOVE_FILE_FROM_SEARCHED', 'REMOVE_FILE_SELECTION']), + ...mapMutations('Files', [ + 'REMOVE_FILES', + 'REMOVE_FILES_FROM_SEARCHED', + 'REMOVE_FILE_SELECTION' + ]), fetchResources, @@ -239,8 +243,8 @@ export default defineComponent({ this.$route.name ) for (const resource of movedResources) { - this.REMOVE_FILE(resource) - this.REMOVE_FILE_FROM_SEARCHED(resource) + this.REMOVE_FILES([resource]) + this.REMOVE_FILES_FROM_SEARCHED([resource]) this.REMOVE_FILE_SELECTION(resource) } }, diff --git a/packages/web-app-files/src/views/spaces/Project.vue b/packages/web-app-files/src/views/spaces/Project.vue index aa0c998de79..af704d218a3 100644 --- a/packages/web-app-files/src/views/spaces/Project.vue +++ b/packages/web-app-files/src/views/spaces/Project.vue @@ -375,8 +375,8 @@ export default defineComponent({ 'LOAD_FILES', 'UPSERT_SPACE', 'CLEAR_CURRENT_FILES_LIST', - 'REMOVE_FILE', - 'REMOVE_FILE_FROM_SEARCHED', + 'REMOVE_FILES', + 'REMOVE_FILES_FROM_SEARCHED', 'REMOVE_FILE_SELECTION' ]), async fileDropped(fileIdTarget) { @@ -398,8 +398,8 @@ export default defineComponent({ this.$route.name ) for (const resource of movedResources) { - this.REMOVE_FILE(resource) - this.REMOVE_FILE_FROM_SEARCHED(resource) + this.REMOVE_FILES([resource]) + this.REMOVE_FILES_FROM_SEARCHED([resource]) this.REMOVE_FILE_SELECTION(resource) } }, diff --git a/packages/web-app-files/tests/unit/components/components.setup.js b/packages/web-app-files/tests/unit/components/components.setup.js index 9a236d3f8b7..072e9a2fdc2 100644 --- a/packages/web-app-files/tests/unit/components/components.setup.js +++ b/packages/web-app-files/tests/unit/components/components.setup.js @@ -142,8 +142,8 @@ export const getStore = function ({ LOAD_FILES: () => {}, SET_FILES_PAGE_LIMIT: () => {}, SET_CURRENT_FOLDER: () => {}, - REMOVE_FILE: () => {}, - REMOVE_FILE_FROM_SEARCHED: () => {}, + REMOVE_FILES: () => {}, + REMOVE_FILES_FROM_SEARCHED: () => {}, REMOVE_FILE_SELECTION: () => {}, SET_FILE_SELECTION: () => {} }, diff --git a/packages/web-app-files/tests/unit/views/views.setup.js b/packages/web-app-files/tests/unit/views/views.setup.js index 66d5b35c334..bb398702bd6 100644 --- a/packages/web-app-files/tests/unit/views/views.setup.js +++ b/packages/web-app-files/tests/unit/views/views.setup.js @@ -190,8 +190,8 @@ export const getStore = function ({ LOAD_FILES: () => {}, SET_FILES_PAGE_LIMIT: () => {}, SET_CURRENT_FOLDER: () => {}, - REMOVE_FILE: () => {}, - REMOVE_FILE_FROM_SEARCHED: () => {}, + REMOVE_FILES: () => {}, + REMOVE_FILES_FROM_SEARCHED: () => {}, REMOVE_FILE_SELECTION: () => {}, SET_FILE_SELECTION: () => {} },