Skip to content

Commit 301f567

Browse files
authored
Merge pull request #54329 from nextcloud/fix/files-batch-actions
2 parents ec024eb + 1413259 commit 301f567

File tree

4 files changed

+59
-4
lines changed

4 files changed

+59
-4
lines changed

apps/files/src/components/FilesListTableHeaderActions.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ export default defineComponent({
151151
.filter(action => !action.renderInline)
152152
// We don't handle actions that are not visible
153153
.filter(action => action.default !== DefaultType.HIDDEN)
154+
// We allow top-level actions that have no execBatch method
155+
// but children actions always need to have it
156+
.filter(action => action.execBatch || !action.parent)
157+
// We filter out actions that are not enabled for the current selection
154158
.filter(action => !action.enabled || action.enabled(this.nodes, this.currentView))
155159
.sort((a, b) => (a.order || 0) - (b.order || 0))
156160
},
@@ -190,7 +194,11 @@ export default defineComponent({
190194
})
191195
192196
// Generate list of all top-level actions ids
193-
const childrenActionsIds = actions.filter(action => action.parent).map(action => action.parent) as string[]
197+
const childrenActionsIds = actions
198+
.filter(action => action.parent)
199+
// Filter out all actions that are not batch actions
200+
.filter(action => action.execBatch)
201+
.map(action => action.parent) as string[]
194202
195203
const menuActions = actions
196204
.filter(action => {

cypress/e2e/files/files-actions.cy.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,51 @@ describe('Files: Actions', { testIsolation: true }, () => {
213213
getSelectionActionEntry('nested-child-1').should('not.exist')
214214
getSelectionActionEntry('nested-child-2').should('not.exist')
215215
})
216+
217+
it('Do not show parent if nested action has no batch support', () => {
218+
const parent = new FileAction({
219+
id: 'nested-action',
220+
displayName: () => 'Nested Action',
221+
exec: cy.spy(),
222+
iconSvgInline: () => '<svg></svg>',
223+
})
224+
225+
const child1 = new FileAction({
226+
id: 'nested-child-1',
227+
displayName: () => 'Nested Child 1',
228+
exec: cy.spy(),
229+
iconSvgInline: () => '<svg></svg>',
230+
parent: 'nested-action',
231+
})
232+
233+
const child2 = new FileAction({
234+
id: 'nested-child-2',
235+
displayName: () => 'Nested Child 2',
236+
exec: cy.spy(),
237+
iconSvgInline: () => '<svg></svg>',
238+
parent: 'nested-action',
239+
})
240+
241+
cy.visit('/apps/files', {
242+
// Cannot use registerFileAction here
243+
onBeforeLoad: (win) => {
244+
if (!win._nc_fileactions) win._nc_fileactions = []
245+
// Cannot use registerFileAction here
246+
win._nc_fileactions.push(parent)
247+
win._nc_fileactions.push(child1)
248+
win._nc_fileactions.push(child2)
249+
},
250+
})
251+
252+
selectRowForFile('image.jpg')
253+
254+
// Open the menu
255+
getSelectionActionButton().click({ force: true })
256+
257+
// Check we have the parent action but not the children
258+
getSelectionActionEntry('nested-action').should('not.exist')
259+
getSelectionActionEntry('menu-back').should('not.exist')
260+
getSelectionActionEntry('nested-child-1').should('not.exist')
261+
getSelectionActionEntry('nested-child-2').should('not.exist')
262+
})
216263
})

dist/files-main.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)