From 4911fb27308892c34c70ec6bf0b8c42a8158bed9 Mon Sep 17 00:00:00 2001 From: Benedikt Kulmann Date: Tue, 9 Nov 2021 14:57:00 +0100 Subject: [PATCH] Fix syntax error and make most actions invisible if no files are selected --- .../web-app-files/src/components/ActionMenuItem.vue | 8 ++++++-- .../AppBar/SelectedResources/BatchActions.vue | 7 ++----- .../web-app-files/src/mixins/actions/acceptShare.js | 3 +++ packages/web-app-files/src/mixins/actions/copy.js | 5 ++++- .../web-app-files/src/mixins/actions/declineShare.js | 3 +++ packages/web-app-files/src/mixins/actions/delete.js | 10 +++++++++- .../web-app-files/src/mixins/actions/downloadFolder.js | 3 +++ packages/web-app-files/src/mixins/actions/move.js | 3 +++ packages/web-app-files/src/mixins/actions/restore.js | 7 ++++++- .../web-app-files/src/mixins/actions/showDetails.js | 7 ++++++- .../web-app-files/src/mixins/actions/showShares.js | 4 ++++ packages/web-app-files/src/mixins/fileActions.js | 2 +- 12 files changed, 50 insertions(+), 12 deletions(-) diff --git a/packages/web-app-files/src/components/ActionMenuItem.vue b/packages/web-app-files/src/components/ActionMenuItem.vue index 82fe37c289b..4e9c7639533 100644 --- a/packages/web-app-files/src/components/ActionMenuItem.vue +++ b/packages/web-app-files/src/components/ActionMenuItem.vue @@ -29,6 +29,10 @@ export default { items: { type: Array, required: true + }, + appearance: { + type: String, + default: 'raw' } }, computed: { @@ -52,8 +56,8 @@ export default { } return { - appearance: 'raw', - ...(action.isDisabled() && { disabled: true }), + appearance: this.appearance, + ...(action.isDisabled && { disabled: action.isDisabled() }), ...(action.variation && { variation: action.variation }) } }, diff --git a/packages/web-app-files/src/components/AppBar/SelectedResources/BatchActions.vue b/packages/web-app-files/src/components/AppBar/SelectedResources/BatchActions.vue index e7c885797f5..7b2fc8ec455 100644 --- a/packages/web-app-files/src/components/AppBar/SelectedResources/BatchActions.vue +++ b/packages/web-app-files/src/components/AppBar/SelectedResources/BatchActions.vue @@ -1,10 +1,11 @@ @@ -40,10 +41,6 @@ export default { ...mapGetters('Files', ['selectedFiles']), ...mapGetters(['homeFolder']), - displayBulkActions() { - return this.$route.meta.hasBulkActions && this.selectedFiles.length > 0 - }, - filterParams() { return { resources: this.selectedFiles diff --git a/packages/web-app-files/src/mixins/actions/acceptShare.js b/packages/web-app-files/src/mixins/actions/acceptShare.js index 3c721a7cfea..46a3f545bb6 100644 --- a/packages/web-app-files/src/mixins/actions/acceptShare.js +++ b/packages/web-app-files/src/mixins/actions/acceptShare.js @@ -20,6 +20,9 @@ export default { if (!isSharedWithMeRoute(this.$route)) { return false } + if (resources.length === 0) { + return false + } const acceptDisabled = resources.some((resource) => { return resource.status === shareStatus.accepted diff --git a/packages/web-app-files/src/mixins/actions/copy.js b/packages/web-app-files/src/mixins/actions/copy.js index d1a24248f98..96563e02bb4 100644 --- a/packages/web-app-files/src/mixins/actions/copy.js +++ b/packages/web-app-files/src/mixins/actions/copy.js @@ -10,7 +10,7 @@ export default { handler: this.$_copy_trigger, label: () => this.$pgettext('Action in the files list row to initiate copying resources', 'Copy'), - isEnabled: () => { + isEnabled: ({ resources }) => { if ( !checkRoute( ['files-personal', 'files-public-list', 'files-favorites'], @@ -19,6 +19,9 @@ export default { ) { return false } + if (resources.length === 0) { + return false + } if (isPublicFilesRoute(this.$route)) { return this.currentFolder.canCreate() diff --git a/packages/web-app-files/src/mixins/actions/declineShare.js b/packages/web-app-files/src/mixins/actions/declineShare.js index 0418f8a5ebe..8e25ce2271a 100644 --- a/packages/web-app-files/src/mixins/actions/declineShare.js +++ b/packages/web-app-files/src/mixins/actions/declineShare.js @@ -20,6 +20,9 @@ export default { if (!isSharedWithMeRoute(this.$route)) { return false } + if (resources.length === 0) { + return false + } const declineDisabled = resources.some((resource) => { return resource.status === shareStatus.declined diff --git a/packages/web-app-files/src/mixins/actions/delete.js b/packages/web-app-files/src/mixins/actions/delete.js index ac51918eafc..e0264612d77 100644 --- a/packages/web-app-files/src/mixins/actions/delete.js +++ b/packages/web-app-files/src/mixins/actions/delete.js @@ -18,6 +18,9 @@ export default { if (!isPersonalRoute(this.$route) && !isPublicFilesRoute(this.$route)) { return false } + if (resources.length === 0) { + return false + } const deleteDisabled = resources.some((resource) => { if (isSameResource(resource, this.currentFolder)) { @@ -35,7 +38,12 @@ export default { icon: 'delete', label: () => this.$gettext('Delete'), handler: this.$_delete_trigger, - isEnabled: () => isTrashbinRoute(this.$route), + isEnabled: ({ resources }) => { + if (!isTrashbinRoute(this.$route)) { + return false + } + return resources.length > 0 + }, componentType: 'oc-button', class: 'oc-files-actions-delete-trigger' } diff --git a/packages/web-app-files/src/mixins/actions/downloadFolder.js b/packages/web-app-files/src/mixins/actions/downloadFolder.js index 5c4df18767a..e0d3a1e4669 100644 --- a/packages/web-app-files/src/mixins/actions/downloadFolder.js +++ b/packages/web-app-files/src/mixins/actions/downloadFolder.js @@ -28,6 +28,9 @@ export default { ) { return false } + if (resources.length === 0) { + return false + } if (resources.length === 1 && resources[0].isFolder) { return false } diff --git a/packages/web-app-files/src/mixins/actions/move.js b/packages/web-app-files/src/mixins/actions/move.js index 30f32019813..efcdfc5adb9 100644 --- a/packages/web-app-files/src/mixins/actions/move.js +++ b/packages/web-app-files/src/mixins/actions/move.js @@ -20,6 +20,9 @@ export default { ) { return false } + if (resources.length === 0) { + return false + } if (!this.currentFolder) { return false diff --git a/packages/web-app-files/src/mixins/actions/restore.js b/packages/web-app-files/src/mixins/actions/restore.js index 1d714617003..9f77acbfb7a 100644 --- a/packages/web-app-files/src/mixins/actions/restore.js +++ b/packages/web-app-files/src/mixins/actions/restore.js @@ -11,7 +11,12 @@ export default { icon: 'restore', label: () => this.$gettext('Restore'), handler: this.$_restore_trigger, - isEnabled: () => isTrashbinRoute(this.$route), + isEnabled: ({ resources }) => { + if (!isTrashbinRoute(this.$route)) { + return false + } + return resources.length > 0 + }, componentType: 'oc-button', class: 'oc-files-actions-restore-trigger' } diff --git a/packages/web-app-files/src/mixins/actions/showDetails.js b/packages/web-app-files/src/mixins/actions/showDetails.js index 5f9ea99b136..4f283c68ec0 100644 --- a/packages/web-app-files/src/mixins/actions/showDetails.js +++ b/packages/web-app-files/src/mixins/actions/showDetails.js @@ -12,7 +12,12 @@ export default { handler: this.$_showDetails_trigger, // we don't have details in the trahsbin, yet. // return hardcoded `true` in all cases once we have them. - isEnabled: () => !isTrashbinRoute(this.$route), + isEnabled: ({ resources }) => { + if (isTrashbinRoute(this.$route)) { + return false + } + return resources.length > 0 + }, componentType: 'oc-button', class: 'oc-files-actions-show-details-trigger' } diff --git a/packages/web-app-files/src/mixins/actions/showShares.js b/packages/web-app-files/src/mixins/actions/showShares.js index a0a81b7983d..ea4af60d383 100644 --- a/packages/web-app-files/src/mixins/actions/showShares.js +++ b/packages/web-app-files/src/mixins/actions/showShares.js @@ -1,4 +1,5 @@ import quickActions, { canShare, openNewCollaboratorsPanel } from '../../quickActions' +import { isTrashbinRoute } from '../../helpers/route' export default { computed: { @@ -10,6 +11,9 @@ export default { label: () => this.$gettext('Share'), handler: this.$_showShares_trigger, isEnabled: ({ resources }) => { + if (isTrashbinRoute(this.$route)) { + return false + } if (resources.length !== 1) { return false } diff --git a/packages/web-app-files/src/mixins/fileActions.js b/packages/web-app-files/src/mixins/fileActions.js index b3c3b0d9dca..7aca32ab0dc 100644 --- a/packages/web-app-files/src/mixins/fileActions.js +++ b/packages/web-app-files/src/mixins/fileActions.js @@ -84,7 +84,7 @@ export default { if (resources.length !== 1) { return false } - if (editor.routes?.length > 0 && !checkRoute(editor.routes, this.$route.name)) { + if (Array.isArray(editor.routes) && !checkRoute(editor.routes, this.$route.name)) { return false }