Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix batch deleting multiple files #7357

Merged
merged 2 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/unreleased/bugfix-batch-delete-multiple-files
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions packages/web-app-files/src/mixins/spaces/actions/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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')
Expand Down
21 changes: 11 additions & 10 deletions packages/web-app-files/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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}"')
Expand Down Expand Up @@ -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')
Expand All @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions packages/web-app-files/src/store/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ export default {
LOAD_FILES_SEARCHED(state, files) {
state.filesSearched = files
},
REMOVE_FILE_FROM_SEARCHED(state, file) {
REMOVE_FILES_FROM_SEARCHED(state, files) {
if (!state.filesSearched) {
return
}

state.filesSearched = state.filesSearched.filter((i) => file.id !== i.id)
state.filesSearched = state.filesSearched.filter((i) => !files.find((f) => f.id === i.id))
},
CLEAR_FILES_SEARCHED(state) {
state.filesSearched = null
Expand Down Expand Up @@ -123,8 +123,8 @@ 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))
},
RENAME_FILE(state, { file, newValue, newPath }) {
const resources = [...state.files]
Expand Down
10 changes: 7 additions & 3 deletions packages/web-app-files/src/views/Personal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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)
}
},
Expand Down
8 changes: 4 additions & 4 deletions packages/web-app-files/src/views/PublicFiles.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]),

Expand All @@ -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)
}
},
Expand Down
10 changes: 7 additions & 3 deletions packages/web-app-files/src/views/shares/SharedResource.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand All @@ -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)
}
},
Expand Down
8 changes: 4 additions & 4 deletions packages/web-app-files/src/views/spaces/Project.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: () => {}
},
Expand Down
4 changes: 2 additions & 2 deletions packages/web-app-files/tests/unit/views/views.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: () => {}
},
Expand Down