Skip to content

Commit fa2fe34

Browse files
authored
Merge pull request #7624 from nextcloud/fix-fileActions-currentFile-not-set-before-using-it
Fix "fileActions.currentFile" not set before using it
2 parents a2a4a55 + ea40ade commit fa2fe34

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

apps/files/js/filelist.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,11 +683,14 @@
683683
// the details to be shown.
684684
event.preventDefault();
685685
var filename = $tr.attr('data-file');
686+
this.fileActions.currentFile = $tr.find('td');
686687
var mime = this.fileActions.getCurrentMimeType();
687688
var type = this.fileActions.getCurrentType();
688689
var permissions = this.fileActions.getCurrentPermissions();
689690
var action = this.fileActions.get(mime, type, permissions)['Details'];
690691
if (action) {
692+
// also set on global object for legacy apps
693+
window.FileActions.currentFile = this.fileActions.currentFile;
691694
action(filename, {
692695
$file: $tr,
693696
fileList: this,

apps/files/tests/js/filelistSpec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,6 +2489,30 @@ describe('OCA.Files.FileList tests', function() {
24892489
expect(context.fileActions).toBeDefined();
24902490
expect(context.dir).toEqual('/subdir');
24912491
});
2492+
it('Clicking on an empty space of the file row will trigger the "Details" action', function() {
2493+
var detailsActionStub = sinon.stub();
2494+
fileList.setFiles(testFiles);
2495+
// Override the "Details" action set internally by the FileList for
2496+
// easier testing.
2497+
fileList.fileActions.registerAction({
2498+
mime: 'all',
2499+
name: 'Details',
2500+
permissions: OC.PERMISSION_NONE,
2501+
actionHandler: detailsActionStub
2502+
});
2503+
// Ensure that the action works even if fileActions.currentFile is
2504+
// not set.
2505+
fileList.fileActions.currentFile = null;
2506+
var $tr = fileList.findFileEl('One.txt');
2507+
$tr.find('td.filename a.name').click();
2508+
expect(detailsActionStub.calledOnce).toEqual(true);
2509+
expect(detailsActionStub.getCall(0).args[0]).toEqual('One.txt');
2510+
var context = detailsActionStub.getCall(0).args[1];
2511+
expect(context.$file.is($tr)).toEqual(true);
2512+
expect(context.fileList).toBe(fileList);
2513+
expect(context.fileActions).toBe(fileList.fileActions);
2514+
expect(context.dir).toEqual('/subdir');
2515+
});
24922516
it('redisplays actions when new actions have been registered', function() {
24932517
var actionStub = sinon.stub();
24942518
var readyHandler = sinon.stub();

0 commit comments

Comments
 (0)