Skip to content

Commit

Permalink
Fix syntax error and make most actions invisible if no files are sele…
Browse files Browse the repository at this point in the history
…cted
  • Loading branch information
kulmann committed Nov 9, 2021
1 parent 428f311 commit 4911fb2
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 12 deletions.
8 changes: 6 additions & 2 deletions packages/web-app-files/src/components/ActionMenuItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export default {
items: {
type: Array,
required: true
},
appearance: {
type: String,
default: 'raw'
}
},
computed: {
Expand All @@ -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 })
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<template>
<oc-list v-if="displayBulkActions" class="oc-files-appbar-batch-actions oc-my-rm uk-width-1-1">
<oc-list class="oc-files-appbar-batch-actions oc-my-rm uk-width-1-1">
<action-menu-item
v-for="(action, i) in menuItemsBatchActions"
:key="`batch-action-${i}`"
:action="action"
:items="selectedFiles"
appearance="outline"
/>
</oc-list>
</template>
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions packages/web-app-files/src/mixins/actions/acceptShare.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion packages/web-app-files/src/mixins/actions/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -19,6 +19,9 @@ export default {
) {
return false
}
if (resources.length === 0) {
return false
}

if (isPublicFilesRoute(this.$route)) {
return this.currentFolder.canCreate()
Expand Down
3 changes: 3 additions & 0 deletions packages/web-app-files/src/mixins/actions/declineShare.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion packages/web-app-files/src/mixins/actions/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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'
}
Expand Down
3 changes: 3 additions & 0 deletions packages/web-app-files/src/mixins/actions/downloadFolder.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export default {
) {
return false
}
if (resources.length === 0) {
return false
}
if (resources.length === 1 && resources[0].isFolder) {
return false
}
Expand Down
3 changes: 3 additions & 0 deletions packages/web-app-files/src/mixins/actions/move.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export default {
) {
return false
}
if (resources.length === 0) {
return false
}

if (!this.currentFolder) {
return false
Expand Down
7 changes: 6 additions & 1 deletion packages/web-app-files/src/mixins/actions/restore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down
7 changes: 6 additions & 1 deletion packages/web-app-files/src/mixins/actions/showDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down
4 changes: 4 additions & 0 deletions packages/web-app-files/src/mixins/actions/showShares.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import quickActions, { canShare, openNewCollaboratorsPanel } from '../../quickActions'
import { isTrashbinRoute } from '../../helpers/route'

export default {
computed: {
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion packages/web-app-files/src/mixins/fileActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 4911fb2

Please sign in to comment.