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

Implement action sub-menus in the multiple files actions bar #45525

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
58 changes: 56 additions & 2 deletions apps/files/src/components/FilesListTableHeaderActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,27 @@
:inline="inlineActions"
:menu-name="inlineActions <= 1 ? t('files', 'Actions') : null"
:open.sync="openedMenu">
<NcActionButton v-for="action in enabledActions"
<NcActions v-for="action in enabledToplevelMenuActions"
:key="action.id"
:menuName="action.displayName(nodes, currentView)" >
<NcActionButton v-for="action in enabledSubLevelMenuActions(action)"
:key="action.id"
:class="'files-list__row-actions-batch-' + action.id"
:close-after-click="true"
:is-menu="false"
@click="onActionClick(action)">
<template #icon>
<NcLoadingIcon v-if="loading === action.id" :size="18" />
<NcIconSvgWrapper v-else :svg="action.iconSvgInline(nodes, currentView)" />
</template>
{{ action.displayName(nodes, currentView) }}
</NcActionButton>
</NcActions>
<NcActionButton v-for="action in enabledToplevelNonMenuActions"
:key="action.id"
:class="'files-list__row-actions-batch-' + action.id"
:close-after-click="true"
:is-menu="false"
@click="onActionClick(action)">
<template #icon>
<NcLoadingIcon v-if="loading === action.id" :size="18" />
Expand All @@ -42,7 +60,7 @@
</template>

<script lang="ts">
import { Node, NodeStatus, View, getFileActions } from '@nextcloud/files'
import { FileAction, Node, NodeStatus, View, getFileActions } from '@nextcloud/files'
import { showError, showSuccess } from '@nextcloud/dialogs'
import { translate } from '@nextcloud/l10n'
import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
Expand Down Expand Up @@ -115,6 +133,32 @@ export default defineComponent({
.sort((a, b) => (a.order || 0) - (b.order || 0))
},

enabledToplevelMenuActions() {
return this.enabledActions
.filter(action => typeof action.parent === 'undefined')
.filter(action => this.isMenu(action.id))
.sort((a, b) => (a.order || 0) - (b.order || 0))
},

enabledToplevelNonMenuActions() {
return this.enabledActions
.filter(action => !action.parent)
.filter(action => !this.isMenu(action.id))
.sort((a, b) => (a.order || 0) - (b.order || 0))
},

enabledSubmenuActions() {
return this.enabledActions
.filter(action => action.parent)
.reduce((arr, action) => {
if (!arr[action.parent]) {
arr[action.parent] = []
}
arr[action.parent].push(action)
return arr
}, {} as Record<string, FileAction>)
},

nodes() {
return this.selectedNodes
.map(fileid => this.getNode(fileid))
Expand Down Expand Up @@ -159,6 +203,16 @@ export default defineComponent({
return this.filesStore.getNode(fileId)
},

isMenu(id: string) {
return this.enabledSubmenuActions[id]?.length > 0
},

enabledSubLevelMenuActions(action) {
return this.enabledActions
.filter(subAction => subAction.parent === action.id)
.sort((a, b) => (a.order || 0) - (b.order || 0))
},

async onActionClick(action) {
const displayName = action.displayName(this.nodes, this.currentView)
const selectionIds = this.selectedNodes
Expand Down
Loading