Skip to content

Commit 137b5a1

Browse files
committed
fix: Return a file element even if the rendered list does not contained one
Signed-off-by: Julius Härtl <jus@bitgrid.net>
1 parent 7f40354 commit 137b5a1

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

apps/files/js/filelist.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,8 +1357,18 @@
13571357
* @return {Object} jQuery object of the matching row
13581358
*/
13591359
findFileEl: function(fileName){
1360-
// use filterAttr to avoid escaping issues
1361-
return this.$fileList.find('tr').filterAttr('data-file', fileName);
1360+
var fileRow = this.$fileList.find('tr').filterAttr('data-file', fileName);
1361+
if (fileRow.length) {
1362+
return fileRow;
1363+
}
1364+
1365+
// The row we try to get might not have been rendered due to pagination,
1366+
// so in case we find the file in the file list return the rendered row instead
1367+
var fileData = this.files.find(function (el){
1368+
return el.name === fileName;
1369+
});
1370+
1371+
return fileData ? this._renderRow(fileData, {updateSummary: false, silent: true}) : fileRow;
13621372
},
13631373

13641374
/**

apps/files/tests/js/filelistSpec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ describe('OCA.Files.FileList tests', function() {
825825
// element is renamed before the request finishes
826826
$tr = fileList.findFileEl('Tu_after_three.txt');
827827
expect($tr.length).toEqual(1);
828-
expect(fileList.findFileEl('One.txt').length).toEqual(0);
828+
expect($('.files-fileList tr').find('[data-name="One.txt"]').length).toEqual(0);
829829
// file actions are hidden
830830
expect($tr.hasClass('busy')).toEqual(true);
831831

@@ -1426,7 +1426,7 @@ describe('OCA.Files.FileList tests', function() {
14261426
name: 'File with index 28b.txt'
14271427
});
14281428
expect($('.files-fileList tr').length).toEqual(20);
1429-
expect(fileList.findFileEl('File with index 28b.txt').length).toEqual(0);
1429+
expect($('.files-fileList tr').find('[data-name="File with index 28b.txt"]').length).toEqual(0);
14301430
fileList._nextPage(true);
14311431
expect($('.files-fileList tr').length).toEqual(40);
14321432
expect(fileList.findFileEl('File with index 28b.txt').index()).toEqual(29);

0 commit comments

Comments
 (0)